@@ -367,6 +367,9 @@ func TestScim(t *testing.T) {
367
367
assert .Equal (t , codersdk .UserStatusSuspended , userRes .Users [0 ].Status )
368
368
})
369
369
370
+ // Create a user via SCIM, which starts as dormant.
371
+ // Log in as the user, making them active.
372
+ // Then patch the user again and the user should still be active.
370
373
t .Run ("ActiveIsActive" , func (t * testing.T ) {
371
374
t .Parallel ()
372
375
@@ -375,9 +378,11 @@ func TestScim(t *testing.T) {
375
378
376
379
scimAPIKey := []byte ("hi" )
377
380
381
+ mockAudit := audit .NewMock ()
378
382
fake := oidctest .NewFakeIDP (t , oidctest .WithServing ())
379
383
client , _ := coderdenttest .New (t , & coderdenttest.Options {
380
384
Options : & coderdtest.Options {
385
+ Auditor : mockAudit ,
381
386
OIDCConfig : fake .OIDCConfig (t , []string {}),
382
387
},
383
388
SCIMAPIKey : scimAPIKey ,
@@ -390,7 +395,9 @@ func TestScim(t *testing.T) {
390
395
},
391
396
},
392
397
})
398
+ mockAudit .ResetLogs ()
393
399
400
+ // User is dormant on create
394
401
sUser := makeScimUser (t )
395
402
res , err := client .Request (ctx , "POST" , "/scim/v2/Users" , sUser , setScimAuth (scimAPIKey ))
396
403
require .NoError (t , err )
@@ -400,10 +407,17 @@ func TestScim(t *testing.T) {
400
407
err = json .NewDecoder (res .Body ).Decode (& sUser )
401
408
require .NoError (t , err )
402
409
410
+ // Check the audit log
411
+ aLogs := mockAudit .AuditLogs ()
412
+ require .Len (t , aLogs , 1 )
413
+ assert .Equal (t , database .AuditActionCreate , aLogs [0 ].Action )
414
+
415
+ // Verify the user is dormant
403
416
scimUser , err := client .User (ctx , sUser .UserName )
404
417
require .NoError (t , err )
405
418
require .Equal (t , codersdk .UserStatusDormant , scimUser .Status , "user starts as dormant" )
406
419
420
+ // Log in as the user, making them active
407
421
//nolint:bodyclose
408
422
scimUserClient , _ := fake .Login (t , client , jwt.MapClaims {
409
423
"email" : sUser .Emails [0 ].Value ,
@@ -413,12 +427,18 @@ func TestScim(t *testing.T) {
413
427
require .Equal (t , codersdk .UserStatusActive , scimUser .Status , "user should now be active" )
414
428
415
429
// Patch the user
430
+ mockAudit .ResetLogs ()
416
431
res , err = client .Request (ctx , "PATCH" , "/scim/v2/Users/" + sUser .ID , sUser , setScimAuth (scimAPIKey ))
417
432
require .NoError (t , err )
418
433
_ , _ = io .Copy (io .Discard , res .Body )
419
434
_ = res .Body .Close ()
420
435
assert .Equal (t , http .StatusOK , res .StatusCode )
421
436
437
+ // Should be no audit logs since there is no diff
438
+ aLogs = mockAudit .AuditLogs ()
439
+ require .Len (t , aLogs , 0 )
440
+
441
+ // Verify the user is still active.
422
442
scimUser , err = client .User (ctx , sUser .UserName )
423
443
require .NoError (t , err )
424
444
require .Equal (t , codersdk .UserStatusActive , scimUser .Status , "user is still active" )
0 commit comments