diff options
Diffstat (limited to 'aai-resources/src/test')
13 files changed, 108 insertions, 593 deletions
diff --git a/aai-resources/src/test/java/org/onap/aai/ResourcesTestConfiguration.java b/aai-resources/src/test/java/org/onap/aai/ResourcesTestConfiguration.java index 93b15192..0d7ff7ef 100644 --- a/aai-resources/src/test/java/org/onap/aai/ResourcesTestConfiguration.java +++ b/aai-resources/src/test/java/org/onap/aai/ResourcesTestConfiguration.java @@ -24,7 +24,6 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.security.KeyStore; import javax.net.ssl.SSLContext; @@ -63,20 +62,7 @@ public class ResourcesTestConfiguration { RestTemplate restTemplate = null; if (env.acceptsProfiles(Profiles.of(ResourcesProfiles.TWO_WAY_SSL, ResourcesProfiles.ONE_WAY_SSL))) { - char[] trustStorePassword = env.getProperty("server.ssl.trust-store-password").toCharArray(); - char[] keyStorePassword = env.getProperty("server.ssl.key-store-password").toCharArray(); - - String keyStore = env.getProperty("server.ssl.key-store"); - String trustStore = env.getProperty("server.ssl.trust-store"); - SSLContextBuilder sslContextBuilder = SSLContextBuilder.create(); - - if (env.acceptsProfiles(Profiles.of(ResourcesProfiles.TWO_WAY_SSL))) { - sslContextBuilder = - sslContextBuilder.loadKeyMaterial(loadPfx(keyStore, keyStorePassword), keyStorePassword); - } - - SSLContext sslContext = - sslContextBuilder.loadTrustMaterial(ResourceUtils.getFile(trustStore), trustStorePassword).build(); + SSLContext sslContext = SSLContextBuilder.create().build(); HttpClient client = HttpClients.custom().setSSLContext(sslContext) .setSSLHostnameVerifier((s, sslSession) -> true).build(); @@ -113,13 +99,4 @@ public class ResourcesTestConfiguration { return restTemplate; } - - private KeyStore loadPfx(String file, char[] password) throws Exception { - KeyStore keyStore = KeyStore.getInstance("PKCS12"); - File key = ResourceUtils.getFile(file); - try (InputStream in = new FileInputStream(key)) { - keyStore.load(in, password); - } - return keyStore; - } } diff --git a/aai-resources/src/test/java/org/onap/aai/config/WebClientConfiguration.java b/aai-resources/src/test/java/org/onap/aai/config/WebClientConfiguration.java index e412dede..e317ef0d 100644 --- a/aai-resources/src/test/java/org/onap/aai/config/WebClientConfiguration.java +++ b/aai-resources/src/test/java/org/onap/aai/config/WebClientConfiguration.java @@ -1,3 +1,23 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2025 Deutsche Telekom. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + package org.onap.aai.config; import java.time.Duration; @@ -7,7 +27,7 @@ import org.onap.aai.setup.SchemaVersions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.TestConfiguration; -import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.boot.test.web.server.LocalServerPort; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Primary; diff --git a/aai-resources/src/test/java/org/onap/aai/it/multitenancy/KeycloakTestConfiguration.java b/aai-resources/src/test/java/org/onap/aai/it/multitenancy/KeycloakTestConfiguration.java deleted file mode 100644 index 1e47c42d..00000000 --- a/aai-resources/src/test/java/org/onap/aai/it/multitenancy/KeycloakTestConfiguration.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.aai.it.multitenancy; - -import com.github.dockerjava.api.model.ExposedPort; -import com.github.dockerjava.api.model.HostConfig; -import com.github.dockerjava.api.model.PortBinding; -import com.github.dockerjava.api.model.Ports; - -import dasniko.testcontainers.keycloak.KeycloakContainer; - -import org.keycloak.adapters.springboot.KeycloakSpringBootProperties; -import org.keycloak.admin.client.Keycloak; -import org.keycloak.admin.client.KeycloakBuilder; -import org.keycloak.representations.adapters.config.AdapterConfig; -import org.springframework.boot.test.context.TestConfiguration; -import org.springframework.context.annotation.Bean; - -@TestConfiguration -class KeycloakTestConfiguration { - - @Bean - public AdapterConfig adapterConfig() { - return new KeycloakSpringBootProperties(); - } - - @Bean - KeycloakContainer keycloakContainer(KeycloakTestProperties properties) { - KeycloakContainer keycloak = - new KeycloakContainer("jboss/keycloak:12.0.4").withRealmImportFile(properties.realmJson) - .withCreateContainerCmdModifier(cmd -> cmd.withHostConfig(new HostConfig().withPortBindings( - new PortBinding(Ports.Binding.bindPort(Integer.parseInt(properties.port)), - new ExposedPort(8080))))); - keycloak.start(); - return keycloak; - } - - @Bean - Keycloak keycloakAdminClient(KeycloakContainer keycloak, KeycloakTestProperties properties) { - return KeycloakBuilder.builder().serverUrl(keycloak.getAuthServerUrl()).realm(properties.realm) - .clientId(properties.adminCli).username(keycloak.getAdminUsername()) - .password(keycloak.getAdminPassword()).build(); - } - - @Bean - RoleHandler roleHandler(Keycloak adminClient, KeycloakTestProperties properties) { - return new RoleHandler(adminClient, properties); - } - - @Bean - KeycloakTestProperties properties() { - return new KeycloakTestProperties(); - } -} diff --git a/aai-resources/src/test/java/org/onap/aai/it/multitenancy/KeycloakTestProperties.java b/aai-resources/src/test/java/org/onap/aai/it/multitenancy/KeycloakTestProperties.java deleted file mode 100644 index 7f1e34ce..00000000 --- a/aai-resources/src/test/java/org/onap/aai/it/multitenancy/KeycloakTestProperties.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.aai.it.multitenancy; - -import org.springframework.beans.factory.annotation.Value; - -class KeycloakTestProperties { - - @Value("${test.keycloak.realm.json}") - public String realmJson; - - @Value("${keycloak.realm}") - public String realm; - - @Value("${keycloak.resource}") - public String clientId; - - @Value("${test.keycloak.client.secret}") - public String clientSecret; - - @Value("${test.keycloak.admin.cli}") - public String adminCli; - - @Value("${test.keycloak.auth-server-port}") - public String port; - -} diff --git a/aai-resources/src/test/java/org/onap/aai/it/multitenancy/MultiTenancyIT.java b/aai-resources/src/test/java/org/onap/aai/it/multitenancy/MultiTenancyIT.java deleted file mode 100644 index 892b8e3e..00000000 --- a/aai-resources/src/test/java/org/onap/aai/it/multitenancy/MultiTenancyIT.java +++ /dev/null @@ -1,124 +0,0 @@ -/** - * ============LICENSE_START================================================== - * org.onap.aai - * =========================================================================== - * Copyright © 2017-2020 AT&T Intellectual Property. All rights reserved. - * =========================================================================== - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END==================================================== - */ - -package org.onap.aai.it.multitenancy; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import dasniko.testcontainers.keycloak.KeycloakContainer; -import org.junit.jupiter.api.Test; - -import java.util.Collections; - -import org.keycloak.admin.client.Keycloak; -import org.keycloak.admin.client.KeycloakBuilder; -import org.keycloak.representations.AccessTokenResponse; -import org.onap.aai.PayloadUtil; -import org.onap.aai.rest.AbstractSpringRestTest; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Import; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.test.context.TestPropertySource; - -@Import(KeycloakTestConfiguration.class) -@TestPropertySource(locations = "classpath:it/application-keycloak-test.properties") -public class MultiTenancyIT extends AbstractSpringRestTest { - - @Autowired - private KeycloakContainer keycloakContainer; - @Autowired - private RoleHandler roleHandler; - @Autowired - private KeycloakTestProperties properties; - - @Test - public void testCreateAndGetPnf() throws Exception { - baseUrl = "http://localhost:" + randomPort; - String endpoint = baseUrl + "/aai/v23/network/pnfs/pnf/pnf-1"; - ResponseEntity<String> responseEntity = null; - - // create pnf with ran (operator) - String username = "ran", password = "ran"; - headers = this.getHeaders(username, password); - httpEntity = new HttpEntity<String>(PayloadUtil.getResourcePayload("pnf.json"), headers); - responseEntity = restTemplate.exchange(endpoint, HttpMethod.PUT, httpEntity, String.class); - assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode()); - - // get pnf with bob (operator_readOnly) - username = "bob"; - password = "bob"; - headers = this.getHeaders(username, password); - httpEntity = new HttpEntity<String>("", headers); - responseEntity = restTemplate.exchange(endpoint, HttpMethod.GET, httpEntity, String.class); - assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); - - // get pnf with ted (selector) - username = "ted"; - password = "ted"; - headers = this.getHeaders(username, password); - httpEntity = new HttpEntity<String>("", headers); - responseEntity = restTemplate.exchange(endpoint, HttpMethod.GET, httpEntity, String.class); - assertEquals(HttpStatus.FORBIDDEN, responseEntity.getStatusCode()); - - // add role to ted and try to get pnf again - roleHandler.addToUser(RoleHandler.OPERATOR_READ_ONLY, username); - headers = this.getHeaders(username, password); - httpEntity = new HttpEntity<String>("", headers); - responseEntity = restTemplate.exchange(endpoint, HttpMethod.GET, httpEntity, String.class); - assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); - - // get pnf with ran - username = "ran"; - password = "ran"; - headers = this.getHeaders(username, password); - httpEntity = new HttpEntity<String>("", headers); - responseEntity = restTemplate.exchange(endpoint, HttpMethod.GET, httpEntity, String.class); - assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); - } - - private HttpHeaders getHeaders(String username, String password) { - HttpHeaders headers = new HttpHeaders(); - - headers.setContentType(MediaType.APPLICATION_JSON); - headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); - headers.add("Real-Time", "true"); - headers.add("X-FromAppId", "JUNIT"); - headers.add("X-TransactionId", "JUNIT"); - headers.add("Authorization", "Bearer " + getStringToken(username, password)); - - return headers; - } - - private String getStringToken(String username, String password) { - Keycloak keycloakClient = KeycloakBuilder.builder().serverUrl(keycloakContainer.getAuthServerUrl()) - .realm(properties.realm).clientId(properties.clientId).clientSecret(properties.clientSecret) - .username(username).password(password).build(); - - AccessTokenResponse tokenResponse = keycloakClient.tokenManager().getAccessToken(); - assertNotNull(tokenResponse); - return tokenResponse.getToken(); - } -} diff --git a/aai-resources/src/test/java/org/onap/aai/it/multitenancy/RoleHandler.java b/aai-resources/src/test/java/org/onap/aai/it/multitenancy/RoleHandler.java deleted file mode 100644 index c9c1fd23..00000000 --- a/aai-resources/src/test/java/org/onap/aai/it/multitenancy/RoleHandler.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.aai.it.multitenancy; - -import java.util.Collections; - -import org.keycloak.admin.client.Keycloak; -import org.keycloak.admin.client.resource.RealmResource; - -class RoleHandler { - - /** - * Following roles should be the same as given roles in multi-tenancy-realm json file - */ - final static String OPERATOR = "operator"; - final static String OPERATOR_READ_ONLY = "operator_readOnly"; - private final Keycloak adminClient; - private final KeycloakTestProperties properties; - - RoleHandler(Keycloak adminClient, KeycloakTestProperties properties) { - this.adminClient = adminClient; - this.properties = properties; - } - - void addToUser(String role, String username) { - RealmResource realm = adminClient.realm(properties.realm); - realm.users().get(username).roles().realmLevel() - .add(Collections.singletonList(realm.roles().get(role).toRepresentation())); - } - - void removeFromUser(String role, String username) { - RealmResource realm = adminClient.realm(properties.realm); - realm.users().get(username).roles().realmLevel() - .remove(Collections.singletonList(realm.roles().get(role).toRepresentation())); - } -} diff --git a/aai-resources/src/test/java/org/onap/aai/rest/AbstractSpringRestTest.java b/aai-resources/src/test/java/org/onap/aai/rest/AbstractSpringRestTest.java index adfa433a..edf905ee 100644 --- a/aai-resources/src/test/java/org/onap/aai/rest/AbstractSpringRestTest.java +++ b/aai-resources/src/test/java/org/onap/aai/rest/AbstractSpringRestTest.java @@ -36,7 +36,6 @@ import org.onap.aai.ResourcesTestConfiguration; import org.onap.aai.dbmap.AAIGraph; import org.onap.aai.exceptions.AAIException; import org.onap.aai.nodes.NodeIngestor; -import org.onap.aai.restclient.PropertyPasswordConfiguration; import org.onap.aai.util.AAIConfig; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -54,7 +53,7 @@ import org.springframework.web.client.RestTemplate; @Import(ResourcesTestConfiguration.class) @TestPropertySource(locations = "classpath:application-test.properties") -@ContextConfiguration(initializers = PropertyPasswordConfiguration.class) +@ContextConfiguration @EnableAutoConfiguration(exclude = {CassandraDataAutoConfiguration.class, CassandraAutoConfiguration.class}) // there is no running cassandra instance for the test @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = ResourcesApp.class) public abstract class AbstractSpringRestTest { diff --git a/aai-resources/src/test/java/org/onap/aai/rest/AuthenticationTest.java b/aai-resources/src/test/java/org/onap/aai/rest/AuthenticationTest.java new file mode 100644 index 00000000..446b3757 --- /dev/null +++ b/aai-resources/src/test/java/org/onap/aai/rest/AuthenticationTest.java @@ -0,0 +1,78 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2025 Deutsche Telekom. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.aai.rest; + +import java.time.Duration; +import java.util.Collections; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.onap.aai.config.AuthProperties; +import org.onap.aai.config.WebClientConfiguration; +import org.onap.aai.setup.SchemaVersions; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.server.LocalServerPort; +import org.springframework.context.annotation.Import; +import org.springframework.http.MediaType; +import org.springframework.test.web.reactive.server.WebTestClient; + +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@Import(WebClientConfiguration.class) +public class AuthenticationTest { + + @Autowired AuthProperties authProperties; + @Autowired SchemaVersions schemaVersions; + @LocalServerPort int port; + + WebTestClient webClient; + + @BeforeEach + void setup() { + webClient = WebTestClient.bindToServer() + .baseUrl("http://localhost:" + port + "/aai/" + schemaVersions.getDefaultVersion()) + .responseTimeout(Duration.ofSeconds(300)) + .defaultHeaders(headers -> { + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + headers.set("X-FromAppId", "test"); + headers.set("X-TransactionId", "someTransaction"); + }) + .build(); + } + + @Test + void thatServiceIsAuthenticated() { + webClient.get() + .uri("/cloud-infrastructure/pservers/pserver/pserver-hostname-test") + .exchange() + .expectStatus() + .isForbidden(); + + webClient.get() + .uri("/cloud-infrastructure/pservers/pserver/pserver-hostname-test") + .headers(headers -> headers.setBasicAuth(authProperties.getUsers().get(0).getUsername(), authProperties.getUsers().get(0).getPassword())) + .exchange() + .expectStatus() + .isNotFound(); + } + +} diff --git a/aai-resources/src/test/java/org/onap/aai/rest/ConfigurationTest.java b/aai-resources/src/test/java/org/onap/aai/rest/ConfigurationTest.java index 15c03cf8..51ab2aa1 100644 --- a/aai-resources/src/test/java/org/onap/aai/rest/ConfigurationTest.java +++ b/aai-resources/src/test/java/org/onap/aai/rest/ConfigurationTest.java @@ -35,7 +35,6 @@ import org.junit.jupiter.api.Test; import org.onap.aai.ResourcesApp; import org.onap.aai.ResourcesTestConfiguration; import org.onap.aai.config.SpringContextAware; -import org.onap.aai.restclient.PropertyPasswordConfiguration; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -61,7 +60,7 @@ import org.springframework.web.client.RestTemplate; @AutoConfigureMetrics @TestPropertySource(locations = "classpath:application-test.properties") -@ContextConfiguration(initializers = PropertyPasswordConfiguration.class, classes = {SpringContextAware.class}) +@ContextConfiguration(classes = {SpringContextAware.class}) @EnableAutoConfiguration(exclude={CassandraDataAutoConfiguration.class, CassandraAutoConfiguration.class}) // there is no running cassandra instance for the test @Import(ResourcesTestConfiguration.class) @SpringBootTest( diff --git a/aai-resources/src/test/java/org/onap/aai/rest/resources/ResourcesControllerTest.java b/aai-resources/src/test/java/org/onap/aai/rest/resources/ResourcesControllerTest.java index da7c0647..6d0dcbf1 100644 --- a/aai-resources/src/test/java/org/onap/aai/rest/resources/ResourcesControllerTest.java +++ b/aai-resources/src/test/java/org/onap/aai/rest/resources/ResourcesControllerTest.java @@ -99,71 +99,11 @@ import reactor.core.publisher.Mono; public class ResourcesControllerTest { private static final Logger logger = LoggerFactory.getLogger(ResourcesController.class.getName()); - private static final Set<Integer> VALID_HTTP_STATUS_CODES = new HashSet<>(); - protected static final MediaType APPLICATION_JSON = MediaType.valueOf("application/json"); - - static { - VALID_HTTP_STATUS_CODES.add(200); - VALID_HTTP_STATUS_CODES.add(201); - VALID_HTTP_STATUS_CODES.add(204); - } + private static final ObjectMapper mapper = new ObjectMapper(); @Autowired WebTestClient webClient; @Autowired SchemaVersions schemaVersions; - ObjectMapper mapper = new ObjectMapper(); - - private ResourcesController resourcesController; - private HttpHeaders httpHeaders; - private UriInfo uriInfo; - private MultivaluedMap<String, String> headersMultiMap; - private MultivaluedMap<String, String> queryParameters; - private List<String> aaiRequestContextList; - private List<MediaType> outputMediaTypes; - private String defaultSchemaVersion; - - @BeforeEach - public void setup() throws AAIException { - if(!AAIGraph.isInit()) { - AAIConfig.init(); - AAIGraph.getInstance(); - } - logger.info("Starting the setup for the integration tests of Rest Endpoints"); - - resourcesController = new ResourcesController(new ResourcesService()); - httpHeaders = Mockito.mock(HttpHeaders.class); - uriInfo = Mockito.mock(UriInfo.class); - - headersMultiMap = new MultivaluedHashMap<>(); - queryParameters = Mockito.spy(new MultivaluedHashMap<>()); - - headersMultiMap.add("X-FromAppId", "JUNIT"); - headersMultiMap.add("X-TransactionId", UUID.randomUUID().toString()); - headersMultiMap.add("Real-Time", "true"); - headersMultiMap.add("Accept", "application/json"); - headersMultiMap.add("aai-request-context", ""); - - outputMediaTypes = new ArrayList<>(); - outputMediaTypes.add(APPLICATION_JSON); - - aaiRequestContextList = new ArrayList<>(); - aaiRequestContextList.add(""); - defaultSchemaVersion = schemaVersions.getDefaultVersion().toString(); - - when(httpHeaders.getAcceptableMediaTypes()).thenReturn(outputMediaTypes); - when(httpHeaders.getRequestHeaders()).thenReturn(headersMultiMap); - - when(httpHeaders.getRequestHeader("aai-request-context")).thenReturn(aaiRequestContextList); - - when(uriInfo.getQueryParameters()).thenReturn(queryParameters); - when(uriInfo.getQueryParameters(false)).thenReturn(queryParameters); - - // TODO - Check if this is valid since RemoveDME2QueryParameters seems to be very unreasonable - Mockito.doReturn(null).when(queryParameters).remove(any()); - - when(httpHeaders.getMediaType()).thenReturn(APPLICATION_JSON); - } - @AfterEach public void tearDown() { JanusGraph janusGraph = AAIGraph.getInstance().getGraph(); @@ -423,11 +363,6 @@ public class ResourcesControllerTest { String patchData = "{\"in-maint\": false}"; - headersMultiMap.add("Content-Type", "application/json"); - - outputMediaTypes.remove(APPLICATION_JSON); - outputMediaTypes.add(MediaType.valueOf("application/merge-patch+json")); - webClient.patch() .uri(uri) .header("Content-Type", "application/merge-patch+json") @@ -496,12 +431,12 @@ public class ResourcesControllerTest { public String getResourcePayload(String resourceName) throws IOException { String rawPayload = IOUtils.toString(this.getClass().getResourceAsStream("/payloads/resource/" + resourceName + ".json"), StandardCharsets.UTF_8); - return String.format(rawPayload, defaultSchemaVersion); + return String.format(rawPayload, schemaVersions.getDefaultVersion()); } public String getRelationshipPayload(String relationshipName) throws IOException { String rawPayload = IOUtils.toString(this.getClass().getResourceAsStream("/payloads/relationship/" + relationshipName + ".json"), StandardCharsets.UTF_8); - return String.format(rawPayload, defaultSchemaVersion); + return String.format(rawPayload, schemaVersions.getDefaultVersion()); } public String getUri(String hostname) { diff --git a/aai-resources/src/test/resources/application-test.properties b/aai-resources/src/test/resources/application-test.properties index 622715d8..e2b11ad2 100644 --- a/aai-resources/src/test/resources/application-test.properties +++ b/aai-resources/src/test/resources/application-test.properties @@ -16,7 +16,6 @@ spring.sleuth.enabled=false spring.autoconfigure.exclude=\ org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\ org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,\ - org.keycloak.adapters.springboot.KeycloakAutoConfiguration,\ org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration,\ org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration @@ -28,17 +27,7 @@ server.tomcat.threads.min-spare=25 server.tomcat.max-idle-time=60000 server.local.startpath=src/main/resources/ -server.basic.auth.location=${server.local.startpath}etc/auth/realm.properties - server.port=8447 -server.ssl.enabled=false -#server.ssl.enabled-protocols=TLSv1.1,TLSv1.2 -#server.ssl.key-store=${server.local.startpath}etc/auth/aai_keystore -#server.ssl.key-store-password=password(OBF:1vn21ugu1saj1v9i1v941sar1ugw1vo0) -#server.ssl.trust-store=${server.local.startpath}etc/auth/aai_keystore -#server.ssl.trust-store-password=password(OBF:1vn21ugu1saj1v9i1v941sar1ugw1vo0) -#server.ssl.client-auth=want -#server.ssl.key-store-type=JKS # Removed deprecated DMaaP reference # dmaap.ribbon.listOfServers=localhost:3904 @@ -82,3 +71,6 @@ scrape.uri.metrics=true aai.notifications.enabled=false aai.graph.properties.path=src/test/resources/etc/appprops/janusgraph-realtime.properties +aai.basic-auth.enabled=true +aai.basic-auth.users[0].username=AAI +aai.basic-auth.users[0].password=AAI diff --git a/aai-resources/src/test/resources/it/application-keycloak-test.properties b/aai-resources/src/test/resources/it/application-keycloak-test.properties deleted file mode 100644 index 6fff1c1c..00000000 --- a/aai-resources/src/test/resources/it/application-keycloak-test.properties +++ /dev/null @@ -1,17 +0,0 @@ -test.keycloak.realm.json=it/multi-tenancy-realm.json -test.keycloak.client.secret=secret -test.keycloak.admin.cli=admin-cli -test.keycloak.auth-server-port=58180 - -keycloak.auth-server-url=http://localhost:58180/auth -keycloak.realm=aai-resources -keycloak.resource=aai-resources-app -keycloak.public-client=true -keycloak.principal-attribute=preferred_username - -keycloak.ssl-required=external -keycloak.bearer-only=true - -multi.tenancy.enabled=true -spring.profiles.active=production,keycloak -schema.version.list=v10,v11,v12,v13,v14,v29,v30 diff --git a/aai-resources/src/test/resources/it/multi-tenancy-realm.json b/aai-resources/src/test/resources/it/multi-tenancy-realm.json deleted file mode 100644 index 401187b2..00000000 --- a/aai-resources/src/test/resources/it/multi-tenancy-realm.json +++ /dev/null @@ -1,173 +0,0 @@ -{ - "id": "aai-resources", - "realm": "aai-resources", - "notBefore": 0, - "revokeRefreshToken": false, - "refreshTokenMaxReuse": 0, - "accessTokenLifespan": 300, - "accessTokenLifespanForImplicitFlow": 900, - "ssoSessionIdleTimeout": 1800, - "ssoSessionMaxLifespan": 36000, - "ssoSessionIdleTimeoutRememberMe": 0, - "ssoSessionMaxLifespanRememberMe": 0, - "offlineSessionIdleTimeout": 2592000, - "offlineSessionMaxLifespanEnabled": false, - "offlineSessionMaxLifespan": 5184000, - "clientSessionIdleTimeout": 0, - "clientSessionMaxLifespan": 0, - "clientOfflineSessionIdleTimeout": 0, - "clientOfflineSessionMaxLifespan": 0, - "accessCodeLifespan": 60, - "accessCodeLifespanUserAction": 300, - "accessCodeLifespanLogin": 1800, - "actionTokenGeneratedByAdminLifespan": 43200, - "actionTokenGeneratedByUserLifespan": 300, - "enabled": true, - "sslRequired": "external", - "registrationAllowed": false, - "registrationEmailAsUsername": false, - "rememberMe": false, - "verifyEmail": false, - "loginWithEmailAllowed": true, - "duplicateEmailsAllowed": false, - "resetPasswordAllowed": false, - "editUsernameAllowed": false, - "bruteForceProtected": false, - "permanentLockout": false, - "maxFailureWaitSeconds": 900, - "minimumQuickLoginWaitSeconds": 60, - "waitIncrementSeconds": 60, - "quickLoginCheckMilliSeconds": 1000, - "maxDeltaTimeSeconds": 43200, - "failureFactor": 30, - "users": [ - { - "username": "admin", - "enabled": true, - "credentials": [ - { - "type": "password", - "value": "admin" - } - ], - "clientRoles": { - "realm-management": ["manage-users", "view-clients", "view-realm", "view-users"] - } - }, - { - "id": "ran", - "username": "ran", - "enabled": true, - "credentials": [ - { - "type": "password", - "value": "ran" - } - ], - "realmRoles": [ - "operator" - ] - }, - { - "id": "bob", - "username": "bob", - "enabled": true, - "credentials": [ - { - "type": "password", - "value": "bob" - } - ], - "realmRoles": [ - "operator_readOnly" - ] - }, - { - "id": "ted", - "username": "ted", - "enabled": true, - "credentials": [ - { - "type": "password", - "value": "ted" - } - ], - "realmRoles": [ - "selector" - ] - } - ], - "roles": { - "realm": [ - { - "name": "operator", - "description": "Operator privileges" - }, - { - "name": "operator_readOnly", - "description": "Operator's read only privileges" - }, - { - "name": "selector", - "description": "Selector privileges" - }, - { - "name": "selector_readOnly", - "description": "Selector's read only privileges" - }, - { - "name": "admin", - "description": "Administrator privileges" - } - ] - }, - "clients": [ - { - "clientId": "aai-resources-app", - "enabled": true, - "secret": "secret", - "directAccessGrantsEnabled": true, - "authorizationServicesEnabled": true, - "authorizationSettings": { - "allowRemoteResourceManagement": true, - "policyEnforcementMode": "ENFORCING" - } - } - ], - "defaultDefaultClientScopes": [ - "roles", - "email", - "web-origins", - "profile", - "role_list" - ], - "clientScopes": [ - { - "id": "0f7dfd8b-c230-4664-8d77-da85bcc4fe2a", - "name": "roles", - "description": "OpenID Connect scope for add user roles to the access token", - "protocol": "openid-connect", - "attributes": { - "include.in.token.scope": "true", - "display.on.consent.screen": "true", - "consent.screen.text": "${rolesScopeConsentText}" - }, - "protocolMappers": [ - { - "id": "4b9f8798-8990-4c0d-87d3-034e72655e3b", - "name": "realm roles", - "protocol": "openid-connect", - "protocolMapper": "oidc-usermodel-realm-role-mapper", - "consentRequired": false, - "config": { - "multivalued": "true", - "user.attribute": "foo", - "access.token.claim": "true", - "claim.name": "realm_access.roles", - "jsonType.label": "String" - } - } - ] - } - ] -}
\ No newline at end of file |