use of io.fabric8.kubernetes.api.model.rbac.RoleBinding in project che-server by eclipse-che.
the class OpenShiftProjectTest method testOpenShiftProjectPreparingRoleBindingWhenProjectDoesNotExistWithCheServerSA.
@Test(dependsOnMethods = "testOpenShiftProjectPreparingWhenProjectDoesNotExistWithCheServerSA")
public void testOpenShiftProjectPreparingRoleBindingWhenProjectDoesNotExistWithCheServerSA() throws Exception {
// given
prepareNamespaceGet(PROJECT_NAME);
Resource resource = prepareProjectResource(PROJECT_NAME);
doThrow(new KubernetesClientException("error", 403, null)).when(resource).get();
final MixedOperation mixedOperation = mock(MixedOperation.class);
final NonNamespaceOperation namespaceOperation = mock(NonNamespaceOperation.class);
doReturn(mixedOperation).when(openShiftCheServerClient).serviceAccounts();
when(mixedOperation.inNamespace(anyString())).thenReturn(namespaceOperation);
when(namespaceOperation.withName(anyString())).thenReturn(serviceAccountResource);
when(serviceAccountResource.get()).thenReturn(mock(ServiceAccount.class));
doReturn(projectRequestOperation).when(openShiftCheServerClient).projectrequests();
// doReturn(metadataNested).when(metadataNested).withName(anyString());
when(openShiftCheServerClient.roleBindings()).thenReturn(mixedRoleBindingOperation);
lenient().when(mixedRoleBindingOperation.inNamespace(anyString())).thenReturn(nonNamespaceRoleBindingOperation);
when(openShiftClient.currentUser()).thenReturn(new UserBuilder().withNewMetadata().withName("jdoe").endMetadata().build());
// when
openShiftProject.prepare(true, true, Map.of(), Map.of());
// then
ArgumentCaptor<RoleBinding> roleBindingArgumentCaptor = ArgumentCaptor.forClass(RoleBinding.class);
verify(nonNamespaceRoleBindingOperation).createOrReplace(roleBindingArgumentCaptor.capture());
RoleBinding roleBinding = roleBindingArgumentCaptor.getValue();
assertNotNull(roleBinding);
assertEquals(roleBinding.getMetadata().getName(), "admin");
assertEquals(roleBinding.getRoleRef().getName(), "admin");
assertEquals(roleBinding.getUserNames(), ImmutableList.of("jdoe"));
}
use of io.fabric8.kubernetes.api.model.rbac.RoleBinding in project kubernetes-client by fabric8io.
the class RoleBindingCrudTest method crudTest.
@Test
public void crudTest() {
RoleBinding roleBinding = new RoleBindingBuilder().withNewMetadata().withName("read-jobs").endMetadata().addToSubjects(0, new SubjectBuilder().withApiGroup("rbac.authorization.k8s.io").withKind("User").withName("jane").withNamespace("default").build()).withRoleRef(new RoleRefBuilder().withApiGroup("rbac.authorization.k8s.io").withKind("Role").withName("job-reader").build()).build();
// test of creation
roleBinding = client.rbac().roleBindings().create(roleBinding);
assertNotNull(roleBinding);
assertEquals("RoleBinding", roleBinding.getKind());
assertEquals("rbac.authorization.k8s.io/v1", roleBinding.getApiVersion());
assertNotNull(roleBinding.getMetadata());
assertEquals("read-jobs", roleBinding.getMetadata().getName());
assertNotNull(roleBinding.getSubjects());
assertEquals(1, roleBinding.getSubjects().size());
assertEquals("rbac.authorization.k8s.io", roleBinding.getSubjects().get(0).getApiGroup());
assertEquals("User", roleBinding.getSubjects().get(0).getKind());
assertEquals("jane", roleBinding.getSubjects().get(0).getName());
assertEquals("default", roleBinding.getSubjects().get(0).getNamespace());
assertNotNull(roleBinding.getRoleRef());
assertEquals("Role", roleBinding.getRoleRef().getKind());
assertEquals("job-reader", roleBinding.getRoleRef().getName());
assertEquals("rbac.authorization.k8s.io", roleBinding.getRoleRef().getApiGroup());
// test of list
RoleBindingList kubernetesRoleBindingList = client.rbac().roleBindings().list();
assertNotNull(kubernetesRoleBindingList);
assertNotNull(kubernetesRoleBindingList.getItems());
assertEquals(1, kubernetesRoleBindingList.getItems().size());
assertNotNull(kubernetesRoleBindingList.getItems().get(0));
assertEquals("RoleBinding", kubernetesRoleBindingList.getItems().get(0).getKind());
assertEquals("rbac.authorization.k8s.io/v1", kubernetesRoleBindingList.getItems().get(0).getApiVersion());
assertNotNull(kubernetesRoleBindingList.getItems().get(0).getMetadata());
assertEquals("read-jobs", kubernetesRoleBindingList.getItems().get(0).getMetadata().getName());
assertNotNull(kubernetesRoleBindingList.getItems().get(0).getSubjects());
assertEquals(1, kubernetesRoleBindingList.getItems().get(0).getSubjects().size());
assertEquals("rbac.authorization.k8s.io", kubernetesRoleBindingList.getItems().get(0).getSubjects().get(0).getApiGroup());
assertEquals("User", kubernetesRoleBindingList.getItems().get(0).getSubjects().get(0).getKind());
assertEquals("jane", kubernetesRoleBindingList.getItems().get(0).getSubjects().get(0).getName());
assertEquals("default", kubernetesRoleBindingList.getItems().get(0).getSubjects().get(0).getNamespace());
assertNotNull(kubernetesRoleBindingList.getItems().get(0).getRoleRef());
assertEquals("Role", kubernetesRoleBindingList.getItems().get(0).getRoleRef().getKind());
assertEquals("job-reader", kubernetesRoleBindingList.getItems().get(0).getRoleRef().getName());
assertEquals("rbac.authorization.k8s.io", kubernetesRoleBindingList.getItems().get(0).getRoleRef().getApiGroup());
// test of updation
roleBinding = client.rbac().roleBindings().withName("read-jobs").edit(r -> new RoleBindingBuilder(r).editSubject(0).withName("jane-new").endSubject().build());
assertNotNull(roleBinding);
assertEquals("RoleBinding", roleBinding.getKind());
assertEquals("rbac.authorization.k8s.io/v1", roleBinding.getApiVersion());
assertNotNull(roleBinding.getMetadata());
assertEquals("read-jobs", roleBinding.getMetadata().getName());
assertNotNull(roleBinding.getSubjects());
assertEquals(1, roleBinding.getSubjects().size());
assertEquals("rbac.authorization.k8s.io", roleBinding.getSubjects().get(0).getApiGroup());
assertEquals("User", roleBinding.getSubjects().get(0).getKind());
assertEquals("jane-new", roleBinding.getSubjects().get(0).getName());
assertEquals("default", roleBinding.getSubjects().get(0).getNamespace());
assertNotNull(roleBinding.getRoleRef());
assertEquals("Role", roleBinding.getRoleRef().getKind());
assertEquals("job-reader", roleBinding.getRoleRef().getName());
assertEquals("rbac.authorization.k8s.io", roleBinding.getRoleRef().getApiGroup());
// test of deletion
boolean deleted = client.rbac().roleBindings().delete();
assertTrue(deleted);
kubernetesRoleBindingList = client.rbac().roleBindings().list();
assertEquals(0, kubernetesRoleBindingList.getItems().size());
}
use of io.fabric8.kubernetes.api.model.rbac.RoleBinding in project kubernetes-client by fabric8io.
the class RoleBindingIT method get.
@Test
public void get() {
RoleBinding roleBinding = client.rbac().roleBindings().inNamespace(session.getNamespace()).withName("rb-get").get();
assertNotNull(roleBinding);
assertEquals("RoleBinding", roleBinding.getKind());
assertNotNull(roleBinding.getMetadata());
assertEquals("rb-get", roleBinding.getMetadata().getName());
assertNotNull(roleBinding.getSubjects());
assertEquals(1, roleBinding.getSubjects().size());
assertEquals("rbac.authorization.k8s.io", roleBinding.getSubjects().get(0).getApiGroup());
assertEquals("User", roleBinding.getSubjects().get(0).getKind());
assertEquals("jane", roleBinding.getSubjects().get(0).getName());
assertEquals("default", roleBinding.getSubjects().get(0).getNamespace());
assertNotNull(roleBinding.getRoleRef());
assertEquals("Role", roleBinding.getRoleRef().getKind());
assertEquals("job-reader", roleBinding.getRoleRef().getName());
assertEquals("rbac.authorization.k8s.io", roleBinding.getRoleRef().getApiGroup());
}
use of io.fabric8.kubernetes.api.model.rbac.RoleBinding in project kubernetes-client by fabric8io.
the class RoleBindingIT method load.
@Test
public void load() {
RoleBinding aRoleBinding = client.rbac().roleBindings().inNamespace(session.getNamespace()).load(getClass().getResourceAsStream("/test-kubernetesrolebinding.yml")).get();
assertNotNull(aRoleBinding);
assertEquals("RoleBinding", aRoleBinding.getKind());
assertNotNull(aRoleBinding.getMetadata());
assertEquals("read-jobs", aRoleBinding.getMetadata().getName());
assertNotNull(aRoleBinding.getSubjects());
assertEquals(1, aRoleBinding.getSubjects().size());
assertEquals("rbac.authorization.k8s.io", aRoleBinding.getSubjects().get(0).getApiGroup());
assertEquals("User", aRoleBinding.getSubjects().get(0).getKind());
assertEquals("jane", aRoleBinding.getSubjects().get(0).getName());
assertEquals("default", aRoleBinding.getSubjects().get(0).getNamespace());
assertNotNull(aRoleBinding.getRoleRef());
assertEquals("Role", aRoleBinding.getRoleRef().getKind());
assertEquals("job-reader", aRoleBinding.getRoleRef().getName());
assertEquals("rbac.authorization.k8s.io", aRoleBinding.getRoleRef().getApiGroup());
}
use of io.fabric8.kubernetes.api.model.rbac.RoleBinding in project kubernetes-client by fabric8io.
the class RoleBindingIT method list.
@Test
public void list() {
RoleBindingList roleBindingList = client.rbac().roleBindings().inNamespace(session.getNamespace()).withLabels(Collections.singletonMap("type", "io.fabric8.roleBindingIT")).list();
assertNotNull(roleBindingList);
assertNotNull(roleBindingList.getItems());
assertEquals(1, roleBindingList.getItems().size());
assertNotNull(roleBindingList.getItems().get(0));
assertEquals("RoleBinding", roleBindingList.getItems().get(0).getKind());
assertNotNull(roleBindingList.getItems().get(0).getMetadata());
assertEquals("rb-list", roleBindingList.getItems().get(0).getMetadata().getName());
assertNotNull(roleBindingList.getItems().get(0).getSubjects());
assertEquals(1, roleBindingList.getItems().get(0).getSubjects().size());
assertEquals("rbac.authorization.k8s.io", roleBindingList.getItems().get(0).getSubjects().get(0).getApiGroup());
assertEquals("User", roleBindingList.getItems().get(0).getSubjects().get(0).getKind());
assertEquals("jane", roleBindingList.getItems().get(0).getSubjects().get(0).getName());
assertEquals("default", roleBindingList.getItems().get(0).getSubjects().get(0).getNamespace());
assertNotNull(roleBindingList.getItems().get(0).getRoleRef());
assertEquals("Role", roleBindingList.getItems().get(0).getRoleRef().getKind());
assertEquals("job-reader", roleBindingList.getItems().get(0).getRoleRef().getName());
}
Aggregations