Search in sources :

Example 1 with TokenReviewStatusBuilder

use of io.fabric8.kubernetes.api.model.authentication.TokenReviewStatusBuilder in project kubernetes-client by fabric8io.

the class TokenReviewTest method testCreate.

@Test
@DisplayName("Should create TokenReview")
void testCreate() {
    // Given
    TokenReview tokenReview = new TokenReviewBuilder().withNewSpec().withToken("eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJhdWQiOlsidmF1bHQiXSwiZXhwIjoxNTUyNjc1").endSpec().build();
    server.expect().post().withPath("/apis/authentication.k8s.io/v1/tokenreviews").andReply(HttpURLConnection.HTTP_OK, recordedRequest -> {
        TokenReview tokenReviewReq = Serialization.unmarshal(recordedRequest.getBody().readString(Charset.defaultCharset()), TokenReview.class);
        tokenReviewReq.setStatus(new TokenReviewStatusBuilder().withAuthenticated(true).withNewUser().withUsername("system:serviceaccount:dev:http-svc-test").withUid("4afdf4d0-46d2-11e9-8716-005056bf4b40").withGroups("system:serviceaccounts", "system:serviceaccounts:dev", "system:authenticated").endUser().addToAudiences("factors").build());
        return tokenReviewReq;
    }).once();
    // When
    tokenReview = client.tokenReviews().create(tokenReview);
    // Then
    assertNotNull(tokenReview);
    assertNotNull(tokenReview.getStatus());
    assertTrue(tokenReview.getStatus().getAuthenticated());
    assertEquals("system:serviceaccount:dev:http-svc-test", tokenReview.getStatus().getUser().getUsername());
    assertEquals("4afdf4d0-46d2-11e9-8716-005056bf4b40", tokenReview.getStatus().getUser().getUid());
    assertEquals(3, tokenReview.getStatus().getUser().getGroups().size());
}
Also used : HttpURLConnection(java.net.HttpURLConnection) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) TokenReview(io.fabric8.kubernetes.api.model.authentication.TokenReview) TokenReviewBuilder(io.fabric8.kubernetes.api.model.authentication.TokenReviewBuilder) DisplayName(org.junit.jupiter.api.DisplayName) Test(org.junit.jupiter.api.Test) Charset(java.nio.charset.Charset) EnableKubernetesMockClient(io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient) KubernetesMockServer(io.fabric8.kubernetes.client.server.mock.KubernetesMockServer) Serialization(io.fabric8.kubernetes.client.utils.Serialization) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TokenReviewStatusBuilder(io.fabric8.kubernetes.api.model.authentication.TokenReviewStatusBuilder) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TokenReviewBuilder(io.fabric8.kubernetes.api.model.authentication.TokenReviewBuilder) TokenReviewStatusBuilder(io.fabric8.kubernetes.api.model.authentication.TokenReviewStatusBuilder) TokenReview(io.fabric8.kubernetes.api.model.authentication.TokenReview) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

TokenReview (io.fabric8.kubernetes.api.model.authentication.TokenReview)1 TokenReviewBuilder (io.fabric8.kubernetes.api.model.authentication.TokenReviewBuilder)1 TokenReviewStatusBuilder (io.fabric8.kubernetes.api.model.authentication.TokenReviewStatusBuilder)1 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)1 EnableKubernetesMockClient (io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient)1 KubernetesMockServer (io.fabric8.kubernetes.client.server.mock.KubernetesMockServer)1 Serialization (io.fabric8.kubernetes.client.utils.Serialization)1 HttpURLConnection (java.net.HttpURLConnection)1 Charset (java.nio.charset.Charset)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)1 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)1 DisplayName (org.junit.jupiter.api.DisplayName)1 Test (org.junit.jupiter.api.Test)1