Skip to content

Commit

Permalink
Issue #79 Adding rules for errors when a secret has the same name as …
Browse files Browse the repository at this point in the history
…a callContent
  • Loading branch information
baubakg committed May 4, 2024
1 parent a5f239c commit 92662a4
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 11 deletions.
10 changes: 5 additions & 5 deletions docs/Technical.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ This document deals with the general technical elements of the project.
## Error Handling
We currently manage the following error types.

| Error Code | Exceptions | Description |
|------------|----------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------|
| 404 | NonExistentJavaObjectException , JsonProcessingException, AmbiguousMethodException, JavaObjectInaccessibleException | Errors due to client side manipulations, and payloads. |
| 408 | IBSTimeOutException | When the underlying java call takes too long to execute. |
| 500 | IBSConfigurationException, IBSRunTimeException, TargetJavaMethodCallException | Errors happening when calling the underlying Java classes. |
| Error Code | Exceptions | Description |
|------------|------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------|
| 404 | NonExistentJavaObjectException , JsonProcessingException, AmbiguousMethodException, JavaObjectInaccessibleException, IBSPayloadException | Errors due to client side manipulations, and payloads. |
| 408 | IBSTimeOutException | When the underlying java call takes too long to execute. |
| 500 | IBSConfigurationException, IBSRunTimeException, TargetJavaMethodCallException | Errors happening when calling the underlying Java classes. |

## Managing Contexts and Static Variables
We have three modes of Integrity management :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class IntegroAPI {
public static final String ERROR_CONTENT_TYPE = "application/problem+json";
public static final String SYSTEM_UP_MESSAGE = "All systems up";
public static final String ERROR_IBS_INTERNAL = "Internal IBS error. Please file a bug report with the project and provide this JSON in the report.";
public static final String ERROR_PAYLOAD_INCONSISTENCY = "We detected stored header ames that match a callContent.";
protected static final String ERROR_JSON_TRANSFORMATION = "JSON Transformation issue : Problem processing request. The given json could not be mapped to a Java Call";
protected static final String ERROR_CALLING_JAVA_METHOD = "Error during call of target Java Class and Method.";
protected static final String ERROR_JAVA_OBJECT_NOT_FOUND = "Could not find the given class or method.";
Expand Down Expand Up @@ -93,6 +94,14 @@ public static void startServices(int port) {
new ErrorObject(e, ERROR_JSON_TRANSFORMATION, statusCode)));
});

exception(IBSPayloadException.class, (e, req, res) -> {
int statusCode = 404;
res.status(statusCode);
res.type(ERROR_CONTENT_TYPE);
res.body(BridgeServiceFactory.createExceptionPayLoad(
new ErrorObject(e, ERROR_PAYLOAD_INCONSISTENCY, statusCode)));
});

exception(AmbiguousMethodException.class, (e, req, res) -> {
int statusCode = 404;
res.status(statusCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,15 @@ public void setAssertions(Map<String, Assertion> assertions) {
* @param in_mapOHeaders A map containing header values coming from the request
*/
public void addSecrets(Map<String, String> in_mapOHeaders) {
in_mapOHeaders.keySet().stream().filter(i -> i.startsWith(ConfigValueHandlerIBS.SECRETS_FILTER_PREFIX.fetchValue())).forEach(fk -> {
this.getLocalClassLoader().getCallResultCache().put(fk, in_mapOHeaders.get(fk));
this.getLocalClassLoader().getSecretsSet().add(fk);
});
in_mapOHeaders.keySet().stream()
.filter(i -> i.startsWith(ConfigValueHandlerIBS.SECRETS_FILTER_PREFIX.fetchValue())).forEach(fk -> {
this.getLocalClassLoader().getCallResultCache().put(fk, in_mapOHeaders.get(fk));
this.getLocalClassLoader().getSecretsSet().add(fk);
});

this.getLocalClassLoader().getSecretsSet().stream().filter(s -> this.getCallContent().keySet().contains(s))
.anyMatch(t -> {
throw new IBSPayloadException("There is a duplicate key between the Secrets and the CallContents");
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2022 Adobe
* All Rights Reserved.
*
* NOTICE: Adobe permits you to use, modify, and distribute this file in
* accordance with the terms of the Adobe license agreement accompanying
* it.
*/
package com.adobe.campaign.tests.bridge.service.exceptions;

/**
* This exception is thrown whenever there is an inconsistency in the payload
*/
public class IBSPayloadException extends RuntimeException {
private static final long serialVersionUID = -6489221630558571708L;

public IBSPayloadException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,23 @@ public void testFetchHeaders() {

}

@Test(description = "Issue #78 accepting header secrets - where the header has the same name as a call content", groups = "E2E")
public void testFetchHeaders_negative() {
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("IBS_HEADER_1", l_cc);

given().body(l_myJavaCall).header("IBS_HEADER_1","REAL").post(EndPointURL + "call").then().statusCode(404)
.assertThat()
.body("title", Matchers.equalTo(IntegroAPI.ERROR_PAYLOAD_INCONSISTENCY));

}



@AfterGroups(groups = "E2E", alwaysRun = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2058,7 +2058,7 @@ public void testWithErrorAtEnvironmentValue() {

//Managing headers
@Test
public void testUsingHeaders() {
public void testUsingHeadersAsVariables() {
Map<String, String> l_headerMap = Map.of("key1", "value1", "key2", "value2");

JavaCalls l_myJavaCalls = new JavaCalls();
Expand All @@ -2077,7 +2077,7 @@ public void testUsingHeaders() {
}

@Test
public void testUsingHeaders_filter() {
public void testUsingHeaders_filterWhichHeadersToInclude() {
ConfigValueHandlerIBS.SECRETS_FILTER_PREFIX.activate("ibs-header-");
Map<String, String> l_secretsMap = Map.of("key1", "value1", "ibs-header-key2", "value2");

Expand All @@ -2090,5 +2090,20 @@ public void testUsingHeaders_filter() {
assertThat("We should not have any call results yet", l_myJavaCalls.getLocalClassLoader().getSecretsSet().size(),
Matchers.equalTo(1));
}

@Test
public void testUsingHeaders_negative() {
Map<String, String> l_secretsMap = Map.of("key1", "value1", "ibs-header-key2", "value2");

JavaCalls l_myJavaCalls = new JavaCalls();
CallContent l_cc = new CallContent();
l_cc.setClassName(SimpleStaticMethods.class.getTypeName());
l_cc.setMethodName("methodReturningString");

l_myJavaCalls.getCallContent().put("ibs-header-key2", l_cc);

Assert.assertThrows(IBSPayloadException.class, () -> l_myJavaCalls.addSecrets(l_secretsMap));

}
}

0 comments on commit 92662a4

Please sign in to comment.