Skip to content

Commit

Permalink
add tests for visa token
Browse files Browse the repository at this point in the history
  • Loading branch information
Parisa68 committed Nov 26, 2024
1 parent c641425 commit d6ab063
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class LocalEGADOAApplicationTests {

private static String validToken;
private static String invalidToken;
private static String validVisaToken;

@SneakyThrows
@BeforeAll
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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("[email protected]/files/body.enc");
Crypt4GHInputStream crypt4GHInputStream = new Crypt4GHInputStream(byteArrayInputStream, privateKey)) {
Expand All @@ -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("[email protected]/files/body.enc");
Crypt4GHInputStream crypt4GHInputStream = new Crypt4GHInputStream(byteArrayInputStream, privateKey)) {
Expand All @@ -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("[email protected]/body.enc").build());
Crypt4GHInputStream crypt4GHInputStream = new Crypt4GHInputStream(byteArrayInputStream, privateKey)) {
Expand All @@ -263,7 +268,72 @@ 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("[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 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("[email protected]/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("[email protected]/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("[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 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("[email protected]/body.enc").build());
Crypt4GHInputStream crypt4GHInputStream = new Crypt4GHInputStream(byteArrayInputStream, privateKey)) {
Expand All @@ -273,7 +343,7 @@ void testS3ExportRequestDatasetValidToken() {
}

@SneakyThrows
void export(String id, boolean dataset) {
void export(String id, boolean dataset, String token) {
String mqConnectionString = "amqps://admin:guest@localhost:5671/sda";
ConnectionFactory factory = new ConnectionFactory();
factory.setUri(mqConnectionString);
Expand All @@ -292,7 +362,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()));
Expand Down
2 changes: 1 addition & 1 deletion test/mock_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,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)


Expand Down

0 comments on commit d6ab063

Please sign in to comment.