Skip to content

Commit

Permalink
[ANCHOR-588] Fix birth_date field type (#1257)
Browse files Browse the repository at this point in the history
### Description

This changes the `birth_date` type from an `Instant` to an ISO-8601 date
validated String.

### Context

SEP-12 dates are ISO-8601 date strings.

### Testing

- `./gradlew test`

### Documentation

N/A

### Known limitations

N/A
  • Loading branch information
philipliu authored Jan 17, 2024
1 parent 6ff840b commit ab082ed
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
import java.time.Instant;
import lombok.Builder;
import lombok.Data;
import org.stellar.anchor.api.sep.sep12.Sep12PutCustomerRequest;
Expand Down Expand Up @@ -57,7 +56,7 @@ public class PutCustomerRequest {
String emailAddress;

@SerializedName("birth_date")
Instant birthDate;
String birthDate;

@SerializedName("birth_place")
String birthPlace;
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/org/stellar/anchor/sep12/Sep12Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public Sep12PutCustomerResponse putCustomer(Sep10Jwt token, Sep12PutCustomerRequ
request.setAccount(token.getAccount());
}

if (StringUtils.isNotEmpty(request.getBirthDate())) {
if (!isValidISO8601Date(request.getBirthDate())) {
throw new SepValidationException("Invalid 'birth_date'");
}
}
if (StringUtils.isNotEmpty(request.getIdIssueDate())) {
if (!isValidISO8601Date(request.getIdIssueDate())) {
throw new SepValidationException("Invalid 'id_issue_date'");
Expand Down
20 changes: 20 additions & 0 deletions core/src/test/kotlin/org/stellar/anchor/sep12/Sep12ServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ class Sep12ServiceTest {
.memoType("id")
.type("sending_user")
.firstName("John")
.birthDate("2000-01-01")
.idIssueDate("2023-12-13")
.idExpirationDate("2023-12-13T19:33:07Z")
.build()
Expand All @@ -257,6 +258,7 @@ class Sep12ServiceTest {
.memoType("id")
.type("sending_user")
.firstName("John")
.birthDate("2000-01-01")
.idIssueDate("2023-12-13")
.idExpirationDate("2023-12-13T19:33:07Z")
.build()
Expand All @@ -277,6 +279,24 @@ class Sep12ServiceTest {
assertEquals(TEST_ACCOUNT, mockPutRequest.account)
}

@Test
fun `Test put customer bad birth_date`() {
// Execute the request
val mockPutRequest =
Sep12PutCustomerRequest.builder()
.account(TEST_ACCOUNT)
.memo(TEST_MEMO)
.memoType("id")
.type("sending_user")
.firstName("John")
.birthDate("2023-12-13T19:33:07X")
.build()
val jwtToken = createJwtToken(TEST_ACCOUNT)

assertThrows<SepValidationException> { sep12Service.putCustomer(jwtToken, mockPutRequest) }
verify(exactly = 0) { customerIntegration.putCustomer(any()) }
}

@Test
fun `Test put customer bad id_issue_date`() {
// Execute the request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ open class Sep6End2EndTest : AbstractIntegrationTests(TestConfig()) {
"last_name" to "Doe",
"address" to "123 Bay Street",
"email_address" to "[email protected]",
"birth_date" to "1990-01-01",
"id_type" to "drivers_license",
"id_country_code" to "CAN",
"id_issue_date" to "2023-01-01",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class CustomerService(private val customerRepository: CustomerRepository) {
lastName = request.lastName ?: customer.lastName,
address = request.address ?: customer.address,
emailAddress = request.emailAddress ?: customer.emailAddress,
birthDate = request.birthDate ?: customer.birthDate,
bankAccountNumber = request.bankAccountNumber ?: customer.bankAccountNumber,
bankAccountType = request.bankAccountType ?: customer.bankAccountType,
bankNumber = request.bankNumber ?: customer.bankNumber,
Expand All @@ -82,6 +83,7 @@ class CustomerService(private val customerRepository: CustomerRepository) {
lastName = request.lastName,
address = request.address,
emailAddress = request.emailAddress,
birthDate = request.birthDate,
bankAccountNumber = request.bankAccountNumber,
bankAccountType = request.bankAccountType,
bankNumber = request.bankNumber,
Expand Down Expand Up @@ -121,7 +123,13 @@ class CustomerService(private val customerRepository: CustomerRepository) {
"address" to
createField(customer.address, "string", "The customer's address", optional = true),
"email_address" to
createField(customer.emailAddress, "string", "The customer's email address"),
createField(
customer.emailAddress,
"string",
"The customer's email address",
),
"birth_date" to
createField(customer.birthDate, "string", "The customer's birth date", optional = true),
"bank_account_number" to
createField(
customer.bankAccountNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class JdbcCustomerRepository(private val db: Database) : CustomerRepository {
address = it[Customers.address],
lastName = it[Customers.lastName],
emailAddress = it[Customers.emailAddress],
birthDate = it[Customers.birthDate],
bankAccountNumber = it[Customers.bankAccountNumber],
bankAccountType = it[Customers.bankAccountType],
bankNumber = it[Customers.bankNumber],
Expand Down Expand Up @@ -77,6 +78,7 @@ class JdbcCustomerRepository(private val db: Database) : CustomerRepository {
lastName = it[Customers.lastName],
address = it[Customers.address],
emailAddress = it[Customers.emailAddress],
birthDate = it[Customers.birthDate],
bankAccountNumber = it[Customers.bankAccountNumber],
bankAccountType = it[Customers.bankAccountType],
bankNumber = it[Customers.bankNumber],
Expand Down Expand Up @@ -104,6 +106,7 @@ class JdbcCustomerRepository(private val db: Database) : CustomerRepository {
it[lastName] = customer.lastName
it[address] = customer.address
it[emailAddress] = customer.emailAddress
it[birthDate] = customer.birthDate
it[bankAccountNumber] = customer.bankAccountNumber
it[bankAccountType] = customer.bankAccountType
it[bankNumber] = customer.bankNumber
Expand All @@ -130,6 +133,7 @@ class JdbcCustomerRepository(private val db: Database) : CustomerRepository {
it[lastName] = customer.lastName
it[address] = customer.address
it[emailAddress] = customer.emailAddress
it[birthDate] = customer.birthDate
it[bankAccountNumber] = customer.bankAccountNumber
it[bankAccountType] = customer.bankAccountType
it[bankNumber] = customer.bankNumber
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ object Customers : Table() {
val lastName = varchar("last_name", 255).nullable()
val address = varchar("address", 255).nullable()
val emailAddress = varchar("email_address", 255).nullable()
val birthDate = varchar("birth_date", 255).nullable()
val bankAccountNumber = varchar("bank_account_number", 255).nullable()
val bankAccountType = varchar("bank_account_type", 255).nullable()
val bankNumber = varchar("bank_number", 255).nullable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ class Sep6EventProcessor(
) : SepAnchorEventProcessor {
companion object {
val requiredKyc =
listOf("id_type", "id_country_code", "id_issue_date", "id_expiration_date", "id_number")
listOf(
"birth_date",
"id_type",
"id_country_code",
"id_issue_date",
"id_expiration_date",
"id_number"
)
val depositRequiredKyc = listOf("address")
val withdrawRequiredKyc =
listOf("bank_account_number", "bank_account_type", "bank_number", "bank_branch_number")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ data class Customer(
@SerialName("last_name") val lastName: String? = null,
val address: String? = null,
@SerialName("email_address") val emailAddress: String? = null,
@SerialName("birth_date") val birthDate: String? = null,
@SerialName("bank_account_number") val bankAccountNumber: String? = null,
@SerialName("bank_account_type") val bankAccountType: String? = null,
@SerialName("bank_number") val bankNumber: String? = null,
Expand Down

0 comments on commit ab082ed

Please sign in to comment.