From 7251624fb38465ab0b370956645fa2133764d92c Mon Sep 17 00:00:00 2001 From: Jamie Li Date: Thu, 15 Jun 2023 11:44:19 -0700 Subject: [PATCH] Fix missing type in the PutCustomerRequest in SEP-24 post transactions --- .../service/SimpleInteractiveUrlConstructor.java | 2 ++ .../SimpleInteractiveUrlConstructorTest.kt | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/platform/src/main/java/org/stellar/anchor/platform/service/SimpleInteractiveUrlConstructor.java b/platform/src/main/java/org/stellar/anchor/platform/service/SimpleInteractiveUrlConstructor.java index 75d44063af..ac81c7beec 100644 --- a/platform/src/main/java/org/stellar/anchor/platform/service/SimpleInteractiveUrlConstructor.java +++ b/platform/src/main/java/org/stellar/anchor/platform/service/SimpleInteractiveUrlConstructor.java @@ -23,6 +23,7 @@ import org.stellar.anchor.util.GsonUtils; public class SimpleInteractiveUrlConstructor extends InteractiveUrlConstructor { + public static final String FORWARD_KYC_CUSTOMER_TYPE = "sep24-customer"; private final PropertySep24Config sep24Config; private final CustomerIntegration customerIntegration; private final JwtService jwtService; @@ -95,6 +96,7 @@ void forwardKycFields(Map request) throws AnchorException { String gsonRequest = gson.toJson(sep9); PutCustomerRequest putCustomerRequest = gson.fromJson(gsonRequest, PutCustomerRequest.class); + putCustomerRequest.setType(FORWARD_KYC_CUSTOMER_TYPE); // forward kyc fields to PUT /customer customerIntegration.putCustomer(putCustomerRequest); } diff --git a/platform/src/test/kotlin/org/stellar/anchor/platform/service/SimpleInteractiveUrlConstructorTest.kt b/platform/src/test/kotlin/org/stellar/anchor/platform/service/SimpleInteractiveUrlConstructorTest.kt index 96cd5cbdf6..bb5fc08487 100644 --- a/platform/src/test/kotlin/org/stellar/anchor/platform/service/SimpleInteractiveUrlConstructorTest.kt +++ b/platform/src/test/kotlin/org/stellar/anchor/platform/service/SimpleInteractiveUrlConstructorTest.kt @@ -5,6 +5,7 @@ import io.mockk.every import io.mockk.impl.annotations.MockK import io.mockk.mockk import io.mockk.slot +import io.mockk.verify import java.time.Instant import java.util.stream.Stream import org.junit.jupiter.api.Assertions.* @@ -77,7 +78,21 @@ class SimpleInteractiveUrlConstructorTest { every { customerIntegration.putCustomer(capture(capturedPutCustomerRequest)) } returns PutCustomerResponse() val constructor = SimpleInteractiveUrlConstructor(sep24Config, customerIntegration, jwtService) + sep24Config.kycFieldsForwarding.isEnabled = true constructor.construct(txn, request as HashMap?) + assertEquals(capturedPutCustomerRequest.captured.type, "sep24-customer") + assertEquals(capturedPutCustomerRequest.captured.firstName, request.get("first_name")) + assertEquals(capturedPutCustomerRequest.captured.lastName, request.get("last_name")) + assertEquals(capturedPutCustomerRequest.captured.emailAddress, request.get("email_address")) + } + + @Test + fun `when kycFieldsForwarding is disabled, the customerIntegration should not receive the kyc fields`() { + val customerIntegration: CustomerIntegration = mockk() + val constructor = SimpleInteractiveUrlConstructor(sep24Config, customerIntegration, jwtService) + sep24Config.kycFieldsForwarding.isEnabled = false + constructor.construct(txn, request as HashMap?) + verify(exactly = 0) { customerIntegration.putCustomer(any()) } } private fun parseJwtFromUrl(url: String?): Sep24InteractiveUrlJwt {