Skip to content

Commit c2043bd

Browse files
committed
fix: apply code formatting
1 parent 2f9fa40 commit c2043bd

File tree

6 files changed

+83
-79
lines changed

6 files changed

+83
-79
lines changed

e2eTests/src/test/java/no/elixir/e2eTests/config/Environment.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,4 @@ public Environment() {
7979
this.egaDevJwtPrivKeyPath = env.get("E2E_TESTS_EGA_DEV_JWT_PRIV_KEYPATH");
8080
this.egaDevPubKeyPath = env.get("E2E_TESTS_EGA_DEV_ARCHIVE_PUB_KEYPATH");
8181
}
82-
8382
}

e2eTests/src/test/java/no/elixir/e2eTests/core/E2EState.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.io.File;
44
import java.security.KeyPair;
5-
65
import no.elixir.crypt4gh.util.KeyUtils;
76
import no.elixir.e2eTests.config.Environment;
87
import org.slf4j.Logger;

e2eTests/src/test/java/no/elixir/e2eTests/features/DownloadWithExportRequestTest.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,19 @@ public static void testDownloadDatasetUsingFegaExportRequestAndVerifyResults() t
8888
E2EState.encFile.getName(),
8989
passportScopedAccessToken,
9090
basedir + "out/" + E2EState.encFile.getName());
91-
assertAll("File validation",
92-
() -> assertTrue(Files.exists(filePath), "File should exist"),
93-
() -> assertTrue(Files.isRegularFile(filePath), "Should be a regular file"),
94-
() -> assertTrue(Files.size(filePath) > 0, "File should not be empty")
95-
);
91+
assertAll(
92+
"File validation",
93+
() -> assertTrue(Files.exists(filePath), "File should exist"),
94+
() -> assertTrue(Files.isRegularFile(filePath), "Should be a regular file"),
95+
() -> assertTrue(Files.size(filePath) > 0, "File should not be empty"));
9696

9797
E2EState.log.info("Decrypting the downloaded file...");
9898

9999
// Decrypt using recipient's private key
100100
ByteArrayOutputStream decryptedOutput = new ByteArrayOutputStream();
101101
try (InputStream encryptedInputStream = Files.newInputStream(filePath);
102-
Crypt4GHInputStream crypt4GHInputStream =
103-
new Crypt4GHInputStream(encryptedInputStream, E2EState.recipientKeypair.getPrivate())) {
102+
Crypt4GHInputStream crypt4GHInputStream =
103+
new Crypt4GHInputStream(encryptedInputStream, E2EState.recipientKeypair.getPrivate())) {
104104
IOUtils.copyLarge(crypt4GHInputStream, decryptedOutput);
105105
}
106106

@@ -114,19 +114,24 @@ public static void testDownloadDatasetUsingFegaExportRequestAndVerifyResults() t
114114
E2EState.log.info("Decrypted MD5 checksum: {}", decryptedMD5);
115115

116116
// Verify checksums match the original file
117-
assertAll("Checksum validation",
118-
() -> assertEquals(E2EState.rawSHA256Checksum, decryptedSHA256,
119-
"SHA256 checksum should match original file"),
120-
() -> assertEquals(E2EState.rawMD5Checksum, decryptedMD5,
121-
"MD5 checksum should match original file")
122-
);
117+
assertAll(
118+
"Checksum validation",
119+
() ->
120+
assertEquals(
121+
E2EState.rawSHA256Checksum,
122+
decryptedSHA256,
123+
"SHA256 checksum should match original file"),
124+
() ->
125+
assertEquals(
126+
E2EState.rawMD5Checksum, decryptedMD5, "MD5 checksum should match original file"));
123127

124128
E2EState.log.info("File successfully decrypted and checksums verified!");
125129
}
126130

127131
private static Path downloadFileViaProxy(String fileName, String accessToken, String outputPath)
128132
throws IOException {
129-
E2EState.log.info("Downloading file via proxy... fileName: {}, outputPath: {}", fileName, outputPath);
133+
E2EState.log.info(
134+
"Downloading file via proxy... fileName: {}, outputPath: {}", fileName, outputPath);
130135
HttpResponse<byte[]> downloadRes =
131136
Unirest.get(buildProxyDownloadUrl(fileName))
132137
.header("Proxy-Authorization", "Bearer " + accessToken)
@@ -241,9 +246,7 @@ private static String buildFegaExportPayload(String visaToken) throws Exception
241246
// Convert to Base64-encoded string (DER format)
242247
String base64PublicKey = Base64.getEncoder().encodeToString(publicKey.getEncoded());
243248
return Strings.EXPORT_REQ_BODY_FEGA.formatted(
244-
E2EState.datasetId,
245-
visaToken,
246-
base64PublicKey, "DATASET_ID");
249+
E2EState.datasetId, visaToken, base64PublicKey, "DATASET_ID");
247250
}
248251

249252
record FileListingResponse(Collection<TsdFile> files, String page) {}

