@@ -325,6 +325,96 @@ func TestUpdateBrokerForUser(t *testing.T) {
325
325
}
326
326
}
327
327
328
+ func TestDisableUser (t * testing.T ) {
329
+ tests := map [string ]struct {
330
+ username string
331
+
332
+ dbFile string
333
+
334
+ wantErr bool
335
+ wantErrType error
336
+ }{
337
+ "Successfully_update_broker_for_user" : {},
338
+
339
+ "Error_if_user_does_not_exist" : {username : "doesnotexist" , wantErrType : db.NoDataFoundError {}},
340
+ }
341
+ for name , tc := range tests {
342
+ t .Run (name , func (t * testing.T ) {
343
+ // We don't care about the output of gpasswd in this test, but we still need to mock it.
344
+ _ = localgroupstestutils .SetupGPasswdMock (t , "empty.group" )
345
+
346
+ if tc .username == "" {
347
+ tc .username = "user1"
348
+ }
349
+ if tc .dbFile == "" {
350
+ tc .dbFile = "multiple_users_and_groups"
351
+ }
352
+
353
+ dbDir := t .TempDir ()
354
+ err := db .Z_ForTests_CreateDBFromYAML (filepath .Join ("testdata" , "db" , tc .dbFile + ".db.yaml" ), dbDir )
355
+ require .NoError (t , err , "Setup: could not create database from testdata" )
356
+ m := newManagerForTests (t , dbDir )
357
+
358
+ err = m .DisableUser (tc .username )
359
+
360
+ requireErrorAssertions (t , err , tc .wantErrType , tc .wantErr )
361
+ if tc .wantErrType != nil || tc .wantErr {
362
+ return
363
+ }
364
+
365
+ got , err := db .Z_ForTests_DumpNormalizedYAML (userstestutils .GetManagerDB (m ))
366
+ require .NoError (t , err , "Created database should be valid yaml content" )
367
+
368
+ golden .CheckOrUpdate (t , got )
369
+ })
370
+ }
371
+ }
372
+
373
+ func TestEnableUser (t * testing.T ) {
374
+ tests := map [string ]struct {
375
+ username string
376
+
377
+ dbFile string
378
+
379
+ wantErr bool
380
+ wantErrType error
381
+ }{
382
+ "Successfully_update_broker_for_user" : {},
383
+
384
+ "Error_if_user_does_not_exist" : {username : "doesnotexist" , wantErrType : db.NoDataFoundError {}},
385
+ }
386
+ for name , tc := range tests {
387
+ t .Run (name , func (t * testing.T ) {
388
+ // We don't care about the output of gpasswd in this test, but we still need to mock it.
389
+ _ = localgroupstestutils .SetupGPasswdMock (t , "empty.group" )
390
+
391
+ if tc .username == "" {
392
+ tc .username = "user1"
393
+ }
394
+ if tc .dbFile == "" {
395
+ tc .dbFile = "disabled_user"
396
+ }
397
+
398
+ dbDir := t .TempDir ()
399
+ err := db .Z_ForTests_CreateDBFromYAML (filepath .Join ("testdata" , "db" , tc .dbFile + ".db.yaml" ), dbDir )
400
+ require .NoError (t , err , "Setup: could not create database from testdata" )
401
+ m := newManagerForTests (t , dbDir )
402
+
403
+ err = m .EnableUser (tc .username )
404
+
405
+ requireErrorAssertions (t , err , tc .wantErrType , tc .wantErr )
406
+ if tc .wantErrType != nil || tc .wantErr {
407
+ return
408
+ }
409
+
410
+ got , err := db .Z_ForTests_DumpNormalizedYAML (userstestutils .GetManagerDB (m ))
411
+ require .NoError (t , err , "Created database should be valid yaml content" )
412
+
413
+ golden .CheckOrUpdate (t , got )
414
+ })
415
+ }
416
+ }
417
+
328
418
//nolint:dupl // This is not a duplicate test
329
419
func TestUserByIDAndName (t * testing.T ) {
330
420
tests := map [string ]struct {
0 commit comments