-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Fix API key cookie authentication (#568) * Add integration test for key cookie authentication * Apply review changes * Add new integration maven module * Apply suggested changes (hopefully) fixing IT Co-authored-by: nmirasch <[email protected]> * removed the final to avoid the 'Confusing overloading of methods' Co-authored-by: nmirasch <[email protected]> --------- Co-authored-by: nmirasch <[email protected]> Co-authored-by: Ricardo Zanini <[email protected]>
- Loading branch information
1 parent
b47f3c2
commit ed66066
Showing
8 changed files
with
274 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>quarkus-openapi-generator-integration-tests</artifactId> | ||
<groupId>io.quarkiverse.openapi.generator</groupId> | ||
<version>3.0.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>quarkus-openapi-generator-it-cookie-authentication</artifactId> | ||
<name>Quarkus - Openapi Generator - Integration Tests - Cookie Authentication</name> | ||
<description>Use cookie authentication</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkiverse.openapi.generator</groupId> | ||
<artifactId>quarkus-openapi-generator</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-junit5</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.github.tomakehurst</groupId> | ||
<artifactId>wiremock-jre8</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-maven-plugin</artifactId> | ||
<extensions>true</extensions> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>build</goal> | ||
<goal>generate-code</goal> | ||
<goal>generate-code-tests</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<profiles> | ||
<profile> | ||
<id>native-image</id> | ||
<activation> | ||
<property> | ||
<name>native</name> | ||
</property> | ||
</activation> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<skipTests>${native.surefire.skip}</skipTests> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-failsafe-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>integration-test</goal> | ||
<goal>verify</goal> | ||
</goals> | ||
<configuration> | ||
<systemPropertyVariables> | ||
<native.image.path> | ||
${project.build.directory}/${project.build.finalName}-runner | ||
</native.image.path> | ||
<java.util.logging.manager>org.jboss.logmanager.LogManager | ||
</java.util.logging.manager> | ||
<maven.home>${maven.home}</maven.home> | ||
</systemPropertyVariables> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<properties> | ||
<quarkus.package.type>native</quarkus.package.type> | ||
</properties> | ||
</profile> | ||
</profiles> | ||
</project> |
46 changes: 46 additions & 0 deletions
46
integration-tests/cookie-authentication/src/main/openapi/cookie-authentication.json
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,46 @@ | ||
{ | ||
"openapi": "3.0.1", | ||
"info": { | ||
"title": "Quarkus - Openapi Generator - Integration Tests - Cookie Authentication", | ||
"version": "v1" | ||
}, | ||
"servers": [ | ||
{ | ||
"url": "http://localhost:8080" | ||
} | ||
], | ||
"security": [ | ||
{ | ||
"cookie": [] | ||
} | ||
], | ||
"tags": [ | ||
{ | ||
"name": "Test" | ||
} | ||
], | ||
"paths": { | ||
"/v1/test": { | ||
"get": { | ||
"tags": [ | ||
"Test" | ||
], | ||
"operationId": "doTest", | ||
"responses": { | ||
"204": { | ||
"description": "Test succeeded" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"components": { | ||
"securitySchemes": { | ||
"cookie": { | ||
"type": "apiKey", | ||
"name": "TASKLIST-SESSION", | ||
"in": "cookie" | ||
} | ||
} | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
integration-tests/cookie-authentication/src/main/resources/application.properties
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,2 @@ | ||
quarkus.openapi-generator.codegen.spec.cookie_authentication_json.mutiny=true | ||
quarkus.openapi-generator.cookie_authentication_json.auth.cookie.api-key=Quarkus |
43 changes: 43 additions & 0 deletions
43
...ntication/src/test/java/io/quarkiverse/openapi/generator/it/CookieAuthenticationTest.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,43 @@ | ||
package io.quarkiverse.openapi.generator.it; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.time.Duration; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.core.Response; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
import org.junit.jupiter.api.Tag; | ||
import org.junit.jupiter.api.Test; | ||
import org.openapi.quarkus.cookie_authentication_json.api.TestApi; | ||
|
||
import com.github.tomakehurst.wiremock.WireMockServer; | ||
|
||
import io.quarkus.test.common.QuarkusTestResource; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
|
||
@QuarkusTest | ||
@QuarkusTestResource(WiremockCookieAuthentication.class) | ||
@Tag("resteasy-reactive") | ||
class CookieAuthenticationTest { | ||
// Injected by Quarkus test resource | ||
WireMockServer wireMockServer; | ||
|
||
@RestClient | ||
@Inject | ||
TestApi testApi; | ||
|
||
@Test | ||
void apiIsBeingGenerated() { | ||
final Response response = testApi.doTest() | ||
.await() | ||
.atMost(Duration.ofSeconds(5L)); | ||
assertThat(response) | ||
.extracting(Response::getStatus) | ||
.isEqualTo(204); | ||
wireMockServer.verify(getRequestedFor(urlEqualTo("/v1/test"))); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...ation/src/test/java/io/quarkiverse/openapi/generator/it/WiremockCookieAuthentication.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,41 @@ | ||
package io.quarkiverse.openapi.generator.it; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.get; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; | ||
|
||
import java.util.Map; | ||
|
||
import com.github.tomakehurst.wiremock.WireMockServer; | ||
import com.github.tomakehurst.wiremock.core.WireMockConfiguration; | ||
|
||
import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; | ||
|
||
public class WiremockCookieAuthentication implements QuarkusTestResourceLifecycleManager { | ||
private static final String URL_KEY = "quarkus.rest-client.cookie_authentication_json.url"; | ||
|
||
private WireMockServer wireMockServer; | ||
|
||
@Override | ||
public Map<String, String> start() { | ||
wireMockServer = new WireMockServer(WireMockConfiguration.wireMockConfig().dynamicPort()); | ||
wireMockServer.start(); | ||
|
||
wireMockServer.stubFor(get(urlPathEqualTo("/v1/test")) | ||
.willReturn(aResponse().withStatus(204))); | ||
|
||
return Map.of(URL_KEY, wireMockServer.baseUrl()); | ||
} | ||
|
||
@Override | ||
public void inject(TestInjector testInjector) { | ||
testInjector.injectIntoFields(wireMockServer, f -> f.getName().equals("wireMockServer")); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
if (wireMockServer != null) { | ||
wireMockServer.stop(); | ||
} | ||
} | ||
} |
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
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
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