This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new a936abf84b9 CAMEL-21154: Handle potential NPE from getSecret operation
response
a936abf84b9 is described below
commit a936abf84b9cf3ba32e25642667d903ca5b9003a
Author: James Netherton <[email protected]>
AuthorDate: Mon Sep 2 14:44:00 2024 +0100
CAMEL-21154: Handle potential NPE from getSecret operation response
---
.../hashicorp/vault/HashicorpVaultProducer.java | 6 +++++-
.../operations/HashicorpProducerCreateSecretIT.java | 17 +++++++++++++----
2 files changed, 18 insertions(+), 5 deletions(-)
diff --git
a/components/camel-hashicorp-vault/src/main/java/org/apache/camel/component/hashicorp/vault/HashicorpVaultProducer.java
b/components/camel-hashicorp-vault/src/main/java/org/apache/camel/component/hashicorp/vault/HashicorpVaultProducer.java
index 571e5002334..b87c11a3591 100644
---
a/components/camel-hashicorp-vault/src/main/java/org/apache/camel/component/hashicorp/vault/HashicorpVaultProducer.java
+++
b/components/camel-hashicorp-vault/src/main/java/org/apache/camel/component/hashicorp/vault/HashicorpVaultProducer.java
@@ -78,7 +78,11 @@ public class HashicorpVaultProducer extends DefaultProducer {
completePath = completePath + "?version=" + secretVersion;
}
VaultResponse rawSecret =
getEndpoint().getVaultTemplate().read(completePath);
- exchange.getMessage().setBody(rawSecret.getData());
+ if (rawSecret != null) {
+ exchange.getMessage().setBody(rawSecret.getData());
+ } else {
+ exchange.getMessage().setBody(null);
+ }
}
private void deleteSecret() {
diff --git
a/components/camel-hashicorp-vault/src/test/java/org/apache/camel/component/hashicorp/vault/integration/operations/HashicorpProducerCreateSecretIT.java
b/components/camel-hashicorp-vault/src/test/java/org/apache/camel/component/hashicorp/vault/integration/operations/HashicorpProducerCreateSecretIT.java
index 34d828b6bfc..02d2a0b2032 100644
---
a/components/camel-hashicorp-vault/src/test/java/org/apache/camel/component/hashicorp/vault/integration/operations/HashicorpProducerCreateSecretIT.java
+++
b/components/camel-hashicorp-vault/src/test/java/org/apache/camel/component/hashicorp/vault/integration/operations/HashicorpProducerCreateSecretIT.java
@@ -30,6 +30,7 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
public class HashicorpProducerCreateSecretIT extends HashicorpVaultBase {
@@ -46,8 +47,8 @@ public class HashicorpProducerCreateSecretIT extends
HashicorpVaultBase {
public void createSecretTest() throws InterruptedException {
mockWrite.expectedMessageCount(1);
- mockRead.expectedMessageCount(1);
- Exchange exchange = template.request("direct:createSecret", new
Processor() {
+ mockRead.expectedMessageCount(2);
+ template.request("direct:createSecret", new Processor() {
@Override
public void process(Exchange exchange) {
HashMap map = new HashMap();
@@ -55,13 +56,21 @@ public class HashicorpProducerCreateSecretIT extends
HashicorpVaultBase {
exchange.getIn().setBody(map);
}
});
- exchange = template.request("direct:readSecret", new Processor() {
+ template.request("direct:readSecret", new Processor() {
@Override
public void process(Exchange exchange) {
exchange.getMessage().setHeader(HashicorpVaultConstants.SECRET_PATH, "test");
}
});
- exchange = template.request("direct:readSecretWithPathParam", null);
+ template.request("direct:readSecretWithPathParam", null);
+
+ Exchange result = template.request("direct:readSecret", new
Processor() {
+ @Override
+ public void process(Exchange exchange) {
+
exchange.getMessage().setHeader(HashicorpVaultConstants.SECRET_PATH, "invalid");
+ }
+ });
+ assertNull(result.getMessage().getBody());
MockEndpoint.assertIsSatisfied(context);
Exchange ret = mockRead.getExchanges().get(0);