use new auth token for merchant in integration tests
This commit is contained in:
parent
83937a7198
commit
f262b28812
@ -1427,6 +1427,7 @@ export class MerchantService implements MerchantServiceInterface {
|
|||||||
console.log("adding instance");
|
console.log("adding instance");
|
||||||
const url = `http://localhost:${this.merchantConfig.httpPort}/private/instances`;
|
const url = `http://localhost:${this.merchantConfig.httpPort}/private/instances`;
|
||||||
await axios.post(url, {
|
await axios.post(url, {
|
||||||
|
auth_token: instanceConfig.authToken,
|
||||||
payto_uris: instanceConfig.paytoUris,
|
payto_uris: instanceConfig.paytoUris,
|
||||||
id: instanceConfig.id,
|
id: instanceConfig.id,
|
||||||
name: instanceConfig.name,
|
name: instanceConfig.name,
|
||||||
@ -1462,6 +1463,7 @@ export class MerchantService implements MerchantServiceInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface MerchantInstanceConfig {
|
export interface MerchantInstanceConfig {
|
||||||
|
authToken?: string;
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
paytoUris: string[];
|
paytoUris: string[];
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
* Imports.
|
* Imports.
|
||||||
*/
|
*/
|
||||||
import { GlobalTestState, MerchantPrivateApi, BankApi } from "./harness";
|
import { GlobalTestState, MerchantPrivateApi, BankApi } from "./harness";
|
||||||
import { createSimpleTestkudosEnvironment, withdrawViaBank } from "./helpers";
|
import { createSimpleTestkudosEnvironment } from "./helpers";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run test for basic, bank-integrated withdrawal.
|
* Run test for basic, bank-integrated withdrawal.
|
||||||
|
@ -22,26 +22,104 @@
|
|||||||
/**
|
/**
|
||||||
* Imports.
|
* Imports.
|
||||||
*/
|
*/
|
||||||
import { GlobalTestState } from "./harness";
|
import { CoinConfig, defaultCoinConfig } from "./denomStructures";
|
||||||
import { createSimpleTestkudosEnvironment, withdrawViaBank } from "./helpers";
|
import {
|
||||||
|
BankService,
|
||||||
|
ExchangeService,
|
||||||
|
GlobalTestState,
|
||||||
|
MerchantService,
|
||||||
|
setupDb,
|
||||||
|
WalletCli,
|
||||||
|
} from "./harness";
|
||||||
|
import { SimpleTestEnvironment } from "./helpers";
|
||||||
|
|
||||||
|
const merchantAuthToken = "secret-token:sandbox";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run a test case with a simple TESTKUDOS Taler environment, consisting
|
||||||
|
* of one exchange, one bank and one merchant.
|
||||||
|
*/
|
||||||
|
export async function createMyEnvironment(
|
||||||
|
t: GlobalTestState,
|
||||||
|
coinConfig: CoinConfig[] = defaultCoinConfig.map((x) => x("TESTKUDOS")),
|
||||||
|
): Promise<SimpleTestEnvironment> {
|
||||||
|
const db = await setupDb(t);
|
||||||
|
|
||||||
|
const bank = await BankService.create(t, {
|
||||||
|
allowRegistrations: true,
|
||||||
|
currency: "TESTKUDOS",
|
||||||
|
database: db.connStr,
|
||||||
|
httpPort: 8082,
|
||||||
|
});
|
||||||
|
|
||||||
|
const exchange = ExchangeService.create(t, {
|
||||||
|
name: "testexchange-1",
|
||||||
|
currency: "TESTKUDOS",
|
||||||
|
httpPort: 8081,
|
||||||
|
database: db.connStr,
|
||||||
|
});
|
||||||
|
|
||||||
|
const merchant = await MerchantService.create(t, {
|
||||||
|
name: "testmerchant-1",
|
||||||
|
currency: "TESTKUDOS",
|
||||||
|
httpPort: 8083,
|
||||||
|
database: db.connStr,
|
||||||
|
});
|
||||||
|
|
||||||
|
const exchangeBankAccount = await bank.createExchangeAccount(
|
||||||
|
"MyExchange",
|
||||||
|
"x",
|
||||||
|
);
|
||||||
|
exchange.addBankAccount("1", exchangeBankAccount);
|
||||||
|
|
||||||
|
bank.setSuggestedExchange(exchange, exchangeBankAccount.accountPaytoUri);
|
||||||
|
|
||||||
|
await bank.start();
|
||||||
|
|
||||||
|
await bank.pingUntilAvailable();
|
||||||
|
|
||||||
|
exchange.addCoinConfigList(coinConfig);
|
||||||
|
|
||||||
|
await exchange.start();
|
||||||
|
await exchange.pingUntilAvailable();
|
||||||
|
|
||||||
|
merchant.addExchange(exchange);
|
||||||
|
|
||||||
|
await merchant.start();
|
||||||
|
await merchant.pingUntilAvailable();
|
||||||
|
|
||||||
|
await merchant.addInstance({
|
||||||
|
id: "default",
|
||||||
|
name: "Default Instance",
|
||||||
|
paytoUris: [`payto://x-taler-bank/merchant-default`],
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("setup done!");
|
||||||
|
|
||||||
|
const wallet = new WalletCli(t);
|
||||||
|
|
||||||
|
return {
|
||||||
|
commonDb: db,
|
||||||
|
exchange,
|
||||||
|
merchant,
|
||||||
|
wallet,
|
||||||
|
bank,
|
||||||
|
exchangeBankAccount,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run test for basic, bank-integrated withdrawal.
|
* Run test for basic, bank-integrated withdrawal.
|
||||||
*/
|
*/
|
||||||
export async function runWallettestingTest(t: GlobalTestState) {
|
export async function runWallettestingTest(t: GlobalTestState) {
|
||||||
const {
|
const { wallet, bank, exchange, merchant } = await createMyEnvironment(t);
|
||||||
wallet,
|
|
||||||
bank,
|
|
||||||
exchange,
|
|
||||||
merchant,
|
|
||||||
} = await createSimpleTestkudosEnvironment(t);
|
|
||||||
|
|
||||||
await wallet.runIntegrationTest({
|
await wallet.runIntegrationTest({
|
||||||
amountToSpend: "TESTKUDOS:5",
|
amountToSpend: "TESTKUDOS:5",
|
||||||
amountToWithdraw: "TESTKUDOS:10",
|
amountToWithdraw: "TESTKUDOS:10",
|
||||||
bankBaseUrl: bank.baseUrl,
|
bankBaseUrl: bank.baseUrl,
|
||||||
exchangeBaseUrl: exchange.baseUrl,
|
exchangeBaseUrl: exchange.baseUrl,
|
||||||
merchantApiKey: "sandbox",
|
merchantAuthToken: merchantAuthToken,
|
||||||
merchantBaseUrl: merchant.makeInstanceBaseUrl(),
|
merchantBaseUrl: merchant.makeInstanceBaseUrl(),
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -70,7 +148,7 @@ export async function runWallettestingTest(t: GlobalTestState) {
|
|||||||
|
|
||||||
await wallet.testPay({
|
await wallet.testPay({
|
||||||
amount: "TESTKUDOS:5",
|
amount: "TESTKUDOS:5",
|
||||||
merchantApiKey: "sandbox",
|
merchantAuthToken: merchantAuthToken,
|
||||||
merchantBaseUrl: merchant.makeInstanceBaseUrl(),
|
merchantBaseUrl: merchant.makeInstanceBaseUrl(),
|
||||||
summary: "foo",
|
summary: "foo",
|
||||||
});
|
});
|
||||||
|
@ -32,6 +32,7 @@ import { TalerErrorCode } from "../TalerErrorCode";
|
|||||||
import { URL } from "../util/url";
|
import { URL } from "../util/url";
|
||||||
import { Logger } from "../util/logging";
|
import { Logger } from "../util/logging";
|
||||||
import { bytesToString } from "../crypto/talerCrypto";
|
import { bytesToString } from "../crypto/talerCrypto";
|
||||||
|
import { j2s } from "../util/helpers";
|
||||||
|
|
||||||
const logger = new Logger("NodeHttpLib.ts");
|
const logger = new Logger("NodeHttpLib.ts");
|
||||||
|
|
||||||
|
@ -31,8 +31,6 @@ import { createTalerWithdrawReserve } from "./reserves";
|
|||||||
import { URL } from "../util/url";
|
import { URL } from "../util/url";
|
||||||
import { Wallet } from "../wallet";
|
import { Wallet } from "../wallet";
|
||||||
import { Amounts } from "../util/amounts";
|
import { Amounts } from "../util/amounts";
|
||||||
import { NodeHttpLib } from "../headless/NodeHttpLib";
|
|
||||||
import { getDefaultNodeWallet } from "../headless/helpers";
|
|
||||||
import {
|
import {
|
||||||
TestPayArgs,
|
TestPayArgs,
|
||||||
PreparePayResultType,
|
PreparePayResultType,
|
||||||
@ -53,7 +51,7 @@ interface BankWithdrawalResponse {
|
|||||||
|
|
||||||
interface MerchantBackendInfo {
|
interface MerchantBackendInfo {
|
||||||
baseUrl: string;
|
baseUrl: string;
|
||||||
apikey: string;
|
authToken?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -109,6 +107,15 @@ export async function withdrawTestBalance(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getMerchantAuthHeader(m: MerchantBackendInfo): Record<string, string> {
|
||||||
|
if (m.authToken) {
|
||||||
|
return {
|
||||||
|
"Authorization": `Bearer ${m.authToken}`,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
async function createBankWithdrawalUri(
|
async function createBankWithdrawalUri(
|
||||||
http: HttpRequestLibrary,
|
http: HttpRequestLibrary,
|
||||||
bankBaseUrl: string,
|
bankBaseUrl: string,
|
||||||
@ -190,9 +197,7 @@ async function refund(
|
|||||||
refund: refundAmount,
|
refund: refundAmount,
|
||||||
};
|
};
|
||||||
const resp = await http.postJson(reqUrl.href, refundReq, {
|
const resp = await http.postJson(reqUrl.href, refundReq, {
|
||||||
headers: {
|
headers: getMerchantAuthHeader(merchantBackend),
|
||||||
Authorization: `ApiKey ${merchantBackend.apikey}`,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
const r = await readSuccessResponseJsonOrThrow(resp, codecForAny());
|
const r = await readSuccessResponseJsonOrThrow(resp, codecForAny());
|
||||||
const refundUri = r.taler_refund_uri;
|
const refundUri = r.taler_refund_uri;
|
||||||
@ -221,9 +226,7 @@ async function createOrder(
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
const resp = await http.postJson(reqUrl, orderReq, {
|
const resp = await http.postJson(reqUrl, orderReq, {
|
||||||
headers: {
|
headers: getMerchantAuthHeader(merchantBackend),
|
||||||
Authorization: `ApiKey ${merchantBackend.apikey}`,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
const r = await readSuccessResponseJsonOrThrow(resp, codecForAny());
|
const r = await readSuccessResponseJsonOrThrow(resp, codecForAny());
|
||||||
const orderId = r.order_id;
|
const orderId = r.order_id;
|
||||||
@ -241,9 +244,7 @@ async function checkPayment(
|
|||||||
const reqUrl = new URL(`/private/orders/${orderId}`, merchantBackend.baseUrl);
|
const reqUrl = new URL(`/private/orders/${orderId}`, merchantBackend.baseUrl);
|
||||||
reqUrl.searchParams.set("order_id", orderId);
|
reqUrl.searchParams.set("order_id", orderId);
|
||||||
const resp = await http.get(reqUrl.href, {
|
const resp = await http.get(reqUrl.href, {
|
||||||
headers: {
|
headers: getMerchantAuthHeader(merchantBackend),
|
||||||
Authorization: `ApiKey ${merchantBackend.apikey}`,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
return readSuccessResponseJsonOrThrow(resp, codecForCheckPaymentResponse());
|
return readSuccessResponseJsonOrThrow(resp, codecForCheckPaymentResponse());
|
||||||
}
|
}
|
||||||
@ -337,7 +338,7 @@ export async function runIntegrationTest(
|
|||||||
|
|
||||||
const myMerchant: MerchantBackendInfo = {
|
const myMerchant: MerchantBackendInfo = {
|
||||||
baseUrl: args.merchantBaseUrl,
|
baseUrl: args.merchantBaseUrl,
|
||||||
apikey: args.merchantApiKey,
|
authToken: args.merchantAuthToken,
|
||||||
};
|
};
|
||||||
|
|
||||||
await makePayment(
|
await makePayment(
|
||||||
@ -415,7 +416,7 @@ export async function testPay(
|
|||||||
) {
|
) {
|
||||||
logger.trace("creating order");
|
logger.trace("creating order");
|
||||||
const merchant = {
|
const merchant = {
|
||||||
apikey: args.merchantApiKey,
|
authToken: args.merchantAuthToken,
|
||||||
baseUrl: args.merchantBaseUrl,
|
baseUrl: args.merchantBaseUrl,
|
||||||
};
|
};
|
||||||
const orderResp = await createOrder(
|
const orderResp = await createOrder(
|
||||||
|
@ -689,7 +689,7 @@ export interface GetExchangeTosResult {
|
|||||||
|
|
||||||
export interface TestPayArgs {
|
export interface TestPayArgs {
|
||||||
merchantBaseUrl: string;
|
merchantBaseUrl: string;
|
||||||
merchantApiKey: string;
|
merchantAuthToken: string;
|
||||||
amount: string;
|
amount: string;
|
||||||
summary: string;
|
summary: string;
|
||||||
}
|
}
|
||||||
@ -697,7 +697,7 @@ export interface TestPayArgs {
|
|||||||
export const codecForTestPayArgs = (): Codec<TestPayArgs> =>
|
export const codecForTestPayArgs = (): Codec<TestPayArgs> =>
|
||||||
buildCodecForObject<TestPayArgs>()
|
buildCodecForObject<TestPayArgs>()
|
||||||
.property("merchantBaseUrl", codecForString())
|
.property("merchantBaseUrl", codecForString())
|
||||||
.property("merchantApiKey", codecForString())
|
.property("merchantAuthToken", codecForString())
|
||||||
.property("amount", codecForString())
|
.property("amount", codecForString())
|
||||||
.property("summary", codecForString())
|
.property("summary", codecForString())
|
||||||
.build("TestPayArgs");
|
.build("TestPayArgs");
|
||||||
@ -706,7 +706,7 @@ export interface IntegrationTestArgs {
|
|||||||
exchangeBaseUrl: string;
|
exchangeBaseUrl: string;
|
||||||
bankBaseUrl: string;
|
bankBaseUrl: string;
|
||||||
merchantBaseUrl: string;
|
merchantBaseUrl: string;
|
||||||
merchantApiKey: string;
|
merchantAuthToken: string;
|
||||||
amountToWithdraw: string;
|
amountToWithdraw: string;
|
||||||
amountToSpend: string;
|
amountToSpend: string;
|
||||||
}
|
}
|
||||||
@ -716,7 +716,7 @@ export const codecForIntegrationTestArgs = (): Codec<IntegrationTestArgs> =>
|
|||||||
.property("exchangeBaseUrl", codecForString())
|
.property("exchangeBaseUrl", codecForString())
|
||||||
.property("bankBaseUrl", codecForString())
|
.property("bankBaseUrl", codecForString())
|
||||||
.property("merchantBaseUrl", codecForString())
|
.property("merchantBaseUrl", codecForString())
|
||||||
.property("merchantApiKey", codecForString())
|
.property("merchantAuthToken", codecForString())
|
||||||
.property("amountToSpend", codecForAmountString())
|
.property("amountToSpend", codecForAmountString())
|
||||||
.property("amountToWithdraw", codecForAmountString())
|
.property("amountToWithdraw", codecForAmountString())
|
||||||
.build("IntegrationTestArgs");
|
.build("IntegrationTestArgs");
|
||||||
|
Loading…
Reference in New Issue
Block a user