@@ -256,6 +256,68 @@ func TestGetShadowEntries(t *testing.T) {
256256 }
257257}
258258
259+ func TestDisablePasswd (t * testing.T ) {
260+ tests := map [string ]struct {
261+ sourceDB string
262+
263+ username string
264+ currentUserNotRoot bool
265+
266+ wantErr bool
267+ }{
268+ "Successfully_disable_user" : {username : "user1" },
269+
270+ "Error_when_username_is_empty" : {wantErr : true },
271+ "Error_when_user_does_not_exist" : {username : "doesnotexist" , wantErr : true },
272+ "Error_when_not_root" : {username : "notroot" , currentUserNotRoot : true , wantErr : true },
273+ }
274+ for name , tc := range tests {
275+ t .Run (name , func (t * testing.T ) {
276+ client := newNSSClient (t , tc .sourceDB , tc .currentUserNotRoot )
277+
278+ _ , err := client .DisablePasswd (context .Background (), & authd.DisablePasswdRequest {Name : tc .username })
279+ if tc .wantErr {
280+ require .Error (t , err , "DisablePasswd should return an error, but did not" )
281+ return
282+ }
283+ require .NoError (t , err , "DisablePasswd should not return an error, but did" )
284+ })
285+ }
286+ }
287+
288+ func TestEnablePasswd (t * testing.T ) {
289+ tests := map [string ]struct {
290+ sourceDB string
291+
292+ username string
293+ currentUserNotRoot bool
294+
295+ wantErr bool
296+ }{
297+ "Successfully_enable_user" : {username : "user1" },
298+
299+ "Error_when_username_is_empty" : {wantErr : true },
300+ "Error_when_user_does_not_exist" : {username : "doesnotexist" , wantErr : true },
301+ "Error_when_not_root" : {username : "notroot" , currentUserNotRoot : true , wantErr : true },
302+ }
303+ for name , tc := range tests {
304+ t .Run (name , func (t * testing.T ) {
305+ if tc .sourceDB == "" {
306+ tc .sourceDB = "disabled-user.db.yaml"
307+ }
308+
309+ client := newNSSClient (t , tc .sourceDB , tc .currentUserNotRoot )
310+
311+ _ , err := client .EnablePasswd (context .Background (), & authd.EnablePasswdRequest {Name : tc .username })
312+ if tc .wantErr {
313+ require .Error (t , err , "EnablePasswd should return an error, but did not" )
314+ return
315+ }
316+ require .NoError (t , err , "EnablePasswd should not return an error, but did" )
317+ })
318+ }
319+ }
320+
259321func TestMockgpasswd (t * testing.T ) {
260322 localgroupstestutils .Mockgpasswd (t )
261323}
0 commit comments