diff --git a/core/src/main/java/io/kestra/core/secret/SecretService.java b/core/src/main/java/io/kestra/core/secret/SecretService.java index 1adb420b02e..db5616b345d 100644 --- a/core/src/main/java/io/kestra/core/secret/SecretService.java +++ b/core/src/main/java/io/kestra/core/secret/SecretService.java @@ -38,6 +38,10 @@ public void decode() { } public String findSecret(String tenantId, String namespace, String key) throws SecretNotFoundException, IOException { - return decodedSecrets.get(key.toUpperCase()); + String secret = decodedSecrets.get(key.toUpperCase()); + if (secret == null) { + throw new SecretNotFoundException("Cannot find secret for key '" + key + "'."); + } + return secret; } } diff --git a/core/src/test/java/io/kestra/core/secret/SecretFunctionTest.java b/core/src/test/java/io/kestra/core/secret/SecretFunctionTest.java index 00544b67607..505c162c17f 100644 --- a/core/src/test/java/io/kestra/core/secret/SecretFunctionTest.java +++ b/core/src/test/java/io/kestra/core/secret/SecretFunctionTest.java @@ -23,6 +23,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; +import static org.junit.jupiter.api.Assertions.assertThrows; @KestraTest public class SecretFunctionTest extends AbstractMemoryRunnerTest { @@ -53,9 +54,9 @@ void getSecret() throws TimeoutException, QueueException { } @Test - void getUnknownSecret() throws IllegalVariableEvaluationException, IOException { - String secret = secretService.findSecret(null, null, "unknown_secret_key"); + void getUnknownSecret() { + var exception = assertThrows(SecretNotFoundException.class, () -> secretService.findSecret(null, null, "unknown_secret_key")); - assertThat(secret, nullValue()); + assertThat(exception.getMessage(), is("Cannot find secret for key 'unknown_secret_key'.")); } }