Skip to content

Commit c8f9394

Browse files
Fix propagation test for bearer provider
Signed-off-by: gabriel-farache <[email protected]>
1 parent 2a6e2c2 commit c8f9394

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

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

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
11
package io.quarkiverse.openapi.generator.providers;
22

33
import static io.quarkiverse.openapi.generator.providers.AbstractAuthenticationPropagationHeadersFactory.propagationHeaderName;
4+
import static org.mockito.Mockito.when;
45

56
import java.io.IOException;
67
import java.util.List;
8+
import java.util.Optional;
79
import java.util.stream.Stream;
810

911
import jakarta.ws.rs.core.HttpHeaders;
1012

13+
import org.eclipse.microprofile.config.Config;
14+
import org.eclipse.microprofile.config.ConfigProvider;
1115
import org.junit.jupiter.api.Test;
1216
import org.junit.jupiter.params.ParameterizedTest;
1317
import org.junit.jupiter.params.provider.Arguments;
1418
import org.junit.jupiter.params.provider.MethodSource;
19+
import org.mockito.MockedStatic;
20+
import org.mockito.Mockito;
21+
22+
import io.quarkiverse.openapi.generator.AuthConfig;
1523

1624
class BearerOpenApiSpecProviderTest extends AbstractOpenApiSpecProviderTest<BearerAuthenticationProvider> {
1725

1826
private static final String INCOMING_TOKEN = "INCOMING_TOKEN";
1927

28+
private static final String PROPAGATED_TOKEN = "PROPAGATED_TOKEN";
29+
2030
private static final String BEARER_SCHEMA = "bearer";
2131
private static final String CUSTOM_SCHEMA = "custom_scheme";
2232
private static final String HEADER_NAME = "HEADER_NAME";
@@ -62,15 +72,25 @@ void filterWithPropagation(String headerName,
6272
propagatedHeaderName = propagationHeaderName(OPEN_API_FILE_SPEC_ID, AUTH_SCHEME_NAME,
6373
HEADER_NAME);
6474
}
65-
headers.putSingle(propagatedHeaderName, INCOMING_TOKEN);
66-
filter(bearerScheme, expectedAuthorizationHeader);
75+
try (MockedStatic<ConfigProvider> configProviderMocked = Mockito.mockStatic(ConfigProvider.class)) {
76+
Config mockedConfig = Mockito.mock(Config.class);
77+
configProviderMocked.when(ConfigProvider::getConfig).thenReturn(mockedConfig);
78+
79+
when(mockedConfig.getOptionalValue(provider.getCanonicalAuthConfigPropertyName(AuthConfig.TOKEN_PROPAGATION),
80+
Boolean.class)).thenReturn(Optional.of(true));
81+
when(mockedConfig.getOptionalValue(provider.getCanonicalAuthConfigPropertyName(AuthConfig.HEADER_NAME),
82+
String.class)).thenReturn(Optional.of(headerName == null ? HttpHeaders.AUTHORIZATION : headerName));
83+
84+
headers.putSingle(propagatedHeaderName, PROPAGATED_TOKEN);
85+
filter(bearerScheme, expectedAuthorizationHeader);
86+
}
6787
}
6888

6989
static Stream<Arguments> filterWithPropagationTestValues() {
7090
return Stream.of(
71-
Arguments.of(null, "bearer", "Bearer " + INCOMING_TOKEN),
72-
Arguments.of(null, CUSTOM_SCHEMA, CUSTOM_SCHEMA + " " + INCOMING_TOKEN),
73-
Arguments.of(HEADER_NAME, "bearer", "Bearer " + INCOMING_TOKEN),
74-
Arguments.of(HEADER_NAME, CUSTOM_SCHEMA, CUSTOM_SCHEMA + " " + INCOMING_TOKEN));
91+
Arguments.of(null, "bearer", "Bearer " + PROPAGATED_TOKEN),
92+
Arguments.of(null, CUSTOM_SCHEMA, CUSTOM_SCHEMA + " " + PROPAGATED_TOKEN),
93+
Arguments.of(HEADER_NAME, "bearer", "Bearer " + PROPAGATED_TOKEN),
94+
Arguments.of(HEADER_NAME, CUSTOM_SCHEMA, CUSTOM_SCHEMA + " " + PROPAGATED_TOKEN));
7595
}
7696
}

0 commit comments

Comments
 (0)