Skip to content

Commit

Permalink
test(openid-connection): ensure token refresh request contains requir…
Browse files Browse the repository at this point in the history
…ed attributes

Signed-off-by: Marc Nuri <marc@marcnuri.com>
  • Loading branch information
manusa committed Apr 18, 2024
1 parent bb3d0c0 commit 0164956
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ protected TestStandardHttpClient(TestStandardHttpClientBuilder builder, AtomicBo

@Override
public void doClose() {
recordedConsumeBytesDirects.clear();
recordedBuildWebSocketDirects.clear();
expectations.values().forEach(e -> {
e.futures.clear();
e.wsFutures.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.fabric8.kubernetes.api.model.NamedContextBuilder;
import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.ConfigBuilder;
import io.fabric8.kubernetes.client.http.TestStandardHttpClient;
import io.fabric8.kubernetes.client.http.TestStandardHttpClientBuilder;
import io.fabric8.kubernetes.client.http.TestStandardHttpClientFactory;
import org.assertj.core.api.InstanceOfAssertFactories;
Expand Down Expand Up @@ -116,6 +117,7 @@ void setUp() throws Exception {
authProviderConfig.put("id-token", "original-token");
authProviderConfig.put("idp-issuer-url", "https://auth.fabric8.example.com");
authProviderConfig.put("client-id", "id-of-test-client");
authProviderConfig.put("client-secret", "secret-of-test-client");
}

@AfterEach
Expand Down Expand Up @@ -359,7 +361,7 @@ void updatesCurrentConfigAuthProviderConfigWithNewTokenInFile() throws Exception

@Test
@DisplayName("Certificate is loaded into HttpClient trust manager")
void certificateIsLoadedIntoHttpClientTrustManager() throws Exception {
void certificateIsLoadedIntoHttpClientTrustManager() {
assertThat(httpClientBuilder.getTrustManagers())
.singleElement()
.asInstanceOf(InstanceOfAssertFactories.type(X509ExtendedTrustManager.class))
Expand All @@ -369,6 +371,20 @@ void certificateIsLoadedIntoHttpClientTrustManager() throws Exception {
.extracting(Principal::getName)
.contains("CN=auth.fabric8.example.com");
}

@Test
@DisplayName("Token refresh request contains valid auth and form data")
void tokenRefreshRequestContainsValidFormData() {
assertThat(httpClientBuilder.build().getRecordedConsumeBytesDirects())
.filteredOn(r -> r.getRequest().uri().getPath().equals("/token"))
.singleElement()
.extracting(TestStandardHttpClient.RecordedConsumeBytesDirect::getRequest)
.hasFieldOrPropertyWithValue("method", "POST")
.hasFieldOrPropertyWithValue("contentType", "application/x-www-form-urlencoded")
.hasFieldOrPropertyWithValue("bodyString",
"refresh_token=original-refresh-token&grant_type=refresh_token&client_id=id-of-test-client&client_secret=secret-of-test-client")
.returns("Basic aWQtb2YtdGVzdC1jbGllbnQ6c2VjcmV0LW9mLXRlc3QtY2xpZW50", r -> r.header("Authorization"));
}
}
}
}
Expand Down

0 comments on commit 0164956

Please sign in to comment.