Skip to content

Commit 185ebd5

Browse files
Add integration tests for custom credential provider
Signed-off-by: gabriel-farache <[email protected]>
1 parent 20e31c2 commit 185ebd5

File tree

13 files changed

+552
-0
lines changed

13 files changed

+552
-0
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<parent>
4+
<artifactId>quarkus-openapi-generator-integration-tests</artifactId>
5+
<groupId>io.quarkiverse.openapi.generator</groupId>
6+
<version>3.0.0-SNAPSHOT</version>
7+
</parent>
8+
<modelVersion>4.0.0</modelVersion>
9+
10+
<artifactId>quarkus-openapi-generator-it-auth-provider</artifactId>
11+
<name>Quarkus - OpenAPI Generator - Integration Tests - Client - Auth Provider</name>
12+
<description>A few use cases that relies on authentication provider use cases with the OpenAPI Generator</description>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>io.quarkiverse.openapi.generator</groupId>
17+
<artifactId>quarkus-openapi-generator</artifactId>
18+
</dependency>
19+
<dependency>
20+
<groupId>io.quarkiverse.openapi.generator</groupId>
21+
<artifactId>quarkus-openapi-generator-oidc</artifactId>
22+
</dependency>
23+
<dependency>
24+
<groupId>io.quarkus</groupId>
25+
<artifactId>quarkus-junit5</artifactId>
26+
<scope>test</scope>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.wiremock</groupId>
30+
<artifactId>wiremock</artifactId>
31+
<scope>test</scope>
32+
</dependency>
33+
<dependency>
34+
<groupId>io.rest-assured</groupId>
35+
<artifactId>rest-assured</artifactId>
36+
<scope>test</scope>
37+
</dependency>
38+
</dependencies>
39+
40+
<build>
41+
<plugins>
42+
<plugin>
43+
<groupId>io.quarkus</groupId>
44+
<artifactId>quarkus-maven-plugin</artifactId>
45+
<extensions>true</extensions>
46+
<executions>
47+
<execution>
48+
<goals>
49+
<goal>build</goal>
50+
<goal>generate-code</goal>
51+
<goal>generate-code-tests</goal>
52+
</goals>
53+
</execution>
54+
</executions>
55+
</plugin>
56+
</plugins>
57+
</build>
58+
<profiles>
59+
<profile>
60+
<id>native-image</id>
61+
<activation>
62+
<property>
63+
<name>native</name>
64+
</property>
65+
</activation>
66+
<build>
67+
<plugins>
68+
<plugin>
69+
<artifactId>maven-surefire-plugin</artifactId>
70+
<configuration>
71+
<skipTests>${native.surefire.skip}</skipTests>
72+
</configuration>
73+
</plugin>
74+
<plugin>
75+
<artifactId>maven-failsafe-plugin</artifactId>
76+
<executions>
77+
<execution>
78+
<goals>
79+
<goal>integration-test</goal>
80+
<goal>verify</goal>
81+
</goals>
82+
<configuration>
83+
<systemPropertyVariables>
84+
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
85+
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
86+
<maven.home>${maven.home}</maven.home>
87+
</systemPropertyVariables>
88+
</configuration>
89+
</execution>
90+
</executions>
91+
</plugin>
92+
</plugins>
93+
</build>
94+
<properties>
95+
<quarkus.package.type>native</quarkus.package.type>
96+
</properties>
97+
</profile>
98+
<profile>
99+
<id>resteasy-reactive</id>
100+
<dependencies>
101+
<dependency>
102+
<groupId>io.quarkus</groupId>
103+
<artifactId>quarkus-rest-client-oidc-filter</artifactId>
104+
</dependency>
105+
</dependencies>
106+
</profile>
107+
<profile>
108+
<id>resteasy-classic</id>
109+
<activation>
110+
<activeByDefault>true</activeByDefault>
111+
</activation>
112+
<dependencies>
113+
<dependency>
114+
<groupId>io.quarkus</groupId>
115+
<artifactId>quarkus-resteasy-client-oidc-filter</artifactId>
116+
</dependency>
117+
<dependency>
118+
<groupId>io.quarkus</groupId>
119+
<artifactId>quarkus-resteasy-multipart</artifactId>
120+
</dependency>
121+
</dependencies>
122+
</profile>
123+
</profiles>
124+
</project>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package io.quarkiverse.openapi.generator.it.auth;
2+
3+
import jakarta.ws.rs.POST;
4+
import jakarta.ws.rs.Path;
5+
6+
import org.eclipse.microprofile.rest.client.inject.RestClient;
7+
8+
@Path("/token_server")
9+
public class TokenServerResource {
10+
11+
@RestClient
12+
org.acme.externalservice1.api.DefaultApi defaultApi1;
13+
14+
@RestClient
15+
org.acme.externalservice2.api.DefaultApi defaultApi2;
16+
17+
@RestClient
18+
org.acme.externalservice3.api.DefaultApi defaultApi3;
19+
20+
@RestClient
21+
org.acme.externalservice5.api.DefaultApi defaultApi5;
22+
23+
@POST
24+
@Path("service1")
25+
public String service1() {
26+
defaultApi1.executeQuery1();
27+
return "hello";
28+
}
29+
30+
@POST
31+
@Path("service2")
32+
public String service2() {
33+
defaultApi2.executeQuery2();
34+
return "hello";
35+
}
36+
37+
@POST
38+
@Path("service3")
39+
public String service3() {
40+
defaultApi3.executeQuery3();
41+
return "hello";
42+
}
43+
44+
@POST
45+
@Path("service5")
46+
public String service5() {
47+
defaultApi5.executeQuery5();
48+
return "hello";
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package io.quarkiverse.openapi.generator.it.auth.provider;
2+
3+
import jakarta.annotation.Priority;
4+
import jakarta.enterprise.context.Dependent;
5+
import jakarta.enterprise.inject.Alternative;
6+
import jakarta.enterprise.inject.Specializes;
7+
import jakarta.ws.rs.client.ClientRequestContext;
8+
import jakarta.ws.rs.core.HttpHeaders;
9+
10+
import org.eclipse.microprofile.config.ConfigProvider;
11+
import org.slf4j.Logger;
12+
import org.slf4j.LoggerFactory;
13+
14+
import io.quarkiverse.openapi.generator.providers.AbstractAuthProvider;
15+
import io.quarkiverse.openapi.generator.providers.ConfigCredentialsProvider;
16+
17+
@Dependent
18+
@Alternative
19+
@Specializes
20+
@Priority(10)
21+
public class CustomCredentialsProvider extends ConfigCredentialsProvider {
22+
static final String BEARER_TOKEN = "bearer-token";
23+
24+
private static final Logger LOGGER = LoggerFactory.getLogger(CustomCredentialsProvider.class);
25+
26+
public CustomCredentialsProvider() {
27+
}
28+
29+
@Override
30+
public String getBearerToken(ClientRequestContext requestContext, String openApiSpecId, String authName) {
31+
return ConfigProvider.getConfig()
32+
.getOptionalValue(
33+
AbstractAuthProvider.getCanonicalAuthConfigPropertyName(BEARER_TOKEN, openApiSpecId, authName),
34+
String.class)
35+
.orElse("") + "_TEST";
36+
}
37+
38+
@Override
39+
public String getOauth2BearerToken(ClientRequestContext requestContext) {
40+
return requestContext.getHeaderString(HttpHeaders.AUTHORIZATION) + "_TEST";
41+
}
42+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
openapi: 3.0.3
3+
info:
4+
title: token-external-service1 API
5+
version: 3.0.0-SNAPSHOT
6+
paths:
7+
/token-external-service1/executeQuery1:
8+
post:
9+
operationId: executeQuery1
10+
responses:
11+
"200":
12+
description: OK
13+
security:
14+
- service1-http-bearer: []
15+
components:
16+
securitySchemes:
17+
service1-http-bearer:
18+
type: http
19+
scheme: bearer
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
openapi: 3.0.3
3+
info:
4+
title: token-external-service2 API
5+
version: 3.0.0-SNAPSHOT
6+
paths:
7+
/token-external-service2/executeQuery2:
8+
post:
9+
operationId: executeQuery2
10+
responses:
11+
"200":
12+
description: OK
13+
security:
14+
- service2-oauth2: []
15+
components:
16+
securitySchemes:
17+
service2-oauth2:
18+
type: oauth2
19+
flows:
20+
clientCredentials:
21+
authorizationUrl: https://example.com/oauth
22+
tokenUrl: https://example.com/oauth/token
23+
scopes: {}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
openapi: 3.0.3
3+
info:
4+
title: token-external-service3 API
5+
version: 3.0.0-SNAPSHOT
6+
paths:
7+
/token-external-service3/executeQuery3:
8+
post:
9+
operationId: executeQuery3
10+
responses:
11+
"200":
12+
description: OK
13+
security:
14+
- service3-http-bearer: []
15+
components:
16+
securitySchemes:
17+
service3-http-bearer:
18+
type: http
19+
scheme: bearer
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
openapi: 3.0.3
3+
info:
4+
title: token-external-service5 API
5+
version: 3.0.0-SNAPSHOT
6+
paths:
7+
/token-external-service5/executeQuery5:
8+
post:
9+
operationId: executeQuery5
10+
responses:
11+
"200":
12+
description: OK
13+
security:
14+
- service5-oauth2: []
15+
components:
16+
securitySchemes:
17+
service5-oauth2:
18+
type: oauth2
19+
flows:
20+
clientCredentials:
21+
authorizationUrl: https://example.com/oauth
22+
tokenUrl: https://example.com/oauth/token
23+
scopes: {}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Authentication properties
2+
org.acme.openapi.security.auth.basic_auth/username=john
3+
org.acme.openapi.security.auth.basic_auth/password=test
4+
customAuth.additionalApiTypeAnnotations=@org.eclipse.microprofile.rest.client.annotation.RegisterClientHeaders;@org.eclipse.microprofile.rest.client.annotation.RegisterProvider(io.quarkiverse.openapi.generator.it.security.auth.DummyApiKeyAuthenticationProvider.class)
5+
6+
# Note: The property value is the name of an existing securityScheme in the spec file
7+
quarkus.openapi-generator.codegen.default-security-scheme=app_id
8+
9+
#Token service
10+
quarkus.openapi-generator.codegen.spec.token_external_service1_yaml.base-package=org.acme.externalservice1
11+
quarkus.openapi-generator.codegen.spec.token_external_service2_yaml.base-package=org.acme.externalservice2
12+
quarkus.openapi-generator.codegen.spec.token_external_service3_yaml.base-package=org.acme.externalservice3
13+
quarkus.openapi-generator.codegen.spec.token_external_service5_yaml.base-package=org.acme.externalservice5
14+
15+
quarkus.rest-client.token_external_service1_yaml.url=${propagation-external-service-mock.url}
16+
quarkus.rest-client.token_external_service2_yaml.url=${propagation-external-service-mock.url}
17+
quarkus.rest-client.token_external_service3_yaml.url=${propagation-external-service-mock.url}
18+
quarkus.rest-client.token_external_service5_yaml.url=${propagation-external-service-mock.url}
19+
20+
# default propagation for token_external_service1 invocation
21+
quarkus.openapi-generator.token_external_service1_yaml.auth.service1_http_bearer.token-propagation=true
22+
# default propagation for token_external_service2 invocation
23+
quarkus.openapi-generator.token_external_service2_yaml.auth.service2_oauth2.token-propagation=true
24+
25+
quarkus.openapi-generator.token_external_service3_yaml.auth.service3_http_bearer.bearer-token=BEARER_TOKEN
26+
27+
# Oidc clients for the services that has oauth2 security.
28+
# Oidc client used by the token_external_service2
29+
quarkus.oidc-client.service2_oauth2.auth-server-url=${keycloak.mock.service.url}
30+
quarkus.oidc-client.service2_oauth2.token-path=${keycloak.mock.service.token-path}
31+
quarkus.oidc-client.service2_oauth2.discovery-enabled=false
32+
quarkus.oidc-client.service2_oauth2.client-id=kogito-app
33+
quarkus.oidc-client.service2_oauth2.grant.type=client
34+
quarkus.oidc-client.service2_oauth2.credentials.client-secret.method=basic
35+
quarkus.oidc-client.service2_oauth2.credentials.client-secret.value=secret
36+
37+
38+
# Oidc client used by the token_external_service5
39+
quarkus.oidc-client.service5_oauth2.auth-server-url=${keycloak.mock.service.url}
40+
quarkus.oidc-client.service5_oauth2.token-path=${keycloak.mock.service.token-path}
41+
quarkus.oidc-client.service5_oauth2.discovery-enabled=false
42+
quarkus.oidc-client.service5_oauth2.client-id=kogito-app
43+
quarkus.oidc-client.service5_oauth2.grant.type=client
44+
quarkus.oidc-client.service5_oauth2.credentials.client-secret.method=basic
45+
quarkus.oidc-client.service5_oauth2.credentials.client-secret.value=secret
46+
47+
quarkus.keycloak.devservices.enabled=false

0 commit comments

Comments
 (0)