use of io.fabric8.kubernetes.api.model.authorization.v1.NonResourceRule 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.NonResourceRule 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());
}
Aggregations