Search in sources :

Example 41 with AccessToken

use of io.vertx.reactivex.ext.auth.oauth2.AccessToken in project java by kubernetes-client.

the class KubeConfigTest method testGCPAuthProviderExpiredTokenWithoutGCloud.

@Test
public void testGCPAuthProviderExpiredTokenWithoutGCloud() {
    String gcpConfigExpiredToken = "apiVersion: v1\n" + "contexts:\n" + "- context:\n" + "    user: gke-cluster\n" + "  name: foo-context\n" + "current-context: foo-context\n" + "users:\n" + "- name: gke-cluster\n" + "  user:\n" + "    auth-provider:\n" + "      config:\n" + "        access-token: fake-token\n" + "        expiry: 1970-01-01T00:00:00Z\n" + "      name: gcp";
    String fakeToken = "new-fake-token";
    String fakeTokenExpiry = "2121-08-05T02:30:24Z";
    GoogleCredentials mockGC = Mockito.mock(GoogleCredentials.class);
    Mockito.when(mockGC.getAccessToken()).thenReturn(new AccessToken(fakeToken, Date.from(Instant.parse(fakeTokenExpiry))));
    KubeConfig.registerAuthenticator(new GCPAuthenticator(null, mockGC));
    try {
        KubeConfig kc = KubeConfig.loadKubeConfig(new StringReader(gcpConfigExpiredToken));
        assertEquals(fakeToken, kc.getAccessToken());
    } catch (Exception ex) {
        ex.printStackTrace();
        fail("Unexpected exception: " + ex);
    }
}
Also used : GCPAuthenticator(io.kubernetes.client.util.authenticators.GCPAuthenticator) AccessToken(com.google.auth.oauth2.AccessToken) StringReader(java.io.StringReader) GoogleCredentials(com.google.auth.oauth2.GoogleCredentials) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)25 AccessToken (com.google.auth.oauth2.AccessToken)21 AccessToken (io.vertx.ext.auth.oauth2.AccessToken)13 Date (java.util.Date)9 JsonObject (io.vertx.core.json.JsonObject)8 IOException (java.io.IOException)8 GoogleCredentials (com.google.auth.oauth2.GoogleCredentials)7 OAuth2TokenImpl (io.vertx.ext.auth.oauth2.impl.OAuth2TokenImpl)7 OAuth2Credentials (com.google.auth.oauth2.OAuth2Credentials)5 Client (javax.ws.rs.client.Client)5 AccessToken (org.glassfish.jersey.client.oauth1.AccessToken)5 ConsumerCredentials (org.glassfish.jersey.client.oauth1.ConsumerCredentials)5 Metadata (io.grpc.Metadata)4 URI (java.net.URI)4 Feature (javax.ws.rs.core.Feature)4 JerseyTest (org.glassfish.jersey.test.JerseyTest)4 ServiceAccountCredentials (com.google.auth.oauth2.ServiceAccountCredentials)3 WebTarget (javax.ws.rs.client.WebTarget)3 Response (javax.ws.rs.core.Response)3 LoggingFeature (org.glassfish.jersey.logging.LoggingFeature)3