An app could have nostrod pay an order: it called Pay of net.catcrafts.Nostro1.Checkout on the system bus, and nostrod paid from an account the user had chosen, after a dialog of its own. On 2026-11-22 the owner decided that a link takes its place. The app registers for payto links (RFC 8905), so that an app or a website can hand one to the desktop, and shows a link as its pay form filled in. The link: - The app's desktop entry takes the scheme (Exec=nostro-app %u, MimeType=x-scheme-handler/payto), and nostro-app takes an argument that is no option as a link: it overwrites it in argv and hands it to App::Open once the app has started. - ReadPaymentLink (Nostro.App:Forms) reads payto://iban/<IBAN> with the options amount, receiver-name and message, and refuses a link rather than guess at it, in a sentence of the app's own with nothing of the link in it. Among what it refuses: an IBAN whose check digits do not hold, one of the three options given twice, instruction, a comma in the amount, and a name or a message with a code point that is Unshown, or Blank and no plain space. - A link that is read waits until the accounts are read and DefaultCheckoutAccount has answered or failed, with a line on the accounts' page. Then App::TakeLink fills in the pay form, which says in a banner that a link filled it in, and with more than one account opens it under the choice of accounts that the form's From row has. A link pays nothing: the form's button sends, and polkit's dialog confirms as for any payment (design rule 12, and 14, which is new). - Unshown and Blank are the two tables the worker's Shown() works from. They move into Nostro:Utils, where the app's reader asks them too. The move is within the library. The reader holds a link's name to those two and to no more of Shown(): a name with an & is read, and the dialog shows it with a + as it does any name. The checkout: - nostrod serves one interface under one bus name. Gone are net.catcrafts.Nostro1.Checkout with its XML and its activation file, the polkit action Checkout, the module Nostro.Checkout with --product=checkout, and the worker's record of orders. That changes the published contract after a release, 0.0.0, and design rule 10 records it as the owner's decision. - DefaultCheckoutAccount and SetDefaultCheckoutAccount keep their names and signatures. The account they keep is where a link's pay form starts: nostrod's dialog for choosing it says "have pay links start from", the app's setting reads "Pay links start from", and `nostro checkout account` prints "pay links start from". - The D-Bus policy still lets nostrod own the old name: the nostrod of 0.0.0 asks for it when it starts, and the system files can be newer than the Flatpak it runs from. install.sh removes the old name's activation file. A user's checkouts.cdb is read by nothing any more, and is left where it is. - The Arch package stops installing the checkout's two files, and its pkgrel goes up to 2. Where makepkg -si finds a package of the version already built it installs that one again, which would bring the activation file back. The guide now says that pkgrel goes up with a change to what the package installs. - Bus::Interface goes too: the worker called it in two places, to tell a call to the checkout from one to the main interface. The review's own files follow. gate0 loses the build of --product=checkout, and the three lens sections that named the checkout no longer do, and ask about a link. The README has "Pay links" in place of "Checkout for apps", and AGENTS.consumer.md says what the app reads of a link. Its line on lib/json.hpp no longer gives a release: the file is of none, and the guide names its commit. The pay form and the accounts' page change only by a banner each, shown while a link is in play, which docs/screenshots/take.sh never has: the README's pictures stand. Tests: ShouldValidateForms reads and refuses links and fills the form from one. ShouldDriveTheApp opens links against a real nostrod on the fake bus: before the accounts are known, with no account, with one and with several, with the accounts known and the system bus gone, for a second user whose first connection pays their own accounts only, one that cannot be read, one whose name has an &, and through polkit's dialog to the payment. It now counts nostrod's answers to hold that the account pay links start from is read again once a connection is removed: the check it had there passed without that. ShouldHandleMoneyAndText holds the two tables at the ends of their ranges. ShouldServeEveryUser holds that nostrod serves no checkout, that the bus's policy lets an older nostrod own the old name, and the account pay links start from. ShouldRunCommands holds the CLI's wording. The review's gate0 passes at this commit: the version check, 17 tests, the builds of the CLI, the library, nostrod, the fake system, the app and its --debug-api build, and five lint runs that report nothing. tests/coverage.sh reports lines, functions and regions at 100.00%. Looked at on 2026-11-22 on the made-up system (run fake), on a desktop (KWin at a scale of 1.85). At 420x760, at --scale 3 --size 360x760 and at 1100x720 in the light look: a link's pay form under the choice of accounts, the form after a tap beside that choice, and the accounts' page while a link waits, its line above the rows that stand in for the accounts (--bank-delay 10000). At 420x760: that line above what the page says when the accounts cannot be read (--polkit deny) and above the accounts themselves (--polkit slow, the link opened in the running app), the settings' row and page for the account pay links start from, the sheet for a link that cannot be read, and with --empty the sheet for no account.
615 lines
48 KiB
C++
615 lines
48 KiB
C++
// SPDX-License-Identifier: GPL-3.0-only
|
|
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
|
|
|
// Nostro.App without nostrod: how money, days and the bank's capitals are worded (in a fixed time zone, so the
|
|
// expectations hold anywhere), what each form reads from what was typed and what it refuses, what a link that asks
|
|
// for a payment is read as and everything it is refused for, what every error nostrod can answer with is explained
|
|
// as, and what the app knows of each bank it can connect.
|
|
|
|
#include <stdlib.h>
|
|
#include <time.h>
|
|
|
|
import std;
|
|
import Nostro;
|
|
import Nostro.Ui;
|
|
import Nostro.App;
|
|
|
|
#include "../Support/Check.inc"
|
|
|
|
using namespace Nostro;
|
|
using namespace Nostro::App;
|
|
using Test::Check;
|
|
using Test::Equal;
|
|
using Test::Throws;
|
|
using Moment = std::chrono::system_clock::time_point;
|
|
|
|
namespace {
|
|
constexpr std::string_view iban = "NL91ABNA0417164300";
|
|
constexpr Currency euro = Currency::Euro;
|
|
|
|
void Words() {
|
|
Equal(GroupIban(iban), std::string("NL91 ABNA 0417 1643 00"), "an IBAN is grouped in fours");
|
|
for(const std::string_view other : {"", "NL9", "bob@example.org", "nl91abna0417164300", "NL91-ABNA", "N191ABNA", "NLA1ABNA", "NL9AABNA", "Savings"}) {
|
|
Equal(GroupIban(other), std::string(other), "what is no IBAN is left as it is");
|
|
}
|
|
Equal(AccountKey(Account{.name = "Main", .bic = "BUNQNL2A", .iban = std::string(iban), .currency = euro, .balance = 0}), std::string(iban), "an account is found by its IBAN");
|
|
Equal(AccountKey(Account{.name = "Pocket", .bic = "", .iban = "", .currency = euro, .balance = 0}), std::string("Pocket"), "or by its name where it has none");
|
|
Equal(PartyName(BunqLabel{.name = "Bob", .iban = std::string(iban)}), std::string("Bob"), "someone is said by name");
|
|
Equal(PartyName(BunqLabel{.name = "", .iban = std::string(iban)}), std::string("NL91 ABNA 0417 1643 00"), "else by IBAN");
|
|
Equal(PartyName(BunqLabel{.name = "", .iban = ""}), std::string("Unknown"), "and as unknown where the bank says neither");
|
|
Equal(PartyName(BunqCounterparty{.type = "IBAN", .value = std::string(iban), .name = "Bob"}), std::string("Bob"), "a payee by the name given");
|
|
Equal(PartyName(BunqCounterparty{.type = "EMAIL", .value = "bob@example.org", .name = ""}), std::string("bob@example.org"), "else by the address");
|
|
for(const auto& [minor, said] : std::array<std::pair<std::int64_t, std::string_view>, 7>{{{0, "€0.00"}, {99999, "€999.99"}, {100000, "€1,000.00"}, {-1250000, "-€12,500.00"}, {123456789012, "€1,234,567,890.12"}, {-5, "-€0.05"}, {100000000, "€1,000,000.00"}}}) {
|
|
Equal(Money(minor, euro), std::string(said), "money has its thousands apart");
|
|
}
|
|
Equal(SignedMoney(1250, euro), std::string("+€12.50"), "money that came in has a plus");
|
|
Equal(SignedMoney(250000, euro), std::string("+€2,500.00"), "and its thousands apart too");
|
|
Equal(SignedMoney(-300, euro), std::string("-€3.00"), "money that went out a minus");
|
|
Equal(SignedMoney(0, euro), std::string("€0.00"), "and nothing has neither");
|
|
|
|
const Moment now = ParseLocalDate("2026-11-19 15:00");
|
|
Check(LocalDay(ParseLocalDate("2026-11-19 00:00")) == LocalDay(ParseLocalDate("2026-11-19 23:59")) && LocalDay(ParseLocalDate("2026-11-19 23:59")) != LocalDay(ParseLocalDate("2026-11-20 00:00")), "a day runs from midnight to midnight");
|
|
Equal(DayLabel(ParseLocalDate("2026-11-19 08:00"), now), std::string("Today"), "today");
|
|
Equal(DayLabel(ParseLocalDate("2026-11-18 23:59"), now), std::string("Yesterday"), "yesterday");
|
|
Equal(DayLabel(ParseLocalDate("2026-11-03 12:00"), now), std::string("Tuesday 3 November"), "a day of this year by its name");
|
|
Equal(DayLabel(ParseLocalDate("2025-12-31 12:00"), now), std::string("Wednesday 31 December 2025"), "one of another year with it");
|
|
// The night the clocks go back: the day before is 25 hours long.
|
|
Equal(DayLabel(ParseLocalDate("2026-10-24 23:30"), ParseLocalDate("2026-10-25 00:30")), std::string("Yesterday"), "yesterday across a change of the clocks");
|
|
Equal(DayLabel(ParseLocalDate("2026-10-25 01:30"), ParseLocalDate("2026-10-26 00:10")), std::string("Yesterday"), "and after it");
|
|
Equal(ShortDate(ParseLocalDate("2026-11-03"), now), std::string("3 Nov"), "a short date");
|
|
Equal(ShortDate(ParseLocalDate("2025-12-31"), now), std::string("31 Dec 2025"), "with its year when that is another");
|
|
Equal(ClockTime(ParseLocalDate("2026-11-03 14:05")), std::string("14:05"), "the time of day");
|
|
Equal(FullTime(ParseLocalDate("2026-11-03 14:05")), std::string("3 November 2026, 14:05"), "a moment in full");
|
|
Equal(DateInput(ParseLocalDate("2026-11-03 14:05")), std::string("2026-11-03"), "a day as a field takes it");
|
|
|
|
const std::array<std::pair<std::string_view, std::string_view>, 10> kinds = {{
|
|
{"MASTERCARD/PAYMENT", "Card payment"}, {"EBA_SDD/SDD", "Direct debit"}, {"EBA_SCT/SCT", "Bank transfer"}, {"IDEAL/PAYMENT", "iDEAL"},
|
|
{"SOFORT/PAYMENT", "Sofort"}, {"SWIFT/PAYMENT", "International transfer"}, {"BUNQ/REQUEST", "Paid request"}, {"BUNQ/PAYMENT", "Payment within the bank"},
|
|
{"NEW/THING", "NEW/THING"}, {"", ""},
|
|
}};
|
|
for(const auto& [kind, label] : kinds) {
|
|
Equal(KindLabel(kind), std::string(label), "a kind of payment in words");
|
|
}
|
|
Equal(StatusLabel("PIN_TRIES_EXCEEDED"), std::string("Pin tries exceeded"), "the bank's capitals as words");
|
|
Equal(StatusLabel("sandbox"), std::string("Sandbox"), "and its small letters with a capital");
|
|
Equal(CardProduct("MASTERCARD_DEBIT"), std::string("Mastercard debit"), "a card's product");
|
|
Equal(CardExpiry("2030-11-30"), std::string("11/30"), "when a card expires, as its face has it");
|
|
for(const std::string_view other : {"", "11/30", "2030-11-3", "2030/11/30", "2030-11_30", "203O-11-30", "2030-11-30T00"}) {
|
|
Equal(CardExpiry(other), std::string(other), "what is no day is left as the bank says it");
|
|
}
|
|
|
|
BunqSchedule schedule{.start = ParseLocalDate("2026-11-03")};
|
|
Equal(ScheduleLabel(schedule, now), std::string("Once on 3 Nov"), "a payment scheduled once");
|
|
schedule.start = ParseLocalDate("2026-11-03 14:05");
|
|
Equal(ScheduleLabel(schedule, now), std::string("Once on 3 Nov, 14:05"), "with its time when that is not midnight");
|
|
schedule.unit = "MONTHLY";
|
|
schedule.start = ParseLocalDate("2026-11-03");
|
|
Equal(ScheduleLabel(schedule, now), std::string("Every month from 3 Nov"), "one that repeats");
|
|
schedule.unit = "WEEKLY";
|
|
schedule.every = 2;
|
|
schedule.end = ParseLocalDate("2027-01-01");
|
|
Equal(ScheduleLabel(schedule, now), std::string("Every 2 weeks from 3 Nov until 1 Jan 2027"), "every so many, until a day");
|
|
schedule.unit = "FORTNIGHTLY";
|
|
schedule.end.reset();
|
|
Equal(ScheduleLabel(schedule, now), std::string("Every 2 Fortnightlys from 3 Nov"), "a unit this does not know is said as bunq says it");
|
|
for(const auto& [unit, word] : std::array<std::pair<std::string_view, std::string_view>, 3>{{{"HOURLY", "hour"}, {"DAILY", "day"}, {"YEARLY", "year"}}}) {
|
|
schedule.unit = unit;
|
|
schedule.every = 1;
|
|
Equal(ScheduleLabel(schedule, now), std::format("Every {} from 3 Nov", word), "each unit bunq has");
|
|
}
|
|
|
|
Equal(Fingerprint("short"), std::string("5 characters"), "a short secret shows nothing of itself but how long it is");
|
|
Equal(Fingerprint("x"), std::string("1 character"), "one character is one");
|
|
Equal(Fingerprint("sandbox_ab12cd34ef56gh78"), std::string("sandbox_ab12… 24 characters"), "a key shows what it is for, how it goes on and how long it is");
|
|
Equal(Fingerprint("sandbox_ab12cd34ef56gh7"), std::string("23 characters"), "one that would show most of itself that way shows nothing of itself");
|
|
Equal(Fingerprint("abcdefghijklmnopqrst"), std::string("abcd… 20 characters"), "one without a mark its first four");
|
|
Equal(Fingerprint("abcdefghijklmn_opqrst"), std::string("abcd… 21 characters"), "and so one whose mark comes late");
|
|
Equal(Fingerprint("ééééééééééééééééé"), std::string("éééé… 17 characters"), "by characters, not by bytes");
|
|
// How a key ends is what was typed last: shown, a key typed by hand would be shown whole, a character at a
|
|
// time. So typing on changes nothing of what is shown but the count.
|
|
std::string typed = "sandbox_ab12cd34ef56gh78";
|
|
for(const char next : std::string_view("WXYZ")) {
|
|
typed += next;
|
|
Equal(Fingerprint(typed), std::format("sandbox_ab12… {} characters", typed.size()), "what is typed after the beginning is never shown");
|
|
}
|
|
}
|
|
|
|
void Reading() {
|
|
for(const auto& [text, minor] : std::array<std::pair<std::string_view, std::int64_t>, 6>{{{"12,50", 1250}, {"12.50", 1250}, {" 12 ", 1200}, {"0,05", 5}, {"12.", 1200}, {"999999999999,99", 99999999999999}}}) {
|
|
const Read<std::int64_t> read = ReadAmount(text, euro);
|
|
Check(read.value == minor && read.error.empty(), std::format("'{}' is an amount", text));
|
|
}
|
|
for(const auto& [text, why] : std::array<std::pair<std::string_view, std::string_view>, 10>{{
|
|
{"", "Enter an amount"}, {" ", "Enter an amount"}, {"abc", "Not an amount"}, {"-5", "Not an amount"}, {",5", "Not an amount"}, {"1,2,3", "Not an amount"},
|
|
{"1,234", "At most 2 decimals"}, {"0", "An amount above zero"}, {"0,00", "An amount above zero"}, {"1234567890123", "That is too much"},
|
|
}}) {
|
|
const Read<std::int64_t> read = ReadAmount(text, euro);
|
|
Check(!read.value && read.error.contains(why), std::format("'{}' is refused: {}", text, why));
|
|
}
|
|
|
|
Equal(PartyKind(""), std::string(), "nothing typed is no kind of address yet");
|
|
Equal(PartyKind(" bob@example.org"), std::string("E-mail address"), "an e-mail address by its @");
|
|
Equal(PartyKind("+31612345678"), std::string("Phone number"), "a phone number by its +");
|
|
Equal(PartyKind("NL91"), std::string("IBAN"), "anything else is an IBAN being typed");
|
|
Read<BunqCounterparty> party = ReadParty(" NL91 ABNA 0417 1643 00 ");
|
|
Check(party.value && party.value->type == "IBAN" && party.value->value == iban, "an IBAN as it is printed");
|
|
party = ReadParty("nl91abna0417164300");
|
|
Check(party.value && party.value->value == iban, "or in small letters");
|
|
party = ReadParty("bob@example.org");
|
|
Check(party.value && party.value->type == "EMAIL" && party.value->value == "bob@example.org", "an e-mail address");
|
|
party = ReadParty("+31 6 1234 5678");
|
|
Check(party.value && party.value->type == "PHONE_NUMBER" && party.value->value == "+31612345678", "a phone number");
|
|
for(const auto& [text, why] : std::array<std::pair<std::string_view, std::string_view>, 7>{{
|
|
{"", "An IBAN, an e-mail address or a phone number"}, {"NL91ABNA0417164301", "Not a valid IBAN"}, {"Bob", "Not a valid IBAN"},
|
|
{"@example.org", "Not an e-mail address"}, {"bob@", "Not an e-mail address"}, {"bob smith@example.org", "Not an e-mail address"}, {"+31x", "Not a phone number"},
|
|
}}) {
|
|
const Read<BunqCounterparty> read = ReadParty(text);
|
|
Check(!read.value && read.error.contains(why), std::format("'{}' is refused: {}", text, why));
|
|
}
|
|
|
|
Check(ReadDay(" 2026-11-03 ").value == ParseLocalDate("2026-11-03"), "a day is its start");
|
|
Check(ReadDay("2026-11-03", "14:05").value == ParseLocalDate("2026-11-03 14:05"), "or the time on it");
|
|
Check(ReadDay("2026-11-03", {}, true).value == ParseLocalDateEnd("2026-11-03"), "or its last moment, for the end of a range");
|
|
Check(ReadDay("2026-11-03", " 14:05 ", true).value == ParseLocalDate("2026-11-03 14:05"), "a time given is that time either way");
|
|
for(const auto& [day, time, why] : std::array<std::tuple<std::string_view, std::string_view, std::string_view>, 5>{{
|
|
{"", "", "A day: YYYY-MM-DD"}, {"2026-13-01", "", "Not a day"}, {"tomorrow", "", "Not a day"}, {"2026-13-01", "10:00", "Not a day"}, {"2026-11-03", "25:00", "Not a time: hh:mm"},
|
|
}}) {
|
|
const Read<Moment> read = ReadDay(day, time);
|
|
Check(!read.value && read.error.contains(why), std::format("'{}' '{}' is refused: {}", day, time, why));
|
|
}
|
|
|
|
Check(ReadCount("3").value == 3u && ReadCount(" 12 ").value == 12u, "a count");
|
|
for(const std::string_view bad : {"", "0", "x", "1.5", "-1"}) {
|
|
const Read<std::uint32_t> read = ReadCount(bad);
|
|
Check(!read.value && read.error == "A whole number, 1 or more", std::format("'{}' is no count", bad));
|
|
}
|
|
}
|
|
|
|
void Paying() {
|
|
const Moment now = ParseLocalDate("2026-11-19 15:00");
|
|
PaymentForm form;
|
|
PaymentOrder order;
|
|
PaymentForm::Errors errors = form.Check(euro, now, order);
|
|
Check(errors.Any() && !errors.to.empty() && !errors.amount.empty() && errors.name.empty(), "an empty form lacks who and how much");
|
|
Check(!PaymentForm::Errors().Any(), "no errors is none");
|
|
|
|
form.to.Set("NL91 ABNA 0417 1643 00");
|
|
form.amount.Set("12,50");
|
|
form.description.Set(" lunch ");
|
|
errors = form.Check(euro, now, order);
|
|
Check(errors.Any() && errors.to.empty() && errors.amount.empty() && errors.name == "The name of the account's holder", "an IBAN needs its holder's name");
|
|
Equal(order.amount, std::int64_t{0}, "and a form with an error gives no order");
|
|
form.name.Set(" Bob ");
|
|
errors = form.Check(euro, now, order);
|
|
Check(!errors.Any() && order.to.type == "IBAN" && order.to.value == iban && order.to.name == "Bob" && order.amount == 1250 && order.description == "lunch" && order.when == When::Now, "a form filled in is an order");
|
|
|
|
form.to.Set("bob@example.org");
|
|
form.name.Clear();
|
|
errors = form.Check(euro, now, order);
|
|
Check(!errors.Any() && order.to.type == "EMAIL" && order.to.name.empty(), "an e-mail address needs no name");
|
|
|
|
// A schedule: a first day, an optional time, and for one that repeats how often and until when.
|
|
form.when = When::Scheduled;
|
|
errors = form.Check(euro, now, order);
|
|
Equal(errors.day, std::string("A day: YYYY-MM-DD"), "a schedule needs its first day");
|
|
form.day.Set("soon");
|
|
Equal(form.Check(euro, now, order).day, std::string("Not a day: YYYY-MM-DD"), "which is a day");
|
|
form.day.Set("2026-11-18");
|
|
Equal(form.Check(euro, now, order).day, std::string("Today or later"), "not one that has passed");
|
|
form.day.Set("2026-11-19");
|
|
Check(!form.Check(euro, now, order).Any() && order.when == When::Scheduled && order.schedule.unit == "ONCE" && order.schedule.start == ParseLocalDate("2026-11-19"), "today will do, once, from the start of the day");
|
|
form.time.Set("25:00");
|
|
Equal(form.Check(euro, now, order).time, std::string("Not a time: hh:mm"), "its time is one");
|
|
form.day.Set("2026-11-20");
|
|
form.time.Set("09:30");
|
|
// Once has nothing to repeat: what is left in those fields is not looked at.
|
|
form.every.Set("0");
|
|
form.until.Set("never");
|
|
Check(!form.Check(euro, now, order).Any() && order.schedule.start == ParseLocalDate("2026-11-20 09:30") && order.schedule.every == 1 && !order.schedule.end, "a time on the day, once");
|
|
form.unit = 3;
|
|
errors = form.Check(euro, now, order);
|
|
Check(errors.every == "A whole number, 1 or more" && errors.until == "Not a day: YYYY-MM-DD", "one that repeats checks how often and until when");
|
|
form.every.Set("2");
|
|
form.until.Set("2026-11-19");
|
|
Equal(form.Check(euro, now, order).until, std::string("After the first payment"), "it ends after it starts");
|
|
form.until.Set("2027-01-01");
|
|
Check(!form.Check(euro, now, order).Any() && order.schedule.unit == "WEEKLY" && order.schedule.every == 2 && order.schedule.end == ParseLocalDateEnd("2027-01-01"), "every other week until the end of a day");
|
|
form.every.Clear();
|
|
form.until.Clear();
|
|
Check(!form.Check(euro, now, order).Any() && order.schedule.every == 1 && !order.schedule.end, "or every week, for as long as it runs");
|
|
form.day.Set("nonsense");
|
|
form.until.Set("2027-01-01");
|
|
Check(form.Check(euro, now, order).until.empty(), "an end is not held against a start that is not there");
|
|
|
|
form.when = When::Draft;
|
|
form.day.Clear();
|
|
Check(!form.Check(euro, now, order).Any() && order.when == When::Draft, "a draft needs no day");
|
|
form.tried = true;
|
|
form.Clear();
|
|
Check(form.to.value.empty() && form.amount.value.empty() && form.when == When::Now && form.unit == 0 && form.day.value.empty() && !form.tried, "a cleared form is as new");
|
|
}
|
|
|
|
// A link that asks for a payment, as a website's pay button opens one: what is read from it, everything it is
|
|
// refused for, and the form it fills in. Whoever wrote the link chose every character of it.
|
|
void Linking() {
|
|
const std::string to = std::format("payto://iban/{}", iban);
|
|
const auto times = [](std::string_view text, std::size_t count) {
|
|
std::string repeated;
|
|
for(std::size_t i = 0; i < count; i++) {
|
|
repeated += text;
|
|
}
|
|
return repeated;
|
|
};
|
|
// The link with options after it.
|
|
const auto with = [&to](std::string_view options) { return std::format("{}?{}", to, options); };
|
|
|
|
struct Asked {
|
|
std::string link;
|
|
std::string name;
|
|
std::optional<std::int64_t> amount;
|
|
std::string description;
|
|
std::string_view what;
|
|
};
|
|
const std::vector<Asked> read = {
|
|
{to, "", std::nullopt, "", "an IBAN alone: how much and what for are the user's to say"},
|
|
{"PAYTO://IBAN/nl91abna0417164300", "", std::nullopt, "", "the scheme in capitals and the IBAN in small letters"},
|
|
{std::format("payto://iban/ABNANL2A/{}", iban), "", std::nullopt, "", "a bank's code of eight before the IBAN, which is left out"},
|
|
{std::format("payto://iban/ABNANL2AXXX/{}", iban), "", std::nullopt, "", "or one of eleven"},
|
|
{with(""), "", std::nullopt, "", "a question mark with nothing after it"},
|
|
{with("amount=EUR:12.50&receiver-name=Shop%20BV&message=Order%201234"), "Shop BV", 1250, "Order 1234", "who, how much and what for"},
|
|
{with("amount=EUR%3A12.5"), "", 1250, "", "the amount's colon as an escape, as a browser's own writer of queries has it"},
|
|
{with("amount=eur:12"), "", 1200, "", "the currency in small letters, and no cents"},
|
|
{with("amount=EUR:0012.50"), "", 1250, "", "zeros before it"},
|
|
{with("amount=EUR:999999999999.99"), "", 99999999999999, "", "the most a form takes"},
|
|
{with("message=a+b%2Bc"), "", std::nullopt, "a b+c", "a plus for a space, and an escaped one for a plus"},
|
|
{with("receiver-name=%20Bob%20"), "Bob", std::nullopt, "", "spaces around a name are not part of it"},
|
|
{with("message"), "", std::nullopt, "", "an option without a value says nothing"},
|
|
{with("AMOUNT=EUR:1&%6Dessage=x&Receiver-Name=Bob"), "Bob", 100, "x", "an option's name in capitals or as escapes is that option"},
|
|
{with("utm_source=mail&sender-name=Eve&flag&=x&&amount=EUR:5&"), "", 500, "", "what Nostro does not know is passed over, wherever it stands"},
|
|
{with("message=caf%C3%A9%20%E2%82%AC%20%F0%9F%98%80"), "", std::nullopt, "café € 😀", "characters of two, three and four bytes, as escapes"},
|
|
{with("receiver-name=Café René"), "Café René", std::nullopt, "", "or as they are"},
|
|
{with("receiver-name=Fish%20%26%20Chips%20%3CNL%3E&message=5%20%24(each)"), "Fish & Chips <NL>", std::nullopt, "5 $(each)", "an &, a <, a > and a $( are a name's and a description's to have: only the system's dialog shows a name otherwise"},
|
|
{std::format("{}?receiver-name={}&message={}", to, times("a", 70), times("b", 140)), times("a", 70), std::nullopt, times("b", 140), "a name of 70 characters and a description of 140"},
|
|
{std::format("{}?receiver-name={}&message={}", to, times("%C3%A9", 70), times("%E2%82%AC", 140)), times("é", 70), std::nullopt, times("€", 140), "counted in characters, not in bytes"},
|
|
};
|
|
for(const Asked& asked : read) {
|
|
const Read<PaymentLink> link = ReadPaymentLink(asked.link);
|
|
Check(link.value && link.error.empty() && link.value->iban == iban && link.value->name == asked.name && link.value->amount == asked.amount && link.value->currency == euro && link.value->description == asked.description, std::format("a link is read: {}", asked.what));
|
|
// What is read is what the form then holds, to the letter, and what its order asks nostrod for.
|
|
PaymentForm form;
|
|
form.Fill(link.value.value_or(PaymentLink()));
|
|
Check(form.linked && form.to.value == iban && form.name.value == asked.name && form.description.value == asked.description && ReadAmount(form.amount.value, euro).value == asked.amount, std::format("and fills the form in with just that: {}", asked.what));
|
|
}
|
|
|
|
constexpr std::string_view notOne = "It is not a link to pay an IBAN";
|
|
constexpr std::string_view noIban = "The IBAN in it is not a valid one";
|
|
constexpr std::string_view damaged = "something in it is there twice, or cannot be read";
|
|
constexpr std::string_view instruction = "a reference of a kind Nostro cannot send along";
|
|
constexpr std::string_view noAmount = "The amount in it cannot be read";
|
|
constexpr std::string_view noCurrency = "a currency Nostro does not pay in";
|
|
constexpr std::string_view notPlain = "holds what a payment cannot carry";
|
|
constexpr std::string_view tooLong = "is too long";
|
|
const std::vector<std::tuple<std::string, std::string_view, std::string_view>> refused = {
|
|
{"", notOne, "nothing"},
|
|
{"https://example.org/pay?to=MARK", notOne, "a web address"},
|
|
{"payto:iban/NL91ABNA0417164300", notOne, "a scheme without its slashes"},
|
|
{"payto://bic/ABNANL2A", notOne, "a bank's code and no account"},
|
|
{"payto://bitcoin/1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa", notOne, "something that is no IBAN"},
|
|
{"payto://user@iban/NL91ABNA0417164300", notOne, "a user before the kind of account"},
|
|
{"payto://pay/iban/NL91ABNA0417164300", notOne, "a kind of account that is none"},
|
|
{"nostro://iban/NL91ABNA0417164300", notOne, "a scheme of Nostro's own, which there is none of"},
|
|
{std::format(" {}", to), notOne, "a space before it"},
|
|
{std::format("{}#MARK", to), notOne, "a fragment"},
|
|
{with("message=a#MARK"), notOne, "a fragment after the options"},
|
|
{with(std::format("x={}", times("a", 4096))), notOne, "a link longer than any that asks for a payment"},
|
|
{std::format("payto://iban/ABNANL2/{}", iban), notOne, "a bank's code of seven"},
|
|
{std::format("payto://iban/ABNANL2AX/{}", iban), notOne, "one of nine"},
|
|
{std::format("payto://iban/ABNA-L2A/{}", iban), notOne, "one that is not letters and digits"},
|
|
{std::format("payto://iban//{}", iban), notOne, "an empty one"},
|
|
{"payto://iban/", noIban, "no IBAN"},
|
|
{"payto://iban/?amount=EUR:1", noIban, "no IBAN before the options"},
|
|
{"payto://iban/NL91ABNA0417164301", noIban, "an IBAN whose check digits do not hold"},
|
|
{"payto://iban/NL91%41BNA0417164300", noIban, "an escape in the IBAN"},
|
|
{"payto://iban/NL91 ABNA 0417 1643 00", noIban, "spaces in it"},
|
|
{"payto://iban/bob@example.org", noIban, "an e-mail address"},
|
|
{"payto://iban/+31612345678", noIban, "a phone number"},
|
|
{std::format("payto://iban/ABNANL2A/ABNANL2A/{}", iban), noIban, "two banks' codes"},
|
|
{"payto://iban/ABNANL2A/", noIban, "a bank's code and nothing after it"},
|
|
{with("amount=EUR:1&amount=EUR:2"), damaged, "two amounts"},
|
|
{with("amount=EUR:1&AMOUNT=EUR:1000"), damaged, "a second amount in capitals"},
|
|
{with("%61mount=EUR:1000&amount=EUR:1"), damaged, "a first amount behind an escape"},
|
|
{with("message=a&x=1&message=MARK"), damaged, "two descriptions"},
|
|
{with("receiver-name=a&receiver-name=MARK"), damaged, "two names"},
|
|
{with("message=100%"), damaged, "a percent sign that begins no escape"},
|
|
{with("message=MARK%4"), damaged, "an escape cut short"},
|
|
{with("receiver-name=%zzMARK"), damaged, "an escape that is no number"},
|
|
{with("receiver-name=%4zMARK"), damaged, "an escape that is half a number"},
|
|
{with("amount=EUR%3"), damaged, "an escape cut short in the amount"},
|
|
{with("instruction=RF18539007547034"), instruction, "a reference for the payee's bank to pass on"},
|
|
{with("instruction="), instruction, "an empty one"},
|
|
{with("instruction"), instruction, "one without a value"},
|
|
{with("INSTRUCTION=MARK"), instruction, "one in capitals"},
|
|
{with("amount=12.50"), noAmount, "an amount without its currency"},
|
|
{with("amount=EUR"), noAmount, "a currency without an amount"},
|
|
{with("amount=EUR:"), noAmount, "a currency and a colon"},
|
|
{with("amount="), noAmount, "an empty amount"},
|
|
{with("amount"), noAmount, "an amount without a value"},
|
|
{with("amount=EUR:12,50"), noAmount, "a comma for the point: twelve hundred and fifty by the letter of RFC 8905, twelve and a half to whoever wrote it"},
|
|
{with("amount=EUR:1,250.00"), noAmount, "a comma between the thousands"},
|
|
{with("amount=EUR:-1"), noAmount, "less than nothing"},
|
|
{with("amount=EUR:+1"), noAmount, "a plus, which reads as a space"},
|
|
{with("amount=EUR:%201"), noAmount, "a space"},
|
|
{with("amount=EUR:12."), noAmount, "a point with nothing after it"},
|
|
{with("amount=EUR:.5"), noAmount, "a point with nothing before it"},
|
|
{with("amount=EUR:1.2.3"), noAmount, "two points"},
|
|
{with("amount=EUR:1e3"), noAmount, "a power of ten"},
|
|
{with("amount=EUR:%D9%A1%D9%A2"), noAmount, "digits of another script"},
|
|
{with("amount=EUR:1.234"), noAmount, "more decimals than the euro has"},
|
|
{with("amount=EUR:0"), noAmount, "nothing"},
|
|
{with("amount=EUR:0.00"), noAmount, "nothing, to the cent"},
|
|
{with("amount=EUR:1234567890123"), noAmount, "more than a form takes"},
|
|
{with("amount=USD:1"), noCurrency, "another currency"},
|
|
{with("amount=Eur:1"), noCurrency, "a currency in neither capitals nor small letters"},
|
|
{with("amount=EURO:1"), noCurrency, "a currency's name"},
|
|
{with("amount=:1"), noCurrency, "no currency before the colon"},
|
|
{with("message=MARK%00"), notPlain, "a zero byte"},
|
|
{with("message=MARK%0AMARK"), notPlain, "a new line"},
|
|
{with("message=MARK%09"), notPlain, "a tab"},
|
|
{with("receiver-name=MARK%7F"), notPlain, "a delete"},
|
|
{with("receiver-name=MARK%C2%85"), notPlain, "a control of the second kind"},
|
|
{with("receiver-name=MA%E2%80%8BRK"), notPlain, "a space without a width"},
|
|
{with("receiver-name=%E2%80%AEMARK"), notPlain, "a mark that turns the text around"},
|
|
{with("receiver-name=MARK%C2%A0BV"), notPlain, "a space that is not the ordinary one"},
|
|
{with("message=MARK%C2%AD"), notPlain, "a soft hyphen"},
|
|
{with("message=%EF%BB%BFMARK"), notPlain, "a byte order mark"},
|
|
{with("message=%EE%80%80MARK"), notPlain, "a character of private use"},
|
|
{with("message=M%C1%81RK"), notPlain, "an A written in two bytes, which reads as one and is none"},
|
|
{with("message=%E0%80%AFMARK"), notPlain, "a slash written in three"},
|
|
{with("message=%F0%80%80%AFMARK"), notPlain, "and in four"},
|
|
{with("message=%ED%A0%80MARK"), notPlain, "half of a pair"},
|
|
{with("message=%F4%90%80%80MARK"), notPlain, "a character beyond the last there is"},
|
|
{with("message=MARK%F0%9F%BF%BE"), notPlain, "the last but one of the second plane, which is no character and which the bus refuses"},
|
|
{with("receiver-name=MARK%F3%AF%BF%BF"), notPlain, "and the last of the fifteenth"},
|
|
{with("message=%F8%88%80%80%80MARK"), notPlain, "five bytes, which begin no character"},
|
|
{with("message=MARK%C3"), notPlain, "a character cut short"},
|
|
{with("message=%FFMARK"), notPlain, "a byte that is in no character"},
|
|
{with("message=MARK%EF%BF%BD"), notPlain, "the mark that stands for what could not be read"},
|
|
{std::format("{}?receiver-name={}", to, times("a", 71)), tooLong, "a name of 71 characters"},
|
|
{std::format("{}?message={}", to, times("%C3%A9", 141)), tooLong, "a description of 141"},
|
|
};
|
|
for(const auto& [link, why, what] : refused) {
|
|
const Read<PaymentLink> none = ReadPaymentLink(link);
|
|
Check(!none.value && none.error.contains(why), std::format("a link is refused for {}: {}", what, why));
|
|
// Why it was refused is said in the app's own words: nothing of a stranger's link comes back in them.
|
|
Check(!none.error.contains("MARK") && !none.error.contains("NL91") && !none.error.contains("payto"), std::format("and what says so holds nothing of the link: {}", what));
|
|
}
|
|
|
|
// The form a link fills in: all of it the link's, in place of whatever was there, and none of it sent.
|
|
const Moment now = ParseLocalDate("2026-11-19 15:00");
|
|
PaymentForm form;
|
|
form.to.Set("bob@example.org");
|
|
form.description.Set("lunch");
|
|
form.when = When::Scheduled;
|
|
form.day.Set("2026-12-01");
|
|
form.unit = 3;
|
|
form.every.Set("2");
|
|
form.tried = true;
|
|
form.Fill(*ReadPaymentLink(with("amount=EUR:12.50&receiver-name=Shop%20BV&message=Order%201234")).value);
|
|
PaymentOrder order;
|
|
Check(!form.Check(euro, now, order).Any() && order.to.type == "IBAN" && order.to.value == iban && order.to.name == "Shop BV" && order.amount == 1250 && order.description == "Order 1234" && order.when == When::Now, "a link's form asks for what the link said, now");
|
|
Check(form.linked && !form.tried && form.day.value.empty() && form.unit == 0 && form.every.value.empty(), "with nothing left of what the form held before, and marked as a link's");
|
|
form.Fill(*ReadPaymentLink(to).value);
|
|
const PaymentForm::Errors errors = form.Check(euro, now, order);
|
|
Check(form.linked && form.amount.value.empty() && form.name.value.empty() && errors.amount == "Enter an amount" && errors.name == "The name of the account's holder", "a link that says no more than who is paid leaves the rest to the user");
|
|
form.Clear();
|
|
Check(!form.linked && form.to.value.empty(), "a cleared form is nobody's");
|
|
}
|
|
|
|
void Asking() {
|
|
RequestForm form;
|
|
RequestOrder order;
|
|
RequestForm::Errors errors = form.Check(euro, order);
|
|
Check(errors.Any() && !errors.from.empty() && !errors.amount.empty() && errors.name.empty() && !RequestForm::Errors().Any(), "an empty request lacks who and how much");
|
|
form.from.Set(iban);
|
|
form.amount.Set("5");
|
|
Equal(form.Check(euro, order).name, std::string("The name of the account's holder"), "an IBAN needs its holder's name");
|
|
form.name.Set("Bob");
|
|
form.description.Set("back");
|
|
Check(!form.Check(euro, order).Any() && order.from.value == iban && order.from.name == "Bob" && order.amount == 500 && order.description == "back", "a request filled in is an order");
|
|
form.from.Set("+31612345678");
|
|
form.name.Clear();
|
|
Check(!form.Check(euro, order).Any() && order.from.type == "PHONE_NUMBER", "a phone number needs no name");
|
|
form.tried = true;
|
|
form.Clear();
|
|
Check(form.from.value.empty() && form.amount.value.empty() && form.description.value.empty() && !form.tried, "a cleared request is as new");
|
|
}
|
|
|
|
void Filtering() {
|
|
const Moment now = ParseLocalDate("2026-11-19 15:00");
|
|
FilterForm form;
|
|
TransactionQuery query;
|
|
query.limit = 300;
|
|
Check(!form.Check(euro, query).Any() && query.search.empty() && !query.amount && query.from == Moment::min() && query.to == Moment::max() && query.limit == 300, "an empty filter asks for everything, as many as before");
|
|
Check(form.Chips(euro, now).empty() && !FilterForm::Errors().Any(), "and shows nothing");
|
|
form.search.Set(" rent ");
|
|
form.amount.Set("12,50");
|
|
form.from.Set("2026-11-01");
|
|
form.to.Set("2026-11-30");
|
|
Check(!form.Check(euro, query).Any() && query.search == "rent" && query.amount == -1250 && query.from == ParseLocalDate("2026-11-01") && query.to == ParseLocalDateEnd("2026-11-30"), "what went out, between two days, the last one whole");
|
|
Check(form.Chips(euro, now) == std::vector<std::string>{"Paid €12.50", "From 1 Nov", "Until 30 Nov"}, "said in a few words each");
|
|
form.received = true;
|
|
Check(!form.Check(euro, query).Any() && query.amount == 1250 && form.Chips(euro, now).front() == "Received €12.50", "or what came in");
|
|
|
|
query = TransactionQuery();
|
|
form.amount.Set("1,234");
|
|
form.from.Set("soon");
|
|
form.to.Set("later");
|
|
const FilterForm::Errors errors = form.Check(euro, query);
|
|
Check(errors.Any() && errors.amount.contains("At most 2 decimals") && errors.from.contains("Not a day") && errors.to.contains("Not a day") && query.search.empty(), "a filter with a mistake asks for nothing");
|
|
Check(form.Chips(euro, now).empty(), "and what cannot be read is no chip");
|
|
form.amount.Clear();
|
|
form.from.Set("2026-11-30");
|
|
form.to.Set("2026-11-01");
|
|
Equal(form.Check(euro, query).to, std::string("On or after the first day"), "a range ends after it starts");
|
|
form.to.Set("2026-11-30");
|
|
Check(!form.Check(euro, query).Any(), "one day is a range");
|
|
form.Reset();
|
|
Check(form.amount.value.empty() && form.from.value.empty() && form.to.value.empty() && !form.received && form.search.value == " rent ", "a reset keeps the search and drops the rest");
|
|
}
|
|
|
|
void Connecting() {
|
|
BunqKeyForm key;
|
|
Check(key.ips.value == "*" && key.Check() == "The API key, from the bunq app", "a new key form allows any address and lacks its key");
|
|
key.key.Set("sandbox_0123456789abcdef");
|
|
key.ips.Set("10.0.0.1");
|
|
key.advanced = true;
|
|
key.tried = true;
|
|
Check(key.Check().empty(), "with a key it can be sent");
|
|
key.Clear();
|
|
Check(key.key.value.empty() && key.ips.value == "*" && !key.advanced && !key.tried, "a cleared key form is as new");
|
|
|
|
BunqOAuthForm oauth;
|
|
BunqOAuthForm::Errors errors = oauth.Check();
|
|
Check(errors.Any() && !errors.clientId.empty() && !errors.redirectUri.empty() && !errors.secret.empty() && !BunqOAuthForm::Errors().Any(), "an empty OAuth form lacks everything");
|
|
oauth.clientId.Set(" client-1 ");
|
|
oauth.secret.Set("secret-1");
|
|
oauth.redirectUri.Set("ftp://example.org/cb");
|
|
Check(!oauth.Check().redirectUri.empty() && oauth.Check().clientId.empty() && oauth.Check().secret.empty(), "a redirect address is a web address");
|
|
oauth.redirectUri.Set("http://127.0.0.1/cb");
|
|
Check(!oauth.Check().Any(), "to this computer itself will do");
|
|
oauth.redirectUri.Set(" https://example.org/cb ");
|
|
oauth.Begin("state123");
|
|
Equal(oauth.address, std::string("https://oauth.bunq.com/auth?response_type=code&client_id=client-1&redirect_uri=https%3A%2F%2Fexample.org%2Fcb&state=state123"), "the address to approve at, with this request's state");
|
|
oauth.sandbox = true;
|
|
oauth.Begin("state456");
|
|
Check(oauth.address.starts_with("https://oauth.sandbox.bunq.com/auth?") && oauth.state == "state456", "the sandbox has its own");
|
|
oauth.redirected.Set(" https://example.org/cb?code=abc&state=state456 ");
|
|
Equal(oauth.Code(), std::string("abc"), "the code in the address the browser was sent to");
|
|
oauth.redirected.Set("https://example.org/cb?code=abc&state=state123");
|
|
Throws<std::runtime_error>([&oauth] { oauth.Code(); }, "its state differs", "an answer to another request is refused");
|
|
oauth.redirected.Set("https://example.org/cb?error=access_denied&error_description=No");
|
|
Throws<std::runtime_error>([&oauth] { oauth.Code(); }, "bunq did not authorize", "and so is bunq's refusal");
|
|
oauth.tried = true;
|
|
oauth.Clear();
|
|
Check(oauth.clientId.value.empty() && oauth.redirectUri.value.empty() && oauth.secret.value.empty() && !oauth.sandbox && oauth.redirected.value.empty() && oauth.state.empty() && oauth.address.empty() && !oauth.tried, "a cleared OAuth form is as new");
|
|
}
|
|
|
|
template<typename E>
|
|
Guidance Explained(E error, Operation operation) {
|
|
return Explain(std::make_exception_ptr(std::move(error)), operation);
|
|
}
|
|
|
|
void Explaining() {
|
|
// What nostrod asks polkit for, and whether money leaves an account by it. Only a reading is the View action,
|
|
// which is the one the policy nostro installs lets pass without a password.
|
|
const std::array<std::tuple<Operation, std::string_view, bool>, 17> operations = {{
|
|
{Operation::Load, Bus::actionView, false},
|
|
{Operation::Send, Bus::actionPay, true}, {Operation::Schedule, Bus::actionPay, true},
|
|
{Operation::PayRequest, Bus::actionPay, true}, {Operation::AcceptDraft, Bus::actionPay, true},
|
|
{Operation::Draft, Bus::actionChange, false}, {Operation::Request, Bus::actionChange, false},
|
|
{Operation::RevokeRequest, Bus::actionChange, false}, {Operation::RejectRequest, Bus::actionChange, false},
|
|
{Operation::CancelSchedule, Bus::actionChange, false}, {Operation::RejectDraft, Bus::actionChange, false},
|
|
{Operation::FreezeCard, Bus::actionChange, false},
|
|
{Operation::UnfreezeCard, Bus::actionUnfreezeCard, false}, {Operation::BlockCard, Bus::actionBlockCard, false},
|
|
{Operation::AddConnection, Bus::actionConnectors, false}, {Operation::RemoveConnection, Bus::actionConnectors, false},
|
|
{Operation::SetCheckoutAccount, Bus::actionConnectors, false},
|
|
}};
|
|
for(const auto& [operation, action, money] : operations) {
|
|
Check(ActionOf(operation) == action && MovesMoney(operation) == money && (ActionOf(operation) == Bus::actionView) == (operation == Operation::Load), std::format("operation {} asks for {}", std::to_underlying(operation), action));
|
|
}
|
|
|
|
Guidance told = Explained(DaemonMissing("not there"), Operation::Load);
|
|
Check(told.problem == Problem::NoService && told.retry && !told.mayHaveHappened && told.detail.contains("README") && told.detail.contains("not there"), "no nostrod: how to get one");
|
|
for(const std::string_view name : {"org.freedesktop.systemd1.NoSuchUnit", "org.freedesktop.DBus.Error.Spawn.ChildExited", "org.freedesktop.DBus.Error.NameHasNoOwner"}) {
|
|
Check(Explained(DaemonError(std::string(name), "could not start"), Operation::Send).problem == Problem::NoService, "a nostrod the bus could not start is no nostrod");
|
|
}
|
|
told = Explained(NoSystemBus("No such file or directory"), Operation::Load);
|
|
Check(told.problem == Problem::NoService && told.retry && !told.mayHaveHappened && told.title == "The system bus cannot be reached" && told.detail.contains("No such file or directory"), "no system bus to reach nostrod over");
|
|
told = Explained(OutcomeUnknown("no answer"), Operation::Send);
|
|
Check(told.problem == Problem::Unknown && told.mayHaveHappened && !told.retry && told.title == "It may have been paid" && told.detail.contains("activity"), "a payment without a clear answer may have been made");
|
|
told = Explained(OutcomeUnknown("no answer"), Operation::RevokeRequest);
|
|
Check(told.problem == Problem::Unknown && told.mayHaveHappened && told.title == "It may have been done", "and any other change may have been");
|
|
told = Explained(std::invalid_argument("no account is called 'Nope'"), Operation::Send);
|
|
Check(told.problem == Problem::Input && !told.mayHaveHappened && !told.retry && told.detail == "no account is called 'Nope'. Nothing was sent.", "what nostrod refused before it began");
|
|
told = Explained(DaemonError(std::string(Bus::errorCancelled), "cancelled"), Operation::Send);
|
|
Check(told.problem == Problem::NotConfirmed && told.detail.contains("Nothing was done") && told.detail.contains("agent"), "no password: nothing was done, and why no dialog may have come");
|
|
told = Explained(DaemonError("org.freedesktop.DBus.Error.AccessDenied", "the system's policy does not allow it"), Operation::Send);
|
|
Check(told.problem == Problem::NotAllowed && told.detail.starts_with("the system's policy does not allow it") && !told.retry, "refused by the system's policy");
|
|
Check(Explained(DaemonError("org.freedesktop.DBus.Error.AccessDenied", "no"), Operation::Load).retry, "a reading may be tried again");
|
|
told = Explained(DaemonError("org.freedesktop.DBus.Error.InteractiveAuthorizationRequired", "x"), Operation::Send);
|
|
Check(told.problem == Problem::CannotAsk && told.detail.contains("README"), "nostrod could not ask");
|
|
told = Explained(DaemonError(std::string(Bus::errorOAuthCannotPay), "x"), Operation::Send);
|
|
Check(told.problem == Problem::OwnAccountsOnly && told.title == "This connection cannot pay others" && told.detail.contains("draft"), "a connection that pays the user's own accounts only");
|
|
Check(!told.detail.contains("bunq") && !told.detail.contains("OAuth"), "said of no bank and of no way to connect to one");
|
|
told = Explained(DaemonError(std::string(Bus::errorBank), "bunq POST /payment: Not enough money. (400)"), Operation::Send);
|
|
Check(told.problem == Problem::Bank && told.title == "The bank refused" && told.detail.contains("Not enough money") && !told.retry && !told.mayHaveHappened, "the bank's own refusal");
|
|
Check(Explained(DaemonError(std::string(Bus::errorBank), "x"), Operation::Load).retry, "of a reading, which may be tried again");
|
|
for(const std::string_view name : {"org.freedesktop.DBus.Error.NoReply", "org.freedesktop.DBus.Error.Timeout"}) {
|
|
told = Explained(DaemonError(std::string(name), "timed out"), Operation::Load);
|
|
Check(told.problem == Problem::Late && told.retry, "a reading that got no answer in time is only late");
|
|
}
|
|
told = Explained(DaemonError(std::string(Bus::errorFailed), "the worker went"), Operation::Send);
|
|
Check(told.problem == Problem::Unknown && told.mayHaveHappened, "a payment nostrod failed at may have been made");
|
|
told = Explained(DaemonError(std::string(Bus::errorFailed), "already connected"), Operation::AddConnection);
|
|
Check(told.problem == Problem::Failed && told.detail == "already connected" && !told.mayHaveHappened && !told.retry, "anything else it failed at is said as it says it");
|
|
Check(Explained(DaemonError(std::string(Bus::errorFailed), "x"), Operation::Load).retry, "and a reading may be tried again");
|
|
told = Explained(std::system_error(std::make_error_code(std::errc::bad_message), "cannot read"), Operation::Send);
|
|
Check(told.problem == Problem::Unknown && told.mayHaveHappened, "an answer to a change that cannot be read leaves it open");
|
|
told = Explained(std::system_error(std::make_error_code(std::errc::not_connected), "cannot call nostrod"), Operation::Load);
|
|
Check(told.problem == Problem::Failed && told.retry && !told.mayHaveHappened, "one to a reading does not");
|
|
told = Explained(std::runtime_error("bunq kept card 7 DEACTIVATED"), Operation::UnfreezeCard);
|
|
Check(told.problem == Problem::Failed && told.detail == "bunq kept card 7 DEACTIVATED" && !told.retry, "any other error is said as it is");
|
|
Check(Explained(std::runtime_error("x"), Operation::Load).retry, "and a reading may be tried again");
|
|
}
|
|
|
|
// What the app knows of the banks: each with its ways to connect, found by what nostrod calls them, and a bank
|
|
// or a way it does not know, which a newer nostrod may have, said by nostrod's own name for it.
|
|
void Knowing() {
|
|
Check(!Banks().empty(), "there is a bank to connect");
|
|
for(const Bank& bank : Banks()) {
|
|
Check(FindBank(bank.id) == &bank && !bank.name.empty() && !bank.ways.empty(), "a bank is found by what nostrod calls it, and has a name and a way in");
|
|
Equal(BankName(bank.id), std::string(bank.name), "and is said by its own name");
|
|
std::set<std::string_view> keys;
|
|
std::set<ConnectForm> forms;
|
|
for(const Way& way : bank.ways) {
|
|
Check(FindWay(bank.id, way.auth) == &way, "a way is found by what nostrod calls it");
|
|
Check(!way.key.empty() && !way.title.empty() && !way.about.empty() && !way.revoke.empty(), "and has its words");
|
|
Equal(WayName(bank.id, way.auth), std::string(way.title), "it is said by its title");
|
|
Equal(OwnAccountsOnly(bank.id, way.auth), way.ownAccountsOnly, "what a connection made that way can pay is the way's to say");
|
|
Equal(Revoking(bank.id, way.auth), std::string(way.revoke), "and so is where it is revoked");
|
|
keys.insert(way.key);
|
|
forms.insert(way.form);
|
|
}
|
|
Check(keys.size() == bank.ways.size() && forms.size() == bank.ways.size(), "its ways are told apart, each with a form of its own");
|
|
}
|
|
|
|
const Bank* const bunq = FindBank(BunqConnector::connectorId);
|
|
Check(bunq != nullptr && bunq->name == "bunq" && bunq->ways.size() == 2, "bunq is one of them, by its connector's own id, with two ways in");
|
|
Check(FindWay("bunq", "api key")->form == ConnectForm::BunqKey && FindWay("bunq", "api key")->key == "key" && !OwnAccountsOnly("bunq", "api key"), "an API key, which does all a user can");
|
|
Check(FindWay("bunq", "oauth")->form == ConnectForm::BunqOAuth && FindWay("bunq", "oauth")->key == "oauth" && OwnAccountsOnly("bunq", "oauth"), "and OAuth, which bunq lets pay between the user's own accounts only");
|
|
Equal(WayName("bunq", "api key"), std::string("API key"), "as nostrod's \"api key\" is said");
|
|
Check(Revoking("bunq", "api key").contains("API key") && Revoking("bunq", "oauth").contains("permission"), "each stays valid at bunq until it is revoked there");
|
|
|
|
Check(FindBank("thrift") == nullptr && FindWay("thrift", "api key") == nullptr && FindWay("bunq", "handshake") == nullptr, "a bank or a way the app does not know is not found");
|
|
Equal(BankName("thrift"), std::string("thrift"), "such a bank is said as nostrod calls it");
|
|
Equal(WayName("thrift", "password"), std::string("password"), "and so is its way");
|
|
Equal(WayName("bunq", "handshake"), std::string("handshake"), "or a new way of a bank it knows");
|
|
Check(!OwnAccountsOnly("thrift", "oauth") && !OwnAccountsOnly("bunq", "handshake"), "of which the app knows no limit");
|
|
Check(Revoking("thrift", "password").contains("at the bank") && Revoking("bunq", "handshake") == Revoking("thrift", "password"), "and no more of revoking it than that it is done at the bank");
|
|
}
|
|
}
|
|
|
|
int main() {
|
|
setenv("TZ", "Europe/Amsterdam", 1);
|
|
tzset();
|
|
Words();
|
|
Reading();
|
|
Paying();
|
|
Linking();
|
|
Asking();
|
|
Filtering();
|
|
Connecting();
|
|
Explaining();
|
|
Knowing();
|
|
return Test::Result();
|
|
}
|