use of io.fabric8.kubernetes.api.model.authorization.v1.SelfSubjectRulesReview in project kubernetes-client by fabric8io.
the class OpenShiftAuthorizationIT method createSelfSubjectRulesReview.
@Test
public void createSelfSubjectRulesReview() {
// Given
SelfSubjectRulesReview ssrr = new SelfSubjectRulesReviewBuilder().build();
// When
SelfSubjectRulesReview createdSsrr = client.selfSubjectRulesReviews().inNamespace(session.getNamespace()).create(ssrr);
// Then
assertNotNull(createdSsrr);
assertNotNull(createdSsrr.getStatus());
assertFalse(createdSsrr.getStatus().getRules().isEmpty());
}
use of io.fabric8.kubernetes.api.model.authorization.v1.SelfSubjectRulesReview in project kubernetes-client by fabric8io.
the class V1SubjectAccessReviewAuthTest method testCreateSelfSubjectRulesReview.
@Test
@DisplayName("Create SelfSubjectRulesReview")
void testCreateSelfSubjectRulesReview() {
// Given
SelfSubjectRulesReview selfSubjectRulesReview = new SelfSubjectRulesReviewBuilder().withNewMetadata().withName("foo").endMetadata().withNewSpec().withNamespace("test").endSpec().build();
server.expect().post().withPath("/apis/authorization.k8s.io/v1/selfsubjectrulesreviews").andReply(HttpURLConnection.HTTP_OK, recordedRequest -> {
SelfSubjectRulesReview reviewResponse = Serialization.unmarshal(recordedRequest.getBody().readString(Charset.defaultCharset()), SelfSubjectRulesReview.class);
List<NonResourceRule> nonResourceRuleList = new ArrayList<>();
nonResourceRuleList.add(new NonResourceRuleBuilder().withNonResourceURLs("*").withVerbs("*").build());
nonResourceRuleList.add(new NonResourceRuleBuilder().withNonResourceURLs("/healthz", "/livez", "/readyz", "/version", "/version/").withVerbs("get").build());
nonResourceRuleList.add(new NonResourceRuleBuilder().withNonResourceURLs("/api", "/api/*", "/apis", "/apis/*", "/healthz", "/livez", "/openapi", "/openapi/*", "/readyz", "/version", "/version/").withVerbs("get").build());
List<ResourceRule> resourceRuleList = new ArrayList<>();
resourceRuleList.add(new ResourceRuleBuilder().withApiGroups("*").withResources("*").withVerbs("*").build());
resourceRuleList.add(new ResourceRuleBuilder().withApiGroups("authorization.k8s.io").withResources("selfsubjectaccessreviews", "selfsubjectrulesreviews").withVerbs("create").build());
reviewResponse.setStatus(new SubjectRulesReviewStatusBuilder().withIncomplete(false).withNonResourceRules(nonResourceRuleList).withResourceRules(resourceRuleList).build());
return reviewResponse;
}).once();
// When
SelfSubjectRulesReview reviewResponse = client.authorization().v1().selfSubjectRulesReview().create(selfSubjectRulesReview);
// Then
assertNotNull(reviewResponse);
assertEquals("test", reviewResponse.getSpec().getNamespace());
assertNotNull(reviewResponse.getStatus());
assertFalse(reviewResponse.getStatus().getIncomplete());
assertEquals(3, reviewResponse.getStatus().getNonResourceRules().size());
assertEquals(2, reviewResponse.getStatus().getResourceRules().size());
}
use of io.fabric8.kubernetes.api.model.authorization.v1.SelfSubjectRulesReview in project kubernetes-client by fabric8io.
the class V1beta1SubjectAccessReviewAuthTest method testCreateSelfSubjectRulesReview.
@Test
void testCreateSelfSubjectRulesReview() {
// Given
SelfSubjectRulesReview selfSubjectRulesReview = new SelfSubjectRulesReviewBuilder().withNewMetadata().withName("foo").endMetadata().withNewSpec().withNamespace("test").endSpec().build();
server.expect().post().withPath("/apis/authorization.k8s.io/v1beta1/selfsubjectrulesreviews").andReply(HttpURLConnection.HTTP_OK, recordedRequest -> {
SelfSubjectRulesReview reviewResponse = Serialization.unmarshal(recordedRequest.getBody().readString(Charset.defaultCharset()), SelfSubjectRulesReview.class);
List<NonResourceRule> nonResourceRuleList = new ArrayList<>();
nonResourceRuleList.add(new NonResourceRuleBuilder().withNonResourceURLs("*").withVerbs("*").build());
nonResourceRuleList.add(new NonResourceRuleBuilder().withNonResourceURLs("/healthz", "/livez", "/readyz", "/version", "/version/").withVerbs("get").build());
nonResourceRuleList.add(new NonResourceRuleBuilder().withNonResourceURLs("/api", "/api/*", "/apis", "/apis/*", "/healthz", "/livez", "/openapi", "/openapi/*", "/readyz", "/version", "/version/").withVerbs("get").build());
List<ResourceRule> resourceRuleList = new ArrayList<>();
resourceRuleList.add(new ResourceRuleBuilder().withApiGroups("*").withResources("*").withVerbs("*").build());
resourceRuleList.add(new ResourceRuleBuilder().withApiGroups("authorization.k8s.io").withResources("selfsubjectaccessreviews", "selfsubjectrulesreviews").withVerbs("create").build());
reviewResponse.setStatus(new SubjectRulesReviewStatusBuilder().withIncomplete(false).withNonResourceRules(nonResourceRuleList).withResourceRules(resourceRuleList).build());
return reviewResponse;
}).once();
// When
SelfSubjectRulesReview reviewResponse = client.authorization().v1beta1().selfSubjectRulesReview().create(selfSubjectRulesReview);
// Then
assertNotNull(reviewResponse);
assertEquals("test", reviewResponse.getSpec().getNamespace());
assertNotNull(reviewResponse.getStatus());
assertFalse(reviewResponse.getStatus().getIncomplete());
assertEquals(3, reviewResponse.getStatus().getNonResourceRules().size());
assertEquals(2, reviewResponse.getStatus().getResourceRules().size());
}
use of io.fabric8.kubernetes.api.model.authorization.v1.SelfSubjectRulesReview in project kubernetes-client by fabric8io.
the class SubjectAccessReviewTest method createSelfSubjectRulesReviews.
@Test
void createSelfSubjectRulesReviews() {
// Given
server.expect().post().withPath("/apis/authorization.openshift.io/v1/namespaces/test/selfsubjectrulesreviews").andReturn(HTTP_CREATED, new SelfSubjectRulesReviewBuilder().withNewSpec().endSpec().withNewStatus().addNewRule().withVerbs("create", "get").withApiGroups("").withResources("buildconfigs/webhooks").endRule().endStatus().build()).once();
// When
SelfSubjectRulesReview response = client.selfSubjectRulesReviews().inNamespace("test").create(new SelfSubjectRulesReviewBuilder().withNewSpec().endSpec().build());
// Then
assertNotNull(response);
assertNotNull(response.getStatus());
assertEquals(1, response.getStatus().getRules().size());
}
Aggregations