Merge branch 'RED-7175' into 'main'
RED-7175 See merge request fforesight/tenant-user-management-service!19
This commit is contained in:
commit
1003f4a4a1
@ -82,7 +82,7 @@ tasks.named<BootBuildImage>("bootBuildImage") {
|
||||
|
||||
|
||||
dependencies {
|
||||
implementation("com.knecon.fforesight:keycloak-commons:0.18.0")
|
||||
implementation("com.knecon.fforesight:keycloak-commons:0.20.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")
|
||||
|
||||
@ -81,7 +81,7 @@ public class DevTestTenantService {
|
||||
.username(tenantsDBName)
|
||||
.password(tenantsDBPassword)
|
||||
.build())
|
||||
.searchConnection(SearchConnection.builder().hosts(Set.of("localhost")).port(9200).scheme("http").numberOfShards("1").numberOfReplicas("5").build())
|
||||
.searchConnection(SearchConnection.builder().hosts(Set.of("localhost")).port(9200).scheme("http").numberOfShards("1").numberOfReplicas("5").indexName("indexname").build())
|
||||
.s3StorageConnection(S3StorageConnection.builder().key("minioadmin").secret("minioadmin").bucketName("redaction").endpoint("http://localhost:9000").build())
|
||||
.build();
|
||||
|
||||
|
||||
@ -34,5 +34,7 @@ public class SearchConnectionEntity {
|
||||
private String numberOfShards;
|
||||
@Column(name = "search_number_of_replicas")
|
||||
private String numberOfReplicas;
|
||||
@Column(name = "search_index_name")
|
||||
private String indexName;
|
||||
|
||||
}
|
||||
|
||||
@ -10,7 +10,6 @@ import com.knecon.fforesight.tenantcommons.model.SearchConnection;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
|
||||
@ -113,6 +113,7 @@ public class TenantManagementService implements TenantProvider {
|
||||
.password(encryptionService.encrypt(tenantRequest.getSearchConnection().getPassword()))
|
||||
.numberOfShards(tenantRequest.getSearchConnection().getNumberOfShards())
|
||||
.numberOfReplicas(tenantRequest.getSearchConnection().getNumberOfReplicas())
|
||||
.indexName(tenantRequest.getSearchConnection().getIndexName())
|
||||
.build())
|
||||
.build();
|
||||
|
||||
@ -407,6 +408,7 @@ public class TenantManagementService implements TenantProvider {
|
||||
.password(encryptionService.encrypt(searchConnection.getPassword()))
|
||||
.numberOfShards(searchConnection.getNumberOfShards())
|
||||
.numberOfReplicas(searchConnection.getNumberOfReplicas())
|
||||
.indexName(searchConnection.getIndexName())
|
||||
.build());
|
||||
}
|
||||
|
||||
@ -508,6 +510,7 @@ public class TenantManagementService implements TenantProvider {
|
||||
.numberOfShards(entity.getSearchConnection().getNumberOfShards())
|
||||
.numberOfReplicas(entity.getSearchConnection().getNumberOfReplicas())
|
||||
.password(entity.getSearchConnection().getPassword())
|
||||
.indexName(entity.getSearchConnection().getIndexName())
|
||||
.build())
|
||||
.build();
|
||||
|
||||
|
||||
@ -7,3 +7,5 @@ databaseChangeLog:
|
||||
file: db/changelog/master/4-add-unique-constraint-for-tenants-table.yaml
|
||||
- include:
|
||||
file: db/changelog/master/5-add-details-column.changelog.yaml
|
||||
- include:
|
||||
file: db/changelog/master/6-add-index-name-column.changelog.yaml
|
||||
|
||||
@ -0,0 +1,11 @@
|
||||
databaseChangeLog:
|
||||
- changeSet:
|
||||
id: add-index-name-column-to-tenant
|
||||
author: ali
|
||||
changes:
|
||||
- addColumn:
|
||||
tableName: tenant
|
||||
columns:
|
||||
- column:
|
||||
name: search_index_name
|
||||
type: TEXT
|
||||
@ -1,8 +1,5 @@
|
||||
package com.knecon.fforesight;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
@ -55,10 +52,12 @@ public class AbstractTenantUserManagementIntegrationTest {
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void createTestTenant(){
|
||||
public void createTestTenant() {
|
||||
|
||||
testTenantService.createTestTenantIfNotExists(TEST_TENANT_ID, minioPort);
|
||||
}
|
||||
|
||||
|
||||
@Slf4j
|
||||
static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
|
||||
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -77,6 +78,7 @@ public class TenantsTest extends AbstractTenantUserManagementIntegrationTest {
|
||||
.port(123)
|
||||
.username("updated_username")
|
||||
.scheme("updated_scheme")
|
||||
.indexName("indexname")
|
||||
.build())
|
||||
.databaseConnection(DatabaseConnection.builder()
|
||||
.database("updated_db")
|
||||
@ -92,7 +94,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 +126,10 @@ public class TenantsTest extends AbstractTenantUserManagementIntegrationTest {
|
||||
TenantContext.clear();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testUpdateTenantWithIncorrectS3Storage() {
|
||||
|
||||
testTenantService.createTestTenantIfNotExists("new_tenant", minioPort);
|
||||
TenantContext.setTenantId("new_tenant");
|
||||
|
||||
@ -145,17 +151,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 +169,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 +195,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 +213,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 +235,7 @@ public class TenantsTest extends AbstractTenantUserManagementIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void testPasswordPolicy() {
|
||||
|
||||
testTenantService.createTestTenantIfNotExists("new_tenant", minioPort);
|
||||
|
||||
TenantContext.setTenantId("new_tenant");
|
||||
@ -242,4 +248,5 @@ public class TenantsTest extends AbstractTenantUserManagementIntegrationTest {
|
||||
|
||||
TenantContext.clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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;
|
||||
@ -70,12 +75,16 @@ public class TestTenantService {
|
||||
.username(SpringPostgreSQLTestContainer.getInstance().getUsername())
|
||||
.password(SpringPostgreSQLTestContainer.getInstance().getPassword())
|
||||
.build())
|
||||
.searchConnection(SearchConnection.builder().hosts(Set.of("localhost")).port(9200).scheme("http").numberOfShards("1").numberOfReplicas("5").build());
|
||||
.searchConnection(SearchConnection.builder().hosts(Set.of("localhost")).port(9200).scheme("http").numberOfShards("1").numberOfReplicas("5").indexName("indexname").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();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user