taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit cc74057905904b22322f59256993d04adfe713d0
parent a0b89530827e4f7d477c02a5fabdb0d0d54c610d
Author: Florian Dold <florian@dold.me>
Date:   Mon, 23 Sep 2024 21:46:32 +0200

wallet-core: check/test bank-integrated withdrawal credit restrictions

Diffstat:
Mpackages/taler-harness/src/integrationtests/test-account-restrictions.ts | 25++++++++++++++++++-------
Mpackages/taler-wallet-core/src/withdraw.ts | 6+++++-
2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/packages/taler-harness/src/integrationtests/test-account-restrictions.ts b/packages/taler-harness/src/integrationtests/test-account-restrictions.ts @@ -66,10 +66,6 @@ export async function runAccountRestrictionsTest(t: GlobalTestState) { // Withdraw digital cash into the wallet. - // The test is incomplete: The wallet can't check the account restrictions - // against the sender wire account, because fakebank doesn't report - // sender_wire yet. - const withdrawalResult = await myWithdrawViaBank(t, { walletClient, bankClient, @@ -80,6 +76,18 @@ export async function runAccountRestrictionsTest(t: GlobalTestState) { await withdrawalResult.withdrawalFinishedCond; + // When withdrawing from an account that doesn't begin with "foo-", + // it fails. + await t.assertThrowsAsync(async () => { + await myWithdrawViaBank(t, { + walletClient, + bankClient, + exchange, + amount: "TESTKUDOS:20", + acctname: "bar-123", + }); + }); + // Invalid account, does not start with "foo-" const err = await t.assertThrowsTalerErrorAsync(async () => { await walletClient.call(WalletApiOperation.CheckDeposit, { @@ -109,13 +117,16 @@ export async function myWithdrawViaBank( }, ): Promise<WithdrawViaBankResult> { const { walletClient: wallet, bankClient, exchange, amount } = p; - - const user = await bankClient.createRandomBankUser(); await bankClient.registerAccountExtended({ name: p.acctname, password: "test", username: p.acctname, }); + const user = { + password: "test", + username: p.acctname, + }; + const accountPaytoUri = `payto://x-taler-bank/localhost/${p.acctname}?receiver-name=${p.acctname}`; const bankClient2 = new TalerCorebankApiClient(bankClient.baseUrl); bankClient2.setAuth({ username: user.username, @@ -159,7 +170,7 @@ export async function myWithdrawViaBank( }); return { - accountPaytoUri: user.accountPaytoUri, + accountPaytoUri, withdrawalFinishedCond, transactionId: acceptRes.transactionId, }; diff --git a/packages/taler-wallet-core/src/withdraw.ts b/packages/taler-wallet-core/src/withdraw.ts @@ -3461,7 +3461,11 @@ export async function confirmWithdrawal( if (!parsedExchangeWire) { continue; } - if (!checkAccountRestriction(senderWire, acc.creditRestrictions ?? [])) { + const checkRes = checkAccountRestriction( + senderWire, + acc.creditRestrictions ?? [], + ); + if (!checkRes.ok) { continue; } acceptable = true;