From a927c5bbd2745a0904f777fad288be391c705993 Mon Sep 17 00:00:00 2001 From: philipliu Date: Wed, 30 Aug 2023 11:01:40 -0400 Subject: [PATCH] Make test routes configurable --- .../callbacks/customer/CustomerRoute.kt | 8 ------- .../callbacks/test/TestCustomerRoute.kt | 21 +++++++++++++++++++ .../org/stellar/reference/data/Config.kt | 1 + .../reference/plugins/ConfigureRouting.kt | 4 ++++ .../src/main/resources/default-config.yaml | 2 ++ 5 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 kotlin-reference-server/src/main/kotlin/org/stellar/reference/callbacks/test/TestCustomerRoute.kt diff --git a/kotlin-reference-server/src/main/kotlin/org/stellar/reference/callbacks/customer/CustomerRoute.kt b/kotlin-reference-server/src/main/kotlin/org/stellar/reference/callbacks/customer/CustomerRoute.kt index 26502c2860..4ed91559a1 100644 --- a/kotlin-reference-server/src/main/kotlin/org/stellar/reference/callbacks/customer/CustomerRoute.kt +++ b/kotlin-reference-server/src/main/kotlin/org/stellar/reference/callbacks/customer/CustomerRoute.kt @@ -45,13 +45,5 @@ fun Route.customer(customerService: CustomerService) { call.respond(HttpStatusCode.NoContent) } } - route("/invalidate_clabe") { - // TODO: Consider to enable this endpoint only when testing - get("{id}") { - val id = call.parameters["id"]!! - customerService.invalidateClabe(id) - call.respond(HttpStatusCode.OK) - } - } } } diff --git a/kotlin-reference-server/src/main/kotlin/org/stellar/reference/callbacks/test/TestCustomerRoute.kt b/kotlin-reference-server/src/main/kotlin/org/stellar/reference/callbacks/test/TestCustomerRoute.kt new file mode 100644 index 0000000000..0f90576f93 --- /dev/null +++ b/kotlin-reference-server/src/main/kotlin/org/stellar/reference/callbacks/test/TestCustomerRoute.kt @@ -0,0 +1,21 @@ +package org.stellar.reference.callbacks.test + +import io.ktor.http.* +import io.ktor.server.application.* +import io.ktor.server.auth.* +import io.ktor.server.response.* +import io.ktor.server.routing.* +import org.stellar.reference.callbacks.customer.CustomerService +import org.stellar.reference.plugins.AUTH_CONFIG_ENDPOINT + +fun Route.testCustomer(customerService: CustomerService) { + authenticate(AUTH_CONFIG_ENDPOINT) { + route("/invalidate_clabe") { + get("{id}") { + val id = call.parameters["id"]!! + customerService.invalidateClabe(id) + call.respond(HttpStatusCode.OK) + } + } + } +} diff --git a/kotlin-reference-server/src/main/kotlin/org/stellar/reference/data/Config.kt b/kotlin-reference-server/src/main/kotlin/org/stellar/reference/data/Config.kt index ab310ad8f9..af818b68bf 100644 --- a/kotlin-reference-server/src/main/kotlin/org/stellar/reference/data/Config.kt +++ b/kotlin-reference-server/src/main/kotlin/org/stellar/reference/data/Config.kt @@ -17,6 +17,7 @@ data class Sep24(val enableTest: Boolean, val secret: String, val interactiveJwt data class AppSettings( val version: String, + val isTest: Boolean, val port: Int, val horizonEndpoint: String, val platformApiEndpoint: String, diff --git a/kotlin-reference-server/src/main/kotlin/org/stellar/reference/plugins/ConfigureRouting.kt b/kotlin-reference-server/src/main/kotlin/org/stellar/reference/plugins/ConfigureRouting.kt index 73d7b9e243..d459973476 100644 --- a/kotlin-reference-server/src/main/kotlin/org/stellar/reference/plugins/ConfigureRouting.kt +++ b/kotlin-reference-server/src/main/kotlin/org/stellar/reference/plugins/ConfigureRouting.kt @@ -10,6 +10,7 @@ import org.stellar.reference.callbacks.fee.fee import org.stellar.reference.callbacks.interactive.sep24Interactive import org.stellar.reference.callbacks.rate.RateService import org.stellar.reference.callbacks.rate.rate +import org.stellar.reference.callbacks.test.testCustomer import org.stellar.reference.callbacks.uniqueaddress.UniqueAddressService import org.stellar.reference.callbacks.uniqueaddress.uniqueAddress import org.stellar.reference.dao.JdbcCustomerRepository @@ -53,4 +54,7 @@ fun Application.configureRouting(cfg: Config) = routing { if (cfg.sep24.enableTest) { testSep24(helper, depositService, withdrawalService, cfg.sep24.interactiveJwtKey) } + if (cfg.appSettings.isTest) { + testCustomer(customerService) + } } diff --git a/kotlin-reference-server/src/main/resources/default-config.yaml b/kotlin-reference-server/src/main/resources/default-config.yaml index c3387130ae..7c8acd107c 100644 --- a/kotlin-reference-server/src/main/resources/default-config.yaml +++ b/kotlin-reference-server/src/main/resources/default-config.yaml @@ -1,5 +1,7 @@ app: version: 0.0.1 + # Enables test endpoints. + isTest: true # The port on which the server will listen for requests. port: 8091 # The URL of the Stellar network to which the Anchor will connect.