Skip to content

Commit

Permalink
ISSUES-603 More real-world scenarios tested
Browse files Browse the repository at this point in the history
  • Loading branch information
nirmalchandra committed Feb 7, 2024
1 parent bbf2dc3 commit 4e804b3
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static org.jsmart.zerocode.core.constants.ZeroCodeReportConstants.RESULT_FAIL;
import static org.jsmart.zerocode.core.constants.ZeroCodeReportConstants.RESULT_PASS;
import static org.jsmart.zerocode.core.constants.ZeroCodeReportConstants.TEST_STEP_CORRELATION_ID;
import static org.jsmart.zerocode.core.utils.TokenUtils.getMasksReplaced;

public class ZerocodeCorrelationshipLogger {
private static final String DISPLAY_DEMARCATION_ = "\n--------- " + TEST_STEP_CORRELATION_ID + " %s ---------";
Expand Down Expand Up @@ -139,11 +140,12 @@ public void print() {
buildResponseDelay();

String customLog = responseLogBuilder.getCustomLog();
String assertionsWithMaskRemoved = getMasksReplaced(responseLogBuilder.getAssertion());
logger.warn(format("%s %s \n*Response delay:%s milli-secs \n%s \n%s \n-done-\n",
requestLogBuilder.toString(),
responseLogBuilder.toString(),
responseDelay,
"---------> Expected Response: <----------\n" + responseLogBuilder.getAssertion(),
"---------> Expected Response: <----------\n" + assertionsWithMaskRemoved,
customLog == null ? "" : "---------> Custom Log: <----------\n" +customLog
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ private String executeApi(String logPrefixRelationshipId,
.method(operationName)
.request(prettyPrintJson(resolvedRequestJsonMaskApplied));

executionResult = prettyPrintJson(resolvedRequestJson);
executionResult = prettyPrintJson(resolvedRequestJsonMaskApplied);
break;

default:
Expand Down Expand Up @@ -541,6 +541,8 @@ private int deriveScenarioLoopTimes(ScenarioSpec scenario) {
private List<FieldAssertionMatcher> compareStepResults(Step thisStep, String actualResult, String expectedResult, String resolvedScenarioState) {
List<FieldAssertionMatcher> failureResults = new ArrayList<>();

expectedResult = zeroCodeAssertionsProcessor.fieldMasksRemoved(expectedResult);

// --------------------
// Validators (pyrest)
// --------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ public class MaskedSecretsInMemoryTest {
@Test
@Scenario("integration_test_files/masked/password_or_secrets_masked_in_log_n_console.json")
public void testSecretPrinted_masked() throws Exception {

}

@Test
@Scenario("integration_test_files/masked/bearer_token_or_secret_masked_reuse_example_.json")
public void testSecretPrintedAssertions_masked() throws Exception {

}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"scenarioName": "Masked Secret path as step param",
"steps": [
{
"name": "get_balance_via_secret_token",
"url": "/home/accounts/123/balance",
"operation": "GET",
"request": {
"headers": {
"Authorization": "Bearer ${MASKED:token1002003004}",
"request-bank-name": "${MASKED:HSBC}",
"secretCode": "${MASKED:Amazing}"
}

},
"assertions": {
"status": 200,
"body" : {
"balance" : 3900,
"name" : "${$.get_balance_via_secret_token.request.headers.request-bank-name}",
"current" : true
}
}
},
{
"name": "find_match",
"url": "/api/v1/search/persons",
"method": "GET",
"request": {
"queryParams": {
"lang": "${$.get_balance_via_secret_token.request.headers.secretCode}",
"city": "${MASKED:Lon}"
}
},
"verify": {
"status": 200,
"body": {
"exactMatches": true,
"name": "Mr Bean",
"lang": "${$.get_balance_via_secret_token.request.headers.secretCode}",
"city": "${$.find_match.request.queryParams.city}"
}
}
}

]
}

Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@
"queryParams": {
"lang": "${MASKED:Amazing}",
"city": "Lon"
},
"body": {
"api_secret" : "${MASKED:pass123}",
"emotion": "${MASKED:Amazing}",
"state": "Amazing"
}
},
"verify": {
"status": 200,
"body": {
"exactMatches": true,
"name": "Mr Bean",
"lang": "Amazing",
"lang": "${$.find_match.request.body.emotion}",
"city": "Lon"
}
}
Expand Down
13 changes: 13 additions & 0 deletions core/src/test/resources/simulators/test_purpose_end_points.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
{
"name": "Mock endpoints Simulator - API Stubs",
"apis": [
{
"name": "Get My Bank Balance",
"operation": "GET",
"url": "/home/accounts/123/balance",
"response": {
"status": 200,
"body": {
"balance": 3900,
"name": "HSBC",
"current": true
}
}
},
{
"name": "Get Bank Account by Id",
"operation": "GET",
Expand Down

0 comments on commit 4e804b3

Please sign in to comment.