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

add tests for visa token #328

Merged
merged 4 commits into from
Nov 28, 2024
Merged
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
113 changes: 105 additions & 8 deletions src/test/java/no/uio/ifi/localega/doa/LocalEGADOAApplicationTests.java
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 @@ -86,6 +87,7 @@ public static void setup() {
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 @@ -218,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 @@ -234,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 @@ -250,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 @@ -266,7 +268,7 @@ 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)) {
Expand All @@ -282,7 +284,7 @@ void testS3ExportRequestReferenceValidToken() {
Assertions.assertTrue(true);
return;
}
export("GDI-NO-10001", true);
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("[email protected]/body.enc").build());
Crypt4GHInputStream crypt4GHInputStream = new Crypt4GHInputStream(byteArrayInputStream, privateKey)) {
Expand All @@ -298,7 +300,7 @@ void testPOSIXExportRequestReferenceValidToken() {
Assertions.assertTrue(true);
return;
}
export("GDI-NO-10001", true);
export("GDI-NO-10001", 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 @@ -308,7 +310,102 @@ void testPOSIXExportRequestReferenceValidToken() {
}

@SneakyThrows
void export(String id, boolean dataset) {
@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)) {
byte[] bytes = IOUtils.toByteArray(crypt4GHInputStream);
Assertions.assertEquals("2aef808fb42fa7b1ba76cb16644773f9902a3fdc2569e8fdc049f38280c4577e", DigestUtils.sha256Hex(bytes));
}
}

@SneakyThrows
@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("[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 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("[email protected]/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);
Expand All @@ -327,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()));
Expand Down
2 changes: 1 addition & 1 deletion test/mock_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,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)


Expand Down