}
private static boolean isAllowedGroup(String group, Set<String> allowedGroups) {
- return allowedGroups.stream().anyMatch(group::startsWith);
+ return allowedGroups.stream().anyMatch(allowedGroup -> isExactGroupOrParentGroup(group, allowedGroup));
+ }
+
+ private static boolean isExactGroupOrParentGroup(String group, String allowedGroup) {
+ return group.equals(allowedGroup) || group.startsWith(allowedGroup + "/");
}
private Set<String> getGroups(OAuth20Service scribe, OAuth2AccessToken accessToken) {
public static Object[][] allowedGroups() {
return new Object[][]{
{Set.of()},
- {Set.of("path")}
+ {Set.of("path")},
+ {Set.of("path/to/group")},
};
}
@Test
- public void onCallback_withGroupSyncAndAllowedGroupsNotMatching_shouldThrow() {
+ @UseDataProvider("notAllowedGroups")
+ public void onCallback_withGroupSyncAndAllowedGroupsNotMatching_shouldThrow(Set<String> notAllowedGroups) {
when(gitLabSettings.syncUserGroups()).thenReturn(true);
- when(gitLabSettings.allowedGroups()).thenReturn(Set.of("path2"));
+ when(gitLabSettings.allowedGroups()).thenReturn(notAllowedGroups);
mockGsonUser();
mockGitlabGroups();
.withMessage("You are not allowed to authenticate");
}
+ @DataProvider
+ public static Object[][] notAllowedGroups() {
+ return new Object[][]{
+ {Set.of("pat")},
+ {Set.of("path2")},
+ };
+ }
+
@Test
public void onCallback_ifScribeFactoryFails_shouldThrow() {
IllegalStateException exception = new IllegalStateException("message");