Skip to content
Open
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
1 change: 1 addition & 0 deletions Rule/gitleaks.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ paths = [
'''\.gem$''',
'''verification-metadata\.xml''',
'''Database.refactorlog''',
'''(?:^|/)dummy-non-secrets(?:/.*)?$''',
]
stopwords = [
"abcdefghijklmnopqrstuvwxyz",
Expand Down
11 changes: 9 additions & 2 deletions common/src/test/java/com/skyflow/config/CredentialsTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
import org.junit.BeforeClass;
import org.junit.Test;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -25,12 +29,15 @@ public class CredentialsTests {
private static String role = null;
private static String context = null;

// Dummy API key lives outside the source tree, in a resource file under dummy-non-secrets/
// (excluded from Gitleaks scans), rather than as a string literal here.
@BeforeClass
public static void setup() {
public static void setup() throws IOException {
path = "valid-path-to-credentials-file";
credentialsString = "valid-credentials-string";
token = "valid-token";
validApiKey = "sky-ab123-abcd1234cdef1234abcd4321cdef4321";
validApiKey = new String(Files.readAllBytes(
Paths.get("./src/test/resources/dummy-non-secrets/dummy-api-key.txt")), StandardCharsets.UTF_8).trim();
invalidApiKey = "invalid-api-key";
roles = new ArrayList<>();
role = "test_credentials_role";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public void testInvalidKeySpecInCredentialsForCredentials() {

@Test
public void testInvalidTokenURIInCredentialsForCredentials() throws SkyflowException {
String filePath = "./src/test/resources/invalidTokenURICredentials.json";
String filePath = "./src/test/resources/dummy-non-secrets/invalidTokenURICredentials.json";
File file = new File(filePath);
try {
BearerToken bearerToken = BearerToken.builder().setCredentials(file).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,12 @@ public void testInvalidPrivateKeyInCredentials() {

@Test
public void testInvalidKeySpecInCredentials() {
String credentialsString = "{\"privateKey\": \"-----BEGIN PRIVATE KEY-----\\ncHJpdmF0ZV9rZXlfdmFsdWU=\\n-----END PRIVATE KEY-----\", \"clientID\": \"client_id_value\", \"keyID\": \"key_id_value\", \"tokenURI\": \"invalid_token_uri\"}";
// Dummy credentials (with a fake, invalid privateKey) live outside the source tree, in a
// resource file under dummy-non-secrets/ (excluded from Gitleaks scans).
String filePath = "./src/test/resources/dummy-non-secrets/invalidKeySpecCredentials.json";
File file = new File(filePath);
try {
SignedDataTokens signedTokens = SignedDataTokens.builder().setCredentials(credentialsString).build();
SignedDataTokens signedTokens = SignedDataTokens.builder().setCredentials(file).build();
signedTokens.getSignedDataTokens();
Assert.fail(EXCEPTION_NOT_THROWN);
} catch (SkyflowException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sky-ab123-abcd1234cdef1234abcd4321cdef4321
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"privateKey": "-----BEGIN PRIVATE KEY-----\ncHJpdmF0ZV9rZXlfdmFsdWU=\n-----END PRIVATE KEY-----", "clientID": "client_id_value", "keyID": "key_id_value", "tokenURI": "invalid_token_uri"}
13 changes: 11 additions & 2 deletions skyvault/src/test/java/com/skyflow/ConnectionClientTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;

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

Credentials credentials = new Credentials();
credentials.setApiKey(apiKey);
Expand Down
14 changes: 11 additions & 3 deletions skyvault/src/test/java/com/skyflow/VaultClientTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
import org.mockito.Mockito;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -58,16 +62,18 @@ public class VaultClientTests {
private static String table = null;
private static String value = null;
private static String columnGroup = null;
private static String apiKey = "sky-ab123-abcd1234cdef1234abcd4321cdef4321";
private static String apiKey = null;
private static ArrayList<DetokenizeData> detokenizeData = null;
private static ArrayList<HashMap<String, Object>> insertValues = null;
private static ArrayList<HashMap<String, Object>> insertTokens = null;
private static HashMap<String, Object> valueMap = null;
private static HashMap<String, Object> tokenMap = null;
private static VaultConfig vaultConfig;

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

String dummyApiKey = new String(Files.readAllBytes(
Paths.get("./src/test/resources/dummy-non-secrets/dummy-api-key.txt")), StandardCharsets.UTF_8).trim();
Credentials credentials = new Credentials();
credentials.setApiKey("sky-ab123-abcd1234cdef1234abcd4321cdef4321");
credentials.setApiKey(dummyApiKey);
vaultConfig.setCredentials(credentials);
vaultClient = new VaultClient(vaultConfig, credentials);
vaultClient.setBearerToken();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sky-ab123-abcd1234cdef1234abcd4321cdef4321
Loading