diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/TokenRefreshInterceptor.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/TokenRefreshInterceptor.java index dde846876fc..678b8cffd62 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/TokenRefreshInterceptor.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/TokenRefreshInterceptor.java @@ -52,7 +52,6 @@ public void before(BasicBuilder headerBuilder, HttpHeaders headers) { } } - @Override public CompletableFuture afterFailure(BasicBuilder headerBuilder, HttpResponse response) { if (response.code() == HttpURLConnection.HTTP_UNAUTHORIZED) { @@ -70,7 +69,7 @@ private CompletableFuture refreshToken(BasicBuilder headerBuilder) { Config newestConfig = Config.autoConfigure(currentContextName); if (newestConfig.getAuthProvider() != null && newestConfig.getAuthProvider().getName().equalsIgnoreCase("oidc")) { newAccessToken = OpenIDConnectionUtils.resolveOIDCTokenFromAuthConfig(newestConfig.getAuthProvider().getConfig(), - factory.newBuilder()); + factory.newBuilder()); } else { newAccessToken = CompletableFuture.completedFuture(newestConfig.getOauthToken()); } diff --git a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/utils/TokenRefreshInterceptorTest.java b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/utils/TokenRefreshInterceptorTest.java index 03be3e93c37..9964030fe5d 100644 --- a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/utils/TokenRefreshInterceptorTest.java +++ b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/utils/TokenRefreshInterceptorTest.java @@ -19,8 +19,6 @@ import io.fabric8.kubernetes.client.http.HttpClient; import io.fabric8.kubernetes.client.http.HttpRequest; import io.fabric8.kubernetes.client.http.TestHttpResponse; -import java.time.Instant; -import java.time.temporal.ChronoUnit; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -28,6 +26,8 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; +import java.time.Instant; +import java.time.temporal.ChronoUnit; import java.util.Objects; import static io.fabric8.kubernetes.client.Config.KUBERNETES_AUTH_SERVICEACCOUNT_TOKEN_FILE_SYSTEM_PROPERTY; @@ -68,7 +68,7 @@ void shouldAutoconfigureAfter1Minute() throws Exception { // Prepare kubeconfig for autoconfiguration File tempFile = Files.createTempFile("test", "kubeconfig").toFile(); Files.copy(Objects.requireNonNull(getClass().getResourceAsStream("/token-refresh-interceptor/kubeconfig")), - Paths.get(tempFile.getPath()), StandardCopyOption.REPLACE_EXISTING); + Paths.get(tempFile.getPath()), StandardCopyOption.REPLACE_EXISTING); System.setProperty(KUBERNETES_KUBECONFIG_FILE, tempFile.getAbsolutePath()); HttpRequest.Builder builder = Mockito.mock(HttpRequest.Builder.class, Mockito.RETURNS_SELF); @@ -77,7 +77,7 @@ void shouldAutoconfigureAfter1Minute() throws Exception { TokenRefreshInterceptor tokenRefreshInterceptor = new TokenRefreshInterceptor(Config.autoConfigure(null), null); // Replace kubeconfig file Files.copy(Objects.requireNonNull(getClass().getResourceAsStream("/token-refresh-interceptor/kubeconfig.new")), - Paths.get(tempFile.getPath()), StandardCopyOption.REPLACE_EXISTING); + Paths.get(tempFile.getPath()), StandardCopyOption.REPLACE_EXISTING); tokenRefreshInterceptor.setLastRefresh(Instant.now().minus(61, ChronoUnit.SECONDS)); tokenRefreshInterceptor.before(builder, null); Mockito.verify(builder).setHeader("Authorization", "Bearer new token"); @@ -87,8 +87,6 @@ void shouldAutoconfigureAfter1Minute() throws Exception { } } - - @Test void shouldReloadInClusterServiceAccount() throws Exception { try {