@@ -9,11 +9,11 @@ import (
9
9
"net/http"
10
10
"net/http/httptest"
11
11
"net/url"
12
- "reflect"
13
12
"sort"
14
13
"testing"
15
14
16
15
"github.com/sirupsen/logrus"
16
+ "github.com/stretchr/testify/assert"
17
17
jose "gopkg.in/square/go-jose.v2"
18
18
19
19
"github.com/dexidp/dex/connector"
@@ -30,15 +30,15 @@ func TestOpen(t *testing.T) {
30
30
31
31
sort .Strings (conn .scopes )
32
32
33
- expectEqual (t , conn .clientID , "testClient" )
34
- expectEqual (t , conn .clientSecret , "testSecret" )
35
- expectEqual (t , conn .redirectURI , testServer .URL + "/callback" )
36
- expectEqual (t , conn .tokenURL , testServer .URL + "/token" )
37
- expectEqual (t , conn .authorizationURL , testServer .URL + "/authorize" )
38
- expectEqual (t , conn .userInfoURL , testServer .URL + "/userinfo" )
39
- expectEqual (t , len (conn .scopes ), 2 )
40
- expectEqual (t , conn .scopes [0 ], "groups" )
41
- expectEqual (t , conn .scopes [1 ], "openid" )
33
+ assert . Equal (t , conn .clientID , "testClient" )
34
+ assert . Equal (t , conn .clientSecret , "testSecret" )
35
+ assert . Equal (t , conn .redirectURI , testServer .URL + "/callback" )
36
+ assert . Equal (t , conn .tokenURL , testServer .URL + "/token" )
37
+ assert . Equal (t , conn .authorizationURL , testServer .URL + "/authorize" )
38
+ assert . Equal (t , conn .userInfoURL , testServer .URL + "/userinfo" )
39
+ assert . Equal (t , len (conn .scopes ), 2 )
40
+ assert . Equal (t , conn .scopes [0 ], "groups" )
41
+ assert . Equal (t , conn .scopes [1 ], "openid" )
42
42
}
43
43
44
44
func TestLoginURL (t * testing.T ) {
@@ -51,10 +51,10 @@ func TestLoginURL(t *testing.T) {
51
51
conn := newConnector (t , testServer .URL )
52
52
53
53
loginURL , err := conn .LoginURL (connector.Scopes {}, conn .redirectURI , "some-state" )
54
- expectEqual (t , err , nil )
54
+ assert . Equal (t , err , nil )
55
55
56
56
expectedURL , err := url .Parse (testServer .URL + "/authorize" )
57
- expectEqual (t , err , nil )
57
+ assert . Equal (t , err , nil )
58
58
59
59
values := url.Values {}
60
60
values .Add ("client_id" , "testClient" )
@@ -64,7 +64,7 @@ func TestLoginURL(t *testing.T) {
64
64
values .Add ("state" , "some-state" )
65
65
expectedURL .RawQuery = values .Encode ()
66
66
67
- expectEqual (t , loginURL , expectedURL .String ())
67
+ assert . Equal (t , loginURL , expectedURL .String ())
68
68
}
69
69
70
70
func TestHandleCallBackForGroupsInUserInfo (t * testing.T ) {
@@ -87,17 +87,17 @@ func TestHandleCallBackForGroupsInUserInfo(t *testing.T) {
87
87
req := newRequestWithAuthCode (t , testServer .URL , "some-code" )
88
88
89
89
identity , err := conn .HandleCallback (connector.Scopes {Groups : true }, req )
90
- expectEqual (t , err , nil )
90
+ assert . Equal (t , err , nil )
91
91
92
92
sort .Strings (identity .Groups )
93
- expectEqual (t , len (identity .Groups ), 2 )
94
- expectEqual (t , identity .Groups [0 ], "admin-group" )
95
- expectEqual (t , identity .Groups [1 ], "user-group" )
96
- expectEqual (t , identity .UserID , "test-user-id" )
97
- expectEqual (t , identity .Username , "test-username" )
98
- expectEqual (t , identity .PreferredUsername , "test-preferred-username" )
99
- expectEqual (t , identity .Email , "test-email" )
100
- expectEqual (t , identity .EmailVerified , true )
93
+ assert . Equal (t , len (identity .Groups ), 2 )
94
+ assert . Equal (t , identity .Groups [0 ], "admin-group" )
95
+ assert . Equal (t , identity .Groups [1 ], "user-group" )
96
+ assert . Equal (t , identity .UserID , "test-user-id" )
97
+ assert . Equal (t , identity .Username , "test-username" )
98
+ assert . Equal (t , identity .PreferredUsername , "test-preferred-username" )
99
+ assert . Equal (t , identity .Email , "test-email" )
100
+ assert . Equal (t , identity .EmailVerified , true )
101
101
}
102
102
103
103
func TestHandleCallBackForGroupsInToken (t * testing.T ) {
@@ -121,15 +121,15 @@ func TestHandleCallBackForGroupsInToken(t *testing.T) {
121
121
req := newRequestWithAuthCode (t , testServer .URL , "some-code" )
122
122
123
123
identity , err := conn .HandleCallback (connector.Scopes {Groups : true }, req )
124
- expectEqual (t , err , nil )
125
-
126
- expectEqual (t , len (identity .Groups ), 1 )
127
- expectEqual (t , identity .Groups [0 ], "test-group" )
128
- expectEqual (t , identity .PreferredUsername , "test-preferred-username" )
129
- expectEqual (t , identity .UserID , "test-user-id" )
130
- expectEqual (t , identity .Username , "test-username" )
131
- expectEqual (t , identity .Email , "test-email" )
132
- expectEqual (t , identity .EmailVerified , true )
124
+ assert . Equal (t , err , nil )
125
+
126
+ assert . Equal (t , len (identity .Groups ), 1 )
127
+ assert . Equal (t , identity .Groups [0 ], "test-group" )
128
+ assert . Equal (t , identity .PreferredUsername , "test-preferred-username" )
129
+ assert . Equal (t , identity .UserID , "test-user-id" )
130
+ assert . Equal (t , identity .Username , "test-username" )
131
+ assert . Equal (t , identity .Email , "test-email" )
132
+ assert . Equal (t , identity .EmailVerified , true )
133
133
}
134
134
135
135
func testSetup (t * testing.T , tokenClaims map [string ]interface {}, userInfoClaims map [string ]interface {}) * httptest.Server {
@@ -230,9 +230,3 @@ func newRequestWithAuthCode(t *testing.T, serverURL string, code string) *http.R
230
230
231
231
return req
232
232
}
233
-
234
- func expectEqual (t * testing.T , a interface {}, b interface {}) {
235
- if ! reflect .DeepEqual (a , b ) {
236
- t .Fatalf ("Expected %+v to equal %+v" , a , b )
237
- }
238
- }
0 commit comments