use of io.fabric8.kubernetes.api.model.authorization.v1beta1.SubjectAccessReview in project kubernetes-client by fabric8io.
the class K8sAuthorizationOnOpenShiftIT method createSubjectAccessReview.
@Test
public void createSubjectAccessReview() {
// Given
String user = client.currentUser().getMetadata().getName();
SubjectAccessReview sar = new SubjectAccessReviewBuilder().withNewSpec().withNewResourceAttributes().withNamespace(session.getNamespace()).withVerb("get").withResource("pods").endResourceAttributes().withUser(user).endSpec().build();
// When
SubjectAccessReview createSar = client.authorization().v1().subjectAccessReview().create(sar);
// Then
assertNotNull(createSar);
assertTrue(createSar.getStatus().getAllowed());
}
use of io.fabric8.kubernetes.api.model.authorization.v1beta1.SubjectAccessReview in project kubernetes-client by fabric8io.
the class V1SubjectAccessReviewAuthTest method createSubjectAccessReviewTest.
@Test
@DisplayName("Should Create SubjectAccessReview")
void createSubjectAccessReviewTest() {
// Given
SubjectAccessReview review = new SubjectAccessReviewBuilder().withNewSpec().withUser("admin-user").withNewResourceAttributes().withResource("pod").withVerb("create").endResourceAttributes().endSpec().build();
server.expect().post().withPath("/apis/authorization.k8s.io/v1/subjectaccessreviews").andReply(HttpURLConnection.HTTP_OK, recordedRequest -> {
LocalSubjectAccessReview reviewResponse = Serialization.unmarshal(recordedRequest.getBody().readString(Charset.defaultCharset()), LocalSubjectAccessReview.class);
reviewResponse.setStatus(new SubjectAccessReviewStatus(true, false, "", ""));
return reviewResponse;
}).once();
// When
SubjectAccessReview reviewResponse = client.authorization().v1().subjectAccessReview().create(review);
// Then
assertNotNull(reviewResponse);
assertEquals(true, reviewResponse.getStatus().getAllowed());
}
use of io.fabric8.kubernetes.api.model.authorization.v1beta1.SubjectAccessReview in project kubernetes-client by fabric8io.
the class SubjectAccessReviewTest method testBuilder.
@Test
public void testBuilder() {
SubjectAccessReview sar = new SubjectAccessReviewBuilder().withNewMetadata().withName("test-sar").endMetadata().withNewSpec().withNewResourceAttributes().withGroup("apps").withResource("deployments").withNamespace("dev").withVerb("create").endResourceAttributes().endSpec().build();
Assertions.assertEquals("test-sar", sar.getMetadata().getName());
Assertions.assertEquals("apps", sar.getSpec().getResourceAttributes().getGroup());
Assertions.assertEquals("deployments", sar.getSpec().getResourceAttributes().getResource());
Assertions.assertEquals("dev", sar.getSpec().getResourceAttributes().getNamespace());
Assertions.assertEquals("create", sar.getSpec().getResourceAttributes().getVerb());
}
use of io.fabric8.kubernetes.api.model.authorization.v1beta1.SubjectAccessReview in project kubernetes-client by fabric8io.
the class V1beta1SubjectAccessReviewAuthTest method createSubjectAccessReviewTest.
@Test
@DisplayName("Should Create SubjectAccessReview")
void createSubjectAccessReviewTest() {
// Given
SubjectAccessReview review = new SubjectAccessReviewBuilder().withNewSpec().withUser("admin-user").withNewResourceAttributes().withResource("pod").withVerb("create").endResourceAttributes().endSpec().build();
server.expect().post().withPath("/apis/authorization.k8s.io/v1beta1/subjectaccessreviews").andReply(HttpURLConnection.HTTP_OK, recordedRequest -> {
LocalSubjectAccessReview reviewResponse = Serialization.unmarshal(recordedRequest.getBody().readString(Charset.defaultCharset()), LocalSubjectAccessReview.class);
reviewResponse.setStatus(new SubjectAccessReviewStatus(true, false, "", ""));
return reviewResponse;
}).once();
// When
SubjectAccessReview reviewResponse = client.authorization().v1beta1().subjectAccessReview().create(review);
// Then
assertNotNull(reviewResponse);
assertEquals(true, reviewResponse.getStatus().getAllowed());
}
use of io.fabric8.kubernetes.api.model.authorization.v1beta1.SubjectAccessReview in project kubernetes-client by fabric8io.
the class SubjectAccessReviewIT method testCreate.
@Test
public void testCreate() {
// Given
SubjectAccessReview sar = new SubjectAccessReviewBuilder().withResource("Pod").withVerb("get").withNamespace(session.getNamespace()).build();
// When
SubjectAccessReviewResponse response = client.subjectAccessReviews().create(sar);
// Then
assertNotNull(response);
assertTrue(response.getAllowed());
}
Aggregations