Skip to content

Commit f1921c3

Browse files
Refactor based on feedback and update tests acordingly
Co-authored-by: Francisco Javier Tirado Sarti <[email protected]>
1 parent 2be2367 commit f1921c3

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

client/runtime/src/main/java/io/quarkiverse/openapi/generator/providers/BearerAuthenticationProvider.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,12 @@ public BearerAuthenticationProvider(final String openApiSpecId, final String nam
2828

2929
@Override
3030
public void filter(ClientRequestContext requestContext) throws IOException {
31-
String bearerToken;
31+
String bearerToken = getBearerToken(requestContext);
32+
3233
if (isTokenPropagation()) {
33-
bearerToken = getTokenForPropagation(requestContext.getHeaders());
34-
bearerToken = sanitizeBearerToken(bearerToken);
35-
} else {
36-
bearerToken = getBearerToken(requestContext);
34+
bearerToken = sanitizeBearerToken(getTokenForPropagation(requestContext.getHeaders()));
3735
}
36+
3837
if (!bearerToken.isBlank()) {
3938
requestContext.getHeaders().add(HttpHeaders.AUTHORIZATION, AuthUtils.authTokenOrBearer(this.scheme, bearerToken));
4039
}

client/runtime/src/test/java/io/quarkiverse/openapi/generator/providers/BasicOpenApiSpecProviderTest.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ class BasicOpenApiSpecProviderTest extends AbstractOpenApiSpecProviderTest<Basic
2828
private static final String USER = "USER";
2929
private static final String PASSWORD = "PASSWORD";
3030

31+
private static final String USER_PROP = "username";
32+
private static final String PASSWORD_PROP = "password";
33+
3134
private static final String CUSTOM_SCHEMA = "custom_scheme";
3235
private static final String HEADER_NAME = "HEADER_NAME";
3336

@@ -53,14 +56,9 @@ private void filter(String expectedAuthorizationHeader) throws IOException {
5356
@MethodSource("filterWithPropagationTestValues")
5457
void filterWithPropagation(String headerName,
5558
String expectedAuthorizationHeader) throws IOException {
56-
String propagatedHeaderName;
57-
if (headerName == null) {
58-
propagatedHeaderName = propagationHeaderName(OPEN_API_FILE_SPEC_ID, AUTH_SCHEME_NAME,
59-
HttpHeaders.AUTHORIZATION);
60-
} else {
61-
propagatedHeaderName = propagationHeaderName(OPEN_API_FILE_SPEC_ID, AUTH_SCHEME_NAME,
62-
HEADER_NAME);
63-
}
59+
String propagatedHeaderName = headerName == null
60+
? propagationHeaderName(OPEN_API_FILE_SPEC_ID, AUTH_SCHEME_NAME, HttpHeaders.AUTHORIZATION)
61+
: propagationHeaderName(OPEN_API_FILE_SPEC_ID, AUTH_SCHEME_NAME, HEADER_NAME);
6462
try (MockedStatic<ConfigProvider> configProviderMocked = Mockito.mockStatic(ConfigProvider.class)) {
6563
Config mockedConfig = Mockito.mock(Config.class);
6664
configProviderMocked.when(ConfigProvider::getConfig).thenReturn(mockedConfig);
@@ -69,7 +67,10 @@ void filterWithPropagation(String headerName,
6967
Boolean.class)).thenReturn(Optional.of(true));
7068
when(mockedConfig.getOptionalValue(provider.getCanonicalAuthConfigPropertyName(AuthConfig.HEADER_NAME),
7169
String.class)).thenReturn(Optional.of(headerName == null ? HttpHeaders.AUTHORIZATION : headerName));
72-
70+
when(mockedConfig.getOptionalValue(provider.getCanonicalAuthConfigPropertyName(USER_PROP),
71+
String.class)).thenReturn(Optional.of(USER));
72+
when(mockedConfig.getOptionalValue(provider.getCanonicalAuthConfigPropertyName(PASSWORD_PROP),
73+
String.class)).thenReturn(Optional.of(PASSWORD));
7374
headers.putSingle(propagatedHeaderName, PROPAGATED_TOKEN);
7475
filter(expectedAuthorizationHeader);
7576
}

client/runtime/src/test/java/io/quarkiverse/openapi/generator/providers/BearerOpenApiSpecProviderTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class BearerOpenApiSpecProviderTest extends AbstractOpenApiSpecProviderTest<Bear
2828
private static final String PROPAGATED_TOKEN = "PROPAGATED_TOKEN";
2929

3030
private static final String BEARER_SCHEMA = "bearer";
31+
32+
private static final String BEARER_TOKEN = "bearer-token";
3133
private static final String CUSTOM_SCHEMA = "custom_scheme";
3234
private static final String HEADER_NAME = "HEADER_NAME";
3335

@@ -88,6 +90,8 @@ void filterWithPropagation(String headerName,
8890
Boolean.class)).thenReturn(Optional.of(true));
8991
when(mockedConfig.getOptionalValue(provider.getCanonicalAuthConfigPropertyName(AuthConfig.HEADER_NAME),
9092
String.class)).thenReturn(Optional.of(headerName == null ? HttpHeaders.AUTHORIZATION : headerName));
93+
when(mockedConfig.getOptionalValue(provider.getCanonicalAuthConfigPropertyName(BEARER_TOKEN),
94+
String.class)).thenReturn(Optional.of(INCOMING_TOKEN));
9195

9296
headers.putSingle(propagatedHeaderName, PROPAGATED_TOKEN);
9397
filter(bearerScheme, expectedAuthorizationHeader);

0 commit comments

Comments
 (0)