Skip to content

Commit

Permalink
MODELINKS-150: Make system user usage optional
Browse files Browse the repository at this point in the history
  • Loading branch information
pfilippov-epam committed Nov 12, 2023
1 parent ee2d7b3 commit 10ec2a0
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ docker run -t -i -p 8081:8081 mod-entities-links
| OKAPI_URL | - | Okapi URL |
| SYSTEM_USER_USERNAME | mod-entities-links | Username for system user |
| SYSTEM_USER_PASSWORD | - | Password for system user |
| SYSTEM_USER_ENABLED | true | Defines if system user must be created at service tenant initialization or used for egress service requests |
| KAFKA_HOST | kafka | Kafka broker hostname |
| KAFKA_PORT | 9092 | Kafka broker port |
| KAFKA_SECURITY_PROTOCOL | PLAINTEXT | Kafka security protocol used to communicate with brokers (SSL or PLAINTEXT) |
Expand Down
5 changes: 3 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>org.folio</groupId>
<artifactId>mod-entities-links</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.0-modelinks-150</version>
<description>Module for storing and processing links between entities</description>
<packaging>jar</packaging>

Expand All @@ -28,6 +28,7 @@
<folio-spring-base.version>7.2.0</folio-spring-base.version>
<hypersistence-utils-hibernate.version>3.6.0</hypersistence-utils-hibernate.version>
<folio-service-tools.version>3.1.0</folio-service-tools.version>
<folio-spring-system-user.version>7.3.0-folspringb-128</folio-spring-system-user.version>
<mapstruct.version>1.5.5.Final</mapstruct.version>
<lombok.mapstruct-binding.version>0.2.0</lombok.mapstruct-binding.version>
<marc4j.version>2.9.5</marc4j.version>
Expand Down Expand Up @@ -63,7 +64,7 @@
<dependency>
<groupId>org.folio</groupId>
<artifactId>folio-spring-system-user</artifactId>
<version>${folio-spring-base.version}</version>
<version>${folio-spring-system-user.version}</version>
</dependency>

<dependency>
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ folio:
environment: ${ENV:folio}
okapi-url: ${OKAPI_URL:http://localhost:9130}
system-user:
enabled: ${SYSTEM_USER_ENABLED:true}
username: ${SYSTEM_USER_USERNAME:mod-entities-links}
password: ${SYSTEM_USER_PASSWORD}
lastname: Automated linking update
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package org.folio.entlinks.controller;

import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.folio.support.TestDataUtils.AuthorityTestData.authority;
import static org.folio.support.TestDataUtils.AuthorityTestData.authoritySourceFile;
import static org.folio.support.base.TestConstants.TENANT_ID;
import static org.folio.support.base.TestConstants.USER_ID;
import static org.folio.support.base.TestConstants.authorityEndpoint;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.Matchers.is;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import java.util.List;
import org.folio.entlinks.domain.entity.Authority;
import org.folio.spring.client.AuthnClient;
import org.folio.spring.client.PermissionsClient;
import org.folio.spring.client.UsersClient;
import org.folio.spring.test.extension.DatabaseCleanup;
import org.folio.spring.test.type.IntegrationTest;
import org.folio.support.DatabaseHelper;
import org.folio.support.base.IntegrationTestBase;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.TestPropertySource;

@IntegrationTest
@DatabaseCleanup(tables = {
DatabaseHelper.AUTHORITY_SOURCE_FILE_CODE_TABLE,
DatabaseHelper.AUTHORITY_DATA_STAT_TABLE,
DatabaseHelper.AUTHORITY_TABLE,
DatabaseHelper.AUTHORITY_SOURCE_FILE_TABLE})
@TestPropertySource(properties = "folio.system-user.enabled=false")
class DisabledSystemUserIT extends IntegrationTestBase {

@BeforeAll
static void prepare() {
setUpTenant();
}

@BeforeEach
void setUp(@Autowired ApplicationContext ctx) {
assertThatThrownBy(() -> ctx.getBean(AuthnClient.class)).isInstanceOf(NoSuchBeanDefinitionException.class);
assertThatThrownBy(() -> ctx.getBean(UsersClient.class)).isInstanceOf(NoSuchBeanDefinitionException.class);
assertThatThrownBy(() -> ctx.getBean(PermissionsClient.class)).isInstanceOf(NoSuchBeanDefinitionException.class);
}

@Test
@DisplayName("Get Collection: find all Authority entities")
void getCollection_positive_entitiesFound() throws Exception {
var createdEntities = createAuthorities();

tryGet(authorityEndpoint())
.andExpect(status().isOk())
.andExpect(jsonPath("totalRecords", is(createdEntities.size())))
.andExpect(jsonPath("authorities[0].metadata", notNullValue()))
.andExpect(jsonPath("authorities[0].metadata.createdDate", notNullValue()))
.andExpect(jsonPath("authorities[0].metadata.createdByUserId", is(USER_ID)))
.andExpect(jsonPath("authorities[0].metadata.updatedDate", notNullValue()))
.andExpect(jsonPath("authorities[0].metadata.updatedByUserId", is(USER_ID)));
}

private List<Authority> createAuthorities() {
createSourceFile();
var entity1 = createAuthority(0);
var entity2 = createAuthority(1);
var entity3 = createAuthority(2);

return List.of(entity1, entity2, entity3);
}

private Authority createAuthority(int authorityNum) {
var entity = authority(authorityNum, 0);
databaseHelper.saveAuthority(TENANT_ID, entity);
return entity;
}

private void createSourceFile() {
var entity = authoritySourceFile(0);
databaseHelper.saveAuthoritySourceFile(TENANT_ID, entity);

entity.getAuthoritySourceFileCodes().forEach(code ->
databaseHelper.saveAuthoritySourceFileCode(TENANT_ID, entity.getId(), code));
}
}
3 changes: 3 additions & 0 deletions src/test/java/org/folio/support/base/IntegrationTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
import org.springframework.kafka.core.DefaultKafkaProducerFactory;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.core.ProducerFactory;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;
Expand All @@ -86,6 +88,7 @@
@SpringBootTest
@ActiveProfiles("test")
@AutoConfigureMockMvc
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
@Import(IntegrationTestBase.KafkaTemplateTestConfiguration.class)
public class IntegrationTestBase {

Expand Down
1 change: 1 addition & 0 deletions src/test/resources/application-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ spring:
folio:
environment: folio-test
system-user:
enabled: true
username: mod-entities-links
password: mod-entities-links
lastname: System
Expand Down
10 changes: 10 additions & 0 deletions src/test/resources/mappings/authn.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@
"Content-Type": "application/json"
}
}
},
{
"request": {
"method": "DELETE",
"url": "/authn/credentials?userId=38d3a441-c100-5e8d-bd12-71bde492b723"
},
"response": {
"status": 204,
"body": ""
}
}
]
}

0 comments on commit 10ec2a0

Please sign in to comment.