Skip to content

Commit

Permalink
Fix #873: Enrollment server fails on NPE when operation parameter is … (
Browse files Browse the repository at this point in the history
#874)

* Fix #873: Enrollment server fails on NPE when operation parameter is null
- Fix omitting nulls
  • Loading branch information
jandusil authored Sep 26, 2023
1 parent fc79f7c commit ae8d13c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ private static StringSubstitutor createStringSubstitutor(final Map<String, Strin
return null;
} else {
final Map<String, String> escapedParameters = parameters.entrySet().stream()
.filter(entry -> entry.getValue() != null)
.collect(toMap(Map.Entry::getKey, it -> StringEscapeUtils.escapeJson(it.getValue())));
return new StringSubstitutor(escapedParameters);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableMap;
import com.wultra.app.enrollmentserver.database.entity.OperationTemplateEntity;
import com.wultra.app.enrollmentserver.errorhandling.MobileTokenConfigurationException;
import com.wultra.security.powerauth.client.model.enumeration.OperationStatus;
import com.wultra.security.powerauth.client.model.enumeration.SignatureType;
import com.wultra.security.powerauth.client.model.response.OperationDetailResponse;
Expand All @@ -29,6 +30,7 @@
import org.springframework.context.i18n.LocaleContextHolder;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -506,11 +508,11 @@ void testConvertAttributes() throws Exception {
assertEquals(new AlertAttribute("operation.alert", AlertAttribute.AlertType.WARNING, "Balance warning",
"Insufficient Balance", "You have only $1.00 on your account with number 238400856/0300."), atributesIterator.next());
assertEquals(new PartyAttribute("operation.partyInfo", "Party Info", PartyInfo.builder()
.logoUrl("https://example.com/img/logo/logo.svg")
.name("Example Ltd.")
.description("Find out more about Example...")
.websiteUrl("https://example.com/hello")
.build()), atributesIterator.next());
.logoUrl("https://example.com/img/logo/logo.svg")
.name("Example Ltd.")
.description("Find out more about Example...")
.websiteUrl("https://example.com/hello")
.build()), atributesIterator.next());
}

@Test
Expand Down Expand Up @@ -592,6 +594,46 @@ void testConvertUiPreapprovalScanQrSuppressed() throws Exception {
assertNull(ui.getPreApprovalScreen());
}

@Test
void testCreateStringSubstitutorWithNullValue() throws MobileTokenConfigurationException {
final OperationDetailResponse operationDetail = createOperationDetailResponse();
final Map<String, String> params = new HashMap<>();
params.put("amount", "100.00");
params.put("currency", "EUR");
params.put("iban", null);
operationDetail.setParameters(params);

final OperationTemplateEntity operationTemplate = new OperationTemplateEntity();
operationTemplate.setAttributes("""
[
{
"id": "operation.amount",
"type": "AMOUNT",
"text": "Amount",
"params": {
"amount": "amount",
"currency": "currency"
}
},
{
"id": "operation.account",
"type": "KEY_VALUE",
"text": "To Account",
"params": {
"value": "iban"
}
}
]""");

final Operation operation = tested.convert(operationDetail, operationTemplate);
assertNotNull(operation);

final List<Attribute> attributes = operation.getFormData().getAttributes();
assertNotNull(attributes);
assertEquals(1, attributes.size());
assertEquals("operation.amount", attributes.get(0).getId());
}

private static OperationDetailResponse createOperationDetailResponse() {
final OperationDetailResponse operationDetail = new OperationDetailResponse();
operationDetail.setSignatureType(List.of(SignatureType.KNOWLEDGE));
Expand Down

0 comments on commit ae8d13c

Please sign in to comment.