Skip to content

Commit a04914c

Browse files
SK-3015-gitleaks-detection-fix-for-updated-scan-result-improved-test-coverage
1 parent 881886b commit a04914c

2 files changed

Lines changed: 22 additions & 12 deletions

File tree

‎skyvault/src/test/java/com/skyflow/ConnectionClientTests.java‎

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ public class ConnectionClientTests {
2121
private static String apiKey = null;
2222
private static ConnectionConfig connectionConfig;
2323

24+
// Token.decoded() rejects anything without 3 dot-separated segments, so a bare placeholder
25+
// like "<TOKEN>" makes Token.isExpired() always return true (never reaches the REUSE_BEARER_TOKEN
26+
// branch in ConnectionClient#setBearerToken). Loaded from dummy-non-secrets/ (Gitleaks-excluded)
27+
// rather than a string literal, since a real JWT shape (eyJ...) would itself trip the scanner.
28+
2429
// @Before (not @BeforeClass): several tests below mutate the shared connectionClient/
2530
// connectionConfig credentials state, so it must reset before every test rather than once
2631
// per class — otherwise test outcomes depend on JUnit's (unspecified) method execution order.
@@ -55,21 +60,24 @@ public void getConnectionConfig() {
5560
}
5661

5762
@Test
58-
public void testSetBearerToken() {
63+
public void testSetBearerToken() throws IOException {
64+
// Loaded from dummy-non-secrets/ (Gitleaks-excluded) rather than a string literal,
65+
// since a real JWT shape (eyJ...) would itself trip the scanner.
66+
String bearerToken = new String(Files.readAllBytes(
67+
Paths.get("./src/test/resources/dummy-non-secrets/dummy-bearer-token.txt")), StandardCharsets.UTF_8).trim();
5968
try {
60-
// Self-contained fake JWT (exp=9999999999, far future) instead of relying on a
61-
// local .env fixture, which may not exist (e.g. in CI/sandbox environments).
62-
String bearerToken = "<BEARER_TOKEN>";
6369
Credentials credentials = new Credentials();
6470
credentials.setToken(bearerToken);
6571
connectionConfig.setCredentials(credentials);
6672
connectionClient.updateConnectionConfig(connectionConfig);
6773

68-
// regular scenario
74+
// regular scenario: token == null → BEARER_TOKEN_EXPIRED branch → generates token
6975
connectionClient.setBearerToken();
76+
Assert.assertEquals(bearerToken, connectionClient.token);
7077

71-
// re-use scenario
78+
// re-use scenario: token valid, not expired → REUSE_BEARER_TOKEN branch
7279
connectionClient.setBearerToken();
80+
Assert.assertEquals(bearerToken, connectionClient.token);
7381
} catch (Exception e) {
7482
Assert.fail(INVALID_EXCEPTION_THROWN);
7583
}
@@ -140,11 +148,12 @@ public void testSetBearerToken_withApiKey_setsAndReusesApiKey() {
140148
}
141149

142150
@Test
143-
public void testSetBearerToken_withValidNonExpiredToken_reusesBearerToken() {
151+
public void testSetBearerToken_withValidNonExpiredToken_reusesBearerToken() throws IOException {
152+
String farFutureJwt = new String(Files.readAllBytes(
153+
Paths.get("./src/test/resources/dummy-non-secrets/dummy-bearer-token.txt")), StandardCharsets.UTF_8).trim();
144154
try {
145-
// far-future JWT: base64({"exp":9999999999}) = eyJleHAiOjk5OTk5OTk5OTl9 — never expires
146155
Credentials creds = new Credentials();
147-
creds.setToken("<BEARER_TOKEN>");
156+
creds.setToken(farFutureJwt);
148157
ConnectionConfig config = new ConnectionConfig();
149158
config.setConnectionId("isolated-token-1");
150159
config.setConnectionUrl("https://test.isolated.url");
@@ -153,11 +162,11 @@ public void testSetBearerToken_withValidNonExpiredToken_reusesBearerToken() {
153162

154163
// First call: this.token == null → Token.isExpired(null)=true → generates token from creds.getToken()
155164
client.setBearerToken();
156-
Assert.assertEquals("<BEARER_TOKEN>", client.token);
165+
Assert.assertEquals(farFutureJwt, client.token);
157166

158-
// Second call: token not null, not empty, not expired → REUSE_BEARER_TOKEN else branch (line 52)
167+
// Second call: token not null, not empty, not expired → REUSE_BEARER_TOKEN else branch
159168
client.setBearerToken();
160-
Assert.assertEquals("<BEARER_TOKEN>", client.token);
169+
Assert.assertEquals(farFutureJwt, client.token);
161170
} catch (Exception e) {
162171
Assert.fail(INVALID_EXCEPTION_THROWN);
163172
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
eyJhbGciOiJub25lIn0.eyJleHAiOjk5OTk5OTk5OTl9.sig

0 commit comments

Comments
 (0)