Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dataset reference test #326

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docker-compose-posix-outbox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ version: '3.3'
services:

db:
image: ghcr.io/neicnordic/sensitive-data-archive:v0.3.23-postgres
image: ghcr.io/neicnordic/sensitive-data-archive:v0.3.120-postgres
ports:
- 5432:5432
environment:
- DB_LEGA_IN_PASSWORD=password
- DB_LEGA_OUT_PASSWORD=password
- LEGA_IN_PASSWORD=rootpasswd
- LEGA_OUT_PASSWORD=rootpasswd
- POSTGRES_SERVER_CERT=/etc/ega/pg.cert
- POSTGRES_SERVER_KEY=/etc/ega/pg.key
- POSTGRES_SERVER_CACERT=/etc/ega/CA.cert
Expand Down
6 changes: 3 additions & 3 deletions docker-compose-s3-outbox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ version: '3.3'
services:

db:
image: ghcr.io/neicnordic/sensitive-data-archive:v0.3.47-postgres
image: ghcr.io/neicnordic/sensitive-data-archive:v0.3.120-postgres
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ 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();
Expand Down Expand Up @@ -272,6 +275,38 @@ void testS3ExportRequestDatasetValidToken() {
}
}

@SneakyThrows
@Test
void testS3ExportRequestReferenceValidToken() {
if (System.getenv("OUTBOX_TYPE").equals("POSIX")) {
Assertions.assertTrue(true);
return;
}
export("GDI-NO-10001", true);
PrivateKey privateKey = KeyUtils.getInstance().readPrivateKey(new File("test/my.sec.pem"), "passw0rd".toCharArray());
try (InputStream byteArrayInputStream = getMinioClient().getObject(GetObjectArgs.builder().bucket("lega").object("[email protected]/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);
PrivateKey privateKey = KeyUtils.getInstance().readPrivateKey(new File("test/my.sec.pem"), "passw0rd".toCharArray());
try (InputStream byteArrayInputStream = new FileInputStream("[email protected]/files/body.enc");
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 mqConnectionString = "amqps://admin:guest@localhost:5671/sda";
Expand Down
20 changes: 18 additions & 2 deletions test/mock_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": "[email protected]",
"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')
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
Loading