Skip to content

Commit 5e81b35

Browse files
committed
pam: add test case Error_when_user_is_disabled while selecting broker
1 parent 63e164d commit 5e81b35

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

internal/services/pam/pam_test.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ func TestSelectBroker(t *testing.T) {
192192
brokerID string
193193
username string
194194
sessionMode string
195+
existingDB string
195196

196197
currentUserNotRoot bool
197198

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

218+
cacheDir := t.TempDir()
219+
if tc.existingDB != "" {
220+
cache.Z_ForTests_CreateDBFromYAML(t, filepath.Join(testutils.TestFamilyPath(t), tc.existingDB), cacheDir)
221+
}
222+
223+
m, err := users.NewManager(users.DefaultConfig, cacheDir)
224+
require.NoError(t, err, "Setup: could not create user manager")
225+
t.Cleanup(func() { _ = m.Stop() })
226+
216227
pm := newPermissionManager(t, tc.currentUserNotRoot)
217-
client := newPamClient(t, nil, globalBrokerManager, &pm)
228+
client := newPamClient(t, m, globalBrokerManager, &pm)
218229

219230
switch tc.brokerID {
220231
case "":
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
GroupByID:
2+
"11111": '{"Name":"group1","GID":11111,"UGID":"12345678"}'
3+
GroupByName:
4+
group1: '{"Name":"group1","GID":11111,"UGID":"12345678"}'
5+
GroupByUGID:
6+
"12345678": '{"Name":"group1","GID":11111,"UGID":"12345678"}'
7+
GroupToUsers:
8+
"11111": '{"GID":11111,"UIDs":[1111]}'
9+
UserByID:
10+
"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"}'
11+
UserByName:
12+
"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"}'
13+
UserToGroups:
14+
"1111": '{"UID":1111,"GIDs":[11111]}'
15+
UserToBroker:
16+
"1111": '"broker-id"'

0 commit comments

Comments
 (0)