e2eTests/src/test/java/no/elixir/e2eTests/features/FinalizeTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public static void verifyAfterFinalizeAndLookUpAccessionID() throws Exception {
3939
PreparedStatement statement = conn.prepareStatement(sql);
4040
String tsdProject = E2EState.env.getTsdProject();
4141
String subject = E2EState.env.getLsaaiSubject();
42-
statement.setString(1, "/%s-%s/files/%s".formatted(tsdProject, subject, E2EState.encFile.getName()));
42+
statement.setString(
43+
1, "/%s-%s/files/%s".formatted(tsdProject, subject, E2EState.encFile.getName()));
4344
ResultSet resultSet = statement.executeQuery();
4445
if (resultSet.wasNull() || !resultSet.next()) {
4546
fail("Verification failed");

e2eTests/src/test/java/no/elixir/e2eTests/features/UploadTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ public static void uploadThroughProxy() throws Exception {
5757
assertEquals(201, jsonResponse.getObject().get("statusCode"));
5858
}
5959

60-
6160
private static String resolveUploadToken() throws Exception {
6261
// if a passport scoped access token is not provided we generate a fake one
6362
if (E2EState.env.getLSAAIToken() == null || E2EState.env.getLSAAIToken().isEmpty()) {
@@ -70,5 +69,4 @@ private static String resolveUploadToken() throws Exception {
7069
return E2EState.env.getLSAAIToken();
7170
}
7271
}
73-
7472
}

e2eTests/src/test/java/no/elixir/e2eTests/utils/TokenUtils.java

Lines changed: 61 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import com.google.gson.Gson;
44
import com.google.gson.JsonObject;
5-
import java.io.StringReader;
65
import io.jsonwebtoken.Jwts;
6+
import java.io.StringReader;
77
import java.nio.charset.Charset;
88
import java.security.KeyFactory;
99
import java.security.Security;
@@ -12,8 +12,8 @@
1212
import java.security.spec.PKCS8EncodedKeySpec;
1313
import java.security.spec.X509EncodedKeySpec;
1414
import java.util.Base64;
15-
import java.util.HashMap;
1615
import java.util.Date;
16+
import java.util.HashMap;
1717
import java.util.Map;
1818
import no.elixir.e2eTests.constants.Strings;
1919
import no.elixir.e2eTests.core.E2EState;
@@ -24,55 +24,58 @@
2424

2525
public class TokenUtils {
2626

27-
public static String generateVisaToken(String resource, String pubKeyPath, String privKeyPath) throws Exception {
28-
RSAPrivateKey privateKey = getPrivateKey(privKeyPath);
29-
String user, aud;
30-
// if the passport scoped access token is present and if the
31-
// integration is set to EGA_DEV environment, we get some
32-
// details from that provided token.
33-
if (E2EState.env.getLSAAIToken() != null
34-
&& !E2EState.env.getLSAAIToken().isEmpty()
35-
&& E2EState.env.getIntegration().equals("EGA_DEV")) {
36-
HashMap<String, String> details = extractDetailsFromLSAAIToken(E2EState.env.getLSAAIToken());
37-
user = details.get("sub");
38-
aud = details.get("aud");
39-
} else {
40-
user = Strings.JWT_SUBJECT;
41-
aud = E2EState.env.getProxyTokenAudience();
42-
}
43-
// Build the GA4GH visa claim
44-
Map<String, Object> ga4ghVisa = new HashMap<>();
45-
ga4ghVisa.put("asserted", Strings.VISA_ASSERTED);
46-
ga4ghVisa.put("by", Strings.VISA_BY);
47-
ga4ghVisa.put("source", Strings.VISA_SOURCE);
48-
ga4ghVisa.put("type", Strings.VISA_TYPE);
49-
ga4ghVisa.put("value", String.format(Strings.VISA_VALUE_TEMPLATE, resource));
50-
// Build and sign the JWT
51-
return Jwts.builder()
52-
.header()
53-
.add("jku", Strings.JWT_JKU)
54-
.add("kid", Strings.JWT_KID)
55-
.add("typ", Strings.JWT_TYP)
56-
.add("alg", Strings.JWT_ALG)
57-
.and()
58-
.subject(user)
59-
.audience()
60-
.add(aud)
61-
.and()
62-
.claim("ga4gh_visa_v1", ga4ghVisa)
63-
.issuer(Strings.JWT_ISSUER)
64-
.expiration(new Date(Strings.JWT_EXPIRATION * 1000))
65-
.issuedAt(new Date(Strings.JWT_ISSUED_AT * 1000))
66-
.id(Strings.JWT_ID)
67-
.signWith(privateKey, Jwts.SIG.RS256)
68-
.compact();
27+
public static String generateVisaToken(String resource, String pubKeyPath, String privKeyPath)
28+
throws Exception {
29+
RSAPrivateKey privateKey = getPrivateKey(privKeyPath);
30+
String user, aud;
31+
// if the passport scoped access token is present and if the
32+
// integration is set to EGA_DEV environment, we get some
33+
// details from that provided token.
34+
if (E2EState.env.getLSAAIToken() != null
35+
&& !E2EState.env.getLSAAIToken().isEmpty()
36+
&& E2EState.env.getIntegration().equals("EGA_DEV")) {
37+
HashMap<String, String> details = extractDetailsFromLSAAIToken(E2EState.env.getLSAAIToken());
38+
user = details.get("sub");
39+
aud = details.get("aud");
40+
} else {
41+
user = Strings.JWT_SUBJECT;
42+
aud = E2EState.env.getProxyTokenAudience();
6943
}
44+
// Build the GA4GH visa claim
45+
Map<String, Object> ga4ghVisa = new HashMap<>();
46+
ga4ghVisa.put("asserted", Strings.VISA_ASSERTED);
47+
ga4ghVisa.put("by", Strings.VISA_BY);
48+
ga4ghVisa.put("source", Strings.VISA_SOURCE);
49+
ga4ghVisa.put("type", Strings.VISA_TYPE);
50+
ga4ghVisa.put("value", String.format(Strings.VISA_VALUE_TEMPLATE, resource));
51+
// Build and sign the JWT
52+
return Jwts.builder()
53+
.header()
54+
.add("jku", Strings.JWT_JKU)
55+
.add("kid", Strings.JWT_KID)
56+
.add("typ", Strings.JWT_TYP)
57+
.add("alg", Strings.JWT_ALG)
58+
.and()
59+
.subject(user)
60+
.audience()
61+
.add(aud)
62+
.and()
63+
.claim("ga4gh_visa_v1", ga4ghVisa)
64+
.issuer(Strings.JWT_ISSUER)
65+
.expiration(new Date(Strings.JWT_EXPIRATION * 1000))
66+
.issuedAt(new Date(Strings.JWT_ISSUED_AT * 1000))
67+
.id(Strings.JWT_ID)
68+
.signWith(privateKey, Jwts.SIG.RS256)
69+
.compact();
70+
}
7071

7172
public static RSAPublicKey getPublicKey(String pubKeyPath) throws Exception {
72-
String keyContent =
73-
FileUtils.readFileToString(E2EState.env.getIntegration().equals("EGA_DEV")
74-
? CertificateUtils.getFile(pubKeyPath)
75-
: CertificateUtils.getCertificateFile(pubKeyPath), Charset.defaultCharset());
73+
String keyContent =
74+
FileUtils.readFileToString(
75+
E2EState.env.getIntegration().equals("EGA_DEV")
76+
? CertificateUtils.getFile(pubKeyPath)
77+
: CertificateUtils.getCertificateFile(pubKeyPath),
78+
Charset.defaultCharset());
7679

7780
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
7881

@@ -91,9 +94,11 @@ public static RSAPublicKey getPublicKey(String pubKeyPath) throws Exception {
9194

9295
public static RSAPrivateKey getPrivateKey(String privKeyPath) throws Exception {
9396
String keyContent =
94-
FileUtils.readFileToString(E2EState.env.getIntegration().equals("EGA_DEV")
97+
FileUtils.readFileToString(
98+
E2EState.env.getIntegration().equals("EGA_DEV")
9599
? CertificateUtils.getFile(privKeyPath)
96-
: CertificateUtils.getCertificateFile(privKeyPath), Charset.defaultCharset());
100+
: CertificateUtils.getCertificateFile(privKeyPath),
101+
Charset.defaultCharset());
97102

98103
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
99104

@@ -114,8 +119,8 @@ public static RSAPrivateKey getPrivateKey(String privKeyPath) throws Exception {
114119
}
115120

116121
/**
117-
* Introduced with EGA_DEV runtime tests. Extracts specific details
118-
* from a given passport scoped access token.
122+
* Introduced with EGA_DEV runtime tests. Extracts specific details from a given passport scoped
123+
* access token.
119124
*
120125
* @param passportScopedAccessToken token to decode
121126
* @return Map containing the `sub` and `aud`
@@ -152,15 +157,14 @@ private static RSAPrivateKey handlePKCS1PrivateKey(String keyContent) throws Exc
152157
return (RSAPrivateKey) converter.getPrivateKey((PrivateKeyInfo) object);
153158
} else if (object instanceof org.bouncycastle.asn1.pkcs.RSAPrivateKey rsaPrivKey) {
154159
org.bouncycastle.asn1.x509.AlgorithmIdentifier algId =
155-
new org.bouncycastle.asn1.x509.AlgorithmIdentifier(
156-
org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers.rsaEncryption);
160+
new org.bouncycastle.asn1.x509.AlgorithmIdentifier(
161+
org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers.rsaEncryption);
157162
PrivateKeyInfo privKeyInfo = new PrivateKeyInfo(algId, rsaPrivKey);
158163
return (RSAPrivateKey) converter.getPrivateKey(privKeyInfo);
159164
}
160165

161166
throw new IllegalArgumentException(
162-
"Unable to parse private key. Object type: "
163-
+ (object != null ? object.getClass().getName() : "null"));
167+
"Unable to parse private key. Object type: "
168+
+ (object != null ? object.getClass().getName() : "null"));
164169
}
165-
166170
}

0 commit comments

Comments
 (0)