diff --git a/@stellar/anchor-tests/package.json b/@stellar/anchor-tests/package.json index e870835..ff35e8a 100644 --- a/@stellar/anchor-tests/package.json +++ b/@stellar/anchor-tests/package.json @@ -1,6 +1,6 @@ { "name": "@stellar/anchor-tests", - "version": "0.1.6", + "version": "0.1.7", "description": "stellar-anchor-tests is a library and command line interface for testing Stellar anchors.", "main": "./lib/index.js", "types": "./lib/index.d.ts", diff --git a/@stellar/anchor-tests/src/tests/sep12/getCustomer.ts b/@stellar/anchor-tests/src/tests/sep12/getCustomer.ts index 5b3758a..becfbc1 100644 --- a/@stellar/anchor-tests/src/tests/sep12/getCustomer.ts +++ b/@stellar/anchor-tests/src/tests/sep12/getCustomer.ts @@ -1,6 +1,7 @@ import { Request } from "node-fetch"; import { validate } from "jsonschema"; import { Keypair } from "stellar-sdk"; +import { URLSearchParams } from "url"; import { Test, Config, Result, NetworkCall } from "../../types"; import { hasNetworkPassphrase } from "../sep1/tests"; @@ -15,6 +16,17 @@ import { canCreateCustomer } from "./putCustomer"; const getCustomerGroup = "GET /customer"; const tests: Test[] = []; +const hasCreateCustomer = (config: Config): Boolean => + Boolean( + config?.sepConfig?.["12"]?.customers?.[ + config?.sepConfig?.["12"]?.createCustomer + ], + ); +const getCreateCustomerType = (config: Config): string | undefined => + config?.sepConfig?.["12"]?.customers?.[ + config?.sepConfig?.["12"]?.createCustomer + ].type; + const requiresJwtToken: Test = { assertion: "requires a SEP-10 JWT", sep: 12, @@ -92,7 +104,13 @@ const newCustomerValidSchema: Test = { }, ...genericFailures, }, - async run(_config: Config): Promise { + async run(config: Config): Promise { + if (!hasCreateCustomer(config)) { + throw new Error( + "SEP-12 configuration data is missing, expected a key within the " + + "'customers' object matching the value assigned to 'createCustomer'", + ); + } const result: Result = { networkCalls: [] }; const clientKeypair = Keypair.random(); const token = await postChallenge( @@ -102,10 +120,16 @@ const newCustomerValidSchema: Test = { result, ); if (!token) return result; + const customerType = getCreateCustomerType(config); + const requestParamsObj: Record = { + account: clientKeypair.publicKey(), + }; + if (customerType) requestParamsObj["type"] = customerType; + const searchParams = new URLSearchParams(requestParamsObj); const getCustomerCall: NetworkCall = { request: new Request( this.context.expects.kycServerUrl + - `/customer?account=${clientKeypair.publicKey()}`, + `/customer?${searchParams.toString()}`, { headers: { Authorization: `Bearer ${token}`, @@ -113,6 +137,7 @@ const newCustomerValidSchema: Test = { }, ), }; + result.networkCalls.push(getCustomerCall); const getCustomerBody = await makeRequest( getCustomerCall, 200, @@ -187,12 +212,24 @@ export const canFetchExistingCustomerById: Test = { }, ...genericFailures, }, - async run(_config: Config): Promise { + async run(config: Config): Promise { + if (!hasCreateCustomer(config)) { + throw new Error( + "SEP-12 configuration data is missing, expected a key within the " + + "'customers' object matching the value assigned to 'createCustomer'", + ); + } const result: Result = { networkCalls: [] }; + const customerType = getCreateCustomerType(config); + const requestParamsObj: Record = { + id: this.context.expects.customerId, + }; + if (customerType) requestParamsObj["type"] = customerType; + const searchParams = new URLSearchParams(requestParamsObj); const getCustomerCall: NetworkCall = { request: new Request( this.context.expects.kycServerUrl + - `/customer?id=${this.context.expects.customerId}`, + `/customer?${searchParams.toString()}`, { headers: { Authorization: `Bearer ${this.context.expects.token}`, @@ -269,12 +306,24 @@ const canFetchExistingCustomerByAccount: Test = { }, ...genericFailures, }, - async run(_config: Config): Promise { + async run(config: Config): Promise { + if (!hasCreateCustomer(config)) { + throw new Error( + "SEP-12 configuration data is missing, expected a key within the " + + "'customers' object matching the value assigned to 'createCustomer'", + ); + } const result: Result = { networkCalls: [] }; + const customerType = getCreateCustomerType(config); + const requestParamsObj: Record = { + account: this.context.expects.clientKeypair.publicKey(), + }; + if (customerType) requestParamsObj["type"] = customerType; + const searchParams = new URLSearchParams(requestParamsObj); const getCustomerCall: NetworkCall = { request: new Request( this.context.expects.kycServerUrl + - `/customer?account=${this.context.expects.clientKeypair.publicKey()}`, + `/customer?${searchParams.toString()}`, { headers: { Authorization: `Bearer ${this.context.expects.token}`, diff --git a/@stellar/anchor-tests/src/tests/sep12/putCustomer.ts b/@stellar/anchor-tests/src/tests/sep12/putCustomer.ts index 094e9f3..4fb97d9 100644 --- a/@stellar/anchor-tests/src/tests/sep12/putCustomer.ts +++ b/@stellar/anchor-tests/src/tests/sep12/putCustomer.ts @@ -1,5 +1,5 @@ import fetch from "node-fetch"; -import { Request } from "node-fetch"; +import { Request, BodyInit } from "node-fetch"; import { Keypair, Memo } from "stellar-sdk"; import { randomBytes } from "crypto"; @@ -14,6 +14,11 @@ import { postChallenge } from "../../helpers/sep10"; const putCustomerGroup = "PUT /customer"; const tests: Test[] = []; +const getCreateCustomer = (config: Config): object => + config?.sepConfig?.["12"]?.customers?.[ + config?.sepConfig?.["12"]?.createCustomer + ]; + const requiresJwt: Test = { assertion: "requires a SEP-10 JWT", sep: 12, @@ -28,24 +33,17 @@ const requiresJwt: Test = { failureModes: genericFailures, async run(config: Config): Promise { const result: Result = { networkCalls: [] }; - if ( - !config.sepConfig || - !config.sepConfig["12"] || - !config.sepConfig["12"].customers || - !config.sepConfig["12"].createCustomer || - !config.sepConfig["12"].customers[config.sepConfig["12"].createCustomer] - ) { + const customerValues = getCreateCustomer(config); + if (!customerValues) { throw new Error( "SEP-12 configuration data is missing, expected a key within the " + "'customers' object matching the value assigned to 'createCustomer'", ); } - const customerValues = - config.sepConfig["12"].customers[config.sepConfig["12"].createCustomer]; const putCustomerCall: NetworkCall = { request: new Request(this.context.expects.kycServerUrl + "/customer", { method: "PUT", - body: customerValues, + body: customerValues as BodyInit, }), }; result.networkCalls.push(putCustomerCall); @@ -109,20 +107,13 @@ export const canCreateCustomer: Test = { }, async run(config: Config): Promise { const result: Result = { networkCalls: [] }; - if ( - !config.sepConfig || - !config.sepConfig["12"] || - !config.sepConfig["12"].customers || - !config.sepConfig["12"].createCustomer || - !config.sepConfig["12"].customers[config.sepConfig["12"].createCustomer] - ) { + const customerValues = getCreateCustomer(config); + if (!customerValues) { throw new Error( "SEP-12 configuration data is missing, expected a key within the " + "'customers' object matching the value assigned to 'createCustomer'", ); } - const customerValues = - config.sepConfig["12"].customers[config.sepConfig["12"].createCustomer]; const putCustomerRequest = makeSep12Request({ url: this.context.expects.kycServerUrl + "/customer", data: { @@ -147,7 +138,7 @@ export const canCreateCustomer: Test = { } if (putCustomerCall.response.status !== 202) { result.failure = makeFailure(this.failureModes.UNEXPECTED_STATUS_CODE, { - customer: config.sepConfig["12"].createCustomer, + customer: config?.sepConfig?.["12"]?.createCustomer, }); result.expected = 202; result.actual = putCustomerCall.response.status; @@ -267,11 +258,8 @@ export const differentMemosSameAccount: Test = { ); } else { if ( - !config.sepConfig || - !config.sepConfig["12"] || - !config.sepConfig["12"].sameAccountDifferentMemos || - !config.sepConfig["12"].customers || - !config.sepConfig["12"].customers[ + !config?.sepConfig?.["12"]?.sameAccountDifferentMemos || + !config.sepConfig["12"]?.customers[ config.sepConfig["12"].sameAccountDifferentMemos[0] ] || !config.sepConfig["12"].customers[ diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..469b3fa --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,24 @@ +# Changelog + +This changelog documents all releases and included changes to the @stellar/anchor-tests library. + +A breaking change will get clearly marked in this log. + +## [v0.1.7](https://github.com/stellar/stellar-anchor-tests/compare/v0.1.6...master) + +### Add +- Use `type` parameter in SEP-12 `GET /customer` requests + +## [v0.1.6](https://github.com/stellar/stellar-anchor-tests/compare/v0.1.5...v0.1.6) + +## [v0.1.5](https://github.com/stellar/stellar-anchor-tests/compare/v0.1.4...v0.1.5) + +## [v0.1.4](https://github.com/stellar/stellar-anchor-tests/compare/v0.1.3...v0.1.4) + +## [v0.1.3](https://github.com/stellar/stellar-anchor-tests/compare/v0.1.2...v0.1.3) + +## [v0.1.2](https://github.com/stellar/stellar-anchor-tests/compare/v0.1.1...v0.1.2) + +## [v0.1.1](https://github.com/stellar/stellar-anchor-tests/compare/v0.1.0...v0.1.1) + +## v0.1.0 \ No newline at end of file diff --git a/ui/src/components/ConfigModalContent/index.tsx b/ui/src/components/ConfigModalContent/index.tsx index 0c7a5a1..706aa39 100644 --- a/ui/src/components/ConfigModalContent/index.tsx +++ b/ui/src/components/ConfigModalContent/index.tsx @@ -128,7 +128,11 @@ export const ConfigModalContent: React.FC = () => ( SEP-9 {" "} - attributes the anchor requires. Currently four customers are required. + attributes the anchor requires, as well as the + + type + {" "} + of the customer. Currently four customers are required.
  • createCustomer: a string matching one of the keys