@@ -28,6 +28,7 @@ func oAuth2ClientEquals(t *testing.T, expect *model.OAuth2Client, actual *httpex
28
28
scopes = append (scopes , scope )
29
29
}
30
30
actual .Value ("scopes" ).Array ().ContainsOnly (scopes ... )
31
+ actual .Value ("confidential" ).Boolean ().IsEqual (expect .Confidential )
31
32
}
32
33
33
34
func TestHandlers_GetClients (t * testing.T ) {
@@ -38,7 +39,7 @@ func TestHandlers_GetClients(t *testing.T) {
38
39
user := env .CreateUser (t , rand )
39
40
user2 := env .CreateUser (t , rand )
40
41
c1 := env .CreateOAuth2Client (t , rand , user .GetID ())
41
- c2 := env .CreateOAuth2Client (t , rand , user2 .GetID ())
42
+ c2 := env .CreateOAuth2Client (t , rand , user2 .GetID (), WithConfidential ( true ) )
42
43
commonSession := env .S (t , user .GetID ())
43
44
44
45
t .Run ("not logged in" , func (t * testing.T ) {
@@ -95,10 +96,11 @@ func TestPostClientsRequest_Validate(t *testing.T) {
95
96
t .Parallel ()
96
97
97
98
type fields struct {
98
- Name string
99
- Description string
100
- CallbackURL string
101
- Scopes model.AccessScopes
99
+ Name string
100
+ Description string
101
+ CallbackURL string
102
+ Scopes model.AccessScopes
103
+ Confidential bool
102
104
}
103
105
tests := []struct {
104
106
name string
@@ -163,6 +165,17 @@ func TestPostClientsRequest_Validate(t *testing.T) {
163
165
},
164
166
false ,
165
167
},
168
+ {
169
+ "success (confidential client)" ,
170
+ fields {
171
+ Name : "test" ,
172
+ Description : "desc" ,
173
+ CallbackURL : "https://example.com" ,
174
+ Scopes : map [model.AccessScope ]struct {}{"read" : {}},
175
+ Confidential : true ,
176
+ },
177
+ false ,
178
+ },
166
179
}
167
180
for _ , tt := range tests {
168
181
t .Run (tt .name , func (t * testing.T ) {
@@ -194,6 +207,15 @@ func TestHandlers_CreateClient(t *testing.T) {
194
207
Scopes : map [model.AccessScope ]struct {}{"read" : {}},
195
208
}
196
209
210
+ // confidential client
211
+ req2 := & PostClientsRequest {
212
+ Name : "test" ,
213
+ Description : "desc" ,
214
+ CallbackURL : "https://example.com" ,
215
+ Scopes : map [model.AccessScope ]struct {}{"read" : {}},
216
+ Confidential : true ,
217
+ }
218
+
197
219
t .Run ("not logged in" , func (t * testing.T ) {
198
220
t .Parallel ()
199
221
e := env .R (t )
@@ -233,6 +255,34 @@ func TestHandlers_CreateClient(t *testing.T) {
233
255
scopes .Value (0 ).String ().IsEqual ("read" )
234
256
obj .Value ("callbackUrl" ).String ().IsEqual ("https://example.com" )
235
257
obj .Value ("secret" ).String ().NotEmpty ()
258
+ obj .Value ("confidential" ).Boolean ().IsFalse ()
259
+
260
+ c , err := env .Repository .GetClient (obj .Value ("id" ).String ().Raw ())
261
+ assert .NoError (t , err )
262
+ oAuth2ClientEquals (t , c , obj )
263
+ })
264
+
265
+ t .Run ("success (confidential client)" , func (t * testing.T ) {
266
+ t .Parallel ()
267
+ e := env .R (t )
268
+ obj := e .POST (path ).
269
+ WithCookie (session .CookieName , commonSession ).
270
+ WithJSON (req2 ).
271
+ Expect ().
272
+ Status (http .StatusCreated ).
273
+ JSON ().
274
+ Object ()
275
+
276
+ obj .Value ("id" ).String ().NotEmpty ()
277
+ obj .Value ("developerId" ).String ().IsEqual (user .GetID ().String ())
278
+ obj .Value ("description" ).String ().IsEqual ("desc" )
279
+ obj .Value ("name" ).String ().IsEqual ("test" )
280
+ scopes := obj .Value ("scopes" ).Array ()
281
+ scopes .Length ().IsEqual (1 )
282
+ scopes .Value (0 ).String ().IsEqual ("read" )
283
+ obj .Value ("callbackUrl" ).String ().IsEqual ("https://example.com" )
284
+ obj .Value ("secret" ).String ().NotEmpty ()
285
+ obj .Value ("confidential" ).Boolean ().IsTrue ()
236
286
237
287
c , err := env .Repository .GetClient (obj .Value ("id" ).String ().Raw ())
238
288
assert .NoError (t , err )
@@ -250,6 +300,7 @@ func TestHandlers_GetClient(t *testing.T) {
250
300
admin := env .CreateAdmin (t , rand )
251
301
c1 := env .CreateOAuth2Client (t , rand , user1 .GetID ())
252
302
c2 := env .CreateOAuth2Client (t , rand , user2 .GetID ())
303
+ c3 := env .CreateOAuth2Client (t , rand , user1 .GetID (), WithConfidential (true ))
253
304
user1Session := env .S (t , user1 .GetID ())
254
305
adminSession := env .S (t , admin .GetID ())
255
306
@@ -337,16 +388,34 @@ func TestHandlers_GetClient(t *testing.T) {
337
388
obj .Value ("callbackUrl" ).String ().NotEmpty ()
338
389
obj .Value ("secret" ).String ().NotEmpty ()
339
390
})
391
+
392
+ t .Run ("success (c3, detail=true)" , func (t * testing.T ) {
393
+ t .Parallel ()
394
+ e := env .R (t )
395
+ obj := e .GET (path , c3 .ID ).
396
+ WithCookie (session .CookieName , user1Session ).
397
+ WithQuery ("detail" , true ).
398
+ Expect ().
399
+ Status (http .StatusOK ).
400
+ JSON ().
401
+ Object ()
402
+
403
+ oAuth2ClientEquals (t , c3 , obj )
404
+ obj .Value ("callbackUrl" ).String ().NotEmpty ()
405
+ obj .Value ("secret" ).String ().NotEmpty ()
406
+ obj .Value ("confidential" ).Boolean ().IsTrue ()
407
+ })
340
408
}
341
409
342
410
func TestPatchClientRequest_Validate (t * testing.T ) {
343
411
t .Parallel ()
344
412
345
413
type fields struct {
346
- Name optional.Of [string ]
347
- Description optional.Of [string ]
348
- CallbackURL optional.Of [string ]
349
- DeveloperID optional.Of [uuid.UUID ]
414
+ Name optional.Of [string ]
415
+ Description optional.Of [string ]
416
+ CallbackURL optional.Of [string ]
417
+ DeveloperID optional.Of [uuid.UUID ]
418
+ Confidential optional.Of [bool ]
350
419
}
351
420
tests := []struct {
352
421
name string
@@ -393,14 +462,20 @@ func TestPatchClientRequest_Validate(t *testing.T) {
393
462
fields {Name : optional .From ("po" )},
394
463
false ,
395
464
},
465
+ {
466
+ "success (confidential client)" ,
467
+ fields {Confidential : optional .From (true )},
468
+ false ,
469
+ },
396
470
}
397
471
for _ , tt := range tests {
398
472
t .Run (tt .name , func (t * testing.T ) {
399
473
r := PatchClientRequest {
400
- Name : tt .fields .Name ,
401
- Description : tt .fields .Description ,
402
- CallbackURL : tt .fields .CallbackURL ,
403
- DeveloperID : tt .fields .DeveloperID ,
474
+ Name : tt .fields .Name ,
475
+ Description : tt .fields .Description ,
476
+ CallbackURL : tt .fields .CallbackURL ,
477
+ DeveloperID : tt .fields .DeveloperID ,
478
+ Confidential : tt .fields .Confidential ,
404
479
}
405
480
if err := r .Validate (); (err != nil ) != tt .wantErr {
406
481
t .Errorf ("Validate() error = %v, wantErr %v" , err , tt .wantErr )
@@ -419,6 +494,7 @@ func TestHandlers_EditClient(t *testing.T) {
419
494
admin := env .CreateAdmin (t , rand )
420
495
c1 := env .CreateOAuth2Client (t , rand , user1 .GetID ())
421
496
c2 := env .CreateOAuth2Client (t , rand , user2 .GetID ())
497
+ c3 := env .CreateOAuth2Client (t , rand , user1 .GetID (), WithConfidential (true ))
422
498
user1Session := env .S (t , user1 .GetID ())
423
499
adminSession := env .S (t , admin .GetID ())
424
500
@@ -488,6 +564,20 @@ func TestHandlers_EditClient(t *testing.T) {
488
564
require .NoError (t , err )
489
565
assert .EqualValues (t , c .Name , "po2" )
490
566
})
567
+
568
+ t .Run ("success (user1, c3, confidential)" , func (t * testing.T ) {
569
+ t .Parallel ()
570
+ e := env .R (t )
571
+ e .PATCH (path , c3 .ID ).
572
+ WithCookie (session .CookieName , user1Session ).
573
+ WithJSON (& PatchClientRequest {Confidential : optional .From (true )}).
574
+ Expect ().
575
+ Status (http .StatusNoContent )
576
+
577
+ c , err := env .Repository .GetClient (c3 .ID )
578
+ require .NoError (t , err )
579
+ assert .True (t , c .Confidential )
580
+ })
491
581
}
492
582
493
583
func TestHandlers_DeleteClient (t * testing.T ) {
0 commit comments