RobertIndie commented on code in PR #21486:
URL: https://github.com/apache/pulsar/pull/21486#discussion_r1379538164
##########
pulsar-broker-common/src/test/java/org/apache/pulsar/broker/authorization/MultiRolesTokenAuthorizationProviderTest.java:
##########
@@ -137,6 +136,41 @@ public String getHttpHeader(String name) {
}).get());
}
+ @Test
+ public void testMultiRolesAuthzWithoutClaim() throws Exception {
+ final SecretKey secretKey =
AuthTokenUtils.createSecretKey(SignatureAlgorithm.HS256);
+ final String testRole = "test-role";
+ // broker will use "sub" as the claim by default.
+ final String token = Jwts.builder()
+ .claim("whatever", testRole).signWith(secretKey).compact();
+ final MultiRolesTokenAuthorizationProvider provider = new
MultiRolesTokenAuthorizationProvider();
+ final AuthenticationDataSource ads = new AuthenticationDataSource() {
+ @Override
+ public boolean hasDataFromHttp() {
+ return true;
+ }
+
+ @Override
+ public String getHttpHeader(String name) {
+ if (name.equals("Authorization")) {
+ return "Bearer " + token;
+ } else {
+ throw new IllegalArgumentException("Wrong HTTP header");
+ }
+ }
+ };
+
+ assertFalse(provider.authorize("test", ads, role -> {
+ if (role == null) {
+ throw new IllegalStateException("We should avoid pass null to
sub providers");
+ }
+ if (role.equals(testRole)) {
+ return CompletableFuture.completedFuture(true);
+ }
+ return CompletableFuture.completedFuture(false);
Review Comment:
```suggestion
return CompletableFuture.completedFuture(role.equals(testRole));
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]