complain about merchant base URL mismatch, fixing #6616

This commit is contained in:
Florian Dold 2020-11-03 16:46:43 +01:00
parent ce326361b4
commit 0d37ec5e91
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
2 changed files with 27 additions and 1 deletions

View File

@ -31,6 +31,14 @@ import { TalerErrorCode } from "../TalerErrorCode";
* but the error has already been reported by writing it to the database. * but the error has already been reported by writing it to the database.
*/ */
export class OperationFailedAndReportedError extends Error { export class OperationFailedAndReportedError extends Error {
static fromCode(
ec: TalerErrorCode,
message: string,
details: Record<string, unknown>,
): OperationFailedAndReportedError {
return new OperationFailedAndReportedError(makeErrorDetails(ec, message, details));
}
constructor(public operationError: TalerErrorDetails) { constructor(public operationError: TalerErrorDetails) {
super(operationError.message); super(operationError.message);

View File

@ -56,7 +56,11 @@ import * as Amounts from "../util/amounts";
import { AmountJson } from "../util/amounts"; import { AmountJson } from "../util/amounts";
import { Logger } from "../util/logging"; import { Logger } from "../util/logging";
import { parsePayUri } from "../util/taleruri"; import { parsePayUri } from "../util/taleruri";
import { guardOperationException, OperationFailedError } from "./errors"; import {
guardOperationException,
OperationFailedAndReportedError,
OperationFailedError,
} from "./errors";
import { createRefreshGroup, getTotalRefreshCost } from "./refresh"; import { createRefreshGroup, getTotalRefreshCost } from "./refresh";
import { InternalWalletState, EXCHANGE_COINS_LOCK } from "./state"; import { InternalWalletState, EXCHANGE_COINS_LOCK } from "./state";
import { import {
@ -661,6 +665,20 @@ async function processDownloadProposalImpl(
); );
const fulfillmentUrl = parsedContractTerms.fulfillment_url; const fulfillmentUrl = parsedContractTerms.fulfillment_url;
const baseUrlForDownload = proposal.merchantBaseUrl;
const baseUrlFromContractTerms = parsedContractTerms.merchant_base_url;
if (baseUrlForDownload !== baseUrlFromContractTerms) {
throw OperationFailedAndReportedError.fromCode(
TalerErrorCode.WALLET_CONTRACT_TERMS_BASE_URL_MISMATCH,
"merchant base URL mismatch",
{
baseUrlForDownload,
baseUrlFromContractTerms,
},
);
}
await ws.db.runWithWriteTransaction( await ws.db.runWithWriteTransaction(
[Stores.proposals, Stores.purchases], [Stores.proposals, Stores.purchases],
async (tx) => { async (tx) => {