Skip to content

Commit

Permalink
add unit test for case insensitive group memberships (#172)
Browse files Browse the repository at this point in the history
* add unit test for case insensitive group memberships

* more proper fix
  • Loading branch information
MatthewBemis committed Aug 6, 2018
1 parent 30b9843 commit 0f66cbe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ class LdapDirectoryDAO(protected val ldapConnectionPool: LDAPConnectionPool, pro
entry <- Option(ldapConnectionPool.getEntry(subjectDn(member), Attr.memberOf))
memberOf <- Option(entry.getAttribute(Attr.memberOf))
} yield {
val memberships = memberOf.getValues.toSet.map(dnToGroupIdentity)
memberships.contains(groupId)
val memberships = memberOf.getValues.map(_.toLowerCase).toSet //toLowerCase because the dn can have varying capitalization
memberships.contains(groupDn(groupId).toLowerCase)
}
isMember.getOrElse(false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,19 @@ class LdapDirectoryDAOSpec extends FlatSpec with Matchers with TestSupport with
assert(runAndWait(dao.isGroupMember(policy1.id, userId)))
}

it should "be case insensitive when checking for group membership" in {
val userId = WorkbenchUserId(UUID.randomUUID().toString)
val user = WorkbenchUser(userId, WorkbenchEmail("foo@bar.com"))

val groupName1 = WorkbenchGroupName(UUID.randomUUID().toString)
val group1 = BasicWorkbenchGroup(groupName1, Set(userId), WorkbenchEmail("g1@example.com"))

runAndWait(dao.createUser(user))
runAndWait(dao.createGroup(group1))

assert(runAndWait(dao.isGroupMember(WorkbenchGroupName(group1.id.value.toUpperCase), userId)))
}

it should "get pet for user" in {
val userId = WorkbenchUserId(UUID.randomUUID().toString)
val user = WorkbenchUser(userId, WorkbenchEmail("foo@bar.com"))
Expand Down

0 comments on commit 0f66cbe

Please sign in to comment.