Skip to content

Commit

Permalink
Add unit tests for sa ldap search
Browse files Browse the repository at this point in the history
Signed-off-by: Chad Roberts <chad.roberts@suse.com>
  • Loading branch information
tashima42 authored and crobby committed Nov 7, 2024
1 parent 944ce71 commit 9f4406e
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions pkg/auth/providers/ldap/ldap_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,84 @@ func Test_ldapProvider_loginUser(t *testing.T) {
wantGroupPrincipals: nil,
wantErr: true,
},
{
name: "successful user login with SearchUsingServiceAccount true",
fields: fields{
userMGR: mockUserManager{
hasAccess: true,
},
tokenMGR: &tokens.Manager{},
caPool: &x509.CertPool{},
userScope: "providername_user",
groupScope: "providername_group",
},
args: args{
lConn: newMockLdapConnClient(),
credential: &v32.BasicLogin{
Username: DummyUsername,
Password: DummyPassword,
},
config: &v3.LdapConfig{
LdapFields: v32.LdapFields{
ServiceAccountDistinguishedName: DummySAUsername,
ServiceAccountPassword: DummySAUPassword,
UserObjectClass: UserObjectClassName,
SearchUsingServiceAccount: true,
},
},
caPool: &x509.CertPool{},
},
wantUserPrincipal: v3.Principal{
ObjectMeta: v1.ObjectMeta{
Name: "providername_user://ldap.test.domain",
},
PrincipalType: "user",
Me: true,
},
wantGroupPrincipals: []v3.Principal{
{
ObjectMeta: v1.ObjectMeta{
Name: "providername_group://ldap.test.domain",
},
PrincipalType: "user",
Me: true,
},
},
wantErr: false,
},
{
name: "user login with invalid credentials with SearchUsingServiceAccount true",
fields: fields{
userMGR: mockUserManager{
hasAccess: false,
},
tokenMGR: &tokens.Manager{},
caPool: &x509.CertPool{},
userScope: "providername_user",
groupScope: "providername_group",
},
args: args{
lConn: &mockLdapConn{
canAuthenticate: false,
},
credential: &v32.BasicLogin{
Username: DummyUsername,
Password: DummyPassword,
},
config: &v3.LdapConfig{
LdapFields: v32.LdapFields{
ServiceAccountDistinguishedName: DummySAUsername,
ServiceAccountPassword: DummySAUPassword,
UserObjectClass: UserObjectClassName,
SearchUsingServiceAccount: true,
},
},
caPool: &x509.CertPool{},
},
wantUserPrincipal: v3.Principal{},
wantGroupPrincipals: nil,
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 9f4406e

Please # to comment.