Refine search
@Test public void testGetSecurityContextShouldFail() { testRequest(Operation::createGet, UriUtils.buildUriPath(PrincipalService.SELF_LINK, "no-such-user", PrincipalService.SECURITY_CONTEXT_SUFFIX), true, new IllegalStateException( "Expected exception != null when retrieving security context for a missing user"), null); }
@Test public void testProjectNameAndIndexServicesAreCreatedOnStart() { String projectNamesUri = UriUtils.buildUriPath(UniquePropertiesService.FACTORY_LINK, UniquePropertiesService.PROJECT_NAMES_ID); assertDocumentExists(projectNamesUri); String projectIndexesUri = UriUtils.buildUriPath(UniquePropertiesService.FACTORY_LINK, UniquePropertiesService.PROJECT_INDEXES_ID); assertDocumentExists(projectIndexesUri); }
@Test public void testGetPrincipalWithInvalidInput() { // Test with empty principal id. testRequest(Operation::createGet, PrincipalService.SELF_LINK, true, new IllegalStateException( "Expected exception != null when searching for principal with empty id."), null); // Test with non present principal id. testRequest(Operation::createGet, UriUtils.buildUriPath(PrincipalService.SELF_LINK, "no-such-user"), true, new IllegalStateException( "Expected exception != null when searching for non present principal."), null); }
@Test public void testBuildUserGroupState() { String testId = "testIdentifier"; String testIdSelfLink = UriUtils.buildUriPath(UserGroupService.FACTORY_LINK, testId); UserGroupState userGroupState = buildUserGroupState(testId); assertEquals(testIdSelfLink, userGroupState.documentSelfLink); }
@Test public void testFromLocalPrincipalToPrincipalOfTypeGroup() { LocalPrincipalState localPrincipal = new LocalPrincipalState(); localPrincipal.id = "superadmins"; localPrincipal.name = "Super Admins"; localPrincipal.type = LocalPrincipalType.GROUP; localPrincipal.groupMembersLinks = new ArrayList<>(); localPrincipal.groupMembersLinks.add(UriUtils .buildUriPath(LocalPrincipalFactoryService.SELF_LINK, "connie@admiral.com")); localPrincipal.groupMembersLinks.add( UriUtils.buildUriPath(LocalPrincipalFactoryService.SELF_LINK, "fritz@admiral.com")); Principal principal = fromLocalPrincipalToPrincipal(localPrincipal); assertEquals(localPrincipal.id, principal.id); assertEquals(localPrincipal.name, principal.name); assertEquals(PrincipalType.GROUP, principal.type); }
@Test public void testInitNoProxyNoList() throws Throwable { HostInitRegistryAdapterServiceConfig.startServices(host); ConfigurationState configurationState = getDocument(ConfigurationState.class, UriUtils.buildUriPath(ConfigurationFactoryService.SELF_LINK, RegistryAdapterService.REGISTRY_PROXY_PARAM_NAME)); assertEquals(RegistryAdapterService.REGISTRY_PROXY_PARAM_NAME + " should be " + RegistryAdapterService.REGISTRY_PROXY_NULL_VALUE, RegistryAdapterService.REGISTRY_PROXY_NULL_VALUE, configurationState.value); configurationState = getDocument(ConfigurationState.class, UriUtils.buildUriPath(ConfigurationFactoryService.SELF_LINK, RegistryAdapterService.REGISTRY_NO_PROXY_LIST_PARAM_NAME)); assertEquals(RegistryAdapterService.REGISTRY_NO_PROXY_LIST_PARAM_NAME + " should be " + RegistryAdapterService.REGISTRY_PROXY_NULL_VALUE, RegistryAdapterService.REGISTRY_PROXY_NULL_VALUE, configurationState.value); }
@Test public void testInitNoProxyWithList() throws Throwable { setProperty(RegistryAdapterService.REGISTRY_NO_PROXY_LIST_PARAM_NAME, noProxyList); HostInitRegistryAdapterServiceConfig.startServices(host); ConfigurationState configurationState = getDocument(ConfigurationState.class, UriUtils.buildUriPath(ConfigurationFactoryService.SELF_LINK, RegistryAdapterService.REGISTRY_PROXY_PARAM_NAME)); assertEquals(RegistryAdapterService.REGISTRY_PROXY_PARAM_NAME + " should be " + RegistryAdapterService.REGISTRY_PROXY_NULL_VALUE, RegistryAdapterService.REGISTRY_PROXY_NULL_VALUE, configurationState.value); configurationState = getDocument(ConfigurationState.class, UriUtils.buildUriPath(ConfigurationFactoryService.SELF_LINK, RegistryAdapterService.REGISTRY_NO_PROXY_LIST_PARAM_NAME)); assertEquals(RegistryAdapterService.REGISTRY_NO_PROXY_LIST_PARAM_NAME + " should be " + noProxyList, noProxyList, configurationState.value); }
@Test public void testInitWithProxyNoList() throws Throwable { setProperty(RegistryAdapterService.REGISTRY_PROXY_PARAM_NAME, proxyAddress); HostInitRegistryAdapterServiceConfig.startServices(host); ConfigurationState configurationState = getDocument(ConfigurationState.class, UriUtils.buildUriPath(ConfigurationFactoryService.SELF_LINK, RegistryAdapterService.REGISTRY_PROXY_PARAM_NAME)); assertEquals(RegistryAdapterService.REGISTRY_PROXY_PARAM_NAME + " should be " + proxyAddress, proxyAddress, configurationState.value); configurationState = getDocument(ConfigurationState.class, UriUtils.buildUriPath(ConfigurationFactoryService.SELF_LINK, RegistryAdapterService.REGISTRY_NO_PROXY_LIST_PARAM_NAME)); assertEquals(RegistryAdapterService.REGISTRY_NO_PROXY_LIST_PARAM_NAME + " should be " + RegistryAdapterService.REGISTRY_PROXY_NULL_VALUE, RegistryAdapterService.REGISTRY_PROXY_NULL_VALUE, configurationState.value); }
@Test public void testResourceGroupsAutoCreatedOnProjectCreate() { String projectId = Service.getId(project.documentSelfLink); String adminsResourceGroupLink = UriUtils.buildUriPath(ResourceGroupService.FACTORY_LINK, AuthRole.PROJECT_ADMIN.buildRoleWithSuffix(projectId)); String membersResourceGroupLink = UriUtils.buildUriPath(ResourceGroupService.FACTORY_LINK, AuthRole.PROJECT_MEMBER.buildRoleWithSuffix(projectId)); String viewersResourceGroupLink = UriUtils.buildUriPath(ResourceGroupService.FACTORY_LINK, AuthRole.PROJECT_VIEWER.buildRoleWithSuffix(projectId)); String extendedMembersResourceGroupLink = UriUtils.buildUriPath( ResourceGroupService.FACTORY_LINK, AuthRole.PROJECT_MEMBER_EXTENDED.buildRoleWithSuffix(projectId)); assertDocumentExists(adminsResourceGroupLink); assertDocumentExists(membersResourceGroupLink); assertDocumentExists(viewersResourceGroupLink); assertDocumentExists(extendedMembersResourceGroupLink); }
@Test public void testPatchUser() throws Throwable { String name = "Fritz Fritz"; LocalPrincipalState fritzState = new LocalPrincipalState(); fritzState.name = name; fritzState = doPatch(fritzState, UriUtils.buildUriPath( LocalPrincipalFactoryService.SELF_LINK, encode(USER_EMAIL_ADMIN))); assertEquals(name, fritzState.name); }
@Test public void testGetPrincipalWithValidInput() { Principal admin = testRequest(Operation::createGet, UriUtils.buildUriPath(PrincipalService.SELF_LINK, USER_EMAIL_ADMIN), false, null, Principal.class); assertNotNull(admin); assertEquals(USER_EMAIL_ADMIN, admin.id); Principal connie = testRequest(Operation::createGet, UriUtils.buildUriPath(PrincipalService.SELF_LINK, USER_EMAIL_CONNIE), false, null, Principal.class); assertNotNull(connie); assertEquals(USER_EMAIL_CONNIE, connie.id); assertTrue(connie.groups.contains(USER_GROUP_DEVELOPERS)); }
@Test public void testInitWithProxyWithList() throws Throwable { setProperty(RegistryAdapterService.REGISTRY_PROXY_PARAM_NAME, proxyAddress); setProperty(RegistryAdapterService.REGISTRY_NO_PROXY_LIST_PARAM_NAME, noProxyList); HostInitRegistryAdapterServiceConfig.startServices(host); ConfigurationState configurationState = getDocument(ConfigurationState.class, UriUtils.buildUriPath(ConfigurationFactoryService.SELF_LINK, RegistryAdapterService.REGISTRY_PROXY_PARAM_NAME)); assertEquals(RegistryAdapterService.REGISTRY_PROXY_PARAM_NAME + " should be " + proxyAddress, proxyAddress, configurationState.value); configurationState = getDocument(ConfigurationState.class, UriUtils.buildUriPath(ConfigurationFactoryService.SELF_LINK, RegistryAdapterService.REGISTRY_NO_PROXY_LIST_PARAM_NAME)); assertEquals(RegistryAdapterService.REGISTRY_NO_PROXY_LIST_PARAM_NAME + " should be " + noProxyList, noProxyList, configurationState.value); }
@Test public void testBuildProjectAdminsUserGroup() { UserGroupState userGroupState = buildProjectAdminsUserGroup(SAMPLE_PROJECT_ID); String id = AuthRole.PROJECT_ADMIN.buildRoleWithSuffix(SAMPLE_PROJECT_ID); String expectedSelfLink = UriUtils.buildUriPath(UserGroupService.FACTORY_LINK, id); assertEquals(expectedSelfLink, userGroupState.documentSelfLink); assertNotNull(userGroupState.query); }
@Test public void testBuildProjectMembersUserGroup() { UserGroupState userGroupState = buildProjectMembersUserGroup(SAMPLE_PROJECT_ID); String id = AuthRole.PROJECT_MEMBER.buildRoleWithSuffix(SAMPLE_PROJECT_ID); String expectedSelfLink = UriUtils.buildUriPath(UserGroupService.FACTORY_LINK, id); assertEquals(expectedSelfLink, userGroupState.documentSelfLink); assertNotNull(userGroupState.query); }
@Test public void testBuildProjectViewersUserGroup() { UserGroupState userGroupState = buildProjectViewersUserGroup(SAMPLE_PROJECT_ID); String id = AuthRole.PROJECT_VIEWER.buildRoleWithSuffix(SAMPLE_PROJECT_ID); String expectedSelfLink = UriUtils.buildUriPath(UserGroupService.FACTORY_LINK, id); assertEquals(expectedSelfLink, userGroupState.documentSelfLink); assertNotNull(userGroupState.query); }
@Test public void testGetSecurityContextShouldPass() throws GeneralSecurityException { // Assume the identity of admin, because basic user should not be able to use // PrincipalService and get data for other users. host.assumeIdentity(buildUserServicePath(USER_EMAIL_ADMIN)); SecurityContext securityContext = testRequest(Operation::createGet, UriUtils.buildUriPath(PrincipalService.SELF_LINK, USER_EMAIL_ADMIN, PrincipalService.SECURITY_CONTEXT_SUFFIX), false, null, SecurityContext.class); assertEquals(USER_EMAIL_ADMIN, securityContext.id); }
@Test public void testUserGroupsAutoCreatedOnProjectCreate() { String adminsLinks = UriUtils.buildUriPath(UserGroupService.FACTORY_LINK, AuthRole.PROJECT_ADMIN .buildRoleWithSuffix(Service.getId(project.documentSelfLink))); String membersLinks = UriUtils.buildUriPath(UserGroupService.FACTORY_LINK, AuthRole.PROJECT_MEMBER .buildRoleWithSuffix(Service.getId(project.documentSelfLink))); String viewersLinks = UriUtils.buildUriPath(UserGroupService.FACTORY_LINK, AuthRole.PROJECT_VIEWER .buildRoleWithSuffix(Service.getId(project.documentSelfLink))); assertDocumentExists(adminsLinks); assertDocumentExists(membersLinks); assertDocumentExists(viewersLinks); }
@Test public void testAssignRoleToUserGroup() throws Throwable { PrincipalRoleAssignment roleAssignment = new PrincipalRoleAssignment(); roleAssignment.add = new ArrayList<>(); roleAssignment.add.add(AuthRole.CLOUD_ADMIN.name()); doRoleAssignment(roleAssignment, USER_GROUP_DEVELOPERS); RoleState roleState = getDocument(RoleState.class, UriUtils.buildUriPath(RoleService.FACTORY_LINK, AuthRole.CLOUD_ADMIN .buildRoleWithSuffix(encode(USER_GROUP_DEVELOPERS)))); assertNotNull(roleState); assertEquals(UriUtils.buildUriPath(UserGroupService.FACTORY_LINK, encode(USER_GROUP_DEVELOPERS)), roleState.userGroupLink); }
@Test public void testNoSelectionWhenContainerWithSamePodButDifferentContextId() throws Throwable { ContainerDescription desc = createDescriptionsWithPodDefined("linked-container", 1).get(0); ContainerState container = createContainer(desc); String differentContextId = UUID.randomUUID().toString(); container.compositeComponentLink = UriUtils.buildUriPath( CompositeComponentFactoryService.SELF_LINK, differentContextId); doOperation(container, UriUtils.buildUri(host, container.documentSelfLink), false, Action.PUT); // marked as dependent, which means not the first container associated with a given pod state.customProperties.put(ContainerAllocationTaskState.FIELD_NAME_CONTEXT_POD_DEPENDENT, POD_ID); filter = new PodAffinityHostFilter(host, desc); Throwable e = filter(Arrays.asList(container.parentLink)); if (e == null) { fail("Expected exception for no container found."); } }
@Test public void testDoNotSelectContainerHostWhenContainerAlreadyProvisionedAndSameHostAndContextId() throws Throwable { ContainerDescription desc1 = createDescriptions(CONTAINER_NAME1); ContainerState container = createContainer(desc1, initialHostLinks.get(0)); assertEquals(UriUtils.buildUriPath( CompositeComponentFactoryService.SELF_LINK, state.contextId), container.compositeComponentLink); String[] anti_affinity = new String[] { ANTI_AFFINITY_PREFIX + CONTAINER_NAME1 }; ContainerDescription desc = createDescriptions(anti_affinity); filter = new ServiceAntiAffinityHostFilter(host, desc); expectedLinks.remove(container.parentLink); filter(expectedLinks); }