Search in sources :

Example 6 with RoleBindingBuilder

use of io.fabric8.openshift.api.model.RoleBindingBuilder in project kubernetes-client by fabric8io.

the class OpenshiftRoleBindingTest method testCreateWithUserNamesAndGroupsAndOverwriteSubjects.

@Test
void testCreateWithUserNamesAndGroupsAndOverwriteSubjects() throws Exception {
    server.expect().post().withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings").andReturn(201, expectedRoleBinding).once();
    RoleBinding response = client.roleBindings().create(new RoleBindingBuilder().withNewMetadata().endMetadata().addToUserNames("testuser1", "testuser2", "system:serviceaccount:test:svcacct").addToGroupNames("testgroup").addNewSubject().withKind("User").withName("unexpected").endSubject().build());
    assertEquals(expectedRoleBinding, response);
    assertEquals(expectedRoleBinding, new ObjectMapper().readerFor(RoleBinding.class).readValue(server.getLastRequest().getBody().inputStream()));
}
Also used : RoleBindingBuilder(io.fabric8.openshift.api.model.RoleBindingBuilder) RoleBinding(io.fabric8.openshift.api.model.RoleBinding) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Example 7 with RoleBindingBuilder

use of io.fabric8.openshift.api.model.RoleBindingBuilder in project kubernetes-client by fabric8io.

the class OpenshiftRoleBindingTest method testReplaceWithUserNamesAndGroupsAndNoSubjects.

@Test
void testReplaceWithUserNamesAndGroupsAndNoSubjects() throws Exception {
    server.expect().get().withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings/testrb").andReturn(200, expectedRoleBinding).once();
    server.expect().put().withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings/testrb").andReturn(200, expectedRoleBinding).once();
    RoleBinding response = client.roleBindings().withName("testrb").replace(new RoleBindingBuilder().withNewMetadata().endMetadata().addToUserNames("testuser1", "testuser2", "system:serviceaccount:test:svcacct").addToGroupNames("testgroup").build());
    assertEquals(expectedRoleBinding, response);
    assertEquals(expectedRoleBinding, new ObjectMapper().readerFor(RoleBinding.class).readValue(server.getLastRequest().getBody().inputStream()));
}
Also used : RoleBindingBuilder(io.fabric8.openshift.api.model.RoleBindingBuilder) RoleBinding(io.fabric8.openshift.api.model.RoleBinding) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Example 8 with RoleBindingBuilder

use of io.fabric8.openshift.api.model.RoleBindingBuilder in project kubernetes-client by fabric8io.

the class OpenshiftRoleBindingTest method testReplaceWithUserNamesAndGroupsAndOverwriteSubjects.

@Test
void testReplaceWithUserNamesAndGroupsAndOverwriteSubjects() throws Exception {
    server.expect().get().withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings/testrb").andReturn(200, expectedRoleBinding).once();
    server.expect().put().withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings/testrb").andReturn(200, expectedRoleBinding).once();
    RoleBinding response = client.roleBindings().withName("testrb").replace(new RoleBindingBuilder().withNewMetadata().endMetadata().addToUserNames("testuser1", "testuser2", "system:serviceaccount:test:svcacct").addToGroupNames("testgroup").addNewSubject().withKind("User").withName("unexpected").endSubject().build());
    assertEquals(expectedRoleBinding, response);
    assertEquals(expectedRoleBinding, new ObjectMapper().readerFor(RoleBinding.class).readValue(server.getLastRequest().getBody().inputStream()));
}
Also used : RoleBindingBuilder(io.fabric8.openshift.api.model.RoleBindingBuilder) RoleBinding(io.fabric8.openshift.api.model.RoleBinding) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Example 9 with RoleBindingBuilder

use of io.fabric8.openshift.api.model.RoleBindingBuilder in project kubernetes-client by fabric8io.

the class OpenshiftRoleBindingTest method testPatchWithOnlySubjects.

