@@ -27,6 +27,7 @@ import (
2727// values in which the order of values does not matter.
2828func TestNewAuthorizeRequest (t * testing.T ) {
2929 var store * MockStorage
30+ var clientManager * MockClientManager
3031
3132 redir , _ := url .Parse ("https://foo.bar/cb" )
3233 specialCharRedir , _ := url .Parse ("web+application://callback" )
@@ -46,7 +47,8 @@ func TestNewAuthorizeRequest(t *testing.T) {
4647 r : & http.Request {},
4748 expectedError : ErrInvalidClient ,
4849 mock : func () {
49- store .EXPECT ().GetClient (gomock .Any (), gomock .Any ()).Return (nil , errors .New ("foo" ))
50+ store .EXPECT ().ClientManager ().Return (clientManager ).Times (1 )
51+ clientManager .EXPECT ().GetClient (gomock .Any (), gomock .Any ()).Return (nil , errors .New ("foo" ))
5052 },
5153 },
5254 /* invalid redirect uri */
@@ -56,7 +58,8 @@ func TestNewAuthorizeRequest(t *testing.T) {
5658 query : url.Values {"redirect_uri" : []string {"invalid" }},
5759 expectedError : ErrInvalidClient ,
5860 mock : func () {
59- store .EXPECT ().GetClient (gomock .Any (), gomock .Any ()).Return (nil , errors .New ("foo" ))
61+ store .EXPECT ().ClientManager ().Return (clientManager ).Times (1 )
62+ clientManager .EXPECT ().GetClient (gomock .Any (), gomock .Any ()).Return (nil , errors .New ("foo" ))
6063 },
6164 },
6265 /* invalid client */
@@ -66,7 +69,8 @@ func TestNewAuthorizeRequest(t *testing.T) {
6669 query : url.Values {"redirect_uri" : []string {"https://foo.bar/cb" }},
6770 expectedError : ErrInvalidClient ,
6871 mock : func () {
69- store .EXPECT ().GetClient (gomock .Any (), gomock .Any ()).Return (nil , errors .New ("foo" ))
72+ store .EXPECT ().ClientManager ().Return (clientManager ).Times (1 )
73+ clientManager .EXPECT ().GetClient (gomock .Any (), gomock .Any ()).Return (nil , errors .New ("foo" ))
7074 },
7175 },
7276 /* redirect client mismatch */
@@ -78,7 +82,8 @@ func TestNewAuthorizeRequest(t *testing.T) {
7882 },
7983 expectedError : ErrInvalidRequest ,
8084 mock : func () {
81- store .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultClient {RedirectURIs : []string {"invalid" }, Scopes : []string {}}, nil )
85+ store .EXPECT ().ClientManager ().Return (clientManager ).Times (1 )
86+ clientManager .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultClient {RedirectURIs : []string {"invalid" }, Scopes : []string {}}, nil )
8287 },
8388 },
8489 /* redirect client mismatch */
@@ -91,7 +96,8 @@ func TestNewAuthorizeRequest(t *testing.T) {
9196 },
9297 expectedError : ErrInvalidRequest ,
9398 mock : func () {
94- store .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultClient {RedirectURIs : []string {"invalid" }, Scopes : []string {}}, nil )
99+ store .EXPECT ().ClientManager ().Return (clientManager ).Times (1 )
100+ clientManager .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultClient {RedirectURIs : []string {"invalid" }, Scopes : []string {}}, nil )
95101 },
96102 },
97103 /* redirect client mismatch */
@@ -104,7 +110,8 @@ func TestNewAuthorizeRequest(t *testing.T) {
104110 },
105111 expectedError : ErrInvalidRequest ,
106112 mock : func () {
107- store .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultClient {RedirectURIs : []string {"invalid" }, Scopes : []string {}}, nil )
113+ store .EXPECT ().ClientManager ().Return (clientManager ).Times (1 )
114+ clientManager .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultClient {RedirectURIs : []string {"invalid" }, Scopes : []string {}}, nil )
108115 },
109116 },
110117 /* no state */
@@ -118,7 +125,8 @@ func TestNewAuthorizeRequest(t *testing.T) {
118125 },
119126 expectedError : ErrInvalidState ,
120127 mock : func () {
121- store .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultClient {RedirectURIs : []string {"https://foo.bar/cb" }, Scopes : []string {}}, nil )
128+ store .EXPECT ().ClientManager ().Return (clientManager ).Times (1 )
129+ clientManager .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultClient {RedirectURIs : []string {"https://foo.bar/cb" }, Scopes : []string {}}, nil )
122130 },
123131 },
124132 /* short state */
@@ -133,7 +141,8 @@ func TestNewAuthorizeRequest(t *testing.T) {
133141 },
134142 expectedError : ErrInvalidState ,
135143 mock : func () {
136- store .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultClient {RedirectURIs : []string {"https://foo.bar/cb" }, Scopes : []string {}}, nil )
144+ store .EXPECT ().ClientManager ().Return (clientManager ).Times (1 )
145+ clientManager .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultClient {RedirectURIs : []string {"https://foo.bar/cb" }, Scopes : []string {}}, nil )
137146 },
138147 },
139148 /* fails because scope not given */
@@ -148,7 +157,8 @@ func TestNewAuthorizeRequest(t *testing.T) {
148157 "scope" : {"foo bar baz" },
149158 },
150159 mock : func () {
151- store .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultClient {RedirectURIs : []string {"https://foo.bar/cb" }, Scopes : []string {"foo" , "bar" }}, nil )
160+ store .EXPECT ().ClientManager ().Return (clientManager ).Times (1 )
161+ clientManager .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultClient {RedirectURIs : []string {"https://foo.bar/cb" }, Scopes : []string {"foo" , "bar" }}, nil )
152162 },
153163 expectedError : ErrInvalidScope ,
154164 },
@@ -165,7 +175,8 @@ func TestNewAuthorizeRequest(t *testing.T) {
165175 "audience" : {"https://cloud.ory.sh/api https://www.ory.sh/api" },
166176 },
167177 mock : func () {
168- store .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultClient {
178+ store .EXPECT ().ClientManager ().Return (clientManager ).Times (1 )
179+ clientManager .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultClient {
169180 RedirectURIs : []string {"https://foo.bar/cb" }, Scopes : []string {"foo" , "bar" },
170181 Audience : []string {"https://cloud.ory.sh/api" },
171182 }, nil )
@@ -185,7 +196,8 @@ func TestNewAuthorizeRequest(t *testing.T) {
185196 "audience" : {"https://cloud.ory.sh/api https://www.ory.sh/api" },
186197 },
187198 mock : func () {
188- store .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultClient {
199+ store .EXPECT ().ClientManager ().Return (clientManager ).Times (1 )
200+ clientManager .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultClient {
189201 ResponseTypes : []string {"code token" },
190202 RedirectURIs : []string {"https://foo.bar/cb" },
191203 Scopes : []string {"foo" , "bar" },
@@ -220,7 +232,8 @@ func TestNewAuthorizeRequest(t *testing.T) {
220232 "audience" : {"https://cloud.ory.sh/api" , "https://www.ory.sh/api" },
221233 },
222234 mock : func () {
223- store .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultClient {
235+ store .EXPECT ().ClientManager ().Return (clientManager ).Times (1 )
236+ clientManager .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultClient {
224237 ResponseTypes : []string {"code token" },
225238 RedirectURIs : []string {"https://foo.bar/cb" },
226239 Scopes : []string {"foo" , "bar" },
@@ -255,7 +268,8 @@ func TestNewAuthorizeRequest(t *testing.T) {
255268 "audience" : {"test value" , "" },
256269 },
257270 mock : func () {
258- store .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultClient {
271+ store .EXPECT ().ClientManager ().Return (clientManager ).Times (1 )
272+ clientManager .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultClient {
259273 ResponseTypes : []string {"code token" },
260274 RedirectURIs : []string {"https://foo.bar/cb" },
261275 Scopes : []string {"foo" , "bar" },
@@ -290,7 +304,8 @@ func TestNewAuthorizeRequest(t *testing.T) {
290304 "audience" : {"https://cloud.ory.sh/api https://www.ory.sh/api" },
291305 },
292306 mock : func () {
293- store .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultClient {
307+ store .EXPECT ().ClientManager ().Return (clientManager ).Times (1 )
308+ clientManager .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultClient {
294309 ResponseTypes : []string {"code token" },
295310 RedirectURIs : []string {"web+application://callback" },
296311 Scopes : []string {"foo" , "bar" },
@@ -325,7 +340,8 @@ func TestNewAuthorizeRequest(t *testing.T) {
325340 "audience" : {"https://cloud.ory.sh/api https://www.ory.sh/api" },
326341 },
327342 mock : func () {
328- store .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultClient {
343+ store .EXPECT ().ClientManager ().Return (clientManager ).Times (1 )
344+ clientManager .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultClient {
329345 ResponseTypes : []string {"code token" },
330346 RedirectURIs : []string {"https://foo.bar/cb" },
331347 Scopes : []string {"foo" , "bar" },
@@ -360,7 +376,8 @@ func TestNewAuthorizeRequest(t *testing.T) {
360376 "response_mode" : {"unknown" },
361377 },
362378 mock : func () {
363- store .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultClient {RedirectURIs : []string {"https://foo.bar/cb" }, Scopes : []string {"foo" , "bar" }, ResponseTypes : []string {"code token" }}, nil )
379+ store .EXPECT ().ClientManager ().Return (clientManager ).Times (1 )
380+ clientManager .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultClient {RedirectURIs : []string {"https://foo.bar/cb" }, Scopes : []string {"foo" , "bar" }, ResponseTypes : []string {"code token" }}, nil )
364381 },
365382 expectedError : ErrUnsupportedResponseMode ,
366383 },
@@ -377,7 +394,8 @@ func TestNewAuthorizeRequest(t *testing.T) {
377394 "response_mode" : {"form_post" },
378395 },
379396 mock : func () {
380- store .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultClient {RedirectURIs : []string {"https://foo.bar/cb" }, Scopes : []string {"foo" , "bar" }, ResponseTypes : []string {"code token" }}, nil )
397+ store .EXPECT ().ClientManager ().Return (clientManager ).Times (1 )
398+ clientManager .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultClient {RedirectURIs : []string {"https://foo.bar/cb" }, Scopes : []string {"foo" , "bar" }, ResponseTypes : []string {"code token" }}, nil )
381399 },
382400 expectedError : ErrUnsupportedResponseMode ,
383401 },
@@ -394,7 +412,8 @@ func TestNewAuthorizeRequest(t *testing.T) {
394412 "response_mode" : {"form_post" },
395413 },
396414 mock : func () {
397- store .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultResponseModeClient {
415+ store .EXPECT ().ClientManager ().Return (clientManager ).Times (1 )
416+ clientManager .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultResponseModeClient {
398417 DefaultClient : & DefaultClient {
399418 RedirectURIs : []string {"https://foo.bar/cb" },
400419 Scopes : []string {"foo" , "bar" },
@@ -419,7 +438,8 @@ func TestNewAuthorizeRequest(t *testing.T) {
419438 "audience" : {"https://cloud.ory.sh/api https://www.ory.sh/api" },
420439 },
421440 mock : func () {
422- store .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultResponseModeClient {
441+ store .EXPECT ().ClientManager ().Return (clientManager ).Times (1 )
442+ clientManager .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultResponseModeClient {
423443 DefaultClient : & DefaultClient {
424444 RedirectURIs : []string {"https://foo.bar/cb" },
425445 Scopes : []string {"foo" , "bar" },
@@ -461,7 +481,8 @@ func TestNewAuthorizeRequest(t *testing.T) {
461481 "audience" : {"https://cloud.ory.sh/api https://www.ory.sh/api" },
462482 },
463483 mock : func () {
464- store .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultResponseModeClient {
484+ store .EXPECT ().ClientManager ().Return (clientManager ).Times (1 )
485+ clientManager .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultResponseModeClient {
465486 DefaultClient : & DefaultClient {
466487 RedirectURIs : []string {"https://foo.bar/cb" },
467488 Scopes : []string {"foo" , "bar" },
@@ -503,7 +524,8 @@ func TestNewAuthorizeRequest(t *testing.T) {
503524 "audience" : {"https://cloud.ory.sh/api https://www.ory.sh/api" },
504525 },
505526 mock : func () {
506- store .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultResponseModeClient {
527+ store .EXPECT ().ClientManager ().Return (clientManager ).Times (1 )
528+ clientManager .EXPECT ().GetClient (gomock .Any (), "1234" ).Return (& DefaultResponseModeClient {
507529 DefaultClient : & DefaultClient {
508530 RedirectURIs : []string {"https://foo.bar/cb" },
509531 Scopes : []string {"foo" , "bar" },
@@ -536,6 +558,7 @@ func TestNewAuthorizeRequest(t *testing.T) {
536558 t .Run (fmt .Sprintf ("case=%d" , k ), func (t * testing.T ) {
537559 ctrl := gomock .NewController (t )
538560 store = NewMockStorage (ctrl )
561+ clientManager = NewMockClientManager (ctrl )
539562 defer ctrl .Finish ()
540563
541564 c .mock ()
0 commit comments