Skip to content

Commit ba9b372

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

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

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

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
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

11+
import io.quarkiverse.openapi.generator.AuthConfig;
912
import jakarta.ws.rs.core.HttpHeaders;
1013

14+
import org.eclipse.microprofile.config.Config;
15+
import org.eclipse.microprofile.config.ConfigProvider;
1116
import org.junit.jupiter.api.Test;
1217
import org.junit.jupiter.params.ParameterizedTest;
1318
import org.junit.jupiter.params.provider.Arguments;
1419
import org.junit.jupiter.params.provider.MethodSource;
20+
import org.mockito.MockedStatic;
21+
import org.mockito.Mockito;
1522

1623
class BearerOpenApiSpecProviderTest extends AbstractOpenApiSpecProviderTest<BearerAuthenticationProvider> {
1724

1825
private static final String INCOMING_TOKEN = "INCOMING_TOKEN";
1926

27+
private static final String PROPAGATED_TOKEN = "PROPAGATED_TOKEN";
28+
2029
private static final String BEARER_SCHEMA = "bearer";
2130
private static final String CUSTOM_SCHEMA = "custom_scheme";
2231
private static final String HEADER_NAME = "HEADER_NAME";
@@ -62,15 +71,25 @@ void filterWithPropagation(String headerName,
6271
propagatedHeaderName = propagationHeaderName(OPEN_API_FILE_SPEC_ID, AUTH_SCHEME_NAME,
6372
HEADER_NAME);
6473
}
65-
headers.putSingle(propagatedHeaderName, INCOMING_TOKEN);
66-
filter(bearerScheme, expectedAuthorizationHeader);
74+
try (MockedStatic<ConfigProvider> configProviderMocked = Mockito.mockStatic(ConfigProvider.class)) {
75+
Config mockedConfig = Mockito.mock(Config.class);
76+
configProviderMocked.when(ConfigProvider::getConfig).thenReturn(mockedConfig);
77+
78+
when(mockedConfig.getOptionalValue(provider.getCanonicalAuthConfigPropertyName(AuthConfig.TOKEN_PROPAGATION),
79+
Boolean.class)).thenReturn(Optional.of(true));
80+
when(mockedConfig.getOptionalValue(provider.getCanonicalAuthConfigPropertyName(AuthConfig.HEADER_NAME),
81+
String.class)).thenReturn(Optional.of(headerName == null ? HttpHeaders.AUTHORIZATION: headerName));
82+
83+
headers.putSingle(propagatedHeaderName, PROPAGATED_TOKEN);
84+
filter(bearerScheme, expectedAuthorizationHeader);
85+
}
6786
}
6887

6988
static Stream<Arguments> filterWithPropagationTestValues() {
7089
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));
90+
Arguments.of(null, "bearer", "Bearer " + PROPAGATED_TOKEN),
91+
Arguments.of(null, CUSTOM_SCHEMA, CUSTOM_SCHEMA + " " + PROPAGATED_TOKEN),
92+
Arguments.of(HEADER_NAME, "bearer", "Bearer " + PROPAGATED_TOKEN),
93+
Arguments.of(HEADER_NAME, CUSTOM_SCHEMA, CUSTOM_SCHEMA + " " + PROPAGATED_TOKEN));
7594
}
7695
}

0 commit comments

Comments
 (0)