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());
}
Aggregations