Skip to content

Commit

Permalink
Fixed Issue #180 fixing expansion of header values in the environment…
Browse files Browse the repository at this point in the history
… variables
  • Loading branch information
baubakg committed Oct 7, 2024
1 parent a7f7982 commit 0c1b33b
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Bridge Service - RELEASE NOTES
## 2.11.18 In Progress
* [#180 Headers not usable as environment variable](https://github.com/adobe/bridgeService/issues/180). We discovered that variable expansion of headers did not cover environment variables.


## 2.11.17
* **New Feature** [#160 Introduce Extraction Plugins](https://github.com/adobe/bridgeService/issues/160). We have now introduced a new plugin mechanism so you can define how an object you are expecting should be deserialized. Please refer to the chapter on ["Deserialization Plugins"](README.md#deserialization-plugins) in the README doc.
* **New Feature** [#162 Deserializing Date Objects](https://github.com/adobe/bridgeService/issues/162). We now allow the deserialization of Date objects. You can decide the formatting of the value. For more information please refer to [Formatting Dates](README.md#formatting-dates) in the README doc.
Expand Down
2 changes: 1 addition & 1 deletion integroBridgeService/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
<groupId>com.adobe.campaign.tests.bridge.testdata</groupId>
<artifactId>bridgeService-data</artifactId>
<version>${project.parent.version}</version>
<scope>${demo.project.mode}</scope>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,15 @@ private void updateEnvironmentVariables() {
"The given environment variables should only contain strings.\n" + badVariables);
}


//Expand header args
Properties l_expandedProperties = new Properties();
getEnvironmentVariables().forEach((k, v) -> {
l_expandedProperties.put(k, getLocalClassLoader().getCallResultCache().getOrDefault(v, v));
});

//Fetch all environment variables
l_setEnvironmentVars.setArgs(new Object[] { environmentVariables });
l_setEnvironmentVars.setArgs(new Object[] { l_expandedProperties });
try {
l_setEnvironmentVars.call(this.getLocalClassLoader());
} catch (NonExistentJavaObjectException nejoe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1969,6 +1969,60 @@ public void testUsingHeaders_negativePassingSecrets()
.contains("value2"));
}

//Issue #180 problems using heades as environment variables
@Test
public void testUsingHeadersAsEnvironmentVariables_issue180() {
Map<String, String> l_headerMap = Map.of("key1", "value1",
ConfigValueHandlerIBS.SECRETS_FILTER_PREFIX.defaultValue + "key2", "boom.com");

JavaCalls l_myJavaCalls = new JavaCalls();

CallContent l_cc = new CallContent();
l_cc.setClassName("com.adobe.campaign.tests.bridge.testdata.two.StaticMethodsIntegrity");
l_cc.setMethodName("assembleBySystemValues");

Properties l_envVars = new Properties();
l_envVars.put("PREFIX", "key1");
l_envVars.put("SUFFIX", ConfigValueHandlerIBS.SECRETS_FILTER_PREFIX.defaultValue +"key2");

l_myJavaCalls.addHeaders(l_headerMap);
l_myJavaCalls.setEnvironmentVariables(l_envVars);
l_myJavaCalls.getCallContent().put("call1", l_cc);

JavaCallResults returnedValue = l_myJavaCalls.submitCalls();

assertThat("We should get a good answer back from the call",
returnedValue.getReturnValues().get("call1").toString(),
Matchers.startsWith(l_headerMap.get("key1")));

assertThat("We should get a good answer back from the call even if it is a secret",
returnedValue.getReturnValues().get("call1").toString(),
Matchers.endsWith("boom.com"));
}


@Test
public void testValueReplacement_issue180() {
Map<String, String> l_headerMap = Map.of("key1", "XXXX",
ConfigValueHandlerIBS.SECRETS_FILTER_PREFIX.defaultValue + "key2", "value2");

JavaCalls jc = new JavaCalls();

jc.addHeaders(l_headerMap);

IntegroBridgeClassLoader icl = jc.getLocalClassLoader();

CallContent l_cc1B = new CallContent();
l_cc1B.setClassName(SimpleStaticMethods.class.getTypeName());
l_cc1B.setMethodName("methodAcceptingTwoArguments");
l_cc1B.setArgs(new Object[] { "key1", "B" });

Object[] result = l_cc1B.expandArgs(icl);
assertThat("We should have replaced the value correctly", result.length, Matchers.equalTo(2));
assertThat("We should have replaced the value correctly", result[0].toString(), Matchers.equalTo("XXXX"));

}

//#111 Var args and list -array interoperability
@Test
public void testInListToArrayTransformation() throws NoSuchMethodException, ClassNotFoundException {
Expand Down

0 comments on commit 0c1b33b

Please sign in to comment.