Commit 1179c8c3 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/common-api-gateway!153
parents 92c7b2f6 babd1c34
package ee.sm.ti.teis.commongateway.representative.authoritypermission.request;
import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO;
import ee.sm.ti.teis.types.enums.AuthorityType;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotNull;
import java.util.UUID;
public class AuthorityPermissionsAuthorityRequest extends AbstractDTO<AuthorityPermissionsAuthorityRequest.Parameters, ErrorDTO> {
public static final String ROUTING_KEY = "api.AuthorityPermissionsAuthorityRequest";
@Override
public String routingKey() {
return ROUTING_KEY;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class Parameters {
@NotNull
private UUID personId;
@NotNull
private AuthorityType authorityType;
private Boolean includeAll;
}
}
package ee.sm.ti.teis.commongateway.representative.authoritypermission.request;
import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotNull;
import java.util.UUID;
public class AuthorityPermissionsGrantorRequest extends AbstractDTO<AuthorityPermissionsGrantorRequest.Parameters, ErrorDTO> {
public static final String ROUTING_KEY = "api.AuthorityPermissionsGrantorRequest";
@Override
public String routingKey() {
return ROUTING_KEY;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class Parameters {
@NotNull
private UUID grantorId;
private Boolean includeAll;
}
}
package ee.sm.ti.teis.commongateway.representative.authoritypermission.request;
import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO;
import ee.sm.ti.teis.commongateway.representative.authoritypermission.dto.CreateAuthorityPermissionDto;
public class CreateAuthorityPermissionRequest extends AbstractDTO<CreateAuthorityPermissionDto, ErrorDTO> {
public static final String ROUTING_KEY = "api.CreateAuthorityPermissionRequest";
@Override
public String routingKey() {
return ROUTING_KEY;
}
}
package ee.sm.ti.teis.commongateway.representative.authoritypermission.request;
import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO;
import ee.sm.ti.teis.commongateway.representative.authoritypermission.dto.UpdateAuthorityPermissionValidUntilDto;
public class UpdateAuthorityPermissionValidUntilRequest extends AbstractDTO<UpdateAuthorityPermissionValidUntilDto, ErrorDTO> {
public static final String ROUTING_KEY = "api.UpdateAuthorityPermissionValidUntilRequest";
@Override
public String routingKey() {
return ROUTING_KEY;
}
}
package ee.sm.ti.teis.commongateway.representative.authoritypermission.response;
import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO;
import ee.sm.ti.teis.commongateway.representative.authoritypermission.dto.AuthorityPermissionAuthorityDto;
public class AuthorityPermissionAuthorityResponse extends AbstractDTO<AuthorityPermissionAuthorityDto, ErrorDTO> {
public static final String ROUTING_KEY = "api.AuthorityPermissionAuthorityResponse";
@Override
public String routingKey() {
return ROUTING_KEY;
}
}
package ee.sm.ti.teis.commongateway.representative.authoritypermission.response;
import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO;
import ee.sm.ti.teis.commongateway.representative.authoritypermission.dto.AuthorityPermissionDto;
import java.util.List;
public class AuthorityPermissionGrantorResponse extends AbstractDTO<List<AuthorityPermissionDto>, ErrorDTO> {
public static final String ROUTING_KEY = "api.AuthorityPermissionGrantorResponse";
@Override
public String routingKey() {
return ROUTING_KEY;
}
}
package ee.sm.ti.teis.commongateway.representative.authoritypermission.response;
import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO;
import ee.sm.ti.teis.commongateway.representative.authoritypermission.dto.AuthorityPermissionDto;
public class CreateAuthorityPermissionResponse extends AbstractDTO<AuthorityPermissionDto, ErrorDTO> {
public static final String ROUTING_KEY = "api.CreateAuthorityPermissionResponse";
@Override
public String routingKey() {
return ROUTING_KEY;
}
}
package ee.sm.ti.teis.commongateway.representative.authoritypermission.response;
import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO;
import ee.sm.ti.teis.commongateway.representative.authoritypermission.dto.AuthorityPermissionDto;
public class UpdateAuthorityPermissionValidUntilResponse extends AbstractDTO<AuthorityPermissionDto, ErrorDTO> {
public static final String ROUTING_KEY = "api.UpdateAuthorityPermissionValidUntilResponse";
@Override
public String routingKey() {
return ROUTING_KEY;
}
}
......@@ -19,7 +19,5 @@ public class UpdateRiskFactorAssessmentDescriptionPublicDto {
private UUID id;
@Size(max = 40)
private String name;
@Size(min = 3)
@NotNull
private String description;
}
......@@ -17,4 +17,5 @@ public class RoleDefinitionLightDto implements Serializable {
private String name;
private String roleCode;
private Long seqNo;
private String roleType;
}
package ee.sm.ti.teis.commongateway.tasks.task.dto;
import ee.sm.ti.teis.commongateway.classifier.ClassifierItemLightDto;
import ee.sm.ti.teis.types.enums.TaskStatusType;
import lombok.*;
......@@ -17,16 +18,19 @@ public class PatchTaskDto extends TaskRequestParamDto {
private LocalDateTime deadlineEnd;
private String description;
private TaskStatusType status;
private ClassifierItemLightDto tag;
@Builder(builderMethodName = "patchTaskDtoBuilder")
public PatchTaskDto(UUID id, String taskDefinitionCode, UUID dataObjectId, UUID employerId, LocalDateTime deadline,
LocalDateTime deadlineEnd, String description, TaskStatusType status) {
LocalDateTime deadlineEnd, String description, TaskStatusType status,
ClassifierItemLightDto tag) {
super(id, taskDefinitionCode, dataObjectId);
this.employerId = employerId;
this.deadline = deadline;
this.deadlineEnd = deadlineEnd;
this.description = description;
this.status = status;
this.tag = tag;
}
public boolean isSingle() {
......
package ee.sm.ti.teis.commongateway.tasks.task.dto;
import ee.sm.ti.teis.commongateway.classifier.ClassifierItemLightDto;
import ee.sm.ti.teis.commongateway.person.PersonDto;
import ee.sm.ti.teis.commongateway.tasks.task.assignee.TaskAssigneeDto;
import ee.sm.ti.teis.commongateway.tasks.task.definition.TaskDefinitionDto;
......@@ -38,5 +39,7 @@ public class TaskDto {
@NotNull
@Valid
private TaskDefinitionDto taskDefinition;
private ClassifierItemLightDto tag;
private ObjectStatus objectStatus;
}
......@@ -2,38 +2,18 @@ description = """common-api-gateway"""
functionalities {
gateway
database
file
}
apply from: this.getClass().getClassLoader().getResource('teis.integrationTest.gradle')
apply from: this.getClass().getClassLoader().getResource('teis.microservice.gradle')
dependencies {
// Spring
compile 'org.springframework.boot:spring-boot-starter-security'
compile 'org.springframework.security:spring-security-oauth2-resource-server'
compile 'org.springframework.security:spring-security-oauth2-client'
compile 'org.springframework.security:spring-security-oauth2-jose'
compile "org.springframework.boot:spring-boot-starter-data-jpa"
// BPM
compile "org.camunda.bpm.springboot:camunda-bpm-spring-boot-starter-webapp:3.2.1"
implementation 'javax.ws.rs:javax.ws.rs-api:2.1.1'
// File storage
compile 'io.minio:minio:6.0.11'
//TeIS
compile "ee.sm.ti.teis:service-common-lib:${commonsVersion}"
compile "ee.sm.ti.teis:gateway-common-lib:${commonsVersion}"
compile project(':common-api-gateway-lib')
// Misc
compile 'io.jsonwebtoken:jjwt-api:0.10.5'
runtime 'io.jsonwebtoken:jjwt-impl:0.10.5',
// Uncomment the next line if you want to use RSASSA-PSS (PS256, PS384, PS512) algorithms:
'org.bouncycastle:bcprov-jdk15on:1.60',
'io.jsonwebtoken:jjwt-jackson:0.10.5'
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.7'
}
// Define the main class for the application
......
......@@ -2,6 +2,7 @@ package ee.sm.ti.teis.commongateway;
import ee.sm.ti.teis.CommonApiGateway;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.ApplicationContextInitializer;
......@@ -14,16 +15,17 @@ import org.testcontainers.junit.jupiter.Testcontainers;
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = CommonApiGateway.class)
@AutoConfigureMockMvc
@ActiveProfiles({"mockauth", "integtest", "no_keycloak"})
@Testcontainers
@ContextConfiguration(initializers = { CommonApiGatewayTestBase.Initializer.class })
@ContextConfiguration(initializers = {CommonApiGatewayTestBase.Initializer.class})
public abstract class CommonApiGatewayTestBase {
private static final GenericContainer rabbitMQContainer;
private static final GenericContainer<?> rabbitMQContainer;
// to speed up tests, lets use static container, it is used in all test classes that are executed inside one Spring Context
static {
rabbitMQContainer = new GenericContainer("rabbitmq:latest").withExposedPorts(5672);
rabbitMQContainer = new GenericContainer<>("rabbitmq:latest").withExposedPorts(5672);
rabbitMQContainer.start();
}
......@@ -34,7 +36,7 @@ public abstract class CommonApiGatewayTestBase {
// It generates random port numbers on host side) and add then to Spring context.
TestPropertyValues
.of("spring.rabbitmq.port:" + rabbitMQContainer.getFirstMappedPort(),
"spring.rabbitmq.host:" + rabbitMQContainer.getContainerIpAddress())
"spring.rabbitmq.host:" + rabbitMQContainer.getContainerIpAddress())
.applyTo(configurableApplicationContext.getEnvironment());
}
}
......
......@@ -19,7 +19,7 @@ public class MessageControllerTest extends CommonApiGatewayTestBase {
@Test
void getMessages() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.getMessages(randomUUID(), new RequestMetaDTO()));
controller.getMessages(randomUUID(), "", new RequestMetaDTO()));
}
@Test
......@@ -43,7 +43,7 @@ public class MessageControllerTest extends CommonApiGatewayTestBase {
@Test
void getMessagesByAddressee() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.getMessagesByAddressee(null, null, new RequestMetaDTO()));
controller.getMessagesByAddressee(null, null, "", new RequestMetaDTO()));
}
}
package ee.sm.ti.teis.commongateway.messages.message;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import static java.util.UUID.randomUUID;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class MessageTestControllerTest extends CommonApiGatewayTestBase {
@Autowired
MessageTestController controller;
@Test
void getMessage_throwsException() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.getMessage(randomUUID(), new RequestMetaDTO()));
}
}
package ee.sm.ti.teis.commongateway.representative.authority;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import static org.junit.jupiter.api.Assertions.assertThrows;
class AuthorityControllerTest extends CommonApiGatewayTestBase {
@Autowired
AuthorityController controller;
@Test
void getAuthorities_badRequest() {
assertThrows(NoResponseFromRabbitException.class,
() -> controller.getAuthorities(null, new RequestMetaDTO()));
}
}
package ee.sm.ti.teis.commongateway.representative.authoritypermission;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.commongateway.representative.authoritypermission.dto.CreateAuthorityPermissionDto;
import ee.sm.ti.teis.commongateway.representative.authoritypermission.dto.UpdateAuthorityPermissionValidUntilDto;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.types.enums.AuthorityType;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import static java.util.UUID.randomUUID;
import static org.junit.jupiter.api.Assertions.assertThrows;
class AuthorityPermissionControllerTest extends CommonApiGatewayTestBase {
@Autowired
AuthorityPermissionController controller;
@Test
void create_badRequest() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.create(new CreateAuthorityPermissionDto(), new RequestMetaDTO()));
}
@Test
void getByAuthority_badRequest() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.getByAuthority(randomUUID(), AuthorityType.OH, null, new RequestMetaDTO()));
}
@Test
void getByGrantor_badRequest() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.getByGrantor(randomUUID(), null, new RequestMetaDTO()));
}
@Test
void updateValidUntil_badRequest() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.updateValidUntil(randomUUID(), new UpdateAuthorityPermissionValidUntilDto(), new RequestMetaDTO()));
}
}
package ee.sm.ti.teis.commongateway.security.auth;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import static ee.sm.ti.teis.commongateway.security.auth.GrantType.AUTHORIZATION_CODE;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
public class AuthPublicControllerMvcTest extends CommonApiGatewayTestBase {
@Mock
KeycloakTokenService keycloakTokenService;
@InjectMocks
AuthPublicController authPublicController;
private MockMvc mockMvc;
@Captor
ArgumentCaptor<TokenRequest> captor;
@BeforeEach
public void setup() {
this.mockMvc = MockMvcBuilders.standaloneSetup(authPublicController).build();
}
@Test
public void get_token_for_authorization_code() throws Exception {
mockMvc.perform(MockMvcRequestBuilders
.post("/public/auth/token")
.content("{\"client_id\": \"teis\", " +
"\"code\": \"88be2960-4b69-47ce-81a1-afdd97df6b58.7e503b86-dd58-488c-b1b1-951d64e60a58.a372a1c2-c9b9-4533-8be5-718243356867\", " +
"\"grant_type\": \"authorization_code\", " +
"\"redirect_uri\": \"http://localhost:4300/login\", " +
"\"scope\": \"openid\"" +
"}")
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andReturn();
verify(keycloakTokenService, times(1)).exchangeAccessTokenRequest(captor.capture(), any());
assertThat(AUTHORIZATION_CODE).isEqualTo(captor.getValue().getGrantType());
assertThat("teis").isEqualTo(captor.getValue().getClientId());
}
}
......@@ -39,4 +39,10 @@ public class AuthPublicControllerTest extends CommonApiGatewayTestBase {
assertThrows(IllegalArgumentException.class, () ->
controller.getAccessToken(tokenRequest, new RequestMetaDTO()));
}
@Test
void logout_throwsIllegalArgumentException() {
assertThrows(IllegalArgumentException.class, () ->
controller.logout(new LogoutRequest(), new RequestMetaDTO()));
}
}
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