-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9436 from stuartwdouglas/9296
Fix issue with build time config in dev mode
- Loading branch information
Showing
4 changed files
with
170 additions
and
52 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
50 changes: 50 additions & 0 deletions
50
...ployment/src/test/java/io/quarkus/elytron/security/jdbc/CustomRoleDecoderDevModeTest.java
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,50 @@ | ||
package io.quarkus.elytron.security.jdbc; | ||
|
||
import java.util.Arrays; | ||
import java.util.stream.Stream; | ||
|
||
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.test.QuarkusDevModeTest; | ||
import io.restassured.RestAssured; | ||
|
||
//see https://github.com/quarkusio/quarkus/issues/9296 | ||
public class CustomRoleDecoderDevModeTest extends JdbcSecurityRealmTest { | ||
|
||
static Class[] testClassesWithCustomRoleDecoder = Stream.concat( | ||
Arrays.stream(testClasses), | ||
Arrays.stream(new Class[] { CustomRoleDecoder.class })).toArray(Class[]::new); | ||
|
||
@RegisterExtension | ||
static final QuarkusDevModeTest config = new QuarkusDevModeTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(testClassesWithCustomRoleDecoder) | ||
.addAsResource("custom-role-decoder/import.sql") | ||
.addAsResource("custom-role-decoder/application.properties", "application.properties")); | ||
|
||
@Test | ||
public void testConfigChange() { | ||
RestAssured.given().auth().preemptive().basic("user", "user") | ||
.when().get("/servlet-secured").then() | ||
.statusCode(200); | ||
//break the build time config | ||
config.modifyResourceFile("application.properties", | ||
s -> s.replace("quarkus.security.jdbc.principal-query.attribute-mappings.0.index=2", | ||
"quarkus.security.jdbc.principal-query.attribute-mappings.0.index=3")); | ||
RestAssured.given().auth().preemptive().basic("user", "user") | ||
.when().get("/servlet-secured").then() | ||
.statusCode(500); | ||
|
||
//now fix it again | ||
config.modifyResourceFile("application.properties", | ||
s -> s.replace("quarkus.security.jdbc.principal-query.attribute-mappings.0.index=3", | ||
"quarkus.security.jdbc.principal-query.attribute-mappings.0.index=2")); | ||
RestAssured.given().auth().preemptive().basic("user", "user") | ||
.when().get("/servlet-secured").then() | ||
.statusCode(200); | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
...ay/deployment/src/test/java/io/quarkus/flyway/test/FlywayMultiDataSourcesDevModeTest.java
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,37 @@ | ||
package io.quarkus.flyway.test; | ||
|
||
import static org.hamcrest.CoreMatchers.containsString; | ||
|
||
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.test.QuarkusDevModeTest; | ||
import io.restassured.RestAssured; | ||
|
||
// see https://github.com/quarkusio/quarkus/issues/9415 | ||
public class FlywayMultiDataSourcesDevModeTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusDevModeTest config = new QuarkusDevModeTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(MultiDataSourcesDevModeEndpoint.class) | ||
.addAsResource("config-for-multiple-datasources.properties", "application.properties")); | ||
|
||
@Test | ||
public void testProperConfigApplied() { | ||
RestAssured.get("/fly").then() | ||
.statusCode(200) | ||
.body(containsString("db/location1,db/location2")); | ||
|
||
RestAssured.get("/fly?name=users").then() | ||
.statusCode(200) | ||
.body(containsString("db/users/location1,db/users/location2")); | ||
|
||
RestAssured.get("/fly?name=inventory").then() | ||
.statusCode(200) | ||
.body(containsString("db/inventory/location1,db/inventory/location")); | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
...yway/deployment/src/test/java/io/quarkus/flyway/test/MultiDataSourcesDevModeEndpoint.java
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,50 @@ | ||
package io.quarkus.flyway.test; | ||
|
||
import java.util.Arrays; | ||
import java.util.stream.Collectors; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.DefaultValue; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.QueryParam; | ||
|
||
import org.flywaydb.core.Flyway; | ||
import org.flywaydb.core.api.Location; | ||
import org.flywaydb.core.api.configuration.Configuration; | ||
|
||
import io.quarkus.flyway.FlywayDataSource; | ||
|
||
@Path("/fly") | ||
public class MultiDataSourcesDevModeEndpoint { | ||
|
||
@Inject | ||
Flyway flywayDefault; | ||
|
||
@Inject | ||
@FlywayDataSource("users") | ||
Flyway flywayUsers; | ||
|
||
@Inject | ||
@FlywayDataSource("inventory") | ||
Flyway flywayInventory; | ||
|
||
@GET | ||
@Produces("text/plain") | ||
public String locations(@QueryParam("name") @DefaultValue("default") String name) { | ||
Configuration configuration; | ||
if ("default".equals(name)) { | ||
configuration = flywayDefault.getConfiguration(); | ||
} else if ("users".equals(name)) { | ||
configuration = flywayUsers.getConfiguration(); | ||
} else if ("inventory".equals(name)) { | ||
configuration = flywayInventory.getConfiguration(); | ||
} else { | ||
throw new RuntimeException("Flyway " + name + " not found"); | ||
} | ||
|
||
return Arrays.stream(configuration.getLocations()).map(Location::getPath).collect(Collectors.joining(",")); | ||
} | ||
|
||
} |