Skip to content

Commit d0dea2f

Browse files
SK-3015 move dummy/fake test secrets into dummy-non-secrets folder (#422)
Gitleaks flagged 5 findings (generic-api-key x3, private-key x2) in test code for a shared dummy API key and fake PEM private keys. Per the ticket's ignorance strategy, dummy/fake secrets now live in resource files under a dummy-non-secrets/ folder (per module), which is excluded from Gitleaks scans via a new path allowlist entry in Rule/gitleaks.toml, instead of as string literals in the .java source. - common/src/test/resources/dummy-non-secrets/invalidTokenURICredentials.json (moved from src/test/resources/, reference in BearerTokenTests.java updated) - common/src/test/resources/dummy-non-secrets/invalidKeySpecCredentials.json (new; SignedDataTokensTests#testInvalidKeySpecInCredentials now loads it as a file instead of inlining the fake PEM key) - common/src/test/resources/dummy-non-secrets/dummy-api-key.txt and skyvault/src/test/resources/dummy-non-secrets/dummy-api-key.txt (new; CredentialsTests, ConnectionClientTests, and VaultClientTests now load the dummy API key from disk instead of hardcoding it) Scope limited to the 5 findings named in SK-3015; other pre-existing occurrences of the same dummy secrets elsewhere in the test suite are unchanged. Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 3379566 commit d0dea2f

10 files changed

Lines changed: 41 additions & 10 deletions

File tree

Rule/gitleaks.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ paths = [
6161
'''\.gem$''',
6262
'''verification-metadata\.xml''',
6363
'''Database.refactorlog''',
64+
'''(?:^|/)dummy-non-secrets(?:/.*)?$''',
6465
]
6566
stopwords = [
6667
"abcdefghijklmnopqrstuvwxyz",

common/src/test/java/com/skyflow/config/CredentialsTests.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
import org.junit.BeforeClass;
1010
import org.junit.Test;
1111

12+
import java.io.IOException;
13+
import java.nio.charset.StandardCharsets;
14+
import java.nio.file.Files;
15+
import java.nio.file.Paths;
1216
import java.util.ArrayList;
1317
import java.util.HashMap;
1418
import java.util.Map;
@@ -25,12 +29,15 @@ public class CredentialsTests {
2529
private static String role = null;
2630
private static String context = null;
2731

32+
// Dummy API key lives outside the source tree, in a resource file under dummy-non-secrets/
33+
// (excluded from Gitleaks scans), rather than as a string literal here.
2834
@BeforeClass
29-
public static void setup() {
35+
public static void setup() throws IOException {
3036
path = "valid-path-to-credentials-file";
3137
credentialsString = "valid-credentials-string";
3238
token = "valid-token";
33-
validApiKey = "sky-ab123-abcd1234cdef1234abcd4321cdef4321";
39+
validApiKey = new String(Files.readAllBytes(
40+
Paths.get("./src/test/resources/dummy-non-secrets/dummy-api-key.txt")), StandardCharsets.UTF_8).trim();
3441
invalidApiKey = "invalid-api-key";
3542
roles = new ArrayList<>();
3643
role = "test_credentials_role";

common/src/test/java/com/skyflow/serviceaccount/util/BearerTokenTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public void testInvalidKeySpecInCredentialsForCredentials() {
249249

250250
@Test
251251
public void testInvalidTokenURIInCredentialsForCredentials() throws SkyflowException {
252-
String filePath = "./src/test/resources/invalidTokenURICredentials.json";
252+
String filePath = "./src/test/resources/dummy-non-secrets/invalidTokenURICredentials.json";
253253
File file = new File(filePath);
254254
try {
255255
BearerToken bearerToken = BearerToken.builder().setCredentials(file).build();

common/src/test/java/com/skyflow/serviceaccount/util/SignedDataTokensTests.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,12 @@ public void testInvalidPrivateKeyInCredentials() {
215215

216216
@Test
217217
public void testInvalidKeySpecInCredentials() {
218-
String credentialsString = "{\"privateKey\": \"-----BEGIN PRIVATE KEY-----\\ncHJpdmF0ZV9rZXlfdmFsdWU=\\n-----END PRIVATE KEY-----\", \"clientID\": \"client_id_value\", \"keyID\": \"key_id_value\", \"tokenURI\": \"invalid_token_uri\"}";
218+
// Dummy credentials (with a fake, invalid privateKey) live outside the source tree, in a
219+
// resource file under dummy-non-secrets/ (excluded from Gitleaks scans).
220+
String filePath = "./src/test/resources/dummy-non-secrets/invalidKeySpecCredentials.json";
221+
File file = new File(filePath);
219222
try {
220-
SignedDataTokens signedTokens = SignedDataTokens.builder().setCredentials(credentialsString).build();
223+
SignedDataTokens signedTokens = SignedDataTokens.builder().setCredentials(file).build();
221224
signedTokens.getSignedDataTokens();
222225
Assert.fail(EXCEPTION_NOT_THROWN);
223226
} catch (SkyflowException e) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sky-ab123-abcd1234cdef1234abcd4321cdef4321
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"privateKey": "-----BEGIN PRIVATE KEY-----\ncHJpdmF0ZV9rZXlfdmFsdWU=\n-----END PRIVATE KEY-----", "clientID": "client_id_value", "keyID": "key_id_value", "tokenURI": "invalid_token_uri"}

common/src/test/resources/invalidTokenURICredentials.json renamed to common/src/test/resources/dummy-non-secrets/invalidTokenURICredentials.json

File renamed without changes.

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
import org.junit.Before;
88
import org.junit.Test;
99

10+
import java.io.IOException;
11+
import java.nio.charset.StandardCharsets;
12+
import java.nio.file.Files;
13+
import java.nio.file.Paths;
14+
1015
public class ConnectionClientTests {
1116
private static final String INVALID_EXCEPTION_THROWN = "Should not have thrown any exception";
1217
private static final String EXCEPTION_NOT_THROWN = "Should have thrown an exception";
@@ -19,11 +24,15 @@ public class ConnectionClientTests {
1924
// @Before (not @BeforeClass): several tests below mutate the shared connectionClient/
2025
// connectionConfig credentials state, so it must reset before every test rather than once
2126
// per class — otherwise test outcomes depend on JUnit's (unspecified) method execution order.
27+
//
28+
// Dummy API key lives outside the source tree, in a resource file under dummy-non-secrets/
29+
// (excluded from Gitleaks scans), rather than as a string literal here.
2230
@Before
23-
public void setup() {
31+
public void setup() throws IOException {
2432
connectionID = "connection123";
2533
connectionURL = "https://test.connection.url";
26-
apiKey = "sky-ab123-abcd1234cdef1234abcd4321cdef4321";
34+
apiKey = new String(Files.readAllBytes(
35+
Paths.get("./src/test/resources/dummy-non-secrets/dummy-api-key.txt")), StandardCharsets.UTF_8).trim();
2736

2837
Credentials credentials = new Credentials();
2938
credentials.setApiKey(apiKey);

skyvault/src/test/java/com/skyflow/VaultClientTests.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
import org.mockito.Mockito;
4646

4747
import java.io.File;
48+
import java.io.IOException;
49+
import java.nio.charset.StandardCharsets;
50+
import java.nio.file.Files;
51+
import java.nio.file.Paths;
4852
import java.util.*;
4953
import java.util.Arrays;
5054
import java.util.Collections;
@@ -58,16 +62,18 @@ public class VaultClientTests {
5862
private static String table = null;
5963
private static String value = null;
6064
private static String columnGroup = null;
61-
private static String apiKey = "sky-ab123-abcd1234cdef1234abcd4321cdef4321";
65+
private static String apiKey = null;
6266
private static ArrayList<DetokenizeData> detokenizeData = null;
6367
private static ArrayList<HashMap<String, Object>> insertValues = null;
6468
private static ArrayList<HashMap<String, Object>> insertTokens = null;
6569
private static HashMap<String, Object> valueMap = null;
6670
private static HashMap<String, Object> tokenMap = null;
6771
private static VaultConfig vaultConfig;
6872

73+
// Dummy API key lives outside the source tree, in a resource file under dummy-non-secrets/
74+
// (excluded from Gitleaks scans), rather than as a string literal here.
6975
@BeforeClass
70-
public static void setup() throws SkyflowException {
76+
public static void setup() throws SkyflowException, IOException {
7177
vaultID = "vault123";
7278
clusterID = "cluster123";
7379
token = "test_token";
@@ -86,8 +92,10 @@ public static void setup() throws SkyflowException {
8692
vaultConfig.setClusterId(clusterID);
8793
vaultConfig.setEnv(Env.PROD);
8894

95+
String dummyApiKey = new String(Files.readAllBytes(
96+
Paths.get("./src/test/resources/dummy-non-secrets/dummy-api-key.txt")), StandardCharsets.UTF_8).trim();
8997
Credentials credentials = new Credentials();
90-
credentials.setApiKey("sky-ab123-abcd1234cdef1234abcd4321cdef4321");
98+
credentials.setApiKey(dummyApiKey);
9199
vaultConfig.setCredentials(credentials);
92100
vaultClient = new VaultClient(vaultConfig, credentials);
93101
vaultClient.setBearerToken();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sky-ab123-abcd1234cdef1234abcd4321cdef4321

0 commit comments

Comments
 (0)