From bfd29a3c2c98e497e2bf6e6156797d12c8a9b2ae Mon Sep 17 00:00:00 2001 From: baubakg Date: Sat, 4 May 2024 14:49:04 +0200 Subject: [PATCH] #79 first working commit --- .../tests/bridge/service/IntegroAPI.java | 5 +++++ .../tests/bridge/service/JavaCalls.java | 8 ++++++++ .../tests/bridge/service/E2ETests.java | 18 ++++++++++++++++++ .../tests/bridge/service/TestFetchCalls.java | 17 +++++++++++++++-- 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/integroBridgeService/src/main/java/com/adobe/campaign/tests/bridge/service/IntegroAPI.java b/integroBridgeService/src/main/java/com/adobe/campaign/tests/bridge/service/IntegroAPI.java index c3d83bfb..921ae810 100644 --- a/integroBridgeService/src/main/java/com/adobe/campaign/tests/bridge/service/IntegroAPI.java +++ b/integroBridgeService/src/main/java/com/adobe/campaign/tests/bridge/service/IntegroAPI.java @@ -13,10 +13,13 @@ import com.fasterxml.jackson.core.JsonProcessingException; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import spark.Request; import java.io.File; import java.util.HashMap; import java.util.Map; +import java.util.Properties; +import java.util.stream.Collectors; import static spark.Spark.*; @@ -77,6 +80,8 @@ public static void startServices(int port) { post("/call", (req, res) -> { JavaCalls fetchedFromJSON = BridgeServiceFactory.createJavaCalls(req.body()); + fetchedFromJSON.addHeaders(req.headers().stream().collect(Collectors.toMap(k -> k, k -> req.headers(k)))); + return BridgeServiceFactory.transformJavaCallResultsToJSON(fetchedFromJSON.submitCalls()); }); diff --git a/integroBridgeService/src/main/java/com/adobe/campaign/tests/bridge/service/JavaCalls.java b/integroBridgeService/src/main/java/com/adobe/campaign/tests/bridge/service/JavaCalls.java index 3be46a92..21c641b4 100644 --- a/integroBridgeService/src/main/java/com/adobe/campaign/tests/bridge/service/JavaCalls.java +++ b/integroBridgeService/src/main/java/com/adobe/campaign/tests/bridge/service/JavaCalls.java @@ -192,4 +192,12 @@ public Map getAssertions() { public void setAssertions(Map assertions) { this.assertions = assertions; } + + /** + * Adds headers to the results cache of the ClassLoader + * @param in_mapOHeaders A map containing header values coming from the request + */ + public void addHeaders(Map in_mapOHeaders) { + in_mapOHeaders.forEach((k,v) -> this.getLocalClassLoader().getCallResultCache().put(k,v)); + } } diff --git a/integroBridgeService/src/test/java/com/adobe/campaign/tests/bridge/service/E2ETests.java b/integroBridgeService/src/test/java/com/adobe/campaign/tests/bridge/service/E2ETests.java index a4f689ae..40132bfa 100644 --- a/integroBridgeService/src/test/java/com/adobe/campaign/tests/bridge/service/E2ETests.java +++ b/integroBridgeService/src/test/java/com/adobe/campaign/tests/bridge/service/E2ETests.java @@ -762,8 +762,26 @@ public void testAssertionsHelloWorldCall() { } + + @Test(description = "Issue #78 accepting header secrets", groups = "E2E") + public void testFetchHeaders() { + JavaCalls l_myJavaCall = new JavaCalls(); + + CallContent l_cc = new CallContent(); + l_cc.setClassName(SimpleStaticMethods.class.getTypeName()); + l_cc.setMethodName("methodAcceptingStringArgument"); + l_cc.setArgs(new Object[] { "IBS_HEADER_1" }); + + l_myJavaCall.getCallContent().put("fetchString", l_cc); + + given().body(l_myJavaCall).header("IBS_HEADER_1","REAL").post(EndPointURL + "call").then().assertThat() + .body("returnValues.fetchString", Matchers.equalTo("REAL_Success")); + + } + @AfterGroups(groups = "E2E", alwaysRun = true) public void tearDown() throws IOException { + ConfigValueHandlerIBS.resetAllValues(); Spark.stop(); serverSocket1.close(); diff --git a/integroBridgeService/src/test/java/com/adobe/campaign/tests/bridge/service/TestFetchCalls.java b/integroBridgeService/src/test/java/com/adobe/campaign/tests/bridge/service/TestFetchCalls.java index ad6bd261..a43ac3ba 100644 --- a/integroBridgeService/src/test/java/com/adobe/campaign/tests/bridge/service/TestFetchCalls.java +++ b/integroBridgeService/src/test/java/com/adobe/campaign/tests/bridge/service/TestFetchCalls.java @@ -17,7 +17,6 @@ import com.adobe.campaign.tests.bridge.testdata.two.StaticMethodsIntegrity; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.commons.lang3.StringUtils; import org.hamcrest.Matchers; import org.testng.Assert; import org.testng.annotations.AfterClass; @@ -1383,7 +1382,6 @@ public void testDurationReplacement() { Long result3 = jcr.expandDurations(100); assertThat(result3, Matchers.equalTo(100l)); - } @Test @@ -2057,5 +2055,20 @@ public void testWithErrorAtEnvironmentValue() { } } + + //Managing headers + @Test + public void testUsingHeaders() { + Map l_headerMap = Map.of("key1", "value1", "key2", "value2"); + + JavaCalls l_myJavaCalls = new JavaCalls(); + + assertThat("We should not have any call results yet", l_myJavaCalls.getLocalClassLoader().getCallResultCache(), + Matchers.anEmptyMap()); + + l_myJavaCalls.addHeaders(l_headerMap); + assertThat("We should not have any call results yet", l_myJavaCalls.getLocalClassLoader().getCallResultCache().size(), + Matchers.equalTo(2)); + } }