ConfigurationState config = new ConfigurationState(); config.documentSelfLink = UriUtils.buildUriPath(ConfigurationFactoryService.SELF_LINK, FileUtil.USER_RESOURCES_PATH_VARIABLE);
ConfigurationState config = new ConfigurationState(); config.documentSelfLink = UriUtils.buildUriPath(ConfigurationFactoryService.SELF_LINK, FileUtil.USER_RESOURCES_PATH_VARIABLE);
ConfigurationState config = new ConfigurationState(); config.key = ConfigurationUtil.EMBEDDED_MODE_PROPERTY; config.value = Boolean.toString(true);
ConfigurationState config = new ConfigurationState(); config.key = "embedded"; config.value = Boolean.toString(true); clonedSecondContainer.tenantLinks.size()); config = new ConfigurationState(); config.key = "embedded"; config.value = Boolean.toString(false);
ConfigurationState config = new ConfigurationState(); config.key = RegistryHostConfigService.ALLOW_REGISTRY_PLAIN_HTTP_CONNECTION_PROP_NAME; config.value = Boolean.toString(true);
ConfigurationState body = new ConfigurationState(); body.key = SSL_TRUST_LAST_UPDATED_DOCUMENT_KEY; body.documentSelfLink = body.key;
ConfigurationState config = new ConfigurationState(); config.documentSelfLink = UriUtils.buildUriPath(ConfigurationFactoryService.SELF_LINK, FileUtil.USER_RESOURCES_PATH_VARIABLE);
private void notifyLastUpdatedSslTrustDocumentService() { ConfigurationState body = new ConfigurationState(); body.key = SslTrustCertificateService.SSL_TRUST_LAST_UPDATED_DOCUMENT_KEY; body.documentSelfLink = UriUtils.buildUriPath(ConfigurationFactoryService.SELF_LINK,
@Test public void testProjectAdminRestrictionsToConfiguration() throws Throwable { ConfigurationState config = new ConfigurationState(); config.key = "key"; config.value = "value"; // use cloud admin for creation of the state host.assumeIdentity(buildUserServicePath(USER_EMAIL_ADMIN)); ConfigurationState createdState = doPost(config, ConfigurationFactoryService.SELF_LINK); assertNotNull(createdState); assertNotNull(createdState.documentSelfLink); assertEquals(config.key, createdState.key); assertEquals(config.value, createdState.value); // switch role to project admin host.assumeIdentity(buildUserServicePath(USER_EMAIL_GLORIA)); // GET ConfigurationState retrievedState = getDocument(ConfigurationState.class, createdState.documentSelfLink); assertNotNull(retrievedState); // POST doPostWithRestrictionVerification(config, ConfigurationFactoryService.SELF_LINK); // PUT createdState.value = "updated-value"; doPutWithRestrictionVerification(createdState, ConfigurationFactoryService.SELF_LINK); // DELETE doDeleteWithRestrictionVerification(createdState, ConfigurationFactoryService.SELF_LINK); }
@Test public void testGetContentWhenNotEmbeddedWithXFrameOptions() throws Exception { URL resource = this.getClass() .getResource("/ui/com/vmware/admiral/UiService/container-icons/vmware/admiral.png"); RestrictiveFileContentService service = new RestrictiveFileContentService( new File(resource.toURI())); service.setSelfLink("/container-icons/vmware/admiral.png"); VerificationHost vh = new VerificationHost() { @Override public void sendRequest(Operation op) { op.fail(Operation.STATUS_CODE_NOT_FOUND); } }; service.setHost(vh); // see comment in RestrictiveFileContentService's isEmbedded assignment ConfigurationState config = new ConfigurationState(); config.key = ConfigurationUtil.EMBEDDED_MODE_PROPERTY; config.value = Boolean.toString(false); ConfigurationUtil.initialize(config); Operation get = new Operation() .setUri(UriUtils.buildUri("/container-icons/vmware/admiral.png")); service.handleGet(get); assertEquals(Operation.STATUS_CODE_OK, get.getStatusCode()); assertEquals("SAMEORIGIN", get.getResponseHeader(ConfigurationUtil.UI_FRAME_OPTIONS_HEADER)); }
@Test public void testCloudAdminHasAccessToConfiguration() throws Throwable { host.assumeIdentity(buildUserServicePath(USER_EMAIL_ADMIN)); ConfigurationState config = new ConfigurationState(); config.key = "key"; config.value = "value"; // POST ConfigurationState createdState = doPost(config, ConfigurationFactoryService.SELF_LINK); assertNotNull(createdState); assertNotNull(createdState.documentSelfLink); assertEquals(config.key, createdState.key); assertEquals(config.value, createdState.value); // GET ConfigurationState retrievedState = getDocument(ConfigurationState.class, createdState.documentSelfLink); assertNotNull(retrievedState); // PUT createdState.value = "updated-value"; ConfigurationState updatedState = doPut(createdState); assertNotNull(updatedState); assertTrue(createdState.value.equals(updatedState.value)); // DELETE doDelete(UriUtils.buildUri(host, createdState.documentSelfLink), false); retrievedState = getDocumentNoWait(ConfigurationState.class, createdState.documentSelfLink); assertNull(retrievedState); }
@Test public void testHarborVerifyOnProjectDelete() throws Throwable { ConfigurationState mockHarborUri = new ConfigurationState(); mockHarborUri.key = Harbor.CONFIGURATION_URL_PROPERTY_NAME; mockHarborUri.value = "test.uri"; mockHarborUri.documentSelfLink = Harbor.CONFIGURATION_URL_PROPERTY_NAME; mockHarborUri = doPost(mockHarborUri, ConfigurationFactoryService.SELF_LINK); assertNotNull(mockHarborUri); assertNotNull(mockHarborUri.documentSelfLink); ProjectState test = createProject("test-project"); assertNotNull(test.documentSelfLink); MockHarborApiProxyService.IS_PROJECT_DELETABLE.set(true); deleteProject(test); test = createProject("test-project"); assertNotNull(test.documentSelfLink); MockHarborApiProxyService.IS_PROJECT_DELETABLE.set(false); try { deleteProject(test); } catch (Throwable ex) { assertTrue(ex instanceof LocalizableValidationException); assertTrue(ex.getMessage() .contains("Project is not removable: mocked message")); } }
@Test public void testBasicUserRestrictionsToConfiguration() throws Throwable { ConfigurationState config = new ConfigurationState(); config.key = "key"; config.value = "value"; // use admin for creation of the state host.assumeIdentity(buildUserServicePath(USER_EMAIL_ADMIN)); ConfigurationState createdState = doPost(config, ConfigurationFactoryService.SELF_LINK); assertNotNull(createdState); assertNotNull(createdState.documentSelfLink); assertEquals(config.key, createdState.key); assertEquals(config.value, createdState.value); // switch role to basic user host.assumeIdentity(buildUserServicePath(USER_EMAIL_BASIC_USER)); // GET ConfigurationState retrievedState = getDocument(ConfigurationState.class, createdState.documentSelfLink); assertNotNull(retrievedState); // POST doPostWithRestrictionVerification(config, ConfigurationFactoryService.SELF_LINK); // PUT createdState.value = "updated-value"; doPutWithRestrictionVerification(createdState, ConfigurationFactoryService.SELF_LINK); // DELETE doDeleteWithRestrictionVerification(createdState, ConfigurationFactoryService.SELF_LINK); }
@Test public void testDeleteDefaultRegistryOnStartup() throws Throwable { RegistryState registryState = new RegistryState(); registryState.documentSelfLink = RegistryService.DEFAULT_INSTANCE_LINK; registryState.endpointType = RegistryState.DOCKER_REGISTRY_ENDPOINT_TYPE; registryState.address = RegistryService.DEFAULT_REGISTRY_ADDRESS; registryState = doPost(registryState, RegistryFactoryService.SELF_LINK); assertNotNull("Failed to create default registry", registryState); ConfigurationState config = new ConfigurationState(); config.key = RegistryService.DISABLE_DEFAULT_REGISTRY_PROP_NAME; config.value = Boolean.toString(true); ConfigurationUtil.initialize(config); RegistryService.buildDefaultStateInstance(host); waitFor("Ensure default registry is deleted.", () -> { List<String> resourceLinks = findResourceLinks(RegistryState.class, Collections.singletonList(RegistryService.DEFAULT_INSTANCE_LINK)); return resourceLinks.size() == 0; }); } }
@Test public void testGetExternalPopularImages() throws Throwable { // with the 'container.user.resources.path' configuration attribute set // the images of the popular-images.json file there will be returned HostInitCommonServiceConfig.startServices(host); waitForServiceAvailability(ConfigurationFactoryService.SELF_LINK); waitForServiceAvailability(UriUtils.buildUriPath(UriUtils.buildUriPath( ConfigurationFactoryService.SELF_LINK, FileUtil.USER_RESOURCES_PATH_VARIABLE))); ConfigurationState config = new ConfigurationState(); config.documentSelfLink = UriUtils.buildUriPath(ConfigurationFactoryService.SELF_LINK, FileUtil.USER_RESOURCES_PATH_VARIABLE); config.key = FileUtil.USER_RESOURCES_PATH_VARIABLE; config.value = Paths.get(PopularImagesServiceTest.class.getResource("/containers").toURI()) .toString(); ConfigurationState storedConfig = doPut(config); assertNotNull(storedConfig); HostInitImageServicesConfig.startServices(host); waitForServiceAvailability(PopularImagesService.SELF_LINK); Collection<?> images = getDocument(Collection.class, PopularImagesService.SELF_LINK); assertNotNull(images); assertEquals(5, images.size()); }
@Test public void testIdempotentPOST() throws Throwable { String selfLinkId = UUID.randomUUID().toString(); ConfigurationState configState1 = new ConfigurationState(); configState1.documentSelfLink = selfLinkId; configState1.key = key1; configState1.value = value1; configState1 = doPost(configState1, ConfigurationFactoryService.SELF_LINK); String value2 = "value2"; ConfigurationState configState2 = new ConfigurationState(); configState2.documentSelfLink = selfLinkId; configState2.key = key1; configState2.value = value2; configState2 = doPost(configState2, ConfigurationFactoryService.SELF_LINK); configurationState = getDocument(ConfigurationState.class, UriUtils.buildUriPath(ConfigurationFactoryService.SELF_LINK, selfLinkId)); // the value should be overridden because of VBV-1587 assertEquals(value2, configurationState.value); }
private void setConfigurationPropertyValue(String key, String value) throws Throwable { String propertySelfLink = UriUtils.buildUriPath(ConfigurationFactoryService.SELF_LINK, key); ConfigurationState configurationState = getDocumentNoWait(ConfigurationState.class, propertySelfLink); if (configurationState != null) { configurationState.documentSelfLink = propertySelfLink; configurationState.key = key; configurationState.value = value; doPut(configurationState); } else { configurationState = new ConfigurationState(); configurationState.documentSelfLink = propertySelfLink; configurationState.key = key; configurationState.value = value; doPost(configurationState, ConfigurationFactoryService.SELF_LINK); } }
/** * Uses java reflections to modify the {@link ConfigurationUtil#configProperties} list to * contain the appropriate entry for the <b>embedded</b> property for the * {@link ConfigurationUtil#isEmbedded()} method to return the same value as the provided * <code>isEmbedded</code> flag. For test purposes only. */ protected void toggleEmbeddedMode(boolean isEmbedded) throws Throwable { final String key = "embedded"; Field field = ConfigurationUtil.class.getDeclaredField("configProperties"); field.setAccessible(true); ConfigurationState embeddedConfig = new ConfigurationState(); embeddedConfig.key = key; embeddedConfig.value = Boolean.toString(isEmbedded); field.set(null, new ConfigurationState[] { embeddedConfig }); field.setAccessible(false); }
@Override public void sendRequest(Operation op) { String path = op.getUri().getPath(); if (path.equals(UriUtils.buildUriPath(ManagementUriParts.CONFIG_PROPS, Harbor.CONFIGURATION_URL_PROPERTY_NAME))) { ConfigurationState state = new ConfigurationState(); state.key = Harbor.CONFIGURATION_URL_PROPERTY_NAME; state.value = SAMPLE_HARBOR_URI.toString(); op.setBody(state); op.complete(); } else if (path.equals(SslTrustImportService.SELF_LINK)) { certificateImportCalled.set(true); } } };
@Override public void sendRequest(Operation op) { if (op.getUri().getPath().equals("/index.html")) { op.setBody("OK"); op.complete(); } else if (op.getUri().getPath().equals("/config/props/embedded")) { ConfigurationState body = new ConfigurationState(); body.key = ConfigurationUtil.EMBEDDED_MODE_PROPERTY; body.value = Boolean.toString(true); op.setBody(body); op.complete(); } else { op.fail(Operation.STATUS_CODE_NOT_FOUND); } } };