Skip to content

Commit

Permalink
test(auths): add a test for basic auth case sensitive
Browse files Browse the repository at this point in the history
close #722
  • Loading branch information
tchiotludo committed Jun 13, 2021
1 parent bba0cc5 commit 717ba81
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.akhq.modules;

import io.micronaut.security.authentication.*;
import io.micronaut.test.extensions.junit5.annotation.MicronautTest;
import io.reactivex.Flowable;
import org.akhq.AbstractTest;
import org.junit.jupiter.api.Test;

import java.util.Collection;
Expand All @@ -13,7 +13,8 @@
import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.*;

public class BasicAuthAuthenticationProviderTest extends AbstractTest {
@MicronautTest
public class BasicAuthAuthenticationProviderTest {
@Inject
BasicAuthAuthenticationProvider auth;

Expand Down Expand Up @@ -41,6 +42,30 @@ public void success() {
assertEquals("test.*", ((List)userDetail.getAttributes("roles", "username").get("topicsFilterRegexp")).get(0));
}

@Test
public void successCase() {
AuthenticationResponse response = Flowable
.fromPublisher(auth.authenticate(null, new UsernamePasswordCredentials(
"MyUser3!@yàhöù.com",
"pass"
))).blockingFirst();

assertThat(response, instanceOf(UserDetails.class));

UserDetails userDetail = (UserDetails) response;

assertTrue(userDetail.isAuthenticated());
assertEquals("MyUser3!@yàhöù.com", userDetail.getUsername());

Collection<String> roles = userDetail.getRoles();

assertThat(roles, hasSize(4));
assertThat(roles, hasItem("topic/read"));
assertThat(roles, hasItem("registry/version/delete"));

assertEquals("test.*", ((List)userDetail.getAttributes("roles", "username").get("topicsFilterRegexp")).get(0));
}

@Test
public void failed_UserNotFound() {
AuthenticationResponse response = Flowable
Expand Down
4 changes: 4 additions & 0 deletions src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ akhq:
password: d74ff0ee8da3b9806b18c877dbf29bbde50b5bd8e4dad7a3a725000feb82e8f1
groups:
- limited
- username: MyUser3!@yàhöù.com
password: d74ff0ee8da3b9806b18c877dbf29bbde50b5bd8e4dad7a3a725000feb82e8f1
groups:
- limited
- username: admin
password: d74ff0ee8da3b9806b18c877dbf29bbde50b5bd8e4dad7a3a725000feb82e8f1
groups:
Expand Down

0 comments on commit 717ba81

Please sign in to comment.