aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-cli/src/integrationtests/harness.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2021-03-02 20:03:39 +0100
committerFlorian Dold <florian@dold.me>2021-03-02 20:03:39 +0100
commit81be4aacd80689542367b1570d4069cba3220ae6 (patch)
treefa1c6ad7a60c2b9a594e9a9cfecafae4ded6dff9 /packages/taler-wallet-cli/src/integrationtests/harness.ts
parent98ab998a1ecf495e85fcc73a29ca88d990415f05 (diff)
downloadwallet-core-81be4aacd80689542367b1570d4069cba3220ae6.tar.xz
add merchant instances/auth test case
Diffstat (limited to 'packages/taler-wallet-cli/src/integrationtests/harness.ts')
-rw-r--r--packages/taler-wallet-cli/src/integrationtests/harness.ts45
1 files changed, 43 insertions, 2 deletions
diff --git a/packages/taler-wallet-cli/src/integrationtests/harness.ts b/packages/taler-wallet-cli/src/integrationtests/harness.ts
index 2fe976f9c..fbc67bb5a 100644
--- a/packages/taler-wallet-cli/src/integrationtests/harness.ts
+++ b/packages/taler-wallet-cli/src/integrationtests/harness.ts
@@ -94,6 +94,7 @@ import {
TippingReserveStatus,
TipCreateConfirmation,
TipCreateRequest,
+ MerchantInstancesResponse,
} from "./merchantApiTypes";
import { ApplyRefundResponse } from "@gnu-taler/taler-wallet-core";
import { PendingOperationsResponse } from "@gnu-taler/taler-wallet-core";
@@ -1171,6 +1172,40 @@ export interface MerchantServiceInterface {
readonly name: string;
}
+export class MerchantApiClient {
+ constructor(
+ private baseUrl: string,
+ private auth: MerchantAuthConfiguration,
+ ) {}
+
+ async changeAuth(auth: MerchantAuthConfiguration): Promise<void> {
+ const baseUrl = this.baseUrl;
+ const url = new URL("private/auth", baseUrl);
+ await axios.post(url.href, auth, {
+ headers: this.makeAuthHeader(),
+ });
+ }
+
+ async getInstances(): Promise<MerchantInstancesResponse> {
+ const url = new URL("private/instances", this.baseUrl);
+ const resp = await axios.get(url.href, {
+ headers: this.makeAuthHeader(),
+ });
+ return resp.data;
+ }
+
+ makeAuthHeader(): Record<string, string> {
+ switch (this.auth.method) {
+ case "external":
+ return {};
+ case "token":
+ return {
+ Authorization: `Bearer ${this.auth.token}`,
+ };
+ }
+ }
+}
+
export namespace MerchantPrivateApi {
export async function createOrder(
merchantService: MerchantServiceInterface,
@@ -1407,8 +1442,9 @@ export class MerchantService implements MerchantServiceInterface {
}
console.log("adding instance");
const url = `http://localhost:${this.merchantConfig.httpPort}/private/instances`;
+ const auth = instanceConfig.auth ?? { method: "external" };
await axios.post(url, {
- auth: { method: "external" },
+ auth,
payto_uris: instanceConfig.paytoUris,
id: instanceConfig.id,
name: instanceConfig.name,
@@ -1443,8 +1479,13 @@ export class MerchantService implements MerchantServiceInterface {
}
}
+export interface MerchantAuthConfiguration {
+ method: "external" | "token";
+ token?: string;
+}
+
export interface MerchantInstanceConfig {
- authToken?: string;
+ auth?: MerchantAuthConfiguration;
id: string;
name: string;
paytoUris: string[];