diff options
Diffstat (limited to 'app/src')
23 files changed, 166 insertions, 196 deletions
diff --git a/app/src/main/resources/application-access-control.yml b/app/src/main/resources/application-access-control.yml index 4da29f1..6fda781 100644 --- a/app/src/main/resources/application-access-control.yml +++ b/app/src/main/resources/application-access-control.yml @@ -1,21 +1,21 @@ -bff.access-control: - ACTIONS_CREATE: [ portal_admin, portal_designer, portal_operator ] - ACTIONS_GET: [ portal_admin, portal_designer, portal_operator ] - ACTIONS_LIST: [ portal_admin, portal_designer, portal_operator ] - ACTIVE_ALARM_LIST: [portal_admin, portal_designer, portal_operator] - KEY_ENCRYPT_BY_USER: [portal_admin, portal_designer, portal_operator] - KEY_ENCRYPT_BY_VALUE: [portal_admin, portal_designer, portal_operator] - PREFERENCES_CREATE: [portal_admin, portal_designer, portal_operator] - PREFERENCES_GET: [portal_admin, portal_designer, portal_operator] - PREFERENCES_UPDATE: [portal_admin, portal_designer, portal_operator] - ROLE_LIST: ["*"] - USER_CREATE: [portal_admin, portal_designer, portal_operator] - USER_DELETE: [portal_admin, portal_designer, portal_operator] - USER_GET: [portal_admin, portal_designer, portal_operator] - USER_LIST_AVAILABLE_ROLES: [portal_admin, portal_designer, portal_operator] - USER_LIST_ROLES: [portal_admin, portal_designer, portal_operator] - USER_LIST: [portal_admin, portal_designer, portal_operator] - USER_UPDATE_PASSWORD: [portal_admin, portal_designer, portal_operator] - USER_UPDATE_ROLES: [portal_admin, portal_designer, portal_operator] - USER_UPDATE: [portal_admin, portal_designer, portal_operator] - +bff: + access-control: + ACTIONS_CREATE: [ portal_admin, portal_designer, portal_operator ] + ACTIONS_GET: [ portal_admin, portal_designer, portal_operator ] + ACTIONS_LIST: [ portal_admin, portal_designer, portal_operator ] + ACTIVE_ALARM_LIST: [portal_admin, portal_designer, portal_operator] + KEY_ENCRYPT_BY_USER: [portal_admin, portal_designer, portal_operator] + KEY_ENCRYPT_BY_VALUE: [portal_admin, portal_designer, portal_operator] + PREFERENCES_CREATE: [portal_admin, portal_designer, portal_operator] + PREFERENCES_GET: [portal_admin, portal_designer, portal_operator] + PREFERENCES_UPDATE: [portal_admin, portal_designer, portal_operator] + ROLE_LIST: ["*"] + USER_CREATE: [portal_admin, portal_designer, portal_operator] + USER_DELETE: [portal_admin, portal_designer, portal_operator] + USER_GET: [portal_admin, portal_designer, portal_operator] + USER_LIST_AVAILABLE_ROLES: [portal_admin, portal_designer, portal_operator] + USER_LIST_ROLES: [portal_admin, portal_designer, portal_operator] + USER_LIST: [portal_admin, portal_designer, portal_operator] + USER_UPDATE_PASSWORD: [portal_admin, portal_designer, portal_operator] + USER_UPDATE_ROLES: [portal_admin, portal_designer, portal_operator] + USER_UPDATE: [portal_admin, portal_designer, portal_operator] diff --git a/app/src/main/resources/application.yml b/app/src/main/resources/application.yml index 367b33c..a99ff0b 100644 --- a/app/src/main/resources/application.yml +++ b/app/src/main/resources/application.yml @@ -52,4 +52,8 @@ bff: preferences-url: ${PREFERENCES_URL} history-url: ${HISTORY_URL} keycloak-url: ${KEYCLOAK_URL} + endpoints: + unauthenticated: /api-docs.html, /api.yaml, /webjars/**, /actuator/** + rbac: + endpoints-excluded: /actuator/**, **/actuator/**, */actuator/**, /**/actuator/**, /*/actuator/** diff --git a/app/src/test/java/org/onap/portalng/bff/BaseIntegrationTest.java b/app/src/test/java/org/onap/portalng/bff/BaseIntegrationTest.java index 1311ac7..a69516c 100644 --- a/app/src/test/java/org/onap/portalng/bff/BaseIntegrationTest.java +++ b/app/src/test/java/org/onap/portalng/bff/BaseIntegrationTest.java @@ -36,7 +36,7 @@ import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.UUID; -import org.apache.http.client.utils.URIBuilder; +import org.apache.hc.core5.net.URIBuilder; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.onap.portalng.bff.config.BffConfig; @@ -52,8 +52,8 @@ import org.springframework.context.annotation.Bean; import org.springframework.http.MediaType; /** Base class for all tests that has the common config including port, realm, logging and auth. */ -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @AutoConfigureWireMock(port = 0) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public abstract class BaseIntegrationTest { @TestConfiguration @@ -86,8 +86,7 @@ public abstract class BaseIntegrationTest { WireMock.stubFor( WireMock.get( - WireMock.urlMatching( - String.format("/realms/%s/protocol/openid-connect/certs", realm))) + WireMock.urlMatching("/realms/%s/protocol/openid-connect/certs".formatted(realm))) .willReturn( WireMock.aResponse() .withHeader("Content-Type", JWKSet.MIME_TYPE) @@ -98,8 +97,7 @@ public abstract class BaseIntegrationTest { WireMock.stubFor( WireMock.post( - WireMock.urlMatching( - String.format("/realms/%s/protocol/openid-connect/token", realm))) + WireMock.urlMatching("/realms/%s/protocol/openid-connect/token".formatted(realm))) .withBasicAuth("test", "test") .withRequestBody(WireMock.containing("grant_type=client_credentials")) .willReturn( diff --git a/app/src/test/java/org/onap/portalng/bff/TokenGenerator.java b/app/src/test/java/org/onap/portalng/bff/TokenGenerator.java index 0c6aa89..5ffe3ef 100644 --- a/app/src/test/java/org/onap/portalng/bff/TokenGenerator.java +++ b/app/src/test/java/org/onap/portalng/bff/TokenGenerator.java @@ -116,7 +116,7 @@ public class TokenGenerator { @Builder.Default private final List<String> roles = Collections.emptyList(); public String issuer() { - return String.format("http://localhost:%d/realms/%s", port, realm); + return "http://localhost:%d/realms/%s".formatted(port, realm); } } } diff --git a/app/src/test/java/org/onap/portalng/bff/actions/ActionsMocks.java b/app/src/test/java/org/onap/portalng/bff/actions/ActionsMocks.java index 39fc3dc..7275737 100644 --- a/app/src/test/java/org/onap/portalng/bff/actions/ActionsMocks.java +++ b/app/src/test/java/org/onap/portalng/bff/actions/ActionsMocks.java @@ -25,7 +25,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.github.tomakehurst.wiremock.client.WireMock; import com.github.tomakehurst.wiremock.matching.EqualToPattern; import io.restassured.http.Header; -import org.apache.http.HttpHeaders; +import org.apache.hc.core5.http.HttpHeaders; import org.onap.portalng.bff.BaseIntegrationTest; import org.onap.portalng.bff.openapi.client_history.model.ActionResponseHistoryDto; import org.onap.portalng.bff.openapi.client_history.model.ActionsListResponseHistoryDto; diff --git a/app/src/test/java/org/onap/portalng/bff/idtoken/IdTokenExchangeFilterFunctionTest.java b/app/src/test/java/org/onap/portalng/bff/idtoken/IdTokenExchangeFilterFunctionTest.java index cb6694a..b7491f2 100644 --- a/app/src/test/java/org/onap/portalng/bff/idtoken/IdTokenExchangeFilterFunctionTest.java +++ b/app/src/test/java/org/onap/portalng/bff/idtoken/IdTokenExchangeFilterFunctionTest.java @@ -30,6 +30,7 @@ import java.util.UUID; import org.junit.jupiter.api.Test; import org.onap.portalng.bff.BaseIntegrationTest; import org.onap.portalng.bff.config.IdTokenExchangeFilterFunction; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpMethod; import org.springframework.mock.http.server.reactive.MockServerHttpRequest; import org.springframework.mock.web.server.MockServerWebExchange; @@ -41,10 +42,10 @@ import reactor.core.publisher.Mono; class IdTokenExchangeFilterFunctionTest extends BaseIntegrationTest { + @Autowired IdTokenExchangeFilterFunction filterFunction; + @Test void idTokenIsCorrectlyPropagated() { - final IdTokenExchangeFilterFunction filterFunction = new IdTokenExchangeFilterFunction(); - final String idToken = UUID.randomUUID().toString(); final ServerWebExchange serverWebExchange = MockServerWebExchange.builder( @@ -72,8 +73,6 @@ class IdTokenExchangeFilterFunctionTest extends BaseIntegrationTest { @Test void exceptionIsThrownWhenIdTokenIsMissingInRequest() { - final IdTokenExchangeFilterFunction filterFunction = new IdTokenExchangeFilterFunction(); - final ServerWebExchange serverWebExchange = MockServerWebExchange.builder(MockServerHttpRequest.get("http://localhost:8000")).build(); diff --git a/app/src/test/java/org/onap/portalng/bff/preferences/CreatePreferencesIntegrationTest.java b/app/src/test/java/org/onap/portalng/bff/preferences/CreatePreferencesIntegrationTest.java index 3b16664..801ebb2 100644 --- a/app/src/test/java/org/onap/portalng/bff/preferences/CreatePreferencesIntegrationTest.java +++ b/app/src/test/java/org/onap/portalng/bff/preferences/CreatePreferencesIntegrationTest.java @@ -38,25 +38,29 @@ class CreatePreferencesIntegrationTest extends PreferencesMocks { void thatPreferencesCanBeCreated() throws Exception { PreferencesPreferencesDto preferencesPreferencesDto = new PreferencesPreferencesDto(); preferencesPreferencesDto.setProperties( - "{\n" - + "\"properties\": {\n" - + "\"appStarter\": \"value1\",\n" - + "\"dashboard\": {\"key1:\" : \"value2\"}\n" - + "}\n" - + "\n" - + "}"); + """ + { + "properties": { + "appStarter": "value1", + "dashboard": {"key1:" : "value2"} + } + + }\ + """); mockCreatePreferences(preferencesPreferencesDto); final CreatePreferencesRequestApiDto request = new CreatePreferencesRequestApiDto() .properties( - "{\n" - + "\"properties\": {\n" - + "\"appStarter\": \"value1\",\n" - + "\"dashboard\": {\"key1:\" : \"value2\"}\n" - + "}\n" - + "\n" - + "}"); + """ + { + "properties": { + "appStarter": "value1", + "dashboard": {"key1:" : "value2"} + } + + }\ + """); final PreferencesResponseApiDto response = createPreferences(request); assertThat(response).isNotNull(); assertThat(response.getProperties()).isEqualTo(preferencesPreferencesDto.getProperties()); @@ -72,25 +76,29 @@ class CreatePreferencesIntegrationTest extends PreferencesMocks { final PreferencesPreferencesDto preferencesPreferencesDto = new PreferencesPreferencesDto() .properties( - "{\n" - + "\"properties\": {\n" - + "\"appStarter\": \"value1\",\n" - + "\"dashboard\": {\"key1:\" : \"value2\"}\n" - + "}\n" - + "\n" - + "}"); + """ + { + "properties": { + "appStarter": "value1", + "dashboard": {"key1:" : "value2"} + } + + }\ + """); mockCreatePreferencesError(preferencesPreferencesDto, problemPreferencesDto); CreatePreferencesRequestApiDto responseBody = new CreatePreferencesRequestApiDto() .properties( - "{\n" - + "\"properties\": {\n" - + "\"appStarter\": \"value1\",\n" - + "\"dashboard\": {\"key1:\" : \"value2\"}\n" - + "}\n" - + "\n" - + "}"); + """ + { + "properties": { + "appStarter": "value1", + "dashboard": {"key1:" : "value2"} + } + + }\ + """); final ProblemApiDto response = requestSpecification() .given() diff --git a/app/src/test/java/org/onap/portalng/bff/preferences/PreferencesMocks.java b/app/src/test/java/org/onap/portalng/bff/preferences/PreferencesMocks.java index 9c5be75..64486c8 100644 --- a/app/src/test/java/org/onap/portalng/bff/preferences/PreferencesMocks.java +++ b/app/src/test/java/org/onap/portalng/bff/preferences/PreferencesMocks.java @@ -28,7 +28,7 @@ import com.github.tomakehurst.wiremock.matching.EqualToPattern; import io.restassured.http.Header; import java.io.File; import java.io.IOException; -import org.apache.http.HttpHeaders; +import org.apache.hc.core5.http.HttpHeaders; import org.onap.portalng.bff.BaseIntegrationTest; import org.onap.portalng.bff.openapi.client_preferences.model.PreferencesPreferencesDto; import org.onap.portalng.bff.openapi.client_preferences.model.ProblemPreferencesDto; diff --git a/app/src/test/java/org/onap/portalng/bff/preferences/UpdatePreferencesIntegrationTest.java b/app/src/test/java/org/onap/portalng/bff/preferences/UpdatePreferencesIntegrationTest.java index 1cd9a70..0c19b7d 100644 --- a/app/src/test/java/org/onap/portalng/bff/preferences/UpdatePreferencesIntegrationTest.java +++ b/app/src/test/java/org/onap/portalng/bff/preferences/UpdatePreferencesIntegrationTest.java @@ -38,25 +38,29 @@ class UpdatePreferencesIntegrationTest extends PreferencesMocks { void thatPreferencesCanBeUpdated() throws Exception { PreferencesPreferencesDto preferencesPreferencesDto = new PreferencesPreferencesDto(); preferencesPreferencesDto.setProperties( - "{\n" - + "\"properties\": {\n" - + "\"appStarter\": \"value1\",\n" - + "\"dashboard\": {\"key1:\" : \"value2\"}\n" - + "}\n" - + "\n" - + "}"); + """ + { + "properties": { + "appStarter": "value1", + "dashboard": {"key1:" : "value2"} + } + + }\ + """); mockUpdatePreferences(preferencesPreferencesDto); final CreatePreferencesRequestApiDto requestApiDto = new CreatePreferencesRequestApiDto() .properties( - "{\n" - + "\"properties\": {\n" - + "\"appStarter\": \"value1\",\n" - + "\"dashboard\": {\"key1:\" : \"value2\"}\n" - + "}\n" - + "\n" - + "}"); + """ + { + "properties": { + "appStarter": "value1", + "dashboard": {"key1:" : "value2"} + } + + }\ + """); final PreferencesResponseApiDto response = updatePreferences(requestApiDto); assertThat(response).isNotNull(); assertThat(response.getProperties()).isEqualTo(preferencesPreferencesDto.getProperties()); @@ -72,25 +76,29 @@ class UpdatePreferencesIntegrationTest extends PreferencesMocks { final PreferencesPreferencesDto preferencesPreferencesDto = new PreferencesPreferencesDto() .properties( - "{\n" - + "\"properties\": {\n" - + "\"appStarter\": \"value1\",\n" - + "\"dashboard\": {\"key1:\" : \"value2\"}\n" - + "}\n" - + "\n" - + "}"); + """ + { + "properties": { + "appStarter": "value1", + "dashboard": {"key1:" : "value2"} + } + + }\ + """); mockUpdatePreferencesError(preferencesPreferencesDto, problemPreferencesDto); CreatePreferencesRequestApiDto requestApiDto = new CreatePreferencesRequestApiDto() .properties( - "{\n" - + "\"properties\": {\n" - + "\"appStarter\": \"value1\",\n" - + "\"dashboard\": {\"key1:\" : \"value2\"}\n" - + "}\n" - + "\n" - + "}"); + """ + { + "properties": { + "appStarter": "value1", + "dashboard": {"key1:" : "value2"} + } + + }\ + """); final ProblemApiDto response = requestSpecification() .given() diff --git a/app/src/test/java/org/onap/portalng/bff/roles/ListRealmRolesIntegrationTest.java b/app/src/test/java/org/onap/portalng/bff/roles/ListRealmRolesIntegrationTest.java index d9fa9e0..8b0215b 100644 --- a/app/src/test/java/org/onap/portalng/bff/roles/ListRealmRolesIntegrationTest.java +++ b/app/src/test/java/org/onap/portalng/bff/roles/ListRealmRolesIntegrationTest.java @@ -59,7 +59,7 @@ class ListRealmRolesIntegrationTest extends RolesMocks { new ErrorResponseKeycloakDto().errorMessage("Some error message"); WireMock.stubFor( - WireMock.get(WireMock.urlMatching(String.format("/admin/realms/%s/roles", realm))) + WireMock.get(WireMock.urlMatching("/admin/realms/%s/roles".formatted(realm))) .willReturn( WireMock.aResponse() .withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE) diff --git a/app/src/test/java/org/onap/portalng/bff/roles/RolesMocks.java b/app/src/test/java/org/onap/portalng/bff/roles/RolesMocks.java index 2f61995..1422043 100644 --- a/app/src/test/java/org/onap/portalng/bff/roles/RolesMocks.java +++ b/app/src/test/java/org/onap/portalng/bff/roles/RolesMocks.java @@ -48,7 +48,7 @@ public class RolesMocks extends BaseIntegrationTest { protected void mockListRealmRoles(List<RoleKeycloakDto> roles) throws Exception { WireMock.stubFor( - WireMock.get(WireMock.urlMatching(String.format("/admin/realms/%s/roles", realm))) + WireMock.get(WireMock.urlMatching("/admin/realms/%s/roles".formatted(realm))) .willReturn( WireMock.aResponse() .withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE) diff --git a/app/src/test/java/org/onap/portalng/bff/users/CreateUserIntegrationTest.java b/app/src/test/java/org/onap/portalng/bff/users/CreateUserIntegrationTest.java index 7928c3b..51c870d 100644 --- a/app/src/test/java/org/onap/portalng/bff/users/CreateUserIntegrationTest.java +++ b/app/src/test/java/org/onap/portalng/bff/users/CreateUserIntegrationTest.java @@ -220,19 +220,17 @@ class CreateUserIntegrationTest extends BaseIntegrationTest { protected void mockCreateUser(UserKeycloakDto request, String userId) throws Exception { WireMock.stubFor( - WireMock.post(WireMock.urlMatching(String.format("/admin/realms/%s/users", realm))) + WireMock.post(WireMock.urlMatching("/admin/realms/%s/users".formatted(realm))) .withRequestBody(WireMock.equalToJson(objectMapper.writeValueAsString(request))) .willReturn( WireMock.aResponse() .withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE) - .withHeader( - "location", String.format("/admin/realms/%s/users/%s", realm, userId)))); + .withHeader("location", "/admin/realms/%s/users/%s".formatted(realm, userId)))); } protected void mockGetUser(String userId, UserKeycloakDto response) throws Exception { WireMock.stubFor( - WireMock.get( - WireMock.urlMatching(String.format("/admin/realms/%s/users/%s", realm, userId))) + WireMock.get(WireMock.urlMatching("/admin/realms/%s/users/%s".formatted(realm, userId))) .willReturn( WireMock.aResponse() .withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE) @@ -243,7 +241,7 @@ class CreateUserIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.post( WireMock.urlMatching( - String.format("/admin/realms/%s/users/%s/role-mappings/realm", realm, userId))) + "/admin/realms/%s/users/%s/role-mappings/realm".formatted(realm, userId))) .willReturn( WireMock.aResponse() .withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE) @@ -258,8 +256,7 @@ class CreateUserIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.put( WireMock.urlMatching( - String.format( - "/admin/realms/%s/users/%s/execute-actions-email", realm, userId))) + "/admin/realms/%s/users/%s/execute-actions-email".formatted(realm, userId))) .withRequestBody(WireMock.equalTo(objectMapper.writeValueAsString(request))) .willReturn( WireMock.aResponse() @@ -273,7 +270,7 @@ class CreateUserIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.get( WireMock.urlMatching( - String.format("/admin/realms/%s/users/%s/role-mappings/realm", realm, userID))) + "/admin/realms/%s/users/%s/role-mappings/realm".formatted(realm, userID))) .willReturn( WireMock.aResponse() .withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE) @@ -285,8 +282,7 @@ class CreateUserIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.put( WireMock.urlMatching( - String.format( - "/admin/realms/%s/users/%s/execute-actions-email", realm, userId))) + "/admin/realms/%s/users/%s/execute-actions-email".formatted(realm, userId))) .withRequestBody(WireMock.equalTo(objectMapper.writeValueAsString(request))) .willReturn( WireMock.aResponse().withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE))); @@ -294,7 +290,7 @@ class CreateUserIntegrationTest extends BaseIntegrationTest { protected void mockListRealmRoles(List<RoleKeycloakDto> roles) throws Exception { WireMock.stubFor( - WireMock.get(WireMock.urlMatching(String.format("/admin/realms/%s/roles", realm))) + WireMock.get(WireMock.urlMatching("/admin/realms/%s/roles".formatted(realm))) .willReturn( WireMock.aResponse() .withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE) diff --git a/app/src/test/java/org/onap/portalng/bff/users/DeleteUserIntegrationTest.java b/app/src/test/java/org/onap/portalng/bff/users/DeleteUserIntegrationTest.java index 15ba9ee..61cff96 100644 --- a/app/src/test/java/org/onap/portalng/bff/users/DeleteUserIntegrationTest.java +++ b/app/src/test/java/org/onap/portalng/bff/users/DeleteUserIntegrationTest.java @@ -37,7 +37,7 @@ class DeleteUserIntegrationTest extends BaseIntegrationTest { @Test void userCanBeDeleted() { WireMock.stubFor( - WireMock.delete(WireMock.urlMatching(String.format("/admin/realms/%s/users/1", realm))) + WireMock.delete(WireMock.urlMatching("/admin/realms/%s/users/1".formatted(realm))) .willReturn(WireMock.aResponse().withStatus(204))); requestSpecification() @@ -55,7 +55,7 @@ class DeleteUserIntegrationTest extends BaseIntegrationTest { new ErrorResponseKeycloakDto().errorMessage("Some error message"); WireMock.stubFor( - WireMock.delete(WireMock.urlMatching(String.format("/admin/realms/%s/users/1", realm))) + WireMock.delete(WireMock.urlMatching("/admin/realms/%s/users/1".formatted(realm))) .willReturn( WireMock.aResponse() .withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE) diff --git a/app/src/test/java/org/onap/portalng/bff/users/GetUserDetailIntegrationTest.java b/app/src/test/java/org/onap/portalng/bff/users/GetUserDetailIntegrationTest.java index 337d3e3..c26ce2e 100644 --- a/app/src/test/java/org/onap/portalng/bff/users/GetUserDetailIntegrationTest.java +++ b/app/src/test/java/org/onap/portalng/bff/users/GetUserDetailIntegrationTest.java @@ -46,7 +46,7 @@ class GetUserDetailIntegrationTest extends BaseIntegrationTest { new UserKeycloakDto().id("1").username("user1").email("user1@localhost").enabled(true); WireMock.stubFor( - WireMock.get(WireMock.urlMatching(String.format("/admin/realms/%s/users/1", realm))) + WireMock.get(WireMock.urlMatching("/admin/realms/%s/users/1".formatted(realm))) .willReturn( WireMock.aResponse() .withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE) @@ -85,7 +85,7 @@ class GetUserDetailIntegrationTest extends BaseIntegrationTest { new ErrorResponseKeycloakDto().errorMessage("Some error message"); WireMock.stubFor( - WireMock.get(WireMock.urlMatching(String.format("/admin/realms/%s/users/1", realm))) + WireMock.get(WireMock.urlMatching("/admin/realms/%s/users/1".formatted(realm))) .willReturn( WireMock.aResponse() .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) @@ -117,7 +117,7 @@ class GetUserDetailIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.get( WireMock.urlMatching( - String.format("/admin/realms/%s/users/%s/role-mappings/realm", realm, userID))) + "/admin/realms/%s/users/%s/role-mappings/realm".formatted(realm, userID))) .willReturn( WireMock.aResponse() .withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE) diff --git a/app/src/test/java/org/onap/portalng/bff/users/ListAssignedRolesIntegrationTest.java b/app/src/test/java/org/onap/portalng/bff/users/ListAssignedRolesIntegrationTest.java index 901308c..d06fb3a 100644 --- a/app/src/test/java/org/onap/portalng/bff/users/ListAssignedRolesIntegrationTest.java +++ b/app/src/test/java/org/onap/portalng/bff/users/ListAssignedRolesIntegrationTest.java @@ -47,7 +47,7 @@ class ListAssignedRolesIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.get( WireMock.urlMatching( - String.format("/admin/realms/%s/users/1/role-mappings/realm", realm))) + "/admin/realms/%s/users/1/role-mappings/realm".formatted(realm))) .willReturn( WireMock.aResponse() .withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE) @@ -82,7 +82,7 @@ class ListAssignedRolesIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.get( WireMock.urlMatching( - String.format("/admin/realms/%s/users/1/role-mappings/realm", realm))) + "/admin/realms/%s/users/1/role-mappings/realm".formatted(realm))) .willReturn( WireMock.aResponse() .withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE) diff --git a/app/src/test/java/org/onap/portalng/bff/users/ListAvailableRolesIntegrationTest.java b/app/src/test/java/org/onap/portalng/bff/users/ListAvailableRolesIntegrationTest.java index 06d9b89..87579eb 100644 --- a/app/src/test/java/org/onap/portalng/bff/users/ListAvailableRolesIntegrationTest.java +++ b/app/src/test/java/org/onap/portalng/bff/users/ListAvailableRolesIntegrationTest.java @@ -47,7 +47,7 @@ class ListAvailableRolesIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.get( WireMock.urlMatching( - String.format("/admin/realms/%s/users/1/role-mappings/realm/available", realm))) + "/admin/realms/%s/users/1/role-mappings/realm/available".formatted(realm))) .willReturn( WireMock.aResponse() .withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE) @@ -82,7 +82,7 @@ class ListAvailableRolesIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.get( WireMock.urlMatching( - String.format("/admin/realms/%s/users/1/role-mappings/realm/available", realm))) + "/admin/realms/%s/users/1/role-mappings/realm/available".formatted(realm))) .willReturn( WireMock.aResponse() .withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE) diff --git a/app/src/test/java/org/onap/portalng/bff/users/ListUsersIntegrationTest.java b/app/src/test/java/org/onap/portalng/bff/users/ListUsersIntegrationTest.java index 2b5fdb4..93c83f4 100644 --- a/app/src/test/java/org/onap/portalng/bff/users/ListUsersIntegrationTest.java +++ b/app/src/test/java/org/onap/portalng/bff/users/ListUsersIntegrationTest.java @@ -162,7 +162,7 @@ class ListUsersIntegrationTest extends BaseIntegrationTest { protected void mockGetUserCount(Integer userCount) { WireMock.stubFor( - WireMock.get(WireMock.urlMatching(String.format("/admin/realms/%s/users/count", realm))) + WireMock.get(WireMock.urlMatching("/admin/realms/%s/users/count".formatted(realm))) .willReturn( WireMock.aResponse() .withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE) @@ -174,7 +174,7 @@ class ListUsersIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.get( WireMock.urlMatching( - String.format("/admin/realms/%s/users\\?first=%s&max=%s", realm, first, max))) + "/admin/realms/%s/users\\?first=%s&max=%s".formatted(realm, first, max))) .willReturn( WireMock.aResponse() .withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE) @@ -183,7 +183,7 @@ class ListUsersIntegrationTest extends BaseIntegrationTest { protected void mockListRealmRoles(List<RoleKeycloakDto> roles) throws Exception { WireMock.stubFor( - WireMock.get(WireMock.urlMatching(String.format("/admin/realms/%s/roles", realm))) + WireMock.get(WireMock.urlMatching("/admin/realms/%s/roles".formatted(realm))) .willReturn( WireMock.aResponse() .withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE) @@ -194,8 +194,7 @@ class ListUsersIntegrationTest extends BaseIntegrationTest { throws Exception { WireMock.stubFor( WireMock.get( - WireMock.urlMatching( - String.format("/admin/realms/%s/roles/%s/users", realm, roleName))) + WireMock.urlMatching("/admin/realms/%s/roles/%s/users".formatted(realm, roleName))) .willReturn( WireMock.aResponse() .withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE) @@ -225,7 +224,7 @@ class ListUsersIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.get( WireMock.urlMatching( - String.format("/admin/realms/%s/users\\?first=%s&max=%s", realm, first, max))) + "/admin/realms/%s/users\\?first=%s&max=%s".formatted(realm, first, max))) .willReturn( WireMock.aResponse() .withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE) diff --git a/app/src/test/java/org/onap/portalng/bff/users/UpdateAssignedRolesIntegrationTest.java b/app/src/test/java/org/onap/portalng/bff/users/UpdateAssignedRolesIntegrationTest.java index 9fcff3b..d3b3de3 100644 --- a/app/src/test/java/org/onap/portalng/bff/users/UpdateAssignedRolesIntegrationTest.java +++ b/app/src/test/java/org/onap/portalng/bff/users/UpdateAssignedRolesIntegrationTest.java @@ -54,7 +54,7 @@ class UpdateAssignedRolesIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.get( WireMock.urlMatching( - String.format("/admin/realms/%s/users/1/role-mappings/realm/available", realm))) + "/admin/realms/%s/users/1/role-mappings/realm/available".formatted(realm))) .inScenario("test") .whenScenarioStateIs(Scenario.STARTED) .willReturn( @@ -65,7 +65,7 @@ class UpdateAssignedRolesIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.get( WireMock.urlMatching( - String.format("/admin/realms/%s/users/1/role-mappings/realm", realm))) + "/admin/realms/%s/users/1/role-mappings/realm".formatted(realm))) .inScenario("test") .whenScenarioStateIs(Scenario.STARTED) .willReturn( @@ -76,7 +76,7 @@ class UpdateAssignedRolesIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.post( WireMock.urlMatching( - String.format("/admin/realms/%s/users/1/role-mappings/realm", realm))) + "/admin/realms/%s/users/1/role-mappings/realm".formatted(realm))) .inScenario("test") .whenScenarioStateIs(Scenario.STARTED) .withRequestBody(WireMock.equalTo(objectMapper.writeValueAsString(keycloakRolesToAdd))) @@ -86,7 +86,7 @@ class UpdateAssignedRolesIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.get( WireMock.urlMatching( - String.format("/admin/realms/%s/users/1/role-mappings/realm", realm))) + "/admin/realms/%s/users/1/role-mappings/realm".formatted(realm))) .inScenario("test") .whenScenarioStateIs("rolesUpdated") .willReturn( @@ -137,7 +137,7 @@ class UpdateAssignedRolesIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.get( WireMock.urlMatching( - String.format("/admin/realms/%s/users/1/role-mappings/realm/available", realm))) + "/admin/realms/%s/users/1/role-mappings/realm/available".formatted(realm))) .inScenario("test") .whenScenarioStateIs(Scenario.STARTED) .willReturn( @@ -148,7 +148,7 @@ class UpdateAssignedRolesIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.get( WireMock.urlMatching( - String.format("/admin/realms/%s/users/1/role-mappings/realm", realm))) + "/admin/realms/%s/users/1/role-mappings/realm".formatted(realm))) .inScenario("test") .whenScenarioStateIs(Scenario.STARTED) .willReturn( @@ -159,7 +159,7 @@ class UpdateAssignedRolesIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.delete( WireMock.urlMatching( - String.format("/admin/realms/%s/users/1/role-mappings/realm", realm))) + "/admin/realms/%s/users/1/role-mappings/realm".formatted(realm))) .inScenario("test") .whenScenarioStateIs(Scenario.STARTED) .withRequestBody( @@ -169,7 +169,7 @@ class UpdateAssignedRolesIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.post( WireMock.urlMatching( - String.format("/admin/realms/%s/users/1/role-mappings/realm", realm))) + "/admin/realms/%s/users/1/role-mappings/realm".formatted(realm))) .inScenario("test") .whenScenarioStateIs(Scenario.STARTED) .withRequestBody(WireMock.equalTo(objectMapper.writeValueAsString(keycloakRolesToAdd))) @@ -179,7 +179,7 @@ class UpdateAssignedRolesIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.get( WireMock.urlMatching( - String.format("/admin/realms/%s/users/1/role-mappings/realm", realm))) + "/admin/realms/%s/users/1/role-mappings/realm".formatted(realm))) .inScenario("test") .whenScenarioStateIs("rolesUpdated") .willReturn( @@ -224,7 +224,7 @@ class UpdateAssignedRolesIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.get( WireMock.urlMatching( - String.format("/admin/realms/%s/users/1/role-mappings/realm/available", realm))) + "/admin/realms/%s/users/1/role-mappings/realm/available".formatted(realm))) .willReturn( WireMock.aResponse() .withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE) @@ -233,7 +233,7 @@ class UpdateAssignedRolesIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.delete( WireMock.urlMatching( - String.format("/admin/realms/%s/users/1/role-mappings/realm", realm))) + "/admin/realms/%s/users/1/role-mappings/realm".formatted(realm))) .withRequestBody( WireMock.equalTo(objectMapper.writeValueAsString(keycloakRolesToRemove))) .willReturn(WireMock.aResponse().withStatus(HttpStatus.NO_CONTENT.value()))); @@ -241,7 +241,7 @@ class UpdateAssignedRolesIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.get( WireMock.urlMatching( - String.format("/admin/realms/%s/users/1/role-mappings/realm", realm))) + "/admin/realms/%s/users/1/role-mappings/realm".formatted(realm))) .willReturn( WireMock.aResponse() .withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE) @@ -285,7 +285,7 @@ class UpdateAssignedRolesIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.get( WireMock.urlMatching( - String.format("/admin/realms/%s/users/1/role-mappings/realm/available", realm))) + "/admin/realms/%s/users/1/role-mappings/realm/available".formatted(realm))) .inScenario("test") .whenScenarioStateIs(Scenario.STARTED) .willReturn( @@ -296,7 +296,7 @@ class UpdateAssignedRolesIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.get( WireMock.urlMatching( - String.format("/admin/realms/%s/users/1/role-mappings/realm", realm))) + "/admin/realms/%s/users/1/role-mappings/realm".formatted(realm))) .inScenario("test") .whenScenarioStateIs(Scenario.STARTED) .willReturn( @@ -307,7 +307,7 @@ class UpdateAssignedRolesIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.post( WireMock.urlMatching( - String.format("/admin/realms/%s/users/1/role-mappings/realm", realm))) + "/admin/realms/%s/users/1/role-mappings/realm".formatted(realm))) .inScenario("test") .whenScenarioStateIs(Scenario.STARTED) .withRequestBody(WireMock.equalTo(objectMapper.writeValueAsString(keycloakRolesToAdd))) @@ -317,7 +317,7 @@ class UpdateAssignedRolesIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.get( WireMock.urlMatching( - String.format("/admin/realms/%s/users/1/role-mappings/realm", realm))) + "/admin/realms/%s/users/1/role-mappings/realm".formatted(realm))) .inScenario("test") .whenScenarioStateIs("rolesUpdated") .willReturn( @@ -370,7 +370,7 @@ class UpdateAssignedRolesIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.get( WireMock.urlMatching( - String.format("/admin/realms/%s/users/1/role-mappings/realm/available", realm))) + "/admin/realms/%s/users/1/role-mappings/realm/available".formatted(realm))) .inScenario("test") .whenScenarioStateIs(Scenario.STARTED) .willReturn( @@ -381,7 +381,7 @@ class UpdateAssignedRolesIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.get( WireMock.urlMatching( - String.format("/admin/realms/%s/users/1/role-mappings/realm", realm))) + "/admin/realms/%s/users/1/role-mappings/realm".formatted(realm))) .inScenario("test") .whenScenarioStateIs(Scenario.STARTED) .willReturn( @@ -393,7 +393,7 @@ class UpdateAssignedRolesIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.delete( WireMock.urlMatching( - String.format("/admin/realms/%s/users/1/role-mappings/realm", realm))) + "/admin/realms/%s/users/1/role-mappings/realm".formatted(realm))) .inScenario("test") .whenScenarioStateIs(Scenario.STARTED) .withRequestBody( @@ -403,7 +403,7 @@ class UpdateAssignedRolesIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.post( WireMock.urlMatching( - String.format("/admin/realms/%s/users/1/role-mappings/realm", realm))) + "/admin/realms/%s/users/1/role-mappings/realm".formatted(realm))) .inScenario("test") .whenScenarioStateIs(Scenario.STARTED) .withRequestBody(WireMock.equalTo(objectMapper.writeValueAsString(keycloakRolesToAdd))) @@ -413,7 +413,7 @@ class UpdateAssignedRolesIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.get( WireMock.urlMatching( - String.format("/admin/realms/%s/users/1/role-mappings/realm", realm))) + "/admin/realms/%s/users/1/role-mappings/realm".formatted(realm))) .inScenario("test") .whenScenarioStateIs("rolesUpdated") .willReturn( diff --git a/app/src/test/java/org/onap/portalng/bff/users/UpdateUserIntegrationTest.java b/app/src/test/java/org/onap/portalng/bff/users/UpdateUserIntegrationTest.java index 349909f..ee62a50 100644 --- a/app/src/test/java/org/onap/portalng/bff/users/UpdateUserIntegrationTest.java +++ b/app/src/test/java/org/onap/portalng/bff/users/UpdateUserIntegrationTest.java @@ -66,7 +66,7 @@ class UpdateUserIntegrationTest extends BaseIntegrationTest { final UserKeycloakDto keycloakRequest = new UserKeycloakDto().firstName("User1").enabled(false); WireMock.stubFor( - WireMock.put(WireMock.urlMatching(String.format("/admin/realms/%s/users/1", realm))) + WireMock.put(WireMock.urlMatching("/admin/realms/%s/users/1".formatted(realm))) .withRequestBody(WireMock.equalTo(objectMapper.writeValueAsString(keycloakRequest))) .willReturn( WireMock.aResponse() @@ -100,8 +100,7 @@ class UpdateUserIntegrationTest extends BaseIntegrationTest { protected void mockUpdateUser(UserKeycloakDto request, String userId) throws Exception { WireMock.stubFor( - WireMock.put( - WireMock.urlMatching(String.format("/admin/realms/%s/users/%s", realm, userId))) + WireMock.put(WireMock.urlMatching("/admin/realms/%s/users/%s".formatted(realm, userId))) .withRequestBody(WireMock.equalTo(objectMapper.writeValueAsString(request))) .willReturn( WireMock.aResponse().withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE))); @@ -109,8 +108,7 @@ class UpdateUserIntegrationTest extends BaseIntegrationTest { protected void mockGetUser(String userId, UserKeycloakDto response) throws Exception { WireMock.stubFor( - WireMock.get( - WireMock.urlMatching(String.format("/admin/realms/%s/users/%s", realm, userId))) + WireMock.get(WireMock.urlMatching("/admin/realms/%s/users/%s".formatted(realm, userId))) .willReturn( WireMock.aResponse() .withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE) @@ -122,7 +120,7 @@ class UpdateUserIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.get( WireMock.urlMatching( - String.format("/admin/realms/%s/users/%s/role-mappings/realm", realm, userID))) + "/admin/realms/%s/users/%s/role-mappings/realm".formatted(realm, userID))) .willReturn( WireMock.aResponse() .withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE) diff --git a/app/src/test/java/org/onap/portalng/bff/users/UpdateUserPasswordIntegrationTest.java b/app/src/test/java/org/onap/portalng/bff/users/UpdateUserPasswordIntegrationTest.java index 11634a8..b88ebff 100644 --- a/app/src/test/java/org/onap/portalng/bff/users/UpdateUserPasswordIntegrationTest.java +++ b/app/src/test/java/org/onap/portalng/bff/users/UpdateUserPasswordIntegrationTest.java @@ -43,8 +43,7 @@ class UpdateUserPasswordIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.put( - WireMock.urlMatching( - String.format("/admin/realms/%s/users/1/reset-password", realm))) + WireMock.urlMatching("/admin/realms/%s/users/1/reset-password".formatted(realm))) .withRequestBody(WireMock.equalTo(objectMapper.writeValueAsString(keycloakRequest))) .willReturn(WireMock.aResponse().withStatus(204))); @@ -72,8 +71,7 @@ class UpdateUserPasswordIntegrationTest extends BaseIntegrationTest { WireMock.stubFor( WireMock.put( - WireMock.urlMatching( - String.format("/admin/realms/%s/users/1/reset-password", realm))) + WireMock.urlMatching("/admin/realms/%s/users/1/reset-password".formatted(realm))) .withRequestBody(WireMock.equalTo(objectMapper.writeValueAsString(keycloakRequest))) .willReturn( WireMock.aResponse() diff --git a/app/src/test/resources/application-access-control.yml b/app/src/test/resources/application-access-control.yml deleted file mode 100644 index 6fda781..0000000 --- a/app/src/test/resources/application-access-control.yml +++ /dev/null @@ -1,21 +0,0 @@ -bff: - access-control: - ACTIONS_CREATE: [ portal_admin, portal_designer, portal_operator ] - ACTIONS_GET: [ portal_admin, portal_designer, portal_operator ] - ACTIONS_LIST: [ portal_admin, portal_designer, portal_operator ] - ACTIVE_ALARM_LIST: [portal_admin, portal_designer, portal_operator] - KEY_ENCRYPT_BY_USER: [portal_admin, portal_designer, portal_operator] - KEY_ENCRYPT_BY_VALUE: [portal_admin, portal_designer, portal_operator] - PREFERENCES_CREATE: [portal_admin, portal_designer, portal_operator] - PREFERENCES_GET: [portal_admin, portal_designer, portal_operator] - PREFERENCES_UPDATE: [portal_admin, portal_designer, portal_operator] - ROLE_LIST: ["*"] - USER_CREATE: [portal_admin, portal_designer, portal_operator] - USER_DELETE: [portal_admin, portal_designer, portal_operator] - USER_GET: [portal_admin, portal_designer, portal_operator] - USER_LIST_AVAILABLE_ROLES: [portal_admin, portal_designer, portal_operator] - USER_LIST_ROLES: [portal_admin, portal_designer, portal_operator] - USER_LIST: [portal_admin, portal_designer, portal_operator] - USER_UPDATE_PASSWORD: [portal_admin, portal_designer, portal_operator] - USER_UPDATE_ROLES: [portal_admin, portal_designer, portal_operator] - USER_UPDATE: [portal_admin, portal_designer, portal_operator] diff --git a/app/src/test/resources/application.yml b/app/src/test/resources/application.yml index 3e423e4..04e6a57 100644 --- a/app/src/test/resources/application.yml +++ b/app/src/test/resources/application.yml @@ -1,7 +1,6 @@ -logging: - level: - org.springframework.web: TRACE - +management: + tracing: + enabled: false spring: profiles: include: @@ -22,12 +21,14 @@ spring: resourceserver: jwt: jwk-set-uri: http://localhost:${wiremock.server.port}/realms/ONAP/protocol/openid-connect/certs - jackson: - serialization: - FAIL_ON_EMPTY_BEANS: false bff: realm: ONAP preferences-url: http://localhost:${wiremock.server.port} history-url: http://localhost:${wiremock.server.port} keycloak-url: http://localhost:${wiremock.server.port} + endpoints: + unauthenticated: /api-docs.html, /api.yaml, /webjars/**, /actuator/** + rbac: + endpoints-excluded: /actuator/**, **/actuator/**, */actuator/**, /**/actuator/**, /*/actuator/** + diff --git a/app/src/test/resources/logback-spring.xml b/app/src/test/resources/logback-spring.xml deleted file mode 100644 index 45bd7e2..0000000 --- a/app/src/test/resources/logback-spring.xml +++ /dev/null @@ -1,18 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<configuration scan="true"> - <include resource="org/springframework/boot/logging/logback/defaults.xml"/> - - <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender"> - <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> - <level>${LOGBACK_LEVEL:-info}</level> - </filter> - <encoder> - <pattern>${CONSOLE_LOG_PATTERN}</pattern> - <charset>utf8</charset> - </encoder> - </appender> - - <root level="all"> - <appender-ref ref="stdout"/> - </root> -</configuration>
\ No newline at end of file |