Skip to content

Commit

Permalink
pam: add test case Error_when_user_is_disabled while selecting broker
Browse files Browse the repository at this point in the history
  • Loading branch information
shiv-tyagi committed Feb 15, 2025
1 parent c496ffd commit 7183092
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
13 changes: 12 additions & 1 deletion internal/services/pam/pam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ func TestSelectBroker(t *testing.T) {
brokerID string
username string
sessionMode string
existingDB string

currentUserNotRoot bool

Expand All @@ -208,13 +209,23 @@ func TestSelectBroker(t *testing.T) {
"Error_when_broker_does_not_exist": {username: "no broker", brokerID: "does not exist", wantErr: true},
"Error_when_broker_does_not_provide_a_session_ID": {username: "NS_no_id", wantErr: true},
"Error_when_starting_the_session": {username: "NS_error", wantErr: true},
"Error_when_user_is_disabled": {username: "disabled", wantErr: true, existingDB: "cache-with-disabled-user.db"},
}
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
t.Parallel()

cacheDir := t.TempDir()
if tc.existingDB != "" {
cache.Z_ForTests_CreateDBFromYAML(t, filepath.Join(testutils.TestFamilyPath(t), tc.existingDB), cacheDir)
}

m, err := users.NewManager(users.DefaultConfig, cacheDir)
require.NoError(t, err, "Setup: could not create user manager")
t.Cleanup(func() { _ = m.Stop() })

pm := newPermissionManager(t, tc.currentUserNotRoot)
client := newPamClient(t, nil, globalBrokerManager, &pm)
client := newPamClient(t, m, globalBrokerManager, &pm)

switch tc.brokerID {
case "":
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
GroupByID:
"11111": '{"Name":"group1","GID":11111,"UGID":"12345678"}'
GroupByName:
group1: '{"Name":"group1","GID":11111,"UGID":"12345678"}'
GroupByUGID:
"12345678": '{"Name":"group1","GID":11111,"UGID":"12345678"}'
GroupToUsers:
"11111": '{"GID":11111,"UIDs":[1111]}'
UserByID:
"1111": '{"Name":"TestSelectBroker/Error_when_user_is_disabled_separator_disabled","UID":1111,"GID":11111,"Gecos":"Disabled User gecos\nOn multiple lines","Dir":"/home/disabled","Shell":"/bin/bash","LastPwdChange":-1,"MaxPwdAge":-1,"PwdWarnPeriod":-1,"PwdInactivity":-1,"MinPwdAge":-1,"ExpirationDate":-1,"Disabled":true,"LastLogin":"AAAAATIME"}'
UserByName:
"TestSelectBroker/Error_when_user_is_disabled_separator_disabled": '{"Name":"TestSelectBroker/Error_when_user_is_disabled_separator_disabled","UID":1111,"GID":11111,"Gecos":"Disabled User gecos\nOn multiple lines","Dir":"/home/disabled","Shell":"/bin/bash","LastPwdChange":-1,"MaxPwdAge":-1,"PwdWarnPeriod":-1,"PwdInactivity":-1,"MinPwdAge":-1,"ExpirationDate":-1,"Disabled":true,"LastLogin":"AAAAATIME"}'
UserToGroups:
"1111": '{"UID":1111,"GIDs":[11111]}'
UserToBroker:
"1111": '"broker-id"'

0 comments on commit 7183092

Please sign in to comment.