From 8b0ed126d3844bfb8043d18a60aba0f2bb079295 Mon Sep 17 00:00:00 2001 From: Dmytro Tkachenko Date: Thu, 30 Jan 2025 14:28:30 +0200 Subject: [PATCH] MODSIDECAR-88 Delete unstable integration test (#168) --- ...ClientCredsRecoveryAndCachingEgressIT.java | 106 ------------------ .../obtain-m2m-client-token-unathorized.json | 32 ------ ...obtain-system-user-token-unauthorized.json | 32 ------ 3 files changed, 170 deletions(-) delete mode 100644 src/test/java/org/folio/sidecar/it/ClientCredsRecoveryAndCachingEgressIT.java delete mode 100644 src/test/resources/mappings/keycloak/obtain-m2m-client-token-unathorized.json delete mode 100644 src/test/resources/mappings/keycloak/obtain-system-user-token-unauthorized.json diff --git a/src/test/java/org/folio/sidecar/it/ClientCredsRecoveryAndCachingEgressIT.java b/src/test/java/org/folio/sidecar/it/ClientCredsRecoveryAndCachingEgressIT.java deleted file mode 100644 index afcc1a8..0000000 --- a/src/test/java/org/folio/sidecar/it/ClientCredsRecoveryAndCachingEgressIT.java +++ /dev/null @@ -1,106 +0,0 @@ -package org.folio.sidecar.it; - -import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON; -import static org.apache.http.HttpStatus.SC_CREATED; -import static org.assertj.core.api.Assertions.assertThat; -import static org.folio.sidecar.support.TestConstants.TENANT_NAME; -import static org.folio.sidecar.utils.SecureStoreUtils.tenantStoreKey; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.nullValue; -import static org.mockito.Mockito.when; - -import io.quarkus.test.junit.TestProfile; -import io.quarkus.test.junit.mockito.InjectSpy; -import io.restassured.filter.log.LogDetail; -import io.vertx.core.Future; -import jakarta.inject.Inject; -import org.eclipse.microprofile.config.inject.ConfigProperty; -import org.folio.sidecar.integration.cred.CredentialService; -import org.folio.sidecar.integration.cred.store.AsyncSecureStore; -import org.folio.sidecar.integration.okapi.OkapiHeaders; -import org.folio.sidecar.support.TestConstants; -import org.folio.sidecar.support.TestJwtGenerator; -import org.folio.sidecar.support.TestUtils; -import org.folio.sidecar.support.extensions.EnableWireMock; -import org.folio.sidecar.support.profile.CommonIntegrationTestProfile; -import org.folio.support.types.IntegrationTest; -import org.hamcrest.Matchers; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -@IntegrationTest -@TestProfile(CommonIntegrationTestProfile.class) -@EnableWireMock(https = true, verbose = true) -class ClientCredsRecoveryAndCachingEgressIT { - - private static final String SUPERSECRET = "supersecret"; - private static final String OUTDATED_SECRET = "outdated_secret"; - - @InjectSpy - AsyncSecureStore secureStore; - @Inject - CredentialService credentialService; - - @ConfigProperty(name = "keycloak.url") String keycloakUrl; - @ConfigProperty(name = "module.name") String moduleName; - @ConfigProperty(name = "keycloak.service.client-id") String serviceClientId; - - String authToken; - - @BeforeEach - void init() { - authToken = TestJwtGenerator.generateJwtString(keycloakUrl, TENANT_NAME); - } - - @Test - void handleEgressRequest_positive() { - credentialService.resetUserCredentials(TENANT_NAME, moduleName); - credentialService.resetServiceClientCredentials(TENANT_NAME); - - when(secureStore.get(tenantStoreKey(TENANT_NAME, moduleName))) - .thenReturn(Future.succeededFuture(OUTDATED_SECRET)) - .thenReturn(Future.succeededFuture(SUPERSECRET)); - - when(secureStore.get(tenantStoreKey(TENANT_NAME, serviceClientId))) - .thenReturn(Future.succeededFuture(OUTDATED_SECRET)) - .thenReturn(Future.succeededFuture(SUPERSECRET)); - - sendRequest(); - - assertUserCredentials(); - assertClientCredentials(); - } - - private void assertClientCredentials() { - var scf = credentialService.getServiceClientCredentials(TENANT_NAME); - assertThat(scf.succeeded()).isTrue(); - assertThat(scf.result().getClientSecret()).isEqualTo(SUPERSECRET); - } - - private void assertUserCredentials() { - var ucf = credentialService.getUserCredentials(TENANT_NAME, moduleName); - assertThat(ucf.succeeded()).isTrue(); - assertThat(ucf.result().getPassword()).isEqualTo(SUPERSECRET); - } - - private void sendRequest() { - TestUtils.givenJson() - .header(OkapiHeaders.TENANT, TENANT_NAME) - .header(OkapiHeaders.AUTHORIZATION, "Bearer " + authToken) - .header(TestConstants.SIDECAR_SIGNATURE_HEADER, "dummy") - .body("{\"name\":\"entity\",\"description\":\"An entity description\"}") - .post("/bar/entities") - .then() - .log().ifValidationFails(LogDetail.ALL) - .assertThat() - .header(OkapiHeaders.TENANT, Matchers.is(TENANT_NAME)) - .header(TestConstants.SIDECAR_SIGNATURE_HEADER, nullValue()) - .statusCode(is(SC_CREATED)) - .contentType(is(APPLICATION_JSON)) - .body( - "id", is("d747fc05-736e-494f-9b25-205c90d9d79a"), - "name", is("entity"), - "description", is("An entity description") - ); - } -} diff --git a/src/test/resources/mappings/keycloak/obtain-m2m-client-token-unathorized.json b/src/test/resources/mappings/keycloak/obtain-m2m-client-token-unathorized.json deleted file mode 100644 index 680c6ef..0000000 --- a/src/test/resources/mappings/keycloak/obtain-m2m-client-token-unathorized.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "mappings": [ - { - "request": { - "method": "POST", - "urlPattern": "/realms/testtenant/protocol/openid-connect/token", - "headers": { - "Content-Type": { - "equalTo": "application/x-www-form-urlencoded" - } - }, - "bodyPatterns": [ - { - "contains": "grant_type=client_credentials" - }, - { - "contains": "client_secret=outdated_secret" - } - ] - }, - "response": { - "status": 401, - "headers": { - "Content-Type": "application/json" - }, - "jsonBody": { - "error": "Not authorized" - } - } - } - ] -} diff --git a/src/test/resources/mappings/keycloak/obtain-system-user-token-unauthorized.json b/src/test/resources/mappings/keycloak/obtain-system-user-token-unauthorized.json deleted file mode 100644 index 05b40f7..0000000 --- a/src/test/resources/mappings/keycloak/obtain-system-user-token-unauthorized.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "mappings": [ - { - "request": { - "method": "POST", - "urlPattern": "/realms/testtenant/protocol/openid-connect/token", - "headers": { - "Content-Type": { - "equalTo": "application/x-www-form-urlencoded" - } - }, - "bodyPatterns": [ - { - "contains": "grant_type=password" - }, - { - "contains": "password=outdated_secret" - } - ] - }, - "response": { - "status": 401, - "headers": { - "Content-Type": "application/json" - }, - "jsonBody": { - "error": "Not authorized" - } - } - } - ] -}