From 0a3e8a5bb7fd9f3a8b7c2ed1585e2ef7a3763835 Mon Sep 17 00:00:00 2001 From: Parisa Date: Wed, 11 Dec 2024 15:53:14 +0100 Subject: [PATCH] Last commit to sync with the old repo. contains: - use reference id for exporting data - Change crypt4gh and clearinghouse settings to use fega-norway repo - rename vars ro increase readability map the datasets with reference to datasets stable id - Handle the cases where the visas are a mix of Fega and non-fega visas - add tests for dataset reference - add tests for visa token --- sda-doa/docker-compose-posix-outbox.yml | 4 +- sda-doa/docker-compose-s3-outbox.yml | 4 +- sda-doa/pom.xml | 21 ++- .../uio/ifi/localega/doa/model/Dataset.java | 28 ++++ .../localega/doa/model/DatasetReferences.java | 28 ++++ .../doa/mq/ExportRequestsListener.java | 27 +++- .../DatasetReferencesRepository.java | 10 ++ .../doa/repositories/DatasetsRepository.java | 9 ++ .../doa/services/MetadataService.java | 21 ++- .../doa/services/StreamingService.java | 14 +- .../doa/LocalEGADOAApplicationTests.java | 148 +++++++++++++++++- sda-doa/test/mock_auth.py | 22 ++- 12 files changed, 296 insertions(+), 40 deletions(-) create mode 100644 sda-doa/src/main/java/no/uio/ifi/localega/doa/model/Dataset.java create mode 100644 sda-doa/src/main/java/no/uio/ifi/localega/doa/model/DatasetReferences.java create mode 100644 sda-doa/src/main/java/no/uio/ifi/localega/doa/repositories/DatasetReferencesRepository.java create mode 100644 sda-doa/src/main/java/no/uio/ifi/localega/doa/repositories/DatasetsRepository.java diff --git a/sda-doa/docker-compose-posix-outbox.yml b/sda-doa/docker-compose-posix-outbox.yml index 7019c719e..3a593186b 100644 --- a/sda-doa/docker-compose-posix-outbox.yml +++ b/sda-doa/docker-compose-posix-outbox.yml @@ -10,8 +10,8 @@ services: ports: - 5432:5432 environment: - - DB_LEGA_IN_PASSWORD=password - - DB_LEGA_OUT_PASSWORD=password + - LEGA_IN_PASSWORD=password + - LEGA_OUT_PASSWORD=password - POSTGRES_SERVER_CERT=/etc/ega/pg.cert - POSTGRES_SERVER_KEY=/etc/ega/pg.key - POSTGRES_SERVER_CACERT=/etc/ega/CA.cert diff --git a/sda-doa/docker-compose-s3-outbox.yml b/sda-doa/docker-compose-s3-outbox.yml index ebcfac1ad..a659a4c91 100644 --- a/sda-doa/docker-compose-s3-outbox.yml +++ b/sda-doa/docker-compose-s3-outbox.yml @@ -7,8 +7,8 @@ services: ports: - 5432:5432 environment: - - DB_LEGA_IN_PASSWORD=password - - DB_LEGA_OUT_PASSWORD=password + - LEGA_IN_PASSWORD=password + - LEGA_OUT_PASSWORD=password - POSTGRES_SERVER_CERT=/etc/ega/pg.cert - POSTGRES_SERVER_KEY=/etc/ega/pg.key - POSTGRES_SERVER_CACERT=/etc/ega/CA.cert diff --git a/sda-doa/pom.xml b/sda-doa/pom.xml index 9c25a9edd..c71607e83 100644 --- a/sda-doa/pom.xml +++ b/sda-doa/pom.xml @@ -18,6 +18,11 @@ + + com.google.code.gson + gson + 2.11.0 + org.springframework.boot spring-boot-starter-data-jpa @@ -109,9 +114,9 @@ test - no.uio.ifi + no.elixir crypt4gh - 2.5.0 + 3.0.5 org.slf4j @@ -122,7 +127,7 @@ no.elixir clearinghouse - 2.0.1 + 2.0.6 org.slf4j @@ -139,14 +144,8 @@ - github-clearinghouse - elixir-oslo-clearinghouse - https://maven.pkg.github.com/elixir-oslo/clearinghouse - - - github-crypt4gh - uio-bmi-Crypt4GH - https://maven.pkg.github.com/uio-bmi/crypt4gh + github-fega-norway + https://maven.pkg.github.com/ELIXIR-NO/FEGA-Norway diff --git a/sda-doa/src/main/java/no/uio/ifi/localega/doa/model/Dataset.java b/sda-doa/src/main/java/no/uio/ifi/localega/doa/model/Dataset.java new file mode 100644 index 000000000..8ec53f8db --- /dev/null +++ b/sda-doa/src/main/java/no/uio/ifi/localega/doa/model/Dataset.java @@ -0,0 +1,28 @@ +package no.uio.ifi.localega.doa.model; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.hibernate.annotations.CacheConcurrencyStrategy; +import org.hibernate.annotations.Immutable; + +@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL) +@Entity +@Immutable +@Getter +@Setter +@ToString +@RequiredArgsConstructor +@Table(name = "datasets", schema = "sda") +public class Dataset { + @Id + private Long id; + + @Column(name = "stable_id", unique = true) + private String stableId; +} diff --git a/sda-doa/src/main/java/no/uio/ifi/localega/doa/model/DatasetReferences.java b/sda-doa/src/main/java/no/uio/ifi/localega/doa/model/DatasetReferences.java new file mode 100644 index 000000000..7be8b112b --- /dev/null +++ b/sda-doa/src/main/java/no/uio/ifi/localega/doa/model/DatasetReferences.java @@ -0,0 +1,28 @@ +package no.uio.ifi.localega.doa.model; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import lombok.*; +import org.hibernate.annotations.CacheConcurrencyStrategy; +import org.hibernate.annotations.Immutable; + +@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL) +@Entity +@Immutable +@Getter +@Setter +@ToString +@RequiredArgsConstructor +@Table(name = "dataset_references", schema = "sda") +public class DatasetReferences { + @Id + private Integer id; + + @Column(name = "dataset_id", nullable = false) + private Integer datasetId; + + @Column(name = "reference_id", nullable = false) + private String referenceId; +} diff --git a/sda-doa/src/main/java/no/uio/ifi/localega/doa/mq/ExportRequestsListener.java b/sda-doa/src/main/java/no/uio/ifi/localega/doa/mq/ExportRequestsListener.java index bd1706c09..152151879 100644 --- a/sda-doa/src/main/java/no/uio/ifi/localega/doa/mq/ExportRequestsListener.java +++ b/sda-doa/src/main/java/no/uio/ifi/localega/doa/mq/ExportRequestsListener.java @@ -73,11 +73,30 @@ public void listen(String message) { String user = claims.get(Claims.SUBJECT).getAsString(); log.info("Export request received from user {}: {}", user, exportRequest); - Collection datasetIds = aaiService.getDatasetIds(exportRequest.getJwtToken()); - if (StringUtils.isNotEmpty(exportRequest.getDatasetId())) { - exportDataset(user, datasetIds, exportRequest.getDatasetId(), exportRequest.getPublicKey(), exportRequest.getStartCoordinate(), exportRequest.getEndCoordinate()); + Collection approvedDatasetIds = aaiService.getDatasetIds(exportRequest.getJwtToken()); + String requestedDatasetId = exportRequest.getDatasetId(); + if (StringUtils.isNotEmpty(requestedDatasetId)) { + if (metadataService.findByReferenceId(requestedDatasetId) != null) { + Integer datasetsDbTableId = metadataService.findByReferenceId(requestedDatasetId).getDatasetId(); + String stableDatasetId = metadataService.getDataset(datasetsDbTableId).getStableId(); + log.info("Reference id {} mapped to dataset id {}", requestedDatasetId, stableDatasetId); + requestedDatasetId = stableDatasetId; // use stable dataset id instead of reference to complete the export as normal + Collection approvedMappedDatasetIds = approvedDatasetIds.stream() + .map(x -> { + var reference = metadataService.findByReferenceId(x); + if (reference != null && reference.getDatasetId() != null) { + var dataset = metadataService.getDataset(reference.getDatasetId()); + return dataset != null ? dataset.getStableId() : x; + } else { + return x; + } + }) + .toList(); + approvedDatasetIds = approvedMappedDatasetIds; + } + exportDataset(user, approvedDatasetIds, requestedDatasetId, exportRequest.getPublicKey(), exportRequest.getStartCoordinate(), exportRequest.getEndCoordinate()); } else if (StringUtils.isNotEmpty(exportRequest.getFileId())) { - exportFile(user, datasetIds, exportRequest.getFileId(), exportRequest.getPublicKey(), exportRequest.getStartCoordinate(), exportRequest.getEndCoordinate()); + exportFile(user, approvedDatasetIds, exportRequest.getFileId(), exportRequest.getPublicKey(), exportRequest.getStartCoordinate(), exportRequest.getEndCoordinate()); } else { throw new RuntimeException("Either Dataset ID or File ID should be specified"); } diff --git a/sda-doa/src/main/java/no/uio/ifi/localega/doa/repositories/DatasetReferencesRepository.java b/sda-doa/src/main/java/no/uio/ifi/localega/doa/repositories/DatasetReferencesRepository.java new file mode 100644 index 000000000..822fc81cd --- /dev/null +++ b/sda-doa/src/main/java/no/uio/ifi/localega/doa/repositories/DatasetReferencesRepository.java @@ -0,0 +1,10 @@ +package no.uio.ifi.localega.doa.repositories; + +import no.uio.ifi.localega.doa.model.DatasetReferences; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface DatasetReferencesRepository extends JpaRepository { + DatasetReferences findByReferenceId(String referenceId); +} diff --git a/sda-doa/src/main/java/no/uio/ifi/localega/doa/repositories/DatasetsRepository.java b/sda-doa/src/main/java/no/uio/ifi/localega/doa/repositories/DatasetsRepository.java new file mode 100644 index 000000000..9b08cce26 --- /dev/null +++ b/sda-doa/src/main/java/no/uio/ifi/localega/doa/repositories/DatasetsRepository.java @@ -0,0 +1,9 @@ +package no.uio.ifi.localega.doa.repositories; + +import no.uio.ifi.localega.doa.model.Dataset; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface DatasetsRepository extends JpaRepository { +} diff --git a/sda-doa/src/main/java/no/uio/ifi/localega/doa/services/MetadataService.java b/sda-doa/src/main/java/no/uio/ifi/localega/doa/services/MetadataService.java index 05f286a3c..20302c7e5 100644 --- a/sda-doa/src/main/java/no/uio/ifi/localega/doa/services/MetadataService.java +++ b/sda-doa/src/main/java/no/uio/ifi/localega/doa/services/MetadataService.java @@ -2,11 +2,11 @@ import lombok.extern.slf4j.Slf4j; import no.uio.ifi.localega.doa.dto.File; +import no.uio.ifi.localega.doa.model.Dataset; import no.uio.ifi.localega.doa.model.DatasetEventLog; +import no.uio.ifi.localega.doa.model.DatasetReferences; import no.uio.ifi.localega.doa.model.LEGADataset; -import no.uio.ifi.localega.doa.repositories.DatasetEventLogRepository; -import no.uio.ifi.localega.doa.repositories.DatasetRepository; -import no.uio.ifi.localega.doa.repositories.FileRepository; +import no.uio.ifi.localega.doa.repositories.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -32,6 +32,12 @@ public class MetadataService { @Autowired private DatasetEventLogRepository datasetEventLogRepository; + @Autowired + private DatasetReferencesRepository datasetReferencesRepository; + + @Autowired + private DatasetsRepository datasetsRepository; + /** * Returns collection of dataset IDs present in the databse. * @@ -88,4 +94,13 @@ public DatasetEventLog findLatestByDatasetId(String datasetId) { return optionalDatasetEventLog.orElse(null); } + public DatasetReferences findByReferenceId(String referenceId) { + Optional optionalDatasetReferences = Optional.ofNullable(datasetReferencesRepository.findByReferenceId(referenceId)); + return optionalDatasetReferences.orElse(null); + } + + public Dataset getDataset(Integer id) { + return datasetsRepository.findById(id).orElse(null); + } + } diff --git a/sda-doa/src/main/java/no/uio/ifi/localega/doa/services/StreamingService.java b/sda-doa/src/main/java/no/uio/ifi/localega/doa/services/StreamingService.java index b59ecd8d2..a887cb26e 100644 --- a/sda-doa/src/main/java/no/uio/ifi/localega/doa/services/StreamingService.java +++ b/sda-doa/src/main/java/no/uio/ifi/localega/doa/services/StreamingService.java @@ -4,13 +4,13 @@ import io.minio.MinioClient; import io.minio.errors.*; import lombok.extern.slf4j.Slf4j; -import no.uio.ifi.crypt4gh.pojo.header.DataEditList; -import no.uio.ifi.crypt4gh.pojo.header.Header; -import no.uio.ifi.crypt4gh.pojo.header.HeaderPacket; -import no.uio.ifi.crypt4gh.pojo.header.X25519ChaCha20IETFPoly1305HeaderPacket; -import no.uio.ifi.crypt4gh.stream.Crypt4GHInputStream; -import no.uio.ifi.crypt4gh.util.Crypt4GHUtils; -import no.uio.ifi.crypt4gh.util.KeyUtils; +import no.elixir.crypt4gh.pojo.header.DataEditList; +import no.elixir.crypt4gh.pojo.header.Header; +import no.elixir.crypt4gh.pojo.header.HeaderPacket; +import no.elixir.crypt4gh.pojo.header.X25519ChaCha20IETFPoly1305HeaderPacket; +import no.elixir.crypt4gh.stream.Crypt4GHInputStream; +import no.elixir.crypt4gh.util.Crypt4GHUtils; +import no.elixir.crypt4gh.util.KeyUtils; import no.uio.ifi.localega.doa.dto.DestinationFormat; import no.uio.ifi.localega.doa.model.LEGADataset; import no.uio.ifi.localega.doa.model.LEGAFile; diff --git a/sda-doa/src/test/java/no/uio/ifi/localega/doa/LocalEGADOAApplicationTests.java b/sda-doa/src/test/java/no/uio/ifi/localega/doa/LocalEGADOAApplicationTests.java index aebad2a5a..2ece458ab 100644 --- a/sda-doa/src/test/java/no/uio/ifi/localega/doa/LocalEGADOAApplicationTests.java +++ b/sda-doa/src/test/java/no/uio/ifi/localega/doa/LocalEGADOAApplicationTests.java @@ -11,8 +11,8 @@ import kong.unirest.json.JSONArray; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; -import no.uio.ifi.crypt4gh.stream.Crypt4GHInputStream; -import no.uio.ifi.crypt4gh.util.KeyUtils; +import no.elixir.crypt4gh.stream.Crypt4GHInputStream; +import no.elixir.crypt4gh.util.KeyUtils; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; @@ -42,6 +42,7 @@ class LocalEGADOAApplicationTests { private static String validToken; private static String invalidToken; + private static String validVisaToken; @SneakyThrows @BeforeAll @@ -78,11 +79,15 @@ public static void setup() { PreparedStatement dataset_event_released = connection.prepareStatement(prepareInsertQueryDatasetEvent("EGAD00010000919", "released", "release")); dataset_event_released.executeUpdate(); + + PreparedStatement datasetReferenceInsert = connection.prepareStatement("INSERT INTO sda.dataset_references(dataset_id, reference_id, reference_scheme) values('1', 'GDI-NO-10001','GDI');"); + datasetReferenceInsert.executeUpdate(); connection.close(); JSONArray tokens = Unirest.get("http://localhost:8000/tokens").asJson().getBody().getArray(); validToken = tokens.getString(0); invalidToken = tokens.getString(1); + validVisaToken = tokens.getString(2); } @SneakyThrows @@ -215,7 +220,7 @@ void testPOSIXExportRequestFileValidToken() { Assertions.assertTrue(true); return; } - export("EGAF00000000014", false); + export("EGAF00000000014", false, validToken); PrivateKey privateKey = KeyUtils.getInstance().readPrivateKey(new File("test/my.sec.pem"), "passw0rd".toCharArray()); try (InputStream byteArrayInputStream = new FileInputStream("requester@elixir-europe.org/files/body.enc"); Crypt4GHInputStream crypt4GHInputStream = new Crypt4GHInputStream(byteArrayInputStream, privateKey)) { @@ -231,7 +236,7 @@ void testPOSIXExportRequestDatasetValidToken() { Assertions.assertTrue(true); return; } - export("EGAD00010000919", true); + export("EGAD00010000919", true, validToken); PrivateKey privateKey = KeyUtils.getInstance().readPrivateKey(new File("test/my.sec.pem"), "passw0rd".toCharArray()); try (InputStream byteArrayInputStream = new FileInputStream("requester@elixir-europe.org/files/body.enc"); Crypt4GHInputStream crypt4GHInputStream = new Crypt4GHInputStream(byteArrayInputStream, privateKey)) { @@ -247,7 +252,7 @@ void testS3ExportRequestFileValidToken() { Assertions.assertTrue(true); return; } - export("EGAF00000000014", false); + export("EGAF00000000014", false, validToken); PrivateKey privateKey = KeyUtils.getInstance().readPrivateKey(new File("test/my.sec.pem"), "passw0rd".toCharArray()); try (InputStream byteArrayInputStream = getMinioClient().getObject(GetObjectArgs.builder().bucket("lega").object("requester@elixir-europe.org/body.enc").build()); Crypt4GHInputStream crypt4GHInputStream = new Crypt4GHInputStream(byteArrayInputStream, privateKey)) { @@ -263,7 +268,103 @@ void testS3ExportRequestDatasetValidToken() { Assertions.assertTrue(true); return; } - export("EGAD00010000919", true); + export("EGAD00010000919", true, validToken); + PrivateKey privateKey = KeyUtils.getInstance().readPrivateKey(new File("test/my.sec.pem"), "passw0rd".toCharArray()); + try (InputStream byteArrayInputStream = getMinioClient().getObject(GetObjectArgs.builder().bucket("lega").object("requester@elixir-europe.org/body.enc").build()); + Crypt4GHInputStream crypt4GHInputStream = new Crypt4GHInputStream(byteArrayInputStream, privateKey)) { + byte[] bytes = IOUtils.toByteArray(crypt4GHInputStream); + Assertions.assertEquals("2aef808fb42fa7b1ba76cb16644773f9902a3fdc2569e8fdc049f38280c4577e", DigestUtils.sha256Hex(bytes)); + } + } + + @SneakyThrows + @Test + void testS3ExportRequestReferenceValidToken() { + if (System.getenv("OUTBOX_TYPE").equals("POSIX")) { + Assertions.assertTrue(true); + return; + } + export("GDI-NO-10001", true, validToken); + PrivateKey privateKey = KeyUtils.getInstance().readPrivateKey(new File("test/my.sec.pem"), "passw0rd".toCharArray()); + try (InputStream byteArrayInputStream = getMinioClient().getObject(GetObjectArgs.builder().bucket("lega").object("requester@elixir-europe.org/body.enc").build()); + Crypt4GHInputStream crypt4GHInputStream = new Crypt4GHInputStream(byteArrayInputStream, privateKey)) { + byte[] bytes = IOUtils.toByteArray(crypt4GHInputStream); + Assertions.assertEquals("2aef808fb42fa7b1ba76cb16644773f9902a3fdc2569e8fdc049f38280c4577e", DigestUtils.sha256Hex(bytes)); + } + } + + @SneakyThrows + @Test + void testPOSIXExportRequestReferenceValidToken() { + if (System.getenv("OUTBOX_TYPE").equals("S3")) { + Assertions.assertTrue(true); + return; + } + export("GDI-NO-10001", true, validToken); + PrivateKey privateKey = KeyUtils.getInstance().readPrivateKey(new File("test/my.sec.pem"), "passw0rd".toCharArray()); + try (InputStream byteArrayInputStream = new FileInputStream("requester@elixir-europe.org/files/body.enc"); + Crypt4GHInputStream crypt4GHInputStream = new Crypt4GHInputStream(byteArrayInputStream, privateKey)) { + byte[] bytes = IOUtils.toByteArray(crypt4GHInputStream); + Assertions.assertEquals("2aef808fb42fa7b1ba76cb16644773f9902a3fdc2569e8fdc049f38280c4577e", DigestUtils.sha256Hex(bytes)); + } + } + + @SneakyThrows + @Test + void testPOSIXExportRequestFileValidVisaToken() { + if (System.getenv("OUTBOX_TYPE").equals("S3")) { + Assertions.assertTrue(true); + return; + } + export("EGAF00000000014", false, validVisaToken); + PrivateKey privateKey = KeyUtils.getInstance().readPrivateKey(new File("test/my.sec.pem"), "passw0rd".toCharArray()); + try (InputStream byteArrayInputStream = new FileInputStream("requester@elixir-europe.org/files/body.enc"); + Crypt4GHInputStream crypt4GHInputStream = new Crypt4GHInputStream(byteArrayInputStream, privateKey)) { + byte[] bytes = IOUtils.toByteArray(crypt4GHInputStream); + Assertions.assertEquals("2aef808fb42fa7b1ba76cb16644773f9902a3fdc2569e8fdc049f38280c4577e", DigestUtils.sha256Hex(bytes)); + } + } + + @SneakyThrows + @Test + void testPOSIXExportRequestDatasetValidVisaToken() { + if (System.getenv("OUTBOX_TYPE").equals("S3")) { + Assertions.assertTrue(true); + return; + } + export("EGAD00010000919", true, validVisaToken); + PrivateKey privateKey = KeyUtils.getInstance().readPrivateKey(new File("test/my.sec.pem"), "passw0rd".toCharArray()); + try (InputStream byteArrayInputStream = new FileInputStream("requester@elixir-europe.org/files/body.enc"); + Crypt4GHInputStream crypt4GHInputStream = new Crypt4GHInputStream(byteArrayInputStream, privateKey)) { + byte[] bytes = IOUtils.toByteArray(crypt4GHInputStream); + Assertions.assertEquals("2aef808fb42fa7b1ba76cb16644773f9902a3fdc2569e8fdc049f38280c4577e", DigestUtils.sha256Hex(bytes)); + } + } + + @SneakyThrows + @Test + void testS3ExportRequestFileValidVisaToken() { + if (System.getenv("OUTBOX_TYPE").equals("POSIX")) { + Assertions.assertTrue(true); + return; + } + export("EGAF00000000014", false, validVisaToken); + PrivateKey privateKey = KeyUtils.getInstance().readPrivateKey(new File("test/my.sec.pem"), "passw0rd".toCharArray()); + try (InputStream byteArrayInputStream = getMinioClient().getObject(GetObjectArgs.builder().bucket("lega").object("requester@elixir-europe.org/body.enc").build()); + Crypt4GHInputStream crypt4GHInputStream = new Crypt4GHInputStream(byteArrayInputStream, privateKey)) { + byte[] bytes = IOUtils.toByteArray(crypt4GHInputStream); + Assertions.assertEquals("2aef808fb42fa7b1ba76cb16644773f9902a3fdc2569e8fdc049f38280c4577e", DigestUtils.sha256Hex(bytes)); + } + } + + @SneakyThrows + @Test + void testS3ExportRequestDatasetValidVisaToken() { + if (System.getenv("OUTBOX_TYPE").equals("POSIX")) { + Assertions.assertTrue(true); + return; + } + export("EGAD00010000919", true, validVisaToken); PrivateKey privateKey = KeyUtils.getInstance().readPrivateKey(new File("test/my.sec.pem"), "passw0rd".toCharArray()); try (InputStream byteArrayInputStream = getMinioClient().getObject(GetObjectArgs.builder().bucket("lega").object("requester@elixir-europe.org/body.enc").build()); Crypt4GHInputStream crypt4GHInputStream = new Crypt4GHInputStream(byteArrayInputStream, privateKey)) { @@ -273,7 +374,38 @@ void testS3ExportRequestDatasetValidToken() { } @SneakyThrows - void export(String id, boolean dataset) { + @Test + void testPOSIXExportRequestReferenceValidVisaToken() { + if (System.getenv("OUTBOX_TYPE").equals("S3")) { + Assertions.assertTrue(true); + return; + } + export("GDI-NO-10001", true, validVisaToken); + PrivateKey privateKey = KeyUtils.getInstance().readPrivateKey(new File("test/my.sec.pem"), "passw0rd".toCharArray()); + try (InputStream byteArrayInputStream = new FileInputStream("requester@elixir-europe.org/files/body.enc"); + Crypt4GHInputStream crypt4GHInputStream = new Crypt4GHInputStream(byteArrayInputStream, privateKey)) { + byte[] bytes = IOUtils.toByteArray(crypt4GHInputStream); + Assertions.assertEquals("2aef808fb42fa7b1ba76cb16644773f9902a3fdc2569e8fdc049f38280c4577e", DigestUtils.sha256Hex(bytes)); + } + } + + @SneakyThrows + @Test + void testS3ExportRequestReferenceValidVisaToken() { + if (System.getenv("OUTBOX_TYPE").equals("POSIX")) { + Assertions.assertTrue(true); + return; + } + export("GDI-NO-10001", true, validVisaToken); + PrivateKey privateKey = KeyUtils.getInstance().readPrivateKey(new File("test/my.sec.pem"), "passw0rd".toCharArray()); + try (InputStream byteArrayInputStream = getMinioClient().getObject(GetObjectArgs.builder().bucket("lega").object("requester@elixir-europe.org/body.enc").build()); + Crypt4GHInputStream crypt4GHInputStream = new Crypt4GHInputStream(byteArrayInputStream, privateKey)) { + byte[] bytes = IOUtils.toByteArray(crypt4GHInputStream); + Assertions.assertEquals("2aef808fb42fa7b1ba76cb16644773f9902a3fdc2569e8fdc049f38280c4577e", DigestUtils.sha256Hex(bytes)); + } + } + @SneakyThrows + void export(String id, boolean dataset, String token) { String mqConnectionString = "amqps://admin:guest@localhost:5671/sda"; ConnectionFactory factory = new ConnectionFactory(); factory.setUri(mqConnectionString); @@ -292,7 +424,7 @@ void export(String id, boolean dataset) { "\t\"%s\": \"%s\",\n" + "\t\"publicKey\": \"%s\"\n" + "}", - validToken, + token, dataset ? "datasetId" : "fileId", id, FileUtils.readFileToString(new File("test/my.pub.pem"), Charset.defaultCharset())); diff --git a/sda-doa/test/mock_auth.py b/sda-doa/test/mock_auth.py index dfd80d7f9..9e90ad1aa 100644 --- a/sda-doa/test/mock_auth.py +++ b/sda-doa/test/mock_auth.py @@ -102,6 +102,20 @@ def generate_token(): "exp": 99999999999, "jti": "9fa600d6-4148-47c1-b708-36c4ba2e980e" } + passport_dataset_gdi = { + "iss": "http://129.177.177.134:8000/", + "sub": "requester@elixir-europe.org", + "ga4gh_visa_v1": { + "type": "ControlledAccessGrants", + "value": "https://www.ebi.ac.uk/ega/GDI-NO-10001", + "source": "https://ga4gh.org/duri/no_org", + "by": "dac", + "asserted": 1568699331 + }, + "iat": 1571144438, + "exp": 99999999999, + "jti": "2b322848-506b-492c-914f-47f9da967cdd" + } public_jwk = jwk.dumps(public_key, kty='RSA') private_jwk = jwk.dumps(pem, kty='RSA') dataset_encoded = jwt.encode(header, dataset_payload, private_jwk).decode('utf-8') @@ -110,8 +124,9 @@ def generate_token(): passport_status_encoded = jwt.encode(header, passport_status, private_jwk).decode('utf-8') passport_dataset1_encoded = jwt.encode(header, passport_dataset1, private_jwk).decode('utf-8') passport_dataset2_encoded = jwt.encode(header, passport_dataset2, private_jwk).decode('utf-8') + passport_dataset_gdi_encoded = jwt.encode(header, passport_dataset_gdi, private_jwk).decode('utf-8') return (public_jwk, dataset_encoded, empty_encoded, passport_terms_encoded, passport_status_encoded, - passport_dataset1_encoded, passport_dataset2_encoded) + passport_dataset1_encoded, passport_dataset2_encoded, passport_dataset_gdi_encoded) DATA = generate_token() @@ -129,7 +144,7 @@ async def jwk_response(request): async def tokens_response(request): """Serve generated tokens.""" - data = [DATA[1], DATA[2]] + data = [DATA[1], DATA[2], DATA[6]] return web.json_response(data) @@ -143,7 +158,8 @@ async def userinfo(request): DATA[3], DATA[4], DATA[5], - DATA[6] + DATA[6], + DATA[7] ] } return web.json_response(data)