commit 555057c2425142c349c90ed58bb8983abc4fda91
parent 57bae624d26245042ea12b5acadc3638319c5c7f
Author: Florian Dold <florian@dold.me>
Date: Sun, 23 Feb 2025 11:34:54 +0100
harness: test AMLO decision with attributes
Diffstat:
3 files changed, 150 insertions(+), 0 deletions(-)
diff --git a/packages/taler-harness/src/harness/environments.ts b/packages/taler-harness/src/harness/environments.ts
@@ -1034,6 +1034,8 @@ export async function postAmlDecision(
newRules: LegitimizationRuleSet;
newMeasures?: string;
properties?: AccountProperties;
+ attributes?: Object;
+ attributes_expiration?: TalerProtocolTimestamp;
},
) {
const { exchangeBaseUrl, paytoHash, amlPriv, amlPub } = req;
@@ -1046,6 +1048,8 @@ export async function postAmlDecision(
new_rules: req.newRules,
new_measures: req.newMeasures,
properties: req.properties ?? {},
+ attributes: req.attributes,
+ attributes_expiration: req.attributes_expiration,
};
const sig = signAmlDecision(decodeCrock(amlPriv), sigData);
diff --git a/packages/taler-harness/src/integrationtests/test-kyc-decision-attr.ts b/packages/taler-harness/src/integrationtests/test-kyc-decision-attr.ts
@@ -0,0 +1,144 @@
+/*
+ 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 {
+ codecForAmlKycAttributes,
+ Configuration,
+ decodeCrock,
+ Duration,
+ encodeCrock,
+ hashNormalizedPaytoUri,
+ j2s,
+ LimitOperationType,
+ signAmlQuery,
+ TalerProtocolTimestamp,
+} from "@gnu-taler/taler-util";
+import { readSuccessResponseJsonOrThrow } from "@gnu-taler/taler-util/http";
+import { createSyncCryptoApi } from "@gnu-taler/taler-wallet-core";
+import {
+ configureCommonKyc,
+ createKycTestkudosEnvironment,
+ postAmlDecision,
+} from "../harness/environments.js";
+import {
+ getTestHarnessPaytoForLabel,
+ GlobalTestState,
+ harnessHttpLib,
+} from "../harness/harness.js";
+
+function adjustExchangeConfig(config: Configuration) {
+ configureCommonKyc(config);
+
+ 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:100");
+ config.setString("KYC-RULE-R1", "timeframe", "1d");
+ config.setString("KYC-RULE-R1", "next_measures", "verboten");
+}
+
+/**
+ * Tests for making AML decisions.
+ * - Test making decisions on unknown accounts.
+ * - Test making decisions with default rules.
+ */
+export async function runKycDecisionAttrTest(t: GlobalTestState) {
+ // Set up test environment
+
+ // FIXME: Reduced test environment without merchant suffices
+ const {
+ walletClient,
+ bankClient,
+ exchange,
+ amlKeypair,
+ exchangeBankAccount,
+ } = await createKycTestkudosEnvironment(t, { adjustExchangeConfig });
+
+ const merchantPayto = getTestHarnessPaytoForLabel("merchant-default");
+
+ const cryptoApi = createSyncCryptoApi();
+
+ const kycPaytoHash = encodeCrock(hashNormalizedPaytoUri(merchantPayto));
+
+ await postAmlDecision(t, {
+ amlPriv: amlKeypair.priv,
+ amlPub: amlKeypair.pub,
+ exchangeBaseUrl: exchange.baseUrl,
+ paytoHash: kycPaytoHash,
+ paytoUri: merchantPayto,
+ attributes: { foo: 42 },
+ attributes_expiration: TalerProtocolTimestamp.never(),
+ newRules: {
+ expiration_time: TalerProtocolTimestamp.now(),
+ custom_measures: {},
+ rules: [
+ {
+ operation_type: LimitOperationType.deposit,
+ display_priority: 1,
+ exposed: true,
+ measures: ["verboten"],
+ threshold: "TESTKUDOS:10",
+ timeframe: Duration.toTalerProtocolDuration(
+ Duration.fromSpec({
+ days: 1,
+ }),
+ ),
+ },
+ {
+ operation_type: LimitOperationType.withdraw,
+ display_priority: 1,
+ exposed: true,
+ measures: ["verboten"],
+ threshold: "TESTKUDOS:0",
+ timeframe: Duration.toTalerProtocolDuration(
+ Duration.fromSpec({
+ days: 1,
+ }),
+ ),
+ },
+ ],
+ },
+ });
+
+ const sig = signAmlQuery(decodeCrock(amlKeypair.priv));
+
+ const attributesResp = await harnessHttpLib.fetch(
+ new URL(
+ `aml/${amlKeypair.pub}/attributes/${kycPaytoHash}`,
+ exchange.baseUrl,
+ ).href,
+ {
+ headers: {
+ "Taler-AML-Officer-Signature": encodeCrock(sig),
+ },
+ },
+ );
+
+ const attrs = await readSuccessResponseJsonOrThrow(
+ attributesResp,
+ codecForAmlKycAttributes(),
+ );
+
+ console.log(j2s(attrs));
+
+ t.assertDeepEqual(attrs.details[0].attributes?.foo, 42);
+}
+
+runKycDecisionAttrTest.suites = ["wallet"];
diff --git a/packages/taler-harness/src/integrationtests/testrunner.ts b/packages/taler-harness/src/integrationtests/testrunner.ts
@@ -157,6 +157,7 @@ import { runWithdrawalHugeTest } from "./test-withdrawal-huge.js";
import { runWithdrawalIdempotentTest } from "./test-withdrawal-idempotent.js";
import { runWithdrawalManualTest } from "./test-withdrawal-manual.js";
import { runWithdrawalPrepareTest } from "./test-withdrawal-prepare.js";
+import { runKycDecisionAttrTest } from "./test-kyc-decision-attr.js";
/**
* Test runner.
@@ -304,6 +305,7 @@ const allTests: TestMainFunction[] = [
runWithdrawalConflictTest,
runBankWopTest,
runKycNewMeasuresProgTest,
+ runKycDecisionAttrTest,
];
export interface TestRunSpec {