Skip to content

Commit

Permalink
Add native tests to make sure the crypto works fine in native mode
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas committed Oct 24, 2019
1 parent 45cde67 commit 883a485
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ quarkus.security.jdbc.principal-query.clear-password-mapper.enabled=true
quarkus.security.jdbc.principal-query.clear-password-mapper.password-index=1
quarkus.security.jdbc.principal-query.attribute-mappings.0.index=2
quarkus.security.jdbc.principal-query.attribute-mappings.0.to=groups
quarkus.http.auth.form.enabled=true
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@

import static org.hamcrest.Matchers.containsString;

import java.util.Base64;

import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import io.restassured.filter.cookie.CookieFilter;

@QuarkusTest
class ElytronSecurityJdbcTest {

public static final String CREDENTIALS = Base64.getEncoder().encodeToString("user:user".getBytes());

@Test
void anonymous() {
RestAssured.given()
Expand All @@ -26,9 +23,31 @@ void anonymous() {

@Test
void authenticated() {
CookieFilter cookies = new CookieFilter();
RestAssured.given()
.redirects().follow(false)
.filter(cookies)
.when()
.get("/api/authenticated")
.then()
.statusCode(302);

RestAssured
.given()
.filter(cookies)
.redirects().follow(false)
.when()
.formParam("j_username", "user")
.formParam("j_password", "user")
.post("/j_security_check")
.then()
.assertThat()
.statusCode(302);

RestAssured.given()
.redirects().follow(false)
.filter(cookies)
.when()
.header("Authorization", "Basic " + CREDENTIALS)
.get("/api/authenticated")
.then()
.statusCode(200)
Expand All @@ -38,17 +57,31 @@ void authenticated() {
@Test
void authenticated_not_authenticated() {
RestAssured.given()
.redirects().follow(false)
.when()
.get("/api/authenticated")
.then()
.statusCode(401);
.statusCode(302);
}

@Test
void forbidden() {
CookieFilter cookies = new CookieFilter();
RestAssured
.given()
.filter(cookies)
.redirects().follow(false)
.when()
.formParam("j_username", "user")
.formParam("j_password", "user")
.post("/j_security_check")
.then()
.assertThat()
.statusCode(302);

RestAssured.given()
.filter(cookies)
.when()
.header("Authorization", "Basic " + CREDENTIALS)
.get("/api/forbidden")
.then()
.statusCode(403);
Expand All @@ -57,10 +90,11 @@ void forbidden() {
@Test
void forbidden_not_authenticated() {
RestAssured.given()
.redirects().follow(false)
.when()
.get("/api/forbidden")
.then()
.statusCode(401);
.statusCode(302);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ quarkus.security.users.embedded.users.mary=mary
quarkus.security.users.embedded.roles.mary=managers
quarkus.security.users.embedded.users.poul=poul
quarkus.security.users.embedded.roles.poul=interns
quarkus.security.users.embedded.auth-mechanism=BASIC
quarkus.security.users.embedded.plain-text=true

0 comments on commit 883a485

Please sign in to comment.