aboutsummaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2021-03-04 13:42:08 +0100
committerFlorian Dold <florian@dold.me>2021-03-04 13:42:08 +0100
commit050461f28da4c97733af412d41c4ac75be877012 (patch)
tree8cdbb2f6738193d56b8d366fa0b70f3e331f0e4c /packages
parent032c486eaf8c6c1a87c5b3afc609898b41eba59b (diff)
test merchant issue reported by MS
Diffstat (limited to 'packages')
-rw-r--r--packages/taler-wallet-cli/src/integrationtests/harness.ts24
-rw-r--r--packages/taler-wallet-cli/src/integrationtests/test-merchant-instances.ts36
2 files changed, 51 insertions, 9 deletions
diff --git a/packages/taler-wallet-cli/src/integrationtests/harness.ts b/packages/taler-wallet-cli/src/integrationtests/harness.ts
index a2d2b8e13..169aa8aa4 100644
--- a/packages/taler-wallet-cli/src/integrationtests/harness.ts
+++ b/packages/taler-wallet-cli/src/integrationtests/harness.ts
@@ -277,7 +277,9 @@ export class GlobalTestState {
}
assertAxiosError(e: any): asserts e is AxiosError {
- return e.isAxiosError;
+ if (!e.isAxiosError) {
+ throw Error("expected axios error");
+ }
}
assertTrue(b: boolean): asserts b {
@@ -1191,6 +1193,14 @@ export class MerchantApiClient {
});
}
+ async deleteInstance(instanceId: string) {
+ const baseUrl = this.baseUrl;
+ const url = new URL(`private/instances/${instanceId}`);
+ await axios.delete(url.href, {
+ headers: this.makeAuthHeader(),
+ });
+ }
+
async createInstance(req: MerchantInstanceConfig): Promise<void> {
const baseUrl = this.baseUrl;
const url = new URL("private/instances", baseUrl);
@@ -1209,10 +1219,14 @@ export class MerchantApiClient {
async getInstanceFullDetails(instanceId: string): Promise<any> {
const url = new URL(`private/instances/${instanceId}`, this.baseUrl);
- const resp = await axios.get(url.href, {
- headers: this.makeAuthHeader(),
- });
- return resp.data;
+ try {
+ const resp = await axios.get(url.href, {
+ headers: this.makeAuthHeader(),
+ });
+ return resp.data;
+ } catch (e) {
+ throw e;
+ }
}
makeAuthHeader(): Record<string, string> {
diff --git a/packages/taler-wallet-cli/src/integrationtests/test-merchant-instances.ts b/packages/taler-wallet-cli/src/integrationtests/test-merchant-instances.ts
index 4691487de..5d1c06e1e 100644
--- a/packages/taler-wallet-cli/src/integrationtests/test-merchant-instances.ts
+++ b/packages/taler-wallet-cli/src/integrationtests/test-merchant-instances.ts
@@ -80,13 +80,23 @@ export async function runMerchantInstancesTest(t: GlobalTestState) {
},
});
+ // Add an instance, no auth!
+ await merchant.addInstance({
+ id: "myinst",
+ name: "Second Instance",
+ paytoUris: [`payto://x-taler-bank/merchant-default`],
+ auth: {
+ method: "external",
+ },
+ });
+
let merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl(), {
method: "external",
});
{
const r = await merchantClient.getInstances();
- t.assertDeepEqual(r.instances.length, 1);
+ t.assertDeepEqual(r.instances.length, 2);
}
// Check that a "malformed" bearer Authorization header gets ignored
@@ -94,7 +104,7 @@ export async function runMerchantInstancesTest(t: GlobalTestState) {
const url = merchant.makeInstanceBaseUrl();
const resp = await axios.get(new URL("private/instances", url).href, {
headers: {
- "Authorization": "foo bar-baz",
+ Authorization: "foo bar-baz",
},
});
t.assertDeepEqual(resp.status, 200);
@@ -133,8 +143,8 @@ export async function runMerchantInstancesTest(t: GlobalTestState) {
const resp = await axios.get(new URL("private/instances", url).href, {
headers: {
// Note the spaces
- "Authorization": "Bearer secret-token:foobar",
- }
+ Authorization: "Bearer secret-token:foobar",
+ },
});
t.assertDeepEqual(resp.status, 200);
}
@@ -146,6 +156,24 @@ export async function runMerchantInstancesTest(t: GlobalTestState) {
// Token should *not* be reported back.
t.assertDeepEqual(fullDetails.auth.token, undefined);
}
+
+ // Check that deleting an instance checks the auth
+ // of the default instance.
+ {
+ const unauthMerchantClient = new MerchantApiClient(
+ merchant.makeInstanceBaseUrl(),
+ {
+ method: "external",
+ },
+ );
+
+ const exc = await t.assertThrowsAsync(async () => {
+ await unauthMerchantClient.deleteInstance("");
+ });
+ console.log(exc);
+ t.assertAxiosError(exc);
+ t.assertDeepEqual(exc.response?.status, 403);
+ }
}
runMerchantInstancesTest.suites = ["merchant"];