-
-
Notifications
You must be signed in to change notification settings - Fork 661
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(auth): allows List or String in topics-filter-regex (#659)
- Loading branch information
Showing
4 changed files
with
90 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package org.akhq.configs; | ||
|
||
import io.micronaut.context.ApplicationContext; | ||
import org.akhq.utils.UserGroupUtils; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertIterableEquals; | ||
|
||
public class UserGroupUtilsTest { | ||
@Test | ||
void testTopicRegexpAsString() { | ||
ApplicationContext ctx = ApplicationContext.run(ApplicationContext.class,"filterregex"); | ||
|
||
UserGroupUtils userGroupUtils = ctx.getBean(UserGroupUtils.class); | ||
|
||
List<String> actual = (List<String>)userGroupUtils.getUserAttributes(List.of("as-string")).get("topicsFilterRegexp"); | ||
|
||
assertEquals( | ||
1, | ||
actual.size() | ||
); | ||
assertIterableEquals( | ||
List.of("test.*"), | ||
actual | ||
); | ||
|
||
ctx.close(); | ||
} | ||
|
||
@Test | ||
void testTopicRegexpAsList() { | ||
|
||
ApplicationContext ctx = ApplicationContext.run(ApplicationContext.class,"filterregex"); | ||
|
||
UserGroupUtils userGroupUtils = ctx.getBean(UserGroupUtils.class); | ||
|
||
List<String> actual = (List<String>)userGroupUtils.getUserAttributes(List.of("as-list")).get("topicsFilterRegexp"); | ||
|
||
assertEquals( | ||
2, | ||
actual.size() | ||
); | ||
assertIterableEquals( | ||
List.of("item1","item2"), | ||
actual | ||
); | ||
|
||
ctx.close(); | ||
} | ||
@Test | ||
void testTopicRegexpAsMixed() { | ||
|
||
ApplicationContext ctx = ApplicationContext.run(ApplicationContext.class,"filterregex"); | ||
|
||
UserGroupUtils userGroupUtils = ctx.getBean(UserGroupUtils.class); | ||
|
||
List<String> actual = (List<String>)userGroupUtils.getUserAttributes(List.of("as-string","as-list")).get("topicsFilterRegexp"); | ||
|
||
assertEquals( | ||
3, | ||
actual.size() | ||
); | ||
assertIterableEquals( | ||
List.of("test.*","item1","item2"), | ||
actual | ||
); | ||
|
||
ctx.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
akhq: | ||
security: | ||
groups: | ||
as-string: | ||
roles: | ||
- topic/read | ||
attributes: | ||
topics-filter-regexp: "test.*" | ||
as-list: | ||
roles: | ||
- topic/read | ||
attributes: | ||
topics-filter-regexp: | ||
- "item1" | ||
- "item2" |