set null org role scope if it dont exist in DB (#60)

* set null org role scope if it dont exist in DB

* bump parent

* bump vulnerability deps

* change container test

---------

Co-authored-by: ggmaleva <ggmaleva@yandex.ru>
This commit is contained in:
Gregory 2023-10-26 17:50:52 +03:00 committed by GitHub
parent eb0fcfaa0e
commit 66e4f69b33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 90 additions and 34 deletions

38
pom.xml
View File

@ -6,7 +6,7 @@
<parent>
<groupId>dev.vality</groupId>
<artifactId>service-parent-pom</artifactId>
<version>2.1.5</version>
<version>2.1.8</version>
</parent>
<artifactId>org-manager</artifactId>
@ -16,18 +16,19 @@
<name>org-manager</name>
<properties>
<maven.compiler.source>15</maven.compiler.source>
<maven.compiler.target>15</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<server.port>8022</server.port>
<server.rest.port>8080</server.rest.port>
<management.port>8023</management.port>
<exposed.ports>${server.port} ${server.rest.port} ${management.port}</exposed.ports>
<spring-security.version>5.6.2</spring-security.version>
<spring-security.version>5.6.12</spring-security.version>
<keycloak.version>17.0.0</keycloak.version>
<schedlock.version>4.34.0</schedlock.version>
<swag.organizations.version>1.19-8707f87-server</swag.organizations.version>
<wiremock-jre8-standalone.version>2.32.0</wiremock-jre8-standalone.version>
</properties>
<dependencies>
@ -71,6 +72,12 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
@ -186,7 +193,7 @@
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.3.3</version>
<version>42.4.3</version>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
@ -195,13 +202,18 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.1-jre</version>
<version>32.0.0-jre</version>
</dependency>
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
<version>0.2.2</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>2.0</version>
</dependency>
<!--test-->
@ -222,6 +234,12 @@
<version>3.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-jre8-standalone</artifactId>
<version>${wiremock-jre8-standalone.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
@ -231,7 +249,7 @@
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<version>1.17.0</version>
<version>1.19.1</version>
<scope>test</scope>
<exclusions>
<exclusion>
@ -240,6 +258,12 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>1.19.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@ -11,6 +11,7 @@ import dev.vality.orgmanager.entity.OrganizationEntity;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
@ -48,8 +49,12 @@ public class BouncerContextConverter {
public OrgRole toOrgRole(MemberRoleEntity entity) {
return new OrgRole()
.setId(entity.getRoleId())
.setScope(new OrgRoleScope()
.setShop(new Entity().setId(entity.getResourceId())));
.setScope(Objects.nonNull(entity.getResourceId())
? new OrgRoleScope()
.setShop(
new Entity()
.setId(entity.getResourceId()))
: null);
}
}

View File

@ -46,6 +46,23 @@ class BouncerContextConverterTest {
assertEquals(expected, actual);
}
@Test
void shouldConvertToOrgRoleWithoutScope() {
MemberRoleEntity entity = MemberRoleEntity.builder()
.id("id")
.roleId("Administrator")
.organizationId("org")
.build();
OrgRole actual = converter.toOrgRole(entity);
OrgRole expected = new OrgRole()
.setId(RoleId.ADMINISTRATOR.getValue())
.setScope(null);
assertEquals(expected, actual);
}
@Test
void shouldConvertToMember() {
Set<OrganizationEntity> organizationEntities = Set.of(TestObjectFactory.buildOrganization());

View File

@ -1,27 +1,27 @@
package dev.vality.orgmanager.repository;
import dev.vality.orgmanager.OrgManagerApplication;
import org.junit.ClassRule;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.springframework.transaction.annotation.Transactional;
import org.testcontainers.containers.PostgreSQLContainer;
import java.time.Duration;
import org.testcontainers.utility.DockerImageName;
@ActiveProfiles("test")
@SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
classes = {OrgManagerApplication.class})
@ContextConfiguration(initializers = InvitationRepositoryTest.Initializer.class)
public abstract class AbstractRepositoryTest {
private static final String POSTGRESQL_IMAGE_NAME = "postgres";
private static final String POSTGRESQL_VERSION = "13.6";
@Autowired
protected InvitationRepository invitationRepository;
@ -54,24 +54,34 @@ public abstract class AbstractRepositoryTest {
organizationRoleRepository.deleteAll();
}
@ClassRule
@SuppressWarnings("rawtypes")
public static PostgreSQLContainer postgres = new PostgreSQLContainer<>("postgres:13.6")
.withStartupTimeout(Duration.ofMinutes(5));
@BeforeAll
static void beforeAll() {
TestPropertyValues.of(
"spring.datasource.url=" + postgres.getJdbcUrl(),
"spring.datasource.username=" + postgres.getUsername(),
"spring.datasource.password=" + postgres.getPassword(),
"spring.flyway.url=" + postgres.getJdbcUrl(),
"spring.flyway.user=" + postgres.getUsername(),
"spring.flyway.password=" + postgres.getPassword());
public static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
@Override
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
postgres.start();
TestPropertyValues.of(
"spring.datasource.url=" + postgres.getJdbcUrl(),
"spring.datasource.username=" + postgres.getUsername(),
"spring.datasource.password=" + postgres.getPassword(),
"spring.flyway.url=" + postgres.getJdbcUrl(),
"spring.flyway.user=" + postgres.getUsername(),
"spring.flyway.password=" + postgres.getPassword())
.and(configurableApplicationContext.getEnvironment().getActiveProfiles())
.applyTo(configurableApplicationContext);
}
}
@SuppressWarnings("rawtypes")
static PostgreSQLContainer postgres = new PostgreSQLContainer<>(DockerImageName
.parse(POSTGRESQL_IMAGE_NAME)
.withTag(POSTGRESQL_VERSION));
static {
postgres.start();
}
@DynamicPropertySource
static void configureProperties(DynamicPropertyRegistry registry) {
registry.add("spring.datasource.url", postgres::getJdbcUrl);
registry.add("spring.datasource.username", postgres::getUsername);
registry.add("spring.datasource.password", postgres::getPassword);
registry.add("spring.flyway.url", postgres::getJdbcUrl);
registry.add("spring.flyway.user", postgres::getUsername);
registry.add("spring.flyway.password", postgres::getPassword);
}
}