taler-typescript-core

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

commit 2f93030ca246e0cb6fd06463988267d6a956c2be
parent 516cc8d050a50646611797087093890de470b909
Author: Florian Dold <florian@dold.me>
Date:   Wed, 11 Dec 2024 18:37:05 +0100

harness: more tests

Diffstat:
Mpackages/taler-harness/src/index.ts | 28++++++++++++++++++++++++----
Apackages/taler-harness/src/integrationtests/test-kyc-amp-timeout-failure.ts | 93+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apackages/taler-harness/src/integrationtests/test-kyc-amp-timeout.ts | 97+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpackages/taler-harness/src/integrationtests/test-kyc-skip-expiration.ts | 2+-
Mpackages/taler-harness/src/integrationtests/test-kyc-two-forms.ts | 2+-
Mpackages/taler-harness/src/integrationtests/testrunner.ts | 4++++
Mpackages/taler-util/src/types-taler-kyc-aml.ts | 2+-
7 files changed, 221 insertions(+), 7 deletions(-)

diff --git a/packages/taler-harness/src/index.ts b/packages/taler-harness/src/index.ts @@ -31,6 +31,7 @@ import { TalerAuthenticationHttpClient, TalerBankConversionHttpClient, TalerCoreBankHttpClient, + TalerKycAml, TalerMerchantInstanceHttpClient, TalerMerchantManagementHttpClient, TalerProtocolTimestamp, @@ -62,9 +63,10 @@ import { } from "@gnu-taler/taler-wallet-core/dbless"; import { deepStrictEqual } from "assert"; import fs from "fs"; +import { AML_PROGRAM_FROM_ATTRIBUTES_TO_CONTEXT } from "integrationtests/test-kyc-skip-expiration.js"; +import { AML_PROGRAM_NEXT_MEASURE_FORM } from "integrationtests/test-kyc-two-forms.js"; import os from "os"; import path from "path"; -import { TalerKycAml } from "@gnu-taler/taler-util"; import { runBench1 } from "./bench1.js"; import { runBench2 } from "./bench2.js"; import { runBench3 } from "./bench3.js"; @@ -82,8 +84,6 @@ import { } from "./harness/harness.js"; import { getTestInfo, runTests } from "./integrationtests/testrunner.js"; import { lintExchangeDeployment } from "./lint.js"; -import { AML_PROGRAM_FROM_ATTRIBUTES_TO_CONTEXT } from "integrationtests/test-kyc-skip-expiration.js"; -import { AML_PROGRAM_NEXT_MEASURE_FORM } from "integrationtests/test-kyc-two-forms.js"; const logger = new Logger("taler-harness:index.ts"); @@ -1436,7 +1436,7 @@ export const amlProgramCli = testingCli.subcommand( const allAmlPrograms: TalerKycAml.AmlProgramDefinition[] = [ { name: "no-rules", - logic: (_input, _config) => { + logic: async (_input, _config) => { const outcome: TalerKycAml.AmlOutcome = { new_rules: { expiration_time: TalerProtocolTimestamp.never(), @@ -1451,6 +1451,26 @@ const allAmlPrograms: TalerKycAml.AmlProgramDefinition[] = [ requiredInputs: [], requiredContext: [], }, + { + name: "fail", + logic: async (_input, _config) => { + throw Error("I am a failed KYC program, oh my!"); + }, + requiredAttributes: [], + requiredInputs: [], + requiredContext: [], + }, + { + name: "hang", + logic: async (_input, _config) => { + // Wait forever + await new Promise<void>(() => {}); + throw Error("not reached"); + }, + requiredAttributes: [], + requiredInputs: [], + requiredContext: [], + }, AML_PROGRAM_FROM_ATTRIBUTES_TO_CONTEXT, AML_PROGRAM_NEXT_MEASURE_FORM, ]; diff --git a/packages/taler-harness/src/integrationtests/test-kyc-amp-timeout-failure.ts b/packages/taler-harness/src/integrationtests/test-kyc-amp-timeout-failure.ts @@ -0,0 +1,93 @@ +/* + This file is part of GNU Taler + (C) 2024 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + +/** + * Imports. + */ +import { Configuration } from "@gnu-taler/taler-util"; +import { + createKycTestkudosEnvironment, + withdrawViaBankV3, +} from "../harness/environments.js"; +import { GlobalTestState } from "../harness/harness.js"; + +function adjustExchangeConfig(config: Configuration) { + config.setString("exchange", "enable_kyc", "yes"); + + config.setString("exchangedb", "MAX_AML_PROGRAM_RUNTIME", "3s"); + + config.setString("KYC-RULE-R1", "operation_type", "withdraw"); + config.setString("KYC-RULE-R1", "enabled", "yes"); + config.setString("KYC-RULE-R1", "exposed", "yes"); + config.setString("KYC-RULE-R1", "is_and_combinator", "no"); + config.setString("KYC-RULE-R1", "threshold", "TESTKUDOS:10"); + config.setString("KYC-RULE-R1", "timeframe", "1d"); + config.setString("KYC-RULE-R1", "next_measures", "M1"); + + //config.setString("KYC-MEASURE-M1", "check_name", "skip"); + config.setString("KYC-MEASURE-M1", "context", "{}"); + config.setString("KYC-MEASURE-M1", "program", "P1"); + + config.setString("KYC-MEASURE-M2", "program", "NONE"); + config.setString("KYC-MEASURE-M2", "check_name", "C2"); + config.setString("KYC-MEASURE-M2", "context", "{}"); + + config.setString("KYC-CHECK-C2", "type", "INFO"); + config.setString("KYC-CHECK-C2", "description", "my check!"); + config.setString("KYC-CHECK-C2", "fallback", "M2"); + + config.setString("AML-PROGRAM-P1", "enabled", "true"); + config.setString("AML-PROGRAM-P1", "description", "hang"); + config.setString("AML-PROGRAM-P1", "description_i18n", "{}"); + config.setString("AML-PROGRAM-P1", "fallback", "M2"); + config.setString( + "AML-PROGRAM-P1", + "command", + "taler-harness aml-program run-program --name fail", + ); + + config.setString("AML-PROGRAM-NONE", "enabled", "true"); + config.setString("AML-PROGRAM-NONE", "description", "nothing"); + config.setString("AML-PROGRAM-NONE", "description_i18n", "{}"); + config.setString("AML-PROGRAM-NONE", "fallback", "M2"); + config.setString("AML-PROGRAM-NONE", "command", "/bin/true"); + + config.setString; +} + +/** + * Tests for making AML decisions. + * - Test making decisions on unknown accounts. + * - Test making decisions with default rules. + */ +export async function runKycAmpFailureTest(t: GlobalTestState) { + // Set up test environment + + // FIXME: Reduced test environment without merchant suffices + const { walletClient, bankClient, exchange, amlKeypair } = + await createKycTestkudosEnvironment(t, { adjustExchangeConfig }); + + const wres = await withdrawViaBankV3(t, { + walletClient, + exchange, + bankClient, + amount: "TESTKUDOS:20", + }); + + await wres.withdrawalFinishedCond; +} + +runKycAmpFailureTest.suites = ["wallet"]; diff --git a/packages/taler-harness/src/integrationtests/test-kyc-amp-timeout.ts b/packages/taler-harness/src/integrationtests/test-kyc-amp-timeout.ts @@ -0,0 +1,97 @@ +/* + This file is part of GNU Taler + (C) 2024 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + +/** + * Imports. + */ +import { Configuration } from "@gnu-taler/taler-util"; +import { + createKycTestkudosEnvironment, + withdrawViaBankV3, +} from "../harness/environments.js"; +import { GlobalTestState } from "../harness/harness.js"; + +function adjustExchangeConfig(config: Configuration) { + config.setString("exchange", "enable_kyc", "yes"); + + config.setString("exchangedb", "MAX_AML_PROGRAM_RUNTIME", "3s"); + + config.setString("KYC-RULE-R1", "operation_type", "withdraw"); + config.setString("KYC-RULE-R1", "enabled", "yes"); + config.setString("KYC-RULE-R1", "exposed", "yes"); + config.setString("KYC-RULE-R1", "is_and_combinator", "no"); + config.setString("KYC-RULE-R1", "threshold", "TESTKUDOS:10"); + config.setString("KYC-RULE-R1", "timeframe", "1d"); + config.setString("KYC-RULE-R1", "next_measures", "M1"); + + //config.setString("KYC-MEASURE-M1", "check_name", "skip"); + config.setString("KYC-MEASURE-M1", "context", "{}"); + config.setString("KYC-MEASURE-M1", "program", "P1"); + + config.setString("KYC-MEASURE-M2", "program", "NONE"); + config.setString("KYC-MEASURE-M2", "check_name", "C2"); + config.setString("KYC-MEASURE-M2", "context", "{}"); + + config.setString("KYC-CHECK-C2", "type", "INFO"); + config.setString("KYC-CHECK-C2", "description", "my check!"); + config.setString("KYC-CHECK-C2", "fallback", "M2"); + + config.setString("AML-PROGRAM-P1", "enabled", "true"); + config.setString("AML-PROGRAM-P1", "description", "hang"); + config.setString("AML-PROGRAM-P1", "description_i18n", "{}"); + config.setString("AML-PROGRAM-P1", "fallback", "M2"); + config.setString( + "AML-PROGRAM-P1", + "command", + "taler-harness aml-program run-program --name hang", + ); + + config.setString("AML-PROGRAM-NONE", "enabled", "true"); + config.setString("AML-PROGRAM-NONE", "description", "nothing"); + config.setString("AML-PROGRAM-NONE", "description_i18n", "{}"); + config.setString("AML-PROGRAM-NONE", "fallback", "M2"); + config.setString( + "AML-PROGRAM-NONE", + "command", + "/bin/true", + ); + + config.setString; +} + +/** + * Tests for making AML decisions. + * - Test making decisions on unknown accounts. + * - Test making decisions with default rules. + */ +export async function runKycAmpTimeoutTest(t: GlobalTestState) { + // Set up test environment + + // FIXME: Reduced test environment without merchant suffices + const { walletClient, bankClient, exchange, amlKeypair } = + await createKycTestkudosEnvironment(t, { adjustExchangeConfig }); + + const wres = await withdrawViaBankV3(t, { + walletClient, + exchange, + bankClient, + amount: "TESTKUDOS:20", + }); + + await wres.withdrawalFinishedCond; +} + +runKycAmpTimeoutTest.suites = ["wallet"]; diff --git a/packages/taler-harness/src/integrationtests/test-kyc-skip-expiration.ts b/packages/taler-harness/src/integrationtests/test-kyc-skip-expiration.ts @@ -44,7 +44,7 @@ import { GlobalTestState, harnessHttpLib, waitMs } from "../harness/harness.js"; export const AML_PROGRAM_FROM_ATTRIBUTES_TO_CONTEXT: TalerKycAml.AmlProgramDefinition = { name: "from-attr-to-context", - logic: (_input, config) => { + logic: async (_input, config) => { const outcome: TalerKycAml.AmlOutcome = { to_investigate: false, // pushing to info into properties for testing purposes diff --git a/packages/taler-harness/src/integrationtests/test-kyc-two-forms.ts b/packages/taler-harness/src/integrationtests/test-kyc-two-forms.ts @@ -56,7 +56,7 @@ const logger = new Logger("test-kyc-two-forms.ts"); export const AML_PROGRAM_NEXT_MEASURE_FORM: TalerKycAml.AmlProgramDefinition = { name: "TWO_FORMS", - logic: (input, config) => { + logic: async (input, config) => { const outcome: TalerKycAml.AmlOutcome = { to_investigate: false, properties: {}, diff --git a/packages/taler-harness/src/integrationtests/testrunner.ts b/packages/taler-harness/src/integrationtests/testrunner.ts @@ -49,6 +49,8 @@ import { runExchangeTimetravelTest } from "./test-exchange-timetravel.js"; import { runFeeRegressionTest } from "./test-fee-regression.js"; import { runForcedSelectionTest } from "./test-forced-selection.js"; import { runKnownAccountsTest } from "./test-known-accounts.js"; +import { runKycAmpFailureTest } from "./test-kyc-amp-timeout-failure.js"; +import { runKycAmpTimeoutTest } from "./test-kyc-amp-timeout.js"; import { runKycBalanceWithdrawalTest } from "./test-kyc-balance-withdrawal.js"; import { runKycDecisionsTest } from "./test-kyc-decisions.js"; import { runKycDepositAggregateImplicitAuthTest } from "./test-kyc-deposit-aggregate-implicit-auth.js"; @@ -290,6 +292,8 @@ const allTests: TestMainFunction[] = [ runKycDecisionsTest, runKnownAccountsTest, runKycDepositAggregateImplicitAuthTest, + runKycAmpTimeoutTest, + runKycAmpFailureTest, ]; export interface TestRunSpec { diff --git a/packages/taler-util/src/types-taler-kyc-aml.ts b/packages/taler-util/src/types-taler-kyc-aml.ts @@ -34,7 +34,7 @@ import { export type AmlProgram = ( input: AmlProgramInput | undefined, config: string | undefined, -) => AmlOutcome; +) => Promise<AmlOutcome>; export type KycConverter = ( input: object | undefined,