diff --git a/build.gradle.kts b/build.gradle.kts index 1e244ab..39a106e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -82,7 +82,7 @@ tasks.named("bootBuildImage") { dependencies { - implementation("com.knecon.fforesight:keycloak-commons:0.18.0") + implementation("com.knecon.fforesight:keycloak-commons:0.19.0") implementation("com.knecon.fforesight:swagger-commons:0.5.0") implementation("org.postgresql:postgresql:42.5.4") implementation("com.google.guava:guava:31.1-jre") @@ -99,7 +99,7 @@ dependencies { implementation("org.apache.commons:commons-lang3:3.12.0") implementation("commons-validator:commons-validator:1.7") implementation("org.springframework.boot:spring-boot-configuration-processor") - implementation("com.iqser.red.commons:storage-commons:2.22.0") + implementation("com.iqser.red.commons:storage-commons:2.43.0") testImplementation("org.springframework.boot:spring-boot-starter-test") testImplementation("org.springframework.cloud:spring-cloud-starter-openfeign") testImplementation("org.projectlombok:lombok") diff --git a/src/test/java/com/knecon/fforesight/tests/TenantsTest.java b/src/test/java/com/knecon/fforesight/tests/TenantsTest.java index f2c3cfc..9c141fb 100644 --- a/src/test/java/com/knecon/fforesight/tests/TenantsTest.java +++ b/src/test/java/com/knecon/fforesight/tests/TenantsTest.java @@ -22,6 +22,7 @@ import com.knecon.fforesight.tenantusermanagement.service.RealmService; import com.knecon.fforesight.utils.TestTenantService; import feign.FeignException; +import software.amazon.awssdk.regions.Region; public class TenantsTest extends AbstractTenantUserManagementIntegrationTest { @@ -37,7 +38,6 @@ public class TenantsTest extends AbstractTenantUserManagementIntegrationTest { @Autowired private RealmService realmService; - private static final String PASSWORD = "**********"; @@ -60,6 +60,7 @@ public class TenantsTest extends AbstractTenantUserManagementIntegrationTest { } + @Test public void testUpdateTenant() { @@ -92,7 +93,9 @@ public class TenantsTest extends AbstractTenantUserManagementIntegrationTest { .key("minioadmin") .secret("minioadmin") .bucketName("redaction2") - .endpoint("http://localhost:" + minioPort).build()) + .region(Region.AWS_GLOBAL.id()) + .endpoint("http://localhost:" + minioPort) + .build()) .build(); var updatedTenant = tenantsClient.updateTenant("new_tenant", tenantRequest); @@ -122,8 +125,10 @@ public class TenantsTest extends AbstractTenantUserManagementIntegrationTest { TenantContext.clear(); } + @Test public void testUpdateTenantWithIncorrectS3Storage() { + testTenantService.createTestTenantIfNotExists("new_tenant", minioPort); TenantContext.setTenantId("new_tenant"); @@ -145,17 +150,16 @@ public class TenantsTest extends AbstractTenantUserManagementIntegrationTest { TenantContext.clear(); } + @Test public void testUpdateTenantWithIncorrectAzureStorage() { + testTenantService.createTestTenantWithoutStorageIfNotExist("new_tenant_without_storage"); TenantContext.setTenantId("new_tenant_without_storage"); var tenantRequest = TenantRequest.builder() .tenantId("new_tenant_without_storage") - .azureStorageConnection(AzureStorageConnection.builder() - .connectionString("updated_connection") - .containerName("updated_container") - .build()) + .azureStorageConnection(AzureStorageConnection.builder().connectionString("updated_connection").containerName("updated_container").build()) .build(); var exception = assertThrows(FeignException.BadRequest.class, () -> tenantsClient.updateTenant("new_tenant_without_storage", tenantRequest)); @@ -164,17 +168,16 @@ public class TenantsTest extends AbstractTenantUserManagementIntegrationTest { TenantContext.clear(); } + @Test public void testUpdateTenantWithBothAzureAndS3Storage() { + testTenantService.createTestTenantIfNotExists("new_tenant", minioPort); TenantContext.setTenantId("new_tenant"); var tenantRequest = TenantRequest.builder() .tenantId("new_tenant") - .azureStorageConnection(AzureStorageConnection.builder() - .connectionString("updated_connection") - .containerName("updated_container") - .build()) + .azureStorageConnection(AzureStorageConnection.builder().connectionString("updated_connection").containerName("updated_container").build()) .s3StorageConnection(S3StorageConnection.builder() .key("updated_key") .bucketName("updated_bucket") @@ -191,17 +194,16 @@ public class TenantsTest extends AbstractTenantUserManagementIntegrationTest { TenantContext.clear(); } + @Test public void testUpdateTenantFromS3ToAzureStorage() { + testTenantService.createTestTenantIfNotExists("new_tenant_with_s3", minioPort); TenantContext.setTenantId("new_tenant_with_s3"); var tenantRequest = TenantRequest.builder() .tenantId("new_tenant_with_s3") - .azureStorageConnection(AzureStorageConnection.builder() - .connectionString("updated_connection") - .containerName("updated_container") - .build()) + .azureStorageConnection(AzureStorageConnection.builder().connectionString("updated_connection").containerName("updated_container").build()) .build(); var exception = assertThrows(FeignException.BadRequest.class, () -> tenantsClient.updateTenant("new_tenant_with_s3", tenantRequest)); @@ -210,8 +212,10 @@ public class TenantsTest extends AbstractTenantUserManagementIntegrationTest { TenantContext.clear(); } + @Test public void testRemovePasswords() { + testTenantService.createTestTenantIfNotExists("new_tenant_passwords", minioPort); TenantContext.setTenantId("new_tenant_passwords"); @@ -230,6 +234,7 @@ public class TenantsTest extends AbstractTenantUserManagementIntegrationTest { @Test public void testPasswordPolicy() { + testTenantService.createTestTenantIfNotExists("new_tenant", minioPort); TenantContext.setTenantId("new_tenant"); @@ -242,4 +247,5 @@ public class TenantsTest extends AbstractTenantUserManagementIntegrationTest { TenantContext.clear(); } + } diff --git a/src/test/java/com/knecon/fforesight/utils/TestTenantService.java b/src/test/java/com/knecon/fforesight/utils/TestTenantService.java index 3f0e171..a9ecbb0 100644 --- a/src/test/java/com/knecon/fforesight/utils/TestTenantService.java +++ b/src/test/java/com/knecon/fforesight/utils/TestTenantService.java @@ -19,6 +19,7 @@ import com.knecon.fforesight.tenantusermanagement.model.TenantUser; import com.knecon.fforesight.testcontainers.SpringPostgreSQLTestContainer; import lombok.RequiredArgsConstructor; +import software.amazon.awssdk.regions.Region; @Service @RequiredArgsConstructor @@ -29,6 +30,7 @@ public class TestTenantService { private final TokenService tokenService; + public void createTestTenantIfNotExists(String testTenantId, int actualPort) { try { @@ -42,7 +44,9 @@ public class TestTenantService { } + public void createTestTenantWithoutStorageIfNotExist(String testTenantId) { + try { var tenantExists = internalTenantsResource.getTenant(testTenantId); assertThat(tenantExists.getGuid()).isNotBlank(); @@ -53,6 +57,7 @@ public class TestTenantService { } } + private void createUser(String testTenantId, int actualPort, boolean withStorage) { // not found TenantRequest tenantRequest; @@ -73,9 +78,13 @@ public class TestTenantService { .searchConnection(SearchConnection.builder().hosts(Set.of("localhost")).port(9200).scheme("http").numberOfShards("1").numberOfReplicas("5").build()); if (withStorage) { - tenantRequest = tenantRequestBuilder - .s3StorageConnection(S3StorageConnection.builder().key("minioadmin").secret("minioadmin").bucketName("redaction").endpoint("http://localhost:" + actualPort).build()) - .build(); + tenantRequest = tenantRequestBuilder.s3StorageConnection(S3StorageConnection.builder() + .key("minioadmin") + .secret("minioadmin") + .bucketName(testTenantId.replaceAll("-", "").replaceAll("_", "")) + .endpoint("http://localhost:" + actualPort) + .region(Region.AWS_GLOBAL.id()) + .build()).build(); } else { tenantRequest = tenantRequestBuilder.build(); }