Skip to content

Commit

Permalink
Merge pull request quarkusio#6247 from geoand/spring-security-devmode…
Browse files Browse the repository at this point in the history
…-test

Add a dev-mode test for the Spring Security module
  • Loading branch information
geoand authored Dec 18, 2019
2 parents 05a11f3 + e84b32a commit b3cdc49
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 0 deletions.
15 changes: 15 additions & 0 deletions extensions/spring-security/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@
<artifactId>quarkus-security-test-utils</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-spring-web-deployment</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-elytron-security-properties-file-deployment</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package io.quarkus.spring.security.deployment;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.spring.security.deployment.springapp.Person;
import io.quarkus.spring.security.deployment.springapp.Roles;
import io.quarkus.spring.security.deployment.springapp.SpringComponent;
import io.quarkus.spring.security.deployment.springapp.SpringController;
import io.quarkus.test.QuarkusDevModeTest;
import io.restassured.RestAssured;

public class AnnotationChangeReloadTest {

@RegisterExtension
static QuarkusDevModeTest TEST = new QuarkusDevModeTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
.addClasses(Roles.class,
Person.class,
SpringComponent.class,
SpringController.class));

@Test()
public void testUpdatedAnnotationWorks() {
RestAssured.given().auth().preemptive().basic("bob", "bob")
.when().get("/secure/admin").then()
.statusCode(403);
RestAssured.given().auth().preemptive().basic("alice", "alice")
.when().get("/secure/admin").then()
.statusCode(200);

TEST.modifySourceFile("SpringComponent.java", s -> s.replace("@PreAuthorize(\"hasRole(@roles.ADMIN)\")",
"@PreAuthorize(\"hasRole(@roles.USER)\")"));

RestAssured.given().auth().preemptive().basic("bob", "bob")
.when().get("/secure/admin").then()
.statusCode(200);
RestAssured.given().auth().preemptive().basic("alice", "alice")
.when().get("/secure/admin").then()
.statusCode(403);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.quarkus.spring.security.deployment.springapp;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/secure")
public class SpringController {

private final SpringComponent springComponent;

public SpringController(SpringComponent springComponent) {
this.springComponent = springComponent;
}

@GetMapping("/admin")
public String accessibleForAdminOnly() {
return springComponent.accessibleForAdminOnly();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
quarkus.security.users.file.enabled=true
quarkus.security.users.file.users=test-users.properties
quarkus.security.users.file.roles=test-roles.properties
#quarkus.security.users.file.auth-mechanism=BASIC
quarkus.security.users.file.plain-text=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bob=user
alice=admin
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bob=bob
alice=alice

0 comments on commit b3cdc49

Please sign in to comment.