Commit 39d21355 authored by Enriko Käsper's avatar Enriko Käsper
Browse files

Merge branch 'develop' into 'master'

Release: merge 'develop' into 'master' created by Enriko Käsper

See merge request teis/commons-public!15
parents 73869f79 652c3702
package ee.sm.ti.teis.types.sensitive;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
@SuppressWarnings("squid:S00100")
class ObscuringUtilsTest {
@Test
void test_obscuring() {
assertThat(ObscuringUtils.obscureFieldValue("Test")).isEqualTo("Te**");
assertThat(ObscuringUtils.obscureFieldValue("Te")).isEqualTo("**");
assertThat(ObscuringUtils.obscureFieldValue(null)).isNull();
}
}
\ No newline at end of file
package ee.sm.ti.teis.types.sensitive;
import lombok.Data;
import org.junit.jupiter.api.Test;
import java.util.Collections;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
@SuppressWarnings("squid:S00100")
class SensitiveTypeTest {
MockChild mockChild = new MockChild("a");
MockParent mockParent = new MockParent(List.of(mockChild));
@Test
void test_sensitive_data() {
assertThat(SensitiveTypeUtils.containsSensitiveData(null)).isFalse();
assertThat(SensitiveTypeUtils.containsSensitiveData(mockParent)).isFalse();
assertThat(SensitiveTypeUtils.containsSensitiveData(mockParent.children)).isTrue();
assertThat(SensitiveTypeUtils.containsSensitiveData(new MockParent(Collections.emptyList()))).isFalse();
assertThat(SensitiveTypeUtils.containsSensitiveData(mockChild)).isTrue();
}
@Test
void test_sensitive_object_ids() {
assertThat(SensitiveTypeUtils.collectSensitiveObjectIds(null)).isEmpty();
assertThat(SensitiveTypeUtils.collectSensitiveObjectIds(mockParent)).isEmpty();
assertThat(SensitiveTypeUtils.collectSensitiveObjectIds(mockParent.children)).isNotEmpty();
assertThat(SensitiveTypeUtils.collectSensitiveObjectIds(List.of())).isEmpty();
assertThat(SensitiveTypeUtils.collectSensitiveObjectIds(new MockParent(Collections.emptyList()))).isEmpty();
assertThat(SensitiveTypeUtils.collectSensitiveObjectIds(mockChild)).isNotEmpty();
}
@Data
public static class MockChild implements SensitiveType {
private final String name;
@Override
public List<String> sensitiveObjectIds() {
return List.of("name");
}
}
@Data
public static class MockParent {
private final List<Object> children;
}
}
\ No newline at end of file
# suppress inspection "UnusedProperty"
theGroup=ee.sm.ti.teis
#publicVersion forSearch ^publicVersion=.*?-SNAPSHOT
version=1.7.0
version=1.8.0
pluginVersion=1.0.1
......@@ -17,6 +17,7 @@ import org.springframework.stereotype.Component;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.Collections;
import java.util.List;
import static ee.sm.ti.teis.logging.MethodExecutionTimeLogger.logMethodExecutionTime;
......@@ -144,7 +145,7 @@ public class RabbitListenerAspect {
@Override
public List<String> sensitiveObjectIdsInPayload() {
return null;
return Collections.emptyList();
}
}
}
......@@ -2,13 +2,13 @@ package ee.sm.ti.teis.configuration;
import ee.sm.ti.teis.converter.TeisMessageConverter;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......@@ -17,6 +17,7 @@ import org.springframework.stereotype.Component;
@Configuration
@EnableRabbit
@RequiredArgsConstructor
public class ExchangeConfig {
public static final int DEFAULT_GW_REPLY_TIMEOUT = 6000;
......@@ -25,11 +26,6 @@ public class ExchangeConfig {
public static final int DEFAULT_OD_REPLY_TIMEOUT = 6000;
private final ExchangeProperties properties;
@Autowired
public ExchangeConfig(ExchangeProperties properties) {
this.properties = properties;
}
@Bean
public RabbitAdmin rabbitAdmin(ConnectionFactory connectionFactory) {
return new RabbitAdmin(connectionFactory);
......
......@@ -9,6 +9,7 @@ import java.util.concurrent.TimeUnit;
import static java.util.OptionalInt.empty;
import static java.util.OptionalInt.of;
@SuppressWarnings("squid:S1214")
public interface QueueList {
int TTL_GW_DEFAULT = 90000;
int TTL_MS_DEFAULT = 60000;
......@@ -30,6 +31,19 @@ public interface QueueList {
addQueue(queues, beanPrefix, routingKey, queueName, "gw-exchange-name", of(TTL_GW_DEFAULT), false);
}
default void addWebsocketQueue(ArrayList<TeisQueue> queues, String beanPrefix, String routingKey, String queueName) {
queues.add(TeisQueue.builder()
.routingKey(routingKey)
.queueName(queueName)
.beanPrefix(beanPrefix)
.ttlMillis(of(TTL_GW_DEFAULT))
.exchangeNameProperty("gw-exchange-name")
.durable(false)
.autoDelete(true)
.exclusive(true)
.build());
}
default void addMsQueue(ArrayList<TeisQueue> queues, String beanPrefix, String routingKey, String queueName) {
addMsQueue(queues, beanPrefix, routingKey, queueName, of(TTL_MS_DEFAULT));
}
......
......@@ -37,6 +37,12 @@ public class TeisQueue {
@Builder.Default
private boolean durable = true;
@Builder.Default
private boolean exclusive = false;
@Builder.Default
private boolean autoDelete = false;
@Builder.Default
private String defaultGateway = "msExchange";
......@@ -44,8 +50,8 @@ public class TeisQueue {
BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(Queue.class);
beanDefinitionBuilder.addConstructorArgValue(parseQueueName(springEnvironment));
beanDefinitionBuilder.addConstructorArgValue(isDurable());
beanDefinitionBuilder.addConstructorArgValue(false);
beanDefinitionBuilder.addConstructorArgValue(false);
beanDefinitionBuilder.addConstructorArgValue(isExclusive());
beanDefinitionBuilder.addConstructorArgValue(isAutoDelete());
HashMap<String, Object> parameters = new HashMap<>();
getTtlMillis().ifPresent(t -> parameters.put("x-message-ttl", t));
beanDefinitionBuilder.addConstructorArgValue(parameters);
......
......@@ -2,9 +2,9 @@ package ee.sm.ti.teis.errors;
public enum CommonErrorCode implements ErrorCode {
BAD_REQUEST("400"), SYSTEM_ERROR("500"), RESOURCE_NOT_FOUND("404"), NO_CONTENT("204"), FORBIDDEN("403"),
RESOURCE_CONFLICT("409"), UNSUPPORTED_MEDIA_TYPE("415");
RESOURCE_CONFLICT("409"), UNSUPPORTED_MEDIA_TYPE("415"), NOT_IMPLEMENTED("501");
private String code;
private final String code;
CommonErrorCode(String code) {
this.code = code;
......
package ee.sm.ti.teis.exceptions;
import java.util.List;
import static ee.sm.ti.teis.errors.CommonErrorCode.NOT_IMPLEMENTED;
import static java.text.MessageFormat.format;
/**
* Super class for domain resources not found exceptions. In REST API, it's usually HTTP response code 404.
*/
public class TeisNotImplementedException extends TeisBusinessException {
private static final long serialVersionUID = 7393340365016294825L;
public TeisNotImplementedException(String message) {
super(NOT_IMPLEMENTED, message);
}
public TeisNotImplementedException(String message, List<Object> messageParameters) {
super(NOT_IMPLEMENTED, format(message, messageParameters.toArray()), messageParameters);
}
}
......@@ -26,7 +26,6 @@ public class SecurityContextCreator {
SecurityContext ctx = SecurityContextHolder.createEmptyContext();
if (requestMetaDTO.getUserId() != null) {
// String userName = requestMetaDTO.getUserType() + USER_NAME_TYPE_SEPARATOR + requestMetaDTO.getUserId();
String userName = requestMetaDTO.getUserId();
Set<GrantedAuthority> authorities =
requestMetaDTO.getPrivileges() != null ?
......
package ee.sm.ti.teis.configuration;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@SuppressWarnings("squid:S00100")
class ExchangeConfigTest {
public static final String GW_EXCHANGE = "GwExchange";
public static final String CS_EXCHANGE = "CsExchange";
public static final String MS_EXCHANGE = "MsExchange";
public static final String OD_EXCHANGE = "OdExchange";
private final ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
ExchangeConfig context;
@BeforeEach
void setUp() {
ExchangeConfig.ExchangeProperties prop = new ExchangeConfig.ExchangeProperties();
prop.setCsExchangeName(CS_EXCHANGE);
prop.setGwExchangeName(GW_EXCHANGE);
prop.setMsExchangeName(MS_EXCHANGE);
prop.setOdExchangeName(OD_EXCHANGE);
context = new ExchangeConfig(prop);
}
@Test
void test_csRabbitTemplate() {
TopicExchange topicExchange = context.csExchange();
RabbitTemplate rabbitTemplate = context.csRabbitTemplate(connectionFactory, context.jsonMessageConverter());
assertThat(topicExchange.getName()).isEqualTo(CS_EXCHANGE);
assertThat(rabbitTemplate.getExchange()).isEqualTo(CS_EXCHANGE);
}
@Test
void test_gwRabbitTemplate() {
TopicExchange topicExchange = context.gwExchange();
RabbitTemplate rabbitTemplate = context.gwRabbitTemplate(connectionFactory, context.jsonMessageConverter());
assertThat(topicExchange.getName()).isEqualTo(GW_EXCHANGE);
assertThat(rabbitTemplate.getExchange()).isEqualTo(GW_EXCHANGE);
}
@Test
void test_msRabbitTemplate() {
TopicExchange topicExchange = context.msExchange();
RabbitTemplate rabbitTemplate = context.msRabbitTemplate(connectionFactory, context.jsonMessageConverter());
assertThat(topicExchange.getName()).isEqualTo(MS_EXCHANGE);
assertThat(rabbitTemplate.getExchange()).isEqualTo(MS_EXCHANGE);
}
@Test
void test_odRabbitTemplate() {
TopicExchange topicExchange = context.odExchange();
RabbitTemplate rabbitTemplate = context.odRabbitTemplate(connectionFactory, context.jsonMessageConverter());
assertThat(topicExchange.getName()).isEqualTo(OD_EXCHANGE);
assertThat(rabbitTemplate.getExchange()).isEqualTo(OD_EXCHANGE);
}
}
\ No newline at end of file
package ee.sm.ti.teis.configuration;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
import java.util.OptionalInt;
import static org.assertj.core.api.Assertions.assertThat;
@SuppressWarnings("squid:S00100")
class QueueListTest {
public static final OptionalInt MILLIS = OptionalInt.of(1);
MockQueueList context = new MockQueueList();
@Test
void test_all_queues() {
List<TeisQueue> q = context.queueList();
assertThat(q.size()).isEqualTo(9);
}
private class MockQueueList implements QueueList {
@Override
public void updateQueues(ArrayList<TeisQueue> q) {
String b = configurationName() + "b";
context.addGwQueue(q, b, "r1", "q1");
context.addWebsocketQueue(q, b, "r2", "q2");
context.addMsQueue(q, b, "r3", "q3");
context.addMsQueue(q, b, "r4", "q4", MILLIS);
context.addDurableMsQueue(q, b, "r5", "q5", MILLIS);
context.addMsQueueWithoutTTL(q, b, "r6", "q6");
context.addCsQueue(q, b, "r7", "q7");
context.addOdQueue(q, b, "r8", "q8");
context.addGwQueue(q, b, "r9", "q9");
}
}
}
\ No newline at end of file
package ee.sm.ti.teis.configuration;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.core.env.Environment;
import java.util.OptionalInt;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.*;
@SuppressWarnings("squid:S00100")
class TeisQueueTest {
TeisQueue context = TeisQueue.builder()
.queueName("name")
.routingKey("rkey")
.beanPrefix("bprefix")
.ttlMillis(OptionalInt.of(10))
.exchangeNameProperty("exchange").build();
@Test
void test_register_queue() {
BeanDefinitionRegistry bdr = mock(BeanDefinitionRegistry.class);
Environment env = mock(Environment.class);
context.registerQueue(env, bdr);
verify(bdr,atLeastOnce()).registerBeanDefinition(anyString(),any(BeanDefinition.class));
}
@Test
void test_create_binding() {
BeanDefinitionRegistry bdr = mock(BeanDefinitionRegistry.class);
Environment env = mock(Environment.class);
context.createBinding(env, bdr);
verify(bdr,atLeastOnce()).registerBeanDefinition(anyString(),any(BeanDefinition.class));
}
}
\ No newline at end of file
package ee.sm.ti.teis.exceptions;
import ee.sm.ti.teis.errors.CommonErrorCode;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
@SuppressWarnings("squid:S00100")
class TeisNotImplementedExceptionTest {
@Test
void constructor_tests() {
assertThat(new TeisNotImplementedException("message").getErrorCode()).isEqualTo(CommonErrorCode.NOT_IMPLEMENTED);
assertThat(new TeisNotImplementedException("message", List.of()).getErrorCode()).isEqualTo(CommonErrorCode.NOT_IMPLEMENTED);
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment