diff options
Diffstat (limited to 'packages/taler-harness')
-rw-r--r-- | packages/taler-harness/src/harness/harness.ts | 26 | ||||
-rw-r--r-- | packages/taler-harness/src/harness/sync.ts | 2 | ||||
-rw-r--r-- | packages/taler-harness/src/index.ts | 124 |
3 files changed, 93 insertions, 59 deletions
diff --git a/packages/taler-harness/src/harness/harness.ts b/packages/taler-harness/src/harness/harness.ts index 68c0744fc..b27eaa371 100644 --- a/packages/taler-harness/src/harness/harness.ts +++ b/packages/taler-harness/src/harness/harness.ts @@ -651,7 +651,7 @@ export class FakebankService config.setString("bank", "max_debt", bc.maxDebt ?? `${bc.currency}:100`); config.setString("bank", "ram_limit", `${1024}`); const cfgFilename = testDir + "/bank.conf"; - config.write(cfgFilename, { excludeDefaults: true }); + config.writeTo(cfgFilename, { excludeDefaults: true }); return new FakebankService(gc, bc, cfgFilename); } @@ -680,7 +680,7 @@ export class FakebankService } const config = Configuration.load(this.configFile); config.setString("bank", "suggested_exchange", e.baseUrl); - config.write(this.configFile, { excludeDefaults: true }); + config.writeTo(this.configFile, { excludeDefaults: true }); } get baseUrl(): string { @@ -790,7 +790,7 @@ export class LibeufinBankService `${bc.currency}:100`, ); const cfgFilename = testDir + "/bank.conf"; - config.write(cfgFilename, { excludeDefaults: true }); + config.writeTo(cfgFilename, { excludeDefaults: true }); return new LibeufinBankService(gc, bc, cfgFilename); } @@ -828,7 +828,7 @@ export class LibeufinBankService "suggested_withdrawal_exchange", e.baseUrl, ); - config.write(this.configFile, { excludeDefaults: true }); + config.writeTo(this.configFile, { excludeDefaults: true }); } get baseUrl(): string { @@ -1052,7 +1052,7 @@ export class ExchangeService implements ExchangeServiceInterface { changeConfig(f: (config: Configuration) => void) { const config = Configuration.load(this.configFilename); f(config); - config.write(this.configFilename, { excludeDefaults: true }); + config.writeTo(this.configFilename, { excludeDefaults: true }); } static create(gc: GlobalTestState, e: ExchangeConfig) { @@ -1118,7 +1118,7 @@ export class ExchangeService implements ExchangeServiceInterface { fs.writeFileSync(masterPrivFile, Buffer.from(exchangeMasterKey.eddsaPriv)); const cfgFilename = testDir + `/exchange-${e.name}.conf`; - config.write(cfgFilename, { excludeDefaults: true }); + config.writeTo(cfgFilename, { excludeDefaults: true }); return new ExchangeService(gc, e, cfgFilename, exchangeMasterKey); } @@ -1127,13 +1127,13 @@ export class ExchangeService implements ExchangeServiceInterface { offeredCoins.forEach((cc) => setCoin(config, cc(this.exchangeConfig.currency)), ); - config.write(this.configFilename, { excludeDefaults: true }); + config.writeTo(this.configFilename, { excludeDefaults: true }); } addCoinConfigList(ccs: CoinConfig[]) { const config = Configuration.load(this.configFilename); ccs.forEach((cc) => setCoin(config, cc)); - config.write(this.configFilename, { excludeDefaults: true }); + config.writeTo(this.configFilename, { excludeDefaults: true }); } enableAgeRestrictions(maskStr: string) { @@ -1144,7 +1144,7 @@ export class ExchangeService implements ExchangeServiceInterface { "age_groups", maskStr, ); - config.write(this.configFilename, { excludeDefaults: true }); + config.writeTo(this.configFilename, { excludeDefaults: true }); } get masterPub() { @@ -1165,7 +1165,7 @@ export class ExchangeService implements ExchangeServiceInterface { ): Promise<void> { const config = Configuration.load(this.configFilename); await f(config); - config.write(this.configFilename, { excludeDefaults: true }); + config.writeTo(this.configFilename, { excludeDefaults: true }); } async addBankAccount( @@ -1206,7 +1206,7 @@ export class ExchangeService implements ExchangeServiceInterface { "password", exchangeBankAccount.accountPassword, ); - config.write(this.configFilename, { excludeDefaults: true }); + config.writeTo(this.configFilename, { excludeDefaults: true }); } exchangeHttpProc: ProcessWrapper | undefined; @@ -1701,7 +1701,7 @@ export class MerchantService implements MerchantServiceInterface { config.setString("merchantdb-postgres", "config", mc.database); // Do not contact demo.taler.net exchange in tests config.setString("merchant-exchange-kudos", "disabled", "yes"); - config.write(cfgFilename, { excludeDefaults: true }); + config.writeTo(cfgFilename, { excludeDefaults: true }); return new MerchantService(gc, mc, cfgFilename); } @@ -1719,7 +1719,7 @@ export class MerchantService implements MerchantServiceInterface { this.merchantConfig.currency, ); config.setString(`merchant-exchange-${e.name}`, "master_key", e.masterPub); - config.write(this.configFilename, { excludeDefaults: true }); + config.writeTo(this.configFilename, { excludeDefaults: true }); } async addDefaultInstance(): Promise<void> { diff --git a/packages/taler-harness/src/harness/sync.ts b/packages/taler-harness/src/harness/sync.ts index 64c9acaef..567a2e92d 100644 --- a/packages/taler-harness/src/harness/sync.ts +++ b/packages/taler-harness/src/harness/sync.ts @@ -85,7 +85,7 @@ export class SyncService { config.setString("syncdb-postgres", "config", sc.database); config.setString("sync", "payment_backend_url", sc.paymentBackendUrl); config.setString("sync", "upload_limit_mb", `${sc.uploadLimitMb}`); - config.write(cfgFilename); + config.writeTo(cfgFilename); return new SyncService(gc, sc, cfgFilename); } diff --git a/packages/taler-harness/src/index.ts b/packages/taler-harness/src/index.ts index 0f282e123..315173b7f 100644 --- a/packages/taler-harness/src/index.ts +++ b/packages/taler-harness/src/index.ts @@ -30,11 +30,11 @@ import { TalerAuthenticationHttpClient, TalerBankConversionHttpClient, TalerCoreBankHttpClient, - TalerErrorCode, TalerMerchantInstanceHttpClient, TalerMerchantManagementHttpClient, TransactionsResponse, - createAccessToken, + createRFC8959AccessTokenEncoded, + createRFC8959AccessTokenPlain, decodeCrock, encodeCrock, generateIban, @@ -42,7 +42,6 @@ import { randomBytes, rsaBlind, setGlobalLogLevelFromString, - setPrintHttpRequestAsCurl, stringifyPayTemplateUri, } from "@gnu-taler/taler-util"; import { clk } from "@gnu-taler/taler-util/clk"; @@ -80,7 +79,6 @@ import { } from "./harness/helpers.js"; import { getTestInfo, runTests } from "./integrationtests/testrunner.js"; import { lintExchangeDeployment } from "./lint.js"; -import { randomUUID } from "crypto"; const logger = new Logger("taler-harness:index.ts"); @@ -356,25 +354,46 @@ advancedCli ); }); -const configCli = testingCli.subcommand("configArgs", "config", { - help: "Subcommands for handling the Taler configuration.", -}); +const configCli = testingCli + .subcommand("configArgs", "config", { + help: "Subcommands for handling the Taler configuration.", + }) + .maybeOption("configEntryFile", ["-c", "--config"], clk.STRING, { + help: "Configuration file to use.", + }) + .maybeOption("project", ["--project"], clk.STRING, { + help: `Selection of the project to inspect/change the config (default: taler).`, + }); -configCli.subcommand("show", "show").action(async (args) => { - const config = Configuration.load(); - const cfgStr = config.stringify({ - diagnostics: true, +configCli + .subcommand("show", "show", { + help: "Show the current configuration.", + }) + .action(async (args) => { + const config = Configuration.load( + args.configArgs.configEntryFile, + args.configArgs.project, + ); + const cfgStr = config.stringify({ + diagnostics: true, + }); + console.log(cfgStr); }); - console.log(cfgStr); -}); configCli - .subcommand("get", "get") + .subcommand("get", "get", { + help: "Get a configuration option.", + }) .requiredArgument("section", clk.STRING) .requiredArgument("option", clk.STRING) - .flag("file", ["-f"]) + .flag("file", ["-f"], { + help: "Treat the value as a filename, expanding placeholders.", + }) .action(async (args) => { - const config = Configuration.load(); + const config = Configuration.load( + args.configArgs.configEntryFile, + args.configArgs.project, + ); let res; if (args.get.file) { res = config.getPath(args.get.section, args.get.option); @@ -389,6 +408,35 @@ configCli } }); +configCli + .subcommand("set", "set", { + help: "Set a configuration option.", + }) + .requiredArgument("section", clk.STRING) + .requiredArgument("option", clk.STRING) + .requiredArgument("value", clk.STRING) + .flag("dry", ["--dry"], { + help: "Do not write the changed config to disk, only write it to stdout.", + }) + .action(async (args) => { + const config = Configuration.load( + args.configArgs.configEntryFile, + args.configArgs.project, + ); + config.setString(args.set.section, args.set.option, args.set.value); + if (args.set.dry) { + console.log( + config.stringify({ + excludeDefaults: true, + }), + ); + } else { + config.write({ + excludeDefaults: true, + }); + } + }); + const deploymentCli = testingCli.subcommand("deploymentArgs", "deployment", { help: "Subcommands for handling GNU Taler deployments.", }); @@ -643,12 +691,12 @@ deploymentCli help: "if everything worked ok, change the password of the accounts at the end", }) .action(async (args) => { - const managementToken = createAccessToken( + const managementToken = createRFC8959AccessTokenPlain( args.provisionBankMerchant.merchantToken, ); const bankAdminPassword = args.provisionBankMerchant.bankPassword; const bankAdminTokenArg = args.provisionBankMerchant.bankToken - ? createAccessToken(args.provisionBankMerchant.bankToken) + ? createRFC8959AccessTokenPlain(args.provisionBankMerchant.bankToken) : undefined; const id = args.provisionBankMerchant.id; const name = args.provisionBankMerchant.name; @@ -765,7 +813,7 @@ deploymentCli address: {}, auth: { method: "token", - token: createAccessToken(password), + token: createRFC8959AccessTokenPlain(password), }, default_pay_delay: Duration.toTalerProtocolDuration( Duration.fromSpec({ hours: 1 }), @@ -797,7 +845,7 @@ deploymentCli */ { const resp = await merchantInstance.addBankAccount( - createAccessToken(password), + createRFC8959AccessTokenEncoded(password), { payto_uri: accountPayto, credit_facade_url: bank.getRevenueAPI(id).href, @@ -840,7 +888,7 @@ deploymentCli { const resp = await merchantInstance.addTemplate( - createAccessToken(password), + createRFC8959AccessTokenEncoded(password), { template_id: "default", template_description: "First template", @@ -920,10 +968,10 @@ deploymentCli { const resp = await merchantInstance.updateCurrentInstanceAuthentication( - createAccessToken(prevPassword), + createRFC8959AccessTokenEncoded(prevPassword), { method: "token", - token: createAccessToken(randomPassword), + token: createRFC8959AccessTokenPlain(randomPassword), }, ); if (resp.type === "fail") { @@ -937,7 +985,7 @@ deploymentCli { const resp = await merchantInstance.updateBankAccount( - createAccessToken(randomPassword), + createRFC8959AccessTokenEncoded(randomPassword), wireAccount, { credit_facade_url: bank.getRevenueAPI(id).href, @@ -995,10 +1043,13 @@ deploymentCli const httpLib = createPlatformHttpLib({}); const baseUrl = args.provisionMerchantInstance.merchantApiBaseUrl; const api = new TalerMerchantManagementHttpClient(baseUrl, httpLib); - const managementToken = createAccessToken( + const managementToken = createRFC8959AccessTokenEncoded( args.provisionMerchantInstance.managementToken, ); - const instanceToken = createAccessToken( + const instanceTokenEnc = createRFC8959AccessTokenPlain( + args.provisionMerchantInstance.instanceToken, + ); + const instanceTokenPlain = createRFC8959AccessTokenPlain( args.provisionMerchantInstance.instanceToken, ); const instanceId = args.provisionMerchantInstance.id; @@ -1012,7 +1063,7 @@ deploymentCli address: {}, auth: { method: "token", - token: instanceToken, + token: instanceTokenPlain, }, default_pay_delay: Duration.toTalerProtocolDuration( Duration.fromSpec({ hours: 1 }), @@ -1035,7 +1086,7 @@ deploymentCli process.exit(2); } - const createAccountResp = await api.addBankAccount(instanceToken, { + const createAccountResp = await api.addBankAccount(instanceTokenEnc, { payto_uri: accountPayto, credit_facade_url: bankURL, credit_facade_credentials: @@ -1147,23 +1198,6 @@ deploymentCli console.log(out); }); -const deploymentConfigCli = deploymentCli.subcommand("configArgs", "config", { - help: "Subcommands the Taler configuration.", -}); - -deploymentConfigCli - .subcommand("show", "show") - .flag("diagnostics", ["-d", "--diagnostics"]) - .maybeArgument("cfgfile", clk.STRING, {}) - .action(async (args) => { - const cfg = Configuration.load(args.show.cfgfile); - console.log( - cfg.stringify({ - diagnostics: args.show.diagnostics, - }), - ); - }); - testingCli.subcommand("logtest", "logtest").action(async (args) => { logger.trace("This is a trace message."); logger.info("This is an info message."); |