@@ -309,7 +309,7 @@ describe("AuthProviderService", async () => {
309
309
const oauthProperty : keyof AuthProviderEntry = "oauth" ;
310
310
expect ( providers [ 0 ] ) . to . not . haveOwnProperty ( oauthProperty ) ;
311
311
} ) ;
312
- it . only ( "as regular member, should find org-level providers if no built-in providers present" , async ( ) => {
312
+ it ( "as regular member, should find org-level providers if no built-in providers present" , async ( ) => {
313
313
const member = await userService . createUser ( {
314
314
identity : {
315
315
authId : "gh-user-2" ,
@@ -337,7 +337,7 @@ describe("AuthProviderService", async () => {
337
337
const oauthProperty : keyof AuthProviderEntry = "oauth" ;
338
338
expect ( providers [ 0 ] ) . to . not . haveOwnProperty ( oauthProperty ) ;
339
339
} ) ;
340
- it . only ( "as regular member, should find only built-in providers if present" , async ( ) => {
340
+ it ( "as regular member, should find only built-in providers if present" , async ( ) => {
341
341
addBuiltInProvider ( "localhost" ) ;
342
342
343
343
const member = await userService . createUser ( {
@@ -359,4 +359,65 @@ describe("AuthProviderService", async () => {
359
359
expect ( providers [ 0 ] . host ) . to . be . equal ( "localhost" ) ;
360
360
} ) ;
361
361
} ) ;
362
+
363
+ describe ( "updateAuthProvider" , async ( ) => {
364
+ it ( "should update user-level provider" , async ( ) => {
365
+ const created = await service . createAuthProviderOfUser ( currentUser . id , newEntry ( ) ) ;
366
+ const someRandomString = String ( Date . now ( ) ) ;
367
+ const updatedClientId = await service . updateAuthProviderOfUser ( currentUser . id , {
368
+ id : created . id ,
369
+ ownerId : currentUser . id ,
370
+ clientId : someRandomString ,
371
+ } ) ;
372
+ expect ( updatedClientId . oauth ?. clientId ) . to . be . equal ( someRandomString ) ;
373
+ expect ( updatedClientId . oauthRevision ) . to . be . not . equal ( created . oauthRevision ) ;
374
+
375
+ const updatedClientSecret = await service . updateAuthProviderOfUser ( currentUser . id , {
376
+ id : created . id ,
377
+ ownerId : currentUser . id ,
378
+ clientSecret : String ( Date . now ( ) ) ,
379
+ } ) ;
380
+ expect ( updatedClientSecret . oauthRevision ) . to . be . not . equal ( updatedClientId . oauthRevision ) ;
381
+ } ) ;
382
+ it ( "should fail if permissions do not permit" , async ( ) => {
383
+ const created = await service . createAuthProviderOfUser ( currentUser . id , newEntry ( ) ) ;
384
+ await expectError (
385
+ ErrorCodes . NOT_FOUND ,
386
+ service . updateAuthProviderOfUser ( "some-stranger" , {
387
+ id : created . id ,
388
+ ownerId : currentUser . id ,
389
+ clientId : "any" ,
390
+ } ) ,
391
+ ) ;
392
+ } ) ;
393
+ it ( "should update org-level provider" , async ( ) => {
394
+ const created = await service . createOrgAuthProvider ( currentUser . id , newOrgEntry ( ) ) ;
395
+ const someRandomString = String ( Date . now ( ) ) ;
396
+ const updatedClientId = await service . updateOrgAuthProvider ( currentUser . id , {
397
+ id : created . id ,
398
+ organizationId : org . id ,
399
+ clientId : someRandomString ,
400
+ } ) ;
401
+ expect ( updatedClientId . oauth ?. clientId ) . to . be . equal ( someRandomString ) ;
402
+ expect ( updatedClientId . oauthRevision ) . to . be . not . equal ( created . oauthRevision ) ;
403
+
404
+ const updatedClientSecret = await service . updateOrgAuthProvider ( currentUser . id , {
405
+ id : created . id ,
406
+ organizationId : org . id ,
407
+ clientSecret : String ( Date . now ( ) ) ,
408
+ } ) ;
409
+ expect ( updatedClientSecret . oauthRevision ) . to . be . not . equal ( updatedClientId . oauthRevision ) ;
410
+ } ) ;
411
+ it ( "should fail if org-permissions do not permit" , async ( ) => {
412
+ const created = await service . createOrgAuthProvider ( currentUser . id , newOrgEntry ( ) ) ;
413
+ await expectError (
414
+ ErrorCodes . NOT_FOUND ,
415
+ service . updateOrgAuthProvider ( "some-stranger" , {
416
+ id : created . id ,
417
+ organizationId : org . id ,
418
+ clientId : "any" ,
419
+ } ) ,
420
+ ) ;
421
+ } ) ;
422
+ } ) ;
362
423
} ) ;
0 commit comments