-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patherrors_test.go
67 lines (63 loc) · 1.54 KB
/
errors_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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package oidc
import (
"errors"
"net/http"
"testing"
xoauth2 "golang.org/x/oauth2"
)
func TestParseExchangeError(t *testing.T) {
for _, tc := range []struct {
Name string
In error
Want string
}{
{
Name: "Generic error",
In: errors.New("Some rando thing happened"),
Want: "error exchanging token: Some rando thing happened",
},
{
Name: "Invalid Grant error",
In: &xoauth2.RetrieveError{
Response: &http.Response{
StatusCode: 400,
Status: "400 Bad Request",
},
Body: []byte(`{"error": "invalid_grant", "error_description":"authentication failure"}`),
},
Want: "invalid_grant error in token request: authentication failure",
},
{
Name: "Internal server error",
In: &xoauth2.RetrieveError{
Response: &http.Response{
StatusCode: 500,
Status: "500 Internal Server Error",
},
Body: []byte(`Boomtown`),
},
Want: "http status 500 Internal Server Error: Boomtown",
},
{
Name: "401 error",
In: &xoauth2.RetrieveError{
Response: &http.Response{
StatusCode: 401,
Status: "401 Unauthorized",
Header: http.Header{
http.CanonicalHeaderKey("www-authenticate"): []string{"Basic"},
},
},
Body: []byte(`{"error": "invalid_client", "error_description":"auth or something"}`),
},
Want: "invalid_client error in token request: auth or something",
},
} {
t.Run(tc.Name, func(t *testing.T) {
got := parseExchangeError(tc.In)
if got.Error() != tc.Want {
t.Errorf("want: %s, got: %s", tc.Want, got.Error())
}
})
}
}