-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathauth_test.go
43 lines (36 loc) · 1.01 KB
/
auth_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package scm
import (
"net/http"
"testing"
)
func TestOkAuth(t *testing.T) {
ar := authResponse{
Jwt: "secret",
Scope: "test_scope",
Type: "test_type",
ExpiresIn: 899,
}
if err := ar.Failed(http.StatusOK, nil); err != nil {
t.Errorf("Auth failed for %d: %s", http.StatusOK, err)
}
}
func TestFailedAuth(t *testing.T) {
ar := authResponse{
Err: "invalid_client",
ErrDesc: "Client authentication failed",
}
data := `{"error_description":"Client authentication failed","error":"invalid_client"}`
if err := ar.Failed(http.StatusBadRequest, []byte(data)); err == nil {
t.Errorf("Auth succeeded for %d", http.StatusBadRequest)
}
}
func TestFailedAuth2(t *testing.T) {
ar := authResponse{
Err: "invalid_client",
ErrDesc: "Client authentication failed",
}
data := `{"error_description":"Client authentication failed","error":"invalid_client"}`
if err := ar.Failed(http.StatusUnauthorized, []byte(data)); err == nil {
t.Errorf("Auth succeeded for %d", http.StatusUnauthorized)
}
}