Skip to content
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
19 changes: 17 additions & 2 deletions common/src/test/java/com/skyflow/BaseSkyflowTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,12 @@ public void testMergeVaultConfigWithNullClusterIdFallsBackToPreviousClusterId()
Assert.assertEquals(clusterID, result.getClusterId());
}

private static class TestSkyflow extends BaseSkyflow<TestSkyflow, BaseVaultConfig, Object> {
private static class TestSkyflow extends BaseSkyflow<TestSkyflow, BaseVaultConfig> {
private final TestSkyflowClientBuilder builder;

private TestSkyflow(TestSkyflowClientBuilder builder) {
super(builder);
this.builder = builder;
}

static TestSkyflowClientBuilder builder() {
Expand All @@ -274,12 +277,19 @@ protected TestSkyflow self() {
return this;
}

Object vault() throws SkyflowException {
return resolveOrThrow(this.builder.vaultClientsMap, null,
ErrorLogs.VAULT_CONFIG_DOES_NOT_EXIST, ErrorMessage.VaultIdNotInConfigList);
}

Object vault(String vaultId) throws SkyflowException {
return resolveOrThrow(this.builder.vaultClientsMap, vaultId,
ErrorLogs.VAULT_CONFIG_DOES_NOT_EXIST, ErrorMessage.VaultIdNotInConfigList);
}

private static class TestSkyflowClientBuilder extends BaseSkyflowClientBuilder<BaseVaultConfig, Object> {
private static class TestSkyflowClientBuilder extends BaseSkyflowClientBuilder<BaseVaultConfig> {
private final java.util.LinkedHashMap<String, Object> vaultClientsMap = new java.util.LinkedHashMap<>();

@Override
protected void validateVaultConfig(BaseVaultConfig vaultConfig) throws SkyflowException {
if (vaultConfig.getVaultId() == null || vaultConfig.getVaultId().trim().isEmpty()) {
Expand All @@ -297,6 +307,11 @@ protected void onVaultConfigUpdated(BaseVaultConfig updatedConfig) {
this.vaultClientsMap.put(updatedConfig.getVaultId(), new Object());
}

@Override
protected void onVaultConfigRemoved(String vaultId) {
this.vaultClientsMap.remove(vaultId);
}

@Override
protected void onCredentialsUpdated(Credentials credentials) {
// no-op: this test double only exercises template orchestration, not propagation
Expand Down
23 changes: 12 additions & 11 deletions common/src/test/java/com/skyflow/BaseVaultClientTests.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.skyflow;

import com.skyflow.config.BaseCredentials;
import com.skyflow.config.BaseVaultConfig;
import com.skyflow.errors.ErrorMessage;
import com.skyflow.errors.SkyflowException;
import com.skyflow.utils.BaseConstants;
Expand Down Expand Up @@ -35,15 +36,15 @@ public void restoreEnvFile() throws IOException {
}
}

private BaseVaultClient<Object> newClient(BaseCredentials commonCredentials) {
return new BaseVaultClient<>(new Object(), commonCredentials);
private BaseVaultClient<BaseVaultConfig> newClient(BaseCredentials commonCredentials) {
return new BaseVaultClient<>(new BaseVaultConfig(), commonCredentials);
}

@Test
public void testPrioritiseCredentials_prefersVaultSpecificCredentials() throws SkyflowException {
BaseCredentials vaultSpecific = new BaseCredentials();
vaultSpecific.setApiKey("test_api_key");
BaseVaultClient<Object> client = newClient(null);
BaseVaultClient<BaseVaultConfig> client = newClient(null);

client.prioritiseCredentials(vaultSpecific);

Expand All @@ -54,7 +55,7 @@ public void testPrioritiseCredentials_prefersVaultSpecificCredentials() throws S
public void testPrioritiseCredentials_fallsBackToCommonCredentials() throws SkyflowException {
BaseCredentials common = new BaseCredentials();
common.setApiKey("common_api_key");
BaseVaultClient<Object> client = newClient(common);
BaseVaultClient<BaseVaultConfig> client = newClient(common);

client.prioritiseCredentials(null);

Expand All @@ -65,7 +66,7 @@ public void testPrioritiseCredentials_fallsBackToCommonCredentials() throws Skyf
public void testPrioritiseCredentials_credentialChange_resetsTokenAndApiKey() throws SkyflowException {
BaseCredentials credentialsA = new BaseCredentials();
credentialsA.setToken("x.eyJleHAiOjk5OTk5OTk5OTl9.y");
BaseVaultClient<Object> client = newClient(null);
BaseVaultClient<BaseVaultConfig> client = newClient(null);

client.prioritiseCredentials(credentialsA);
client.token = "cached-token";
Expand All @@ -83,7 +84,7 @@ public void testPrioritiseCredentials_credentialChange_resetsTokenAndApiKey() th
public void testSetBearerToken_withApiKey() throws SkyflowException {
BaseCredentials creds = new BaseCredentials();
creds.setApiKey("sky-ab123-abcd1234cdef1234abcd4321cdef4321");
BaseVaultClient<Object> client = newClient(null);
BaseVaultClient<BaseVaultConfig> client = newClient(null);

client.setBearerToken(creds);

Expand All @@ -94,7 +95,7 @@ public void testSetBearerToken_withApiKey() throws SkyflowException {
public void testSetBearerToken_generatesTokenWhenNull() throws SkyflowException {
BaseCredentials creds = new BaseCredentials();
creds.setToken("x.eyJleHAiOjk5OTk5OTk5OTl9.y");
BaseVaultClient<Object> client = newClient(null);
BaseVaultClient<BaseVaultConfig> client = newClient(null);

client.setBearerToken(creds);

Expand All @@ -105,7 +106,7 @@ public void testSetBearerToken_generatesTokenWhenNull() throws SkyflowException
public void testSetBearerToken_reusesValidNonExpiredToken() throws SkyflowException {
BaseCredentials creds = new BaseCredentials();
creds.setToken("x.eyJleHAiOjk5OTk5OTk5OTl9.y");
BaseVaultClient<Object> client = newClient(null);
BaseVaultClient<BaseVaultConfig> client = newClient(null);

// First call: token=null → generates from creds.getToken()
client.setBearerToken(creds);
Expand All @@ -118,7 +119,7 @@ public void testSetBearerToken_reusesValidNonExpiredToken() throws SkyflowExcept

@Test
public void testSetBearerToken_noCredentials_throwsEmptyCredentials() {
BaseVaultClient<Object> client = newClient(null);
BaseVaultClient<BaseVaultConfig> client = newClient(null);
try {
client.setBearerToken(null);
Assert.fail("Should have thrown SkyflowException");
Expand All @@ -137,7 +138,7 @@ public void testPrioritiseCredentials_dotenvReturnsCredentials_setsCredentials()
fw.write(BaseConstants.ENV_CREDENTIALS_KEY_NAME + "={\"token\":\"env-token-value\"}\n");
}

BaseVaultClient<Object> client = newClient(null);
BaseVaultClient<BaseVaultConfig> client = newClient(null);
client.prioritiseCredentials(null);

Assert.assertNotNull(client.finalCredentials);
Expand All @@ -154,7 +155,7 @@ public void testPrioritiseCredentials_dotenvKeyMissing_throwsSkyflowException()
fw.write("SOME_OTHER_KEY=some_value\n");
}

BaseVaultClient<Object> client = newClient(null);
BaseVaultClient<BaseVaultConfig> client = newClient(null);
try {
client.prioritiseCredentials(null);
Assert.fail("Should have thrown SkyflowException");
Expand Down
Loading