@Test
void testPatchWithOnlySubjects() throws Exception {
    server.expect().get().withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings/testrb").andReturn(200, new RoleBindingBuilder().addToUserNames("unexpected").build()).once();
    server.expect().patch().withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings/testrb").andReturn(200, expectedRoleBinding).once();
    RoleBinding response = client.roleBindings().withName("testrb").patch(new RoleBindingBuilder().withNewMetadata().endMetadata().addNewSubject().withKind("User").withName("testuser1").endSubject().addNewSubject().withKind("User").withName("testuser2").endSubject().addNewSubject().withKind("ServiceAccount").withName("svcacct").endSubject().addNewSubject().withKind("Group").withName("testgroup").endSubject().build());
    assertEquals(expectedRoleBinding, response);
    assertEquals("[{\"op\":\"replace\",\"path\":\"/userNames/0\",\"value\":\"testuser1\"},{\"op\":\"add\",\"path\":\"/userNames/1\",\"value\":\"testuser2\"},{\"op\":\"add\",\"path\":\"/userNames/2\",\"value\":\"system:serviceaccount:test:svcacct\"},{\"op\":\"add\",\"path\":\"/metadata\",\"value\":{}},{\"op\":\"add\",\"path\":\"/groupNames\",\"value\":[\"testgroup\"]},{\"op\":\"add\",\"path\":\"/subjects\",\"value\":[{\"kind\":\"User\",\"name\":\"testuser1\"},{\"kind\":\"User\",\"name\":\"testuser2\"},{\"kind\":\"ServiceAccount\",\"name\":\"svcacct\",\"namespace\":\"test\"},{\"kind\":\"Group\",\"name\":\"testgroup\"}]}]", server.getLastRequest().getBody().readUtf8());
}
Also used : RoleBindingBuilder(io.fabric8.openshift.api.model.RoleBindingBuilder) RoleBinding(io.fabric8.openshift.api.model.RoleBinding) Test(org.junit.jupiter.api.Test)

Example 10 with RoleBindingBuilder

use of io.fabric8.openshift.api.model.RoleBindingBuilder in project kubernetes-client by fabric8io.

the class OpenshiftRoleBindingTest method testCreateWithUserNamesAndGroupsAndNoSubjects.

@Test
void testCreateWithUserNamesAndGroupsAndNoSubjects() throws Exception {
    server.expect().post().withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings").andReturn(201, expectedRoleBinding).once();
    RoleBinding response = client.roleBindings().create(new RoleBindingBuilder().withNewMetadata().endMetadata().addToUserNames("testuser1", "testuser2", "system:serviceaccount:test:svcacct").addToGroupNames("testgroup").build());
    assertEquals(expectedRoleBinding, response);
    assertEquals(expectedRoleBinding, new ObjectMapper().readerFor(RoleBinding.class).readValue(server.getLastRequest().getBody().inputStream()));
}
Also used : RoleBindingBuilder(io.fabric8.openshift.api.model.RoleBindingBuilder) RoleBinding(io.fabric8.openshift.api.model.RoleBinding) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Aggregations

RoleBindingBuilder (io.fabric8.kubernetes.api.model.rbac.RoleBindingBuilder)23 RoleBindingBuilder (io.fabric8.openshift.api.model.RoleBindingBuilder)13 Test (org.junit.jupiter.api.Test)13 RoleRefBuilder (io.fabric8.kubernetes.api.model.rbac.RoleRefBuilder)10 Subject (io.fabric8.kubernetes.api.model.rbac.Subject)10 SubjectBuilder (io.fabric8.kubernetes.api.model.rbac.SubjectBuilder)10 RoleBinding (io.fabric8.openshift.api.model.RoleBinding)10 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 RoleBinding (io.fabric8.kubernetes.api.model.rbac.RoleBinding)7 RoleRef (io.fabric8.kubernetes.api.model.rbac.RoleRef)6 Test (org.testng.annotations.Test)6 RoleBuilder (io.fabric8.kubernetes.api.model.rbac.RoleBuilder)4 RoleBindingList (io.fabric8.kubernetes.api.model.rbac.RoleBindingList)3 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)3 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)2 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)2 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)2 ServiceAccountBuilder (io.fabric8.kubernetes.api.model.ServiceAccountBuilder)2 ClusterRoleBindingBuilder (io.fabric8.kubernetes.api.model.rbac.ClusterRoleBindingBuilder)2 Role (io.fabric8.kubernetes.api.model.rbac.Role)2