Skip to content

Commit

Permalink
test(ldap/roles): add test to demonstrate the bug when multiple DNs e…
Browse files Browse the repository at this point in the history
…xist for a user id.
  • Loading branch information
kirangodishala committed Jul 30, 2024
1 parent 97c5b33 commit ff31f1a
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,33 @@ class LdapUserRolesProviderTest extends Specification {
1 * provider.loadRolesForUsers(_ as Collection<ExternalUser>)
}

void "loadRolesForUser returns no roles when multiple DNs exist for a user id"(){
given:
def user = externalUser("user1")

def configProps = baseConfigProps()

def provider = Spy(LdapUserRolesProvider) {
1 * setConfigProps(_ as LdapConfig.ConfigProps)
1 * setLdapTemplate(_ as SpringSecurityLdapTemplate)
1 * loadRolesForUser(_ as ExternalUser)
1 * getUserFullDn(_ as String)
0 * _
}
provider.ldapTemplate = Mock(SpringSecurityLdapTemplate) {
1 * searchForSingleEntry(*_) >> { throw new IncorrectResultSizeDataAccessException(1) } //due to multiple DNs
0 * _
}
provider.setConfigProps(configProps)

when:
configProps.groupSearchBase = "notEmpty"
configProps.userSearchFilter = "notEmpty"
def roles = provider.loadRolesForUser(user)

then:
roles == []
}

private static ExternalUser externalUser(String id) {
return new ExternalUser().setId(id)
Expand Down

0 comments on commit ff31f1a

Please sign in to comment.