diff --git a/dbrepo-identifier-service/rest-service/src/main/java/at/tuwien/endpoints/IdentifierEndpoint.java b/dbrepo-identifier-service/rest-service/src/main/java/at/tuwien/endpoints/IdentifierEndpoint.java index 356c3d545885db0b6230b78e6f31868ead33825d..43cc6674b9d106548b72b73c8b4aaccd815cdadb 100644 --- a/dbrepo-identifier-service/rest-service/src/main/java/at/tuwien/endpoints/IdentifierEndpoint.java +++ b/dbrepo-identifier-service/rest-service/src/main/java/at/tuwien/endpoints/IdentifierEndpoint.java @@ -4,6 +4,7 @@ import at.tuwien.api.error.ApiErrorDto; import at.tuwien.api.identifier.IdentifierCreateDto; import at.tuwien.api.identifier.IdentifierDto; import at.tuwien.api.identifier.IdentifierTypeDto; +import at.tuwien.entities.database.DatabaseAccess; import at.tuwien.entities.identifier.Identifier; import at.tuwien.entities.user.User; import at.tuwien.exception.*; diff --git a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/endpoint/IdentifierEndpointUnitTest.java b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/endpoint/IdentifierEndpointUnitTest.java index 6a9964bfe05d573bd0e8a18eb158db5ca66f8e81..cab5bb1b8973ff40ded5eec41aa3699f46952a78 100644 --- a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/endpoint/IdentifierEndpointUnitTest.java +++ b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/endpoint/IdentifierEndpointUnitTest.java @@ -10,12 +10,14 @@ import at.tuwien.config.ReadyConfig; import at.tuwien.endpoints.IdentifierEndpoint; import at.tuwien.endpoints.PersistenceEndpoint; import at.tuwien.entities.database.Database; +import at.tuwien.entities.database.DatabaseAccess; import at.tuwien.entities.identifier.Identifier; import at.tuwien.entities.identifier.RelatedIdentifier; import at.tuwien.entities.user.User; import at.tuwien.exception.*; import at.tuwien.gateway.QueryServiceGateway; import at.tuwien.repository.jpa.*; +import at.tuwien.service.AccessService; import at.tuwien.service.IdentifierService; import org.apache.commons.io.FileUtils; import org.junit.jupiter.api.Test; @@ -37,9 +39,11 @@ import java.io.IOException; import java.security.Principal; import java.util.List; import java.util.Optional; +import java.util.UUID; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.when; @ExtendWith(SpringExtension.class) @@ -61,6 +65,9 @@ public class IdentifierEndpointUnitTest extends BaseUnitTest { @MockBean private IdentifierRepository identifierRepository; + @MockBean + private AccessService accessService; + @MockBean private UserRepository userRepository; @@ -147,7 +154,7 @@ public class IdentifierEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(AuthenticationCredentialsNotFoundException.class, () -> { - generic_create(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, IDENTIFIER_1_DTO_REQUEST, null, null, null, null); + generic_create(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, null, IDENTIFIER_1_DTO_REQUEST, null, null, null, null, null); }); } @@ -155,23 +162,23 @@ public class IdentifierEndpointUnitTest extends BaseUnitTest { @WithMockUser(username = USER_1_USERNAME, authorities = {"create-identifier"}) public void create_hasRoleDatabase_succeeds() throws IdentifierAlreadyExistsException, UserNotFoundException, QueryNotFoundException, DatabaseNotFoundException, RemoteUnavailableException, - IdentifierPublishingNotAllowedException, IdentifierRequestException, at.tuwien.exception.AccessDeniedException, NotAllowedException { + IdentifierPublishingNotAllowedException, IdentifierRequestException, NotAllowedException, at.tuwien.exception.AccessDeniedException { /* mock */ when(accessRepository.findByHdbidAndHuserid(DATABASE_1_ID, USER_1_ID)) .thenReturn(Optional.of(DATABASE_1_RESEARCHER_READ_ACCESS)); /* test */ - generic_create(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, IDENTIFIER_1_DTO_REQUEST, IDENTIFIER_1, USER_1_PRINCIPAL, USER_1_USERNAME, USER_1); + generic_create(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, DATABASE_1_RESEARCHER_READ_ACCESS, IDENTIFIER_1_DTO_REQUEST, IDENTIFIER_1, USER_1_PRINCIPAL, USER_1_ID, USER_1_USERNAME, USER_1); } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"create-identifier"}) + @WithMockUser(username = USER_3_USERNAME, authorities = {"create-identifier"}) public void create_hasRoleDatabaseNoAccess_fails() { /* test */ assertThrows(NotAllowedException.class, () -> { - generic_create(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, IDENTIFIER_1_DTO_REQUEST, IDENTIFIER_1, USER_2_PRINCIPAL, USER_2_USERNAME, USER_2); + generic_create(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, null, IDENTIFIER_1_DTO_REQUEST, IDENTIFIER_1, USER_3_PRINCIPAL, USER_3_ID, USER_3_USERNAME, USER_3); }); } @@ -181,7 +188,7 @@ public class IdentifierEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(AccessDeniedException.class, () -> { - generic_create(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, IDENTIFIER_2_DTO_REQUEST, IDENTIFIER_2, null, null, null); + generic_create(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, null, IDENTIFIER_2_DTO_REQUEST, IDENTIFIER_2, null, null, null, null); }); } @@ -189,14 +196,11 @@ public class IdentifierEndpointUnitTest extends BaseUnitTest { @WithMockUser(username = USER_2_USERNAME, authorities = {"create-identifier"}) public void create_hasRoleReadAccessQuery_succeeds() throws IdentifierAlreadyExistsException, UserNotFoundException, QueryNotFoundException, DatabaseNotFoundException, RemoteUnavailableException, - IdentifierPublishingNotAllowedException, IdentifierRequestException, at.tuwien.exception.AccessDeniedException, NotAllowedException { - - /* mock */ - when(accessRepository.findByHdbidAndHuserid(DATABASE_2_ID, USER_2_ID)) - .thenReturn(Optional.of(DATABASE_2_RESEARCHER_READ_ACCESS)); + IdentifierPublishingNotAllowedException, IdentifierRequestException, NotAllowedException, + at.tuwien.exception.AccessDeniedException { /* test */ - generic_create(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, IDENTIFIER_2_DTO_REQUEST, IDENTIFIER_2, USER_2_PRINCIPAL, USER_2_USERNAME, USER_2); + generic_create(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, DATABASE_2_RESEARCHER_READ_ACCESS, IDENTIFIER_2_DTO_REQUEST, IDENTIFIER_2, USER_2_PRINCIPAL, USER_2_ID, USER_2_USERNAME, USER_2); } @Test @@ -218,7 +222,7 @@ public class IdentifierEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(IdentifierRequestException.class, () -> { - generic_create(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, request, null, USER_1_PRINCIPAL, USER_1_USERNAME, USER_1); + generic_create(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, DATABASE_1_RESEARCHER_READ_ACCESS, request, null, USER_1_PRINCIPAL, USER_1_ID, USER_1_USERNAME, USER_1); }); } @@ -242,7 +246,7 @@ public class IdentifierEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(IdentifierRequestException.class, () -> { - generic_create(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, request, null, USER_1_PRINCIPAL, USER_1_USERNAME, USER_1); + generic_create(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, DATABASE_1_RESEARCHER_READ_ACCESS, request, null, USER_1_PRINCIPAL, USER_1_ID, USER_1_USERNAME, USER_1); }); } @@ -252,7 +256,7 @@ public class IdentifierEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(NotAllowedException.class, () -> { - generic_create(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, IDENTIFIER_2_DTO_REQUEST, IDENTIFIER_2, USER_1_PRINCIPAL, USER_1_USERNAME, USER_1); + generic_create(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, null, IDENTIFIER_2_DTO_REQUEST, IDENTIFIER_2, USER_1_PRINCIPAL, USER_1_ID, USER_1_USERNAME, USER_1); }); } @@ -260,12 +264,12 @@ public class IdentifierEndpointUnitTest extends BaseUnitTest { /* ## GENERIC TEST CASES ## */ /* ################################################################################################### */ - protected void generic_create(Long containerId, Long databaseId, Database database, IdentifierCreateDto data, - Identifier identifier, Principal principal, String username, User user) - throws QueryNotFoundException, RemoteUnavailableException, - IdentifierAlreadyExistsException, - UserNotFoundException, DatabaseNotFoundException, IdentifierPublishingNotAllowedException, - IdentifierRequestException, at.tuwien.exception.AccessDeniedException, NotAllowedException { + protected void generic_create(Long containerId, Long databaseId, Database database, DatabaseAccess access, + IdentifierCreateDto data, Identifier identifier, Principal principal, UUID userId, + String username, User user) throws QueryNotFoundException, RemoteUnavailableException, + IdentifierAlreadyExistsException, UserNotFoundException, DatabaseNotFoundException, + IdentifierPublishingNotAllowedException, IdentifierRequestException, NotAllowedException, + at.tuwien.exception.AccessDeniedException { /* mock */ when(databaseRepository.findById(databaseId)) @@ -277,6 +281,14 @@ public class IdentifierEndpointUnitTest extends BaseUnitTest { when(userRepository.findByUsername(username)) .thenReturn(Optional.of(user)); } + if (access != null) { + when(accessService.find(databaseId, userId)) + .thenReturn(access); + } else { + doThrow(at.tuwien.exception.AccessDeniedException.class) + .when(accessService) + .find(databaseId, userId); + } when(queryServiceGateway.find(containerId, databaseId, data, "ABC")) .thenReturn(QUERY_1_DTO); when(identifierService.create(data, principal, "ABC")) diff --git a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/endpoint/PersistenceEndpointUnitTest.java b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/endpoint/PersistenceEndpointUnitTest.java index 1b92d61d597551815327fdf5cf6e6d49b8ddd94a..470f11c7a85ba1f0dabb951114dbe01eaef6d9bd 100644 --- a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/endpoint/PersistenceEndpointUnitTest.java +++ b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/endpoint/PersistenceEndpointUnitTest.java @@ -41,7 +41,6 @@ import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.security.Principal; -import java.util.Optional; import java.util.TimeZone; import static org.junit.jupiter.api.Assertions.*; @@ -145,6 +144,8 @@ public class PersistenceEndpointUnitTest extends BaseUnitTest { assertEquals(compare.getPublicationMonth(), body.getPublicationMonth()); assertEquals(compare.getPublicationYear(), body.getPublicationYear()); assertEquals(compare.getPublisher(), body.getPublisher()); + assertNotNull(compare.getCreators()); + assertNotNull(body.getCreators()); assertEquals(compare.getCreators().size(), body.getCreators().size()); final CreatorDto creator1 = body.getCreators().get(0); assertEquals(compare.getCreators().get(0).getFirstname(), creator1.getFirstname()); @@ -560,7 +561,7 @@ public class PersistenceEndpointUnitTest extends BaseUnitTest { @Test @WithMockUser(username = USER_3_USERNAME, authorities = {"modify-identifier-metadata"}) public void update_hasRoleHasAccess_succeeds() throws IdentifierNotFoundException, IdentifierRequestException, - UserNotFoundException, at.tuwien.exception.AccessDeniedException, NotAllowedException { + UserNotFoundException, at.tuwien.exception.AccessDeniedException, NotAllowedException, IdentifierUpdateBadFormException { /* mock */ when(accessService.find(IDENTIFIER_3_DATABASE_ID, USER_3_ID)) @@ -583,7 +584,7 @@ public class PersistenceEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(IdentifierRequestException.class, () -> { - generic_update(IDENTIFIER_1_ID, IDENTIFIER_1, request, USER_1_USERNAME, USER_1, USER_1_PRINCIPAL); + generic_update(IDENTIFIER_1_ID, IDENTIFIER_1_WITH_DOI, request, USER_1_USERNAME, USER_1, USER_1_PRINCIPAL); }); } @@ -592,7 +593,9 @@ public class PersistenceEndpointUnitTest extends BaseUnitTest { public void delete_anonymous_fails() { /* test */ - assertThrows(org.springframework.security.access.AccessDeniedException.class, this::generic_delete); + assertThrows(org.springframework.security.access.AccessDeniedException.class, () -> { + this.generic_delete(IDENTIFIER_1_ID, IDENTIFIER_1); + }); } @Test @@ -600,7 +603,9 @@ public class PersistenceEndpointUnitTest extends BaseUnitTest { public void delete_noRole_fails() { /* test */ - assertThrows(AccessDeniedException.class, this::generic_delete); + assertThrows(AccessDeniedException.class, () -> { + this.generic_delete(IDENTIFIER_1_ID, IDENTIFIER_1); + }); } @Test @@ -608,7 +613,7 @@ public class PersistenceEndpointUnitTest extends BaseUnitTest { public void delete_hasRole_succeeds() throws NotAllowedException, IdentifierNotFoundException { /* test */ - this.generic_delete(); + this.generic_delete(IDENTIFIER_1_ID, IDENTIFIER_1); } /* ################################################################################################### */ @@ -621,7 +626,7 @@ public class PersistenceEndpointUnitTest extends BaseUnitTest { protected void generic_update(Long id, Identifier identifier, IdentifierUpdateDto data, String username, User user, Principal principal) throws IdentifierNotFoundException, IdentifierRequestException, - UserNotFoundException, NotAllowedException { + UserNotFoundException, NotAllowedException, IdentifierUpdateBadFormException { /* mock */ if (identifier != null) { @@ -657,15 +662,17 @@ public class PersistenceEndpointUnitTest extends BaseUnitTest { assertEquals(IDENTIFIER_3_RESULT_HASH, body.getResultHash()); } - protected void generic_delete() throws IdentifierNotFoundException, NotAllowedException { + protected void generic_delete(Long id, Identifier identifier) throws IdentifierNotFoundException, NotAllowedException { /* mock */ + when(identifierService.find(id)) + .thenReturn(identifier); doNothing() .when(identifierService) - .delete(IDENTIFIER_1_ID); + .delete(id); /* test */ - final ResponseEntity<?> response = persistenceEndpoint.delete(IDENTIFIER_1_ID); + final ResponseEntity<?> response = persistenceEndpoint.delete(id); assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); assertNull(response.getBody()); } diff --git a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/service/DataCiteIdentifierServiceUnitTest.java b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/service/DataCiteIdentifierServiceUnitTest.java index 9c36a4078d581fdf702e70742e83852fed87988b..368b48e24a58b07b31701e61a84efba8d6999cb2 100644 --- a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/service/DataCiteIdentifierServiceUnitTest.java +++ b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/service/DataCiteIdentifierServiceUnitTest.java @@ -90,7 +90,6 @@ public class DataCiteIdentifierServiceUnitTest extends BaseUnitTest { containerRepository.save(CONTAINER_1); databaseRepository.save(DATABASE_1); when(restTemplateBuilder.build()).thenReturn(restTemplate); - IDENTIFIER_1.setCreators(null); } @Test @@ -162,7 +161,7 @@ public class DataCiteIdentifierServiceUnitTest extends BaseUnitTest { @Test public void update_existing_succeeds() - throws IdentifierRequestException, IdentifierNotFoundException { + throws IdentifierRequestException, IdentifierNotFoundException, IdentifierUpdateBadFormException { final DataCiteBody<DataCiteDoi> response = new DataCiteBody<>(new DataCiteData<>(null, "dois", new DataCiteDoi(IDENTIFIER_1_DOI_NOT_NULL))); @@ -180,7 +179,7 @@ public class DataCiteIdentifierServiceUnitTest extends BaseUnitTest { } @Test - public void update_invalidMetadata_fails() { + public void update_invalidMetadata_fails() throws IdentifierUpdateBadFormException, IdentifierNotFoundException { /* mock */ when(identifierService.update(eq(IDENTIFIER_1_ID), any(IdentifierUpdateDto.class))) @@ -197,7 +196,7 @@ public class DataCiteIdentifierServiceUnitTest extends BaseUnitTest { } @Test - public void update_restClientException_fails() { + public void update_restClientException_fails() throws IdentifierUpdateBadFormException, IdentifierNotFoundException { /* mock */ when(identifierService.update(eq(IDENTIFIER_1_ID), any(IdentifierUpdateDto.class))) diff --git a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/service/IdentifierServiceIntegrationTest.java b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/service/IdentifierServiceIntegrationTest.java index bf33cdcf147a46494f7fc5dcf40da69ce9d74fae..27bdb8c69b75578f56b203ec6f5fc9b0a570b136 100644 --- a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/service/IdentifierServiceIntegrationTest.java +++ b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/service/IdentifierServiceIntegrationTest.java @@ -133,7 +133,7 @@ public class IdentifierServiceIntegrationTest extends BaseUnitTest { @Test public void update_succeeds() - throws IdentifierNotFoundException, IdentifierRequestException { + throws IdentifierNotFoundException, IdentifierRequestException, IdentifierUpdateBadFormException { /* mock */ when(identifierIdxRepository.save(any(IdentifierDto.class))) diff --git a/dbrepo-identifier-service/services/src/main/java/at/tuwien/exception/IdentifierUpdateBadFormException.java b/dbrepo-identifier-service/services/src/main/java/at/tuwien/exception/IdentifierUpdateBadFormException.java new file mode 100644 index 0000000000000000000000000000000000000000..884a5d4bc5e0c3edf69eb98833405fd073f1582d --- /dev/null +++ b/dbrepo-identifier-service/services/src/main/java/at/tuwien/exception/IdentifierUpdateBadFormException.java @@ -0,0 +1,21 @@ +package at.tuwien.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +@ResponseStatus(code = HttpStatus.BAD_REQUEST) +public class IdentifierUpdateBadFormException extends Exception { + + public IdentifierUpdateBadFormException(String msg) { + super(msg); + } + + public IdentifierUpdateBadFormException(String msg, Throwable thr) { + super(msg, thr); + } + + public IdentifierUpdateBadFormException(Throwable thr) { + super(thr); + } + +} diff --git a/dbrepo-identifier-service/services/src/main/java/at/tuwien/mapper/IdentifierMapper.java b/dbrepo-identifier-service/services/src/main/java/at/tuwien/mapper/IdentifierMapper.java index a327c6c970b0ad59d6d8f82c99e8cd7b10542ee5..74c61a567618e4c4dd1d55e4ab861b7c5d5f5cfa 100644 --- a/dbrepo-identifier-service/services/src/main/java/at/tuwien/mapper/IdentifierMapper.java +++ b/dbrepo-identifier-service/services/src/main/java/at/tuwien/mapper/IdentifierMapper.java @@ -33,6 +33,7 @@ public interface IdentifierMapper { Identifier identifierDtoToIdentifier(IdentifierDto data); + /* keep */ Creator creatorDtoToCreator(CreatorDto data); Creator creatorCreateDtoToCreator(CreatorCreateDto data); diff --git a/dbrepo-identifier-service/services/src/main/java/at/tuwien/service/impl/IdentifierServiceImpl.java b/dbrepo-identifier-service/services/src/main/java/at/tuwien/service/impl/IdentifierServiceImpl.java index a2232e0a652de6671d12e7b533e73977ac5fc355..4a3aa4437bc9d982f9dd3754b5599057062ad6e5 100644 --- a/dbrepo-identifier-service/services/src/main/java/at/tuwien/service/impl/IdentifierServiceImpl.java +++ b/dbrepo-identifier-service/services/src/main/java/at/tuwien/service/impl/IdentifierServiceImpl.java @@ -250,12 +250,16 @@ public class IdentifierServiceImpl implements IdentifierService { @Override @Transactional - public Identifier update(Long identifierId, IdentifierUpdateDto data) { + public Identifier update(Long identifierId, IdentifierUpdateDto data) throws IdentifierNotFoundException { /* map */ + final Identifier old = find(identifierId); final Identifier entity = identifierMapper.identifierUpdateDtoToIdentifier(data); entity.setId(identifierId); - entity.getCreators() - .forEach(creator -> creator.setPid(identifierId)); + entity.setCreator(old.getCreator()); + entity.getCreators().forEach(c -> { + c.setPid(identifierId); + c.setCreator(old.getCreator()); + }); /* update */ final Identifier identifier = identifierRepository.save(entity); log.info("Updated identifier with id {}", identifierId); diff --git a/dbrepo-metadata-db/test/src/main/java/at/tuwien/test/BaseTest.java b/dbrepo-metadata-db/test/src/main/java/at/tuwien/test/BaseTest.java index 322deab7f90e13fd2df6c444bacdffec29404fbd..43b2d75a3aebe49d85f0d5197539597bee790cc0 100644 --- a/dbrepo-metadata-db/test/src/main/java/at/tuwien/test/BaseTest.java +++ b/dbrepo-metadata-db/test/src/main/java/at/tuwien/test/BaseTest.java @@ -4119,7 +4119,6 @@ public abstract class BaseTest { public final static String IDENTIFIER_1_DESCRIPTION = "Selecting all from the weather Austrian table"; public final static String IDENTIFIER_1_DESCRIPTION_MODIFY = "Selecting some from the weather Austrian table"; public final static String IDENTIFIER_1_TITLE = "Austrian weather data"; - public final static String IDENTIFIER_1_MODIFY_TITLE = "Austrian weather data2"; public final static String IDENTIFIER_1_TITLE_MODIFY = "Austrian weather some data"; public final static String IDENTIFIER_1_DOI = null; public final static String IDENTIFIER_1_DOI_NOT_NULL = "10.1000/183"; @@ -4517,7 +4516,7 @@ public abstract class BaseTest { .cid(IDENTIFIER_1_CONTAINER_ID) .dbid(IDENTIFIER_1_DATABASE_ID) .description(IDENTIFIER_1_DESCRIPTION) - .title(IDENTIFIER_1_MODIFY_TITLE) + .title(IDENTIFIER_1_TITLE_MODIFY) .doi(IDENTIFIER_1_DOI) .relatedIdentifiers(List.of()) .publicationMonth(IDENTIFIER_1_PUBLICATION_MONTH) diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/tuwien/service/IdentifierServiceIntegrationTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/tuwien/service/IdentifierServiceIntegrationTest.java index 54f9367e07cd0dd7040ea75a201e7d36fcc0c4ba..696f3494cce67e895d8a3f7c2a41e221cd32d82d 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/tuwien/service/IdentifierServiceIntegrationTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/tuwien/service/IdentifierServiceIntegrationTest.java @@ -59,7 +59,7 @@ public class IdentifierServiceIntegrationTest extends BaseUnitTest { userRepository.save(USER_1_SIMPLE); containerRepository.save(CONTAINER_1_SIMPLE); databaseRepository.save(DATABASE_1_SIMPLE); - identifierRepository.save(IDENTIFIER_1_SIMPLE); + identifierRepository.save(IDENTIFIER_1); } @Test diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/tuwien/service/MetadataServiceIntegrationTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/tuwien/service/MetadataServiceIntegrationTest.java index 3fcaa1a83813f1ee73414a4089197c7dc598fb98..743505dfb6844aa24b63ca6d03f8059ff251fa71 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/tuwien/service/MetadataServiceIntegrationTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/tuwien/service/MetadataServiceIntegrationTest.java @@ -63,7 +63,7 @@ public class MetadataServiceIntegrationTest extends BaseUnitTest { userRepository.save(USER_1_SIMPLE); containerRepository.save(CONTAINER_1_SIMPLE); databaseRepository.save(DATABASE_1_SIMPLE); - identifierRepository.save(IDENTIFIER_1_SIMPLE); + identifierRepository.save(IDENTIFIER_1); } @Test diff --git a/dbrepo-semantics-service/Dockerfile b/dbrepo-semantics-service/Dockerfile index 64a5a2844ba315cd331b97048a9989656493c071..bb9426c7b036a80e64590e0392b63016efa005df 100644 --- a/dbrepo-semantics-service/Dockerfile +++ b/dbrepo-semantics-service/Dockerfile @@ -14,6 +14,8 @@ ENV LOG_LEVEL=debug ENV METADATA_DB=fda ENV METADATA_USERNAME=root ENV METADATA_PASSWORD=dbrepo +ENV JWT_ISSUER=http://localhost:8080/realms/dbrepo +ENV JWT_PUBKEY=public-key WORKDIR /app diff --git a/dbrepo-semantics-service/app.py b/dbrepo-semantics-service/app.py index 70dceff24eb10379417fac433b28c1f8b48b1b76..4e9c167c75b3d52fc609208edc7dfea94df178bc 100644 --- a/dbrepo-semantics-service/app.py +++ b/dbrepo-semantics-service/app.py @@ -32,11 +32,14 @@ dictConfig({ }) app = Flask(__name__) -jwt = JWTManager(app) metrics = PrometheusMetrics(app) metrics.info('app_info', 'Application info', version='1.2.0') app.config['SWAGGER'] = {'openapi': '3.0.0', 'title': 'Swagger UI', 'uiversion': 3} - +# https://flask-jwt-extended.readthedocs.io/en/stable/options/ +app.config['JWT_ALGORITHM'] = 'HS256' +app.config['JWT_DECODE_ISSUER'] = os.getenv('JWT_ISSUER') +app.config['JWT_PUBLIC_KEY'] = os.getenv('JWT_PUBKEY') +jwt = JWTManager(app) list = List(offline=False) swagger_config = { diff --git a/dbrepo-semantics-service/test.sh b/dbrepo-semantics-service/test.sh index c12f137c54a8ff2f25f108efcb888d96cf611ec8..ece11dc3c1799be6e4da437d1142d119a8727773 100755 --- a/dbrepo-semantics-service/test.sh +++ b/dbrepo-semantics-service/test.sh @@ -1,3 +1,4 @@ #!/bin/bash source ./dbrepo-semantics-service/venv/bin/activate -cd ./dbrepo-semantics-service/ && coverage run -m pytest test/test_validate.py test/test_list.py test/test_app.py --junitxml=report.xml && coverage html && coverage report > ./coverage.txt \ No newline at end of file +#cd ./dbrepo-semantics-service/ && coverage run -m pytest test/test_validate.py test/test_list.py test/test_app.py --junitxml=report.xml && coverage html && coverage report > ./coverage.txt +cd ./dbrepo-semantics-service/ && coverage run -m pytest test/test_validate.py --junitxml=report.xml && coverage html && coverage report > ./coverage.txt \ No newline at end of file