feat: open payto links on the pay form, and take the checkout over D-Bus out
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.
This commit is contained in:
parent
25d991658f
commit
b43ab124a6
42 changed files with 1234 additions and 994 deletions
|
|
@ -222,7 +222,7 @@ namespace {
|
|||
Check(!Result<std::vector<ConnectorCards>>(loop, [&client](auto then) { return client.Cards(std::move(then)); }).at(0).cards.empty(), "the cards");
|
||||
Equal(Result<BunqCard>(loop, [&client, card](auto then) { return client.SetCardStatus(card, "DEACTIVATED", std::move(then)); }).status, std::string("DEACTIVATED"), "a card frozen");
|
||||
|
||||
Check(!Result<std::optional<Account>>(loop, [&client](auto then) { return client.DefaultCheckoutAccount(std::move(then)); }).has_value(), "no account pays checkouts yet");
|
||||
Check(!Result<std::optional<Account>>(loop, [&client](auto then) { return client.DefaultCheckoutAccount(std::move(then)); }).has_value(), "no account is the one pay links start from yet");
|
||||
Equal(Result<Account>(loop, [&client](auto then) { return client.SetDefaultCheckoutAccount(aliceMain, std::move(then)); }).iban, aliceMain, "until one is chosen");
|
||||
|
||||
const AddedConnector oauth = Result<AddedConnector>(loop, [&client, &bunq](auto then) { return client.AddBunqOAuth("production", bunq.clientId, bunq.clientSecret, "http://127.0.0.1/cb", "code-carol", std::move(then)); });
|
||||
|
|
|
|||
|
|
@ -53,6 +53,8 @@ namespace fs = std::filesystem;
|
|||
namespace {
|
||||
constexpr std::uint16_t port = 47307;
|
||||
constexpr std::uint32_t uid = 4242;
|
||||
// A second user of the machine, with connections of their own.
|
||||
constexpr std::uint32_t erinUid = 4243;
|
||||
constexpr std::string_view busName = "net.catcrafts.Nostro1";
|
||||
const std::string aliceKey = "key-alice-0123456789abcdef";
|
||||
const std::string aliceMain = "NL23BUNQ2025123456";
|
||||
|
|
@ -63,6 +65,8 @@ namespace {
|
|||
const std::string daveIban = "NL06BUNQ2025444444";
|
||||
const std::string otherAliceIban = "NL25BUNQ2025555555";
|
||||
const std::string strangerIban = "NL44BUNQ2025666666";
|
||||
// A link as a website's pay button opens one: to Bob's account, under a shop's name, with what is owed and for what.
|
||||
const std::string shopLink = std::format("payto://iban/{}?amount=EUR:12.50&receiver-name=Shop%20BV&message=Order%201234", bobIban);
|
||||
|
||||
void SetPolkit(Fake::Bus& bus, Fake::Polkit outcome, std::string_view action = {}) {
|
||||
std::lock_guard lock(bus.mutex);
|
||||
|
|
@ -313,6 +317,26 @@ namespace {
|
|||
return change == std::views::reverse(bus.checks).end() ? std::string() : change->action;
|
||||
}
|
||||
|
||||
// What the system's dialog said that change was: nostrod's own words for it, from its own data.
|
||||
std::string Summary(Fake::Bus& bus) {
|
||||
std::lock_guard lock(bus.mutex);
|
||||
const auto change = std::ranges::find_if(std::views::reverse(bus.checks), [](const Fake::PolkitCheck& check) { return check.action != Bus::actionView; });
|
||||
return change == std::views::reverse(bus.checks).end() || !change->details.contains("summary") ? std::string() : change->details.at("summary");
|
||||
}
|
||||
|
||||
// How often polkit was asked about a change: what a screen reads is a check too, for looking.
|
||||
std::size_t Changes(Fake::Bus& bus) {
|
||||
std::lock_guard lock(bus.mutex);
|
||||
return static_cast<std::size_t>(std::ranges::count_if(bus.checks, [](const Fake::PolkitCheck& check) { return check.action != Bus::actionView; }));
|
||||
}
|
||||
|
||||
// What the bank was last sent as a payment or a draft of one.
|
||||
std::string LastPayment(Fake::Bunq& bunq) {
|
||||
const std::vector<Fake::Logged> log = bunq.Log();
|
||||
const auto sent = std::ranges::find_if(std::views::reverse(log), [](const Fake::Logged& entry) { return entry.method == "POST" && entry.path.contains("payment"); });
|
||||
return sent == std::views::reverse(log).end() ? std::string() : sent->body;
|
||||
}
|
||||
|
||||
// Before nostrod runs: no system bus at all, then a bus without nostrod, then nostrod without a connection.
|
||||
void Starting(Driver& d, pid_t& nostrod, const fs::path& state) {
|
||||
d.noBus = true;
|
||||
|
|
@ -339,6 +363,18 @@ namespace {
|
|||
Check(Has(d, "nav.accounts") && Has(d, "nav.cards") && Has(d, "nav.settings"), "the app's places are along the bottom");
|
||||
Equal(d.connects, 2, "one connection to the bus is all it took");
|
||||
|
||||
// A link that asks for a payment, and no account to pay it from: that is said, and no form is opened.
|
||||
Check(d.app.Open(shopLink), "a link is taken");
|
||||
Settle(d);
|
||||
Equal(d.app.Screen(), std::string("accounts+link"), "a link opens no form where there is no account to pay from");
|
||||
Shows(d.ui, "No account to pay from", "which is said");
|
||||
Shows(d.ui, "This link asks for a payment", "with what the link was for");
|
||||
Hides(d.ui, "Shop BV", "and with nothing of what the link said");
|
||||
Tap(d, "link.close");
|
||||
Equal(d.app.Screen(), std::string("accounts"), "closed, it leaves the welcome");
|
||||
Shows(d.ui, "Welcome to Nostro", "where a bank can be connected");
|
||||
Hides(d.ui, "A link asks for a payment", "and the link waits for nothing");
|
||||
|
||||
// Every place says so when it has nothing to show.
|
||||
Press(d, "nav.cards");
|
||||
Shows(d.ui, "No cards", "no cards");
|
||||
|
|
@ -348,7 +384,7 @@ namespace {
|
|||
Shows(d.ui, "No bank is connected yet", "none to list");
|
||||
Tap(d, "bar.back");
|
||||
Tap(d, "settings.checkout");
|
||||
Shows(d.ui, "No accounts to choose from", "and no account to pay at checkout from");
|
||||
Shows(d.ui, "No accounts to choose from", "and no account for a pay link to start from");
|
||||
Tap(d, "bar.back");
|
||||
Tap(d, "nav.accounts");
|
||||
// A connection without an account: there is nothing to pay from.
|
||||
|
|
@ -366,6 +402,19 @@ namespace {
|
|||
other.RemoveConnector("Eve");
|
||||
Press(d, "bar.refresh");
|
||||
Shows(d.ui, "Welcome to Nostro", "without it the welcome is back");
|
||||
// One account in all: a link's form opens from it at once, since there is nothing to choose between.
|
||||
other.AddBunq(daveKey, "*", "");
|
||||
Press(d, "bar.refresh");
|
||||
Shows(d.ui, "Play money", "a single account");
|
||||
Check(d.app.Open(shopLink), "a link is taken");
|
||||
Build(d);
|
||||
Equal(d.app.Screen(), std::string("pay"), "with one account a link opens its form without asking which account pays");
|
||||
Shows(d.ui, "Play money", "from the one there is");
|
||||
Shows(d.ui, "Shop BV", "filled in");
|
||||
Tap(d, "bar.back");
|
||||
other.RemoveConnector("Dave");
|
||||
Press(d, "bar.refresh");
|
||||
Shows(d.ui, "Welcome to Nostro", "and with that account gone the welcome is back");
|
||||
// Connecting a bank from there: which bank first, then how, and then the form of that way.
|
||||
Check(Has(d, "welcome.connect") && d.ui.Find("welcome.connect")->label == "Connect a bank", "which offers to connect a bank, whichever");
|
||||
Tap(d, "welcome.connect");
|
||||
|
|
@ -450,7 +499,7 @@ namespace {
|
|||
Hides(d.ui, "Welcome to Nostro", "the welcome is over");
|
||||
Check(Has(d, "home.pay") && Has(d, "home.request"), "paying and asking are at hand");
|
||||
Tap(d, "nav.settings");
|
||||
Shows(d.ui, "No account chosen", "no account pays at checkout yet");
|
||||
Shows(d.ui, "No account chosen", "no account is chosen for pay links to start from yet");
|
||||
Tap(d, "settings.connections");
|
||||
Check(Has(d, "connections.add") && d.ui.Find("connections.add")->label == "Add a connection", "the settings add a connection too, of whichever bank");
|
||||
Adding(d, "key");
|
||||
|
|
@ -811,6 +860,7 @@ namespace {
|
|||
d.ui.KeyDown(Key::Escape, {});
|
||||
Check(!d.ui.Tap("pay.submit") && !d.ui.Tap("bar.back") && d.ui.Focused().empty(), "under which the form is out of reach: of a finger, and of the key that sent it");
|
||||
Check(!d.app.Navigate("cards") && d.app.Screen() == "pay+working", "nor is the screen left by name while it is under way");
|
||||
Check(!d.app.Open(shopLink) && d.app.Screen() == "pay+working", "or for a link that asks for another payment");
|
||||
Settle(d);
|
||||
Shows(d.ui, "Paid €12.50 to Bob", "the payment made is said");
|
||||
Check(Has(d, "copy.Payment") && !Test::Says(d.ui, "Press a line to copy it"), "with the bank's number of it, which can be copied without a word about it");
|
||||
|
|
@ -906,6 +956,27 @@ namespace {
|
|||
Equal(d.app.Screen(), page, "which shows the account");
|
||||
Shows(d.ui, "Today", "and its payments");
|
||||
Tap(d, "bar.back");
|
||||
|
||||
// A link that asks for a payment, while no account is chosen for links to start from: its form starts from
|
||||
// the first account that pays anyone, which the bank lists the savings as, whichever account paid last. Which
|
||||
// account pays is the first thing asked, over the form, and a tap beside the question keeps that one.
|
||||
Tap(d, "home.pay");
|
||||
Shows(d.ui, "Main", "the pay form pays from the account that paid last");
|
||||
Tap(d, "bar.back");
|
||||
Check(d.app.Open(shopLink), "a link is taken");
|
||||
Build(d);
|
||||
Equal(d.app.Screen(), std::string("pay+accounts"), "and opens the pay form, with the choice of the account that pays over it");
|
||||
Shows(d.ui, "Choose an account", "which asks for one");
|
||||
Check(Has(d, std::format("pick.{}", aliceMain)) && Has(d, std::format("pick.{}", aliceSavings)), "of every account there is");
|
||||
Check(!d.ui.Tap("pay.submit") && !d.ui.Tap("bar.back"), "and covers the form, its button too");
|
||||
TapBeside(d);
|
||||
Equal(d.app.Screen(), std::string("pay"), "a tap beside it leaves the form");
|
||||
Shows(d.ui, "Savings", "paying from the first account, where none was chosen for links to start from");
|
||||
Hides(d.ui, "Main", "not from the one the form paid from last");
|
||||
Tap(d, "pay.from");
|
||||
Tap(d, std::format("pick.{}", aliceMain));
|
||||
Tap(d, "bar.back");
|
||||
Equal(d.app.Screen(), std::string("accounts"), "the way back from it leads to the accounts");
|
||||
}
|
||||
|
||||
// Asking for money, and the request sent looked at and revoked.
|
||||
|
|
@ -1300,11 +1371,11 @@ namespace {
|
|||
Tap(d, "nav.accounts");
|
||||
}
|
||||
|
||||
// The settings: the account that pays at checkout, what the app is, and the connections, removed by name and,
|
||||
// where two have one name, by number.
|
||||
// The settings: the account a pay link's form starts from, what the app is, and the connections, removed by name
|
||||
// and, where two have one name, by number.
|
||||
void Settings(Driver& d, Fake::Bus& bus, Fake::Bunq& bunq) {
|
||||
Tap(d, "nav.settings");
|
||||
for(const std::string_view said : {"Bank connections", "2 connected", "Pay at checkout from", "No account chosen", "About and security", "Nostro 1.2.3"}) {
|
||||
for(const std::string_view said : {"Bank connections", "2 connected", "Pay links start from", "No account chosen", "About and security", "Nostro 1.2.3"}) {
|
||||
Shows(d.ui, said, "the settings are listed");
|
||||
}
|
||||
Tap(d, "settings.about");
|
||||
|
|
@ -1316,15 +1387,19 @@ namespace {
|
|||
Tap(d, "bar.back");
|
||||
|
||||
Tap(d, "settings.checkout");
|
||||
Equal(d.app.Screen(), std::string("checkout"), "the account that pays at checkout has a page");
|
||||
Shows(d.ui, "Play money", "which lists the accounts");
|
||||
Equal(d.app.Screen(), std::string("checkout"), "the account pay links start from has a page");
|
||||
Shows(d.ui, "Pay links", "called after what it is for");
|
||||
Shows(d.ui, "A shop's pay link opens Nostro", "which says what a pay link is");
|
||||
Shows(d.ui, "choose another one", "and that the account is only where its form starts");
|
||||
Shows(d.ui, "Play money", "and lists the accounts");
|
||||
SetPolkit(bus, Fake::Polkit::Password, Bus::actionConnectors);
|
||||
Tap(d, std::format("checkout.{}", aliceMain));
|
||||
Shows(d.ui, "Letting apps ask you to pay from Main", "choosing one is under way");
|
||||
Shows(d.ui, "Having pay links start from Main", "choosing one is under way");
|
||||
Shows(d.ui, "Confirm it in your system's password dialog.", "and needs the password");
|
||||
Settle(d);
|
||||
Shows(d.ui, "Apps now ask you to pay from Main", "the choice is said");
|
||||
Shows(d.ui, "Pay links now start from Main", "the choice is said");
|
||||
Equal(Action(bus), std::string(Bus::actionConnectors), "after the password for changing connections");
|
||||
Equal(Summary(bus), std::format("have pay links start from {} (Main)", aliceMain), "which the system's dialog asked for in nostrod's words for it");
|
||||
Tap(d, "bar.back");
|
||||
Shows(d.ui, std::format("Main · {}", GroupIban(aliceMain)), "and shown in the settings");
|
||||
|
||||
|
|
@ -1350,6 +1425,7 @@ namespace {
|
|||
Shows(d.ui, "The API key itself stays valid", "with what stays valid at its bank, by the way it was connected");
|
||||
Tap(d, "confirm.no");
|
||||
Equal(d.app.Screen(), std::string("connections"), "and can be thought better of");
|
||||
const std::size_t reads = Answers(d, "DefaultCheckoutAccount ok");
|
||||
Tap(d, dave);
|
||||
Tap(d, "detail.remove");
|
||||
Tap(d, "confirm.yes");
|
||||
|
|
@ -1360,7 +1436,7 @@ namespace {
|
|||
Check(!Has(d, dave), "and no longer listed");
|
||||
Tap(d, "bar.back");
|
||||
Shows(d.ui, "1 connected", "one is left");
|
||||
Shows(d.ui, "Pay at checkout from", "and the checkout's account is read again");
|
||||
Equal(Answers(d, "DefaultCheckoutAccount ok"), reads + 1, "and the account pay links start from is read again: the connection may have held it");
|
||||
|
||||
// Two connections of one name: the one to remove is told apart by its accounts, and removed by its number.
|
||||
Client other = Client::System();
|
||||
|
|
@ -1548,12 +1624,301 @@ namespace {
|
|||
Tap(d, "bar.back");
|
||||
Tap(d, "nav.settings");
|
||||
Tap(d, "settings.checkout");
|
||||
Check(!d.ui.Find(std::format("checkout.{}", carolIban))->enabled && d.ui.Find(std::format("checkout.{}", aliceMain))->enabled, "nor can it pay at a checkout");
|
||||
Check(!d.ui.Find(std::format("checkout.{}", carolIban))->enabled && d.ui.Find(std::format("checkout.{}", aliceMain))->enabled, "nor can a pay link be set to start from it");
|
||||
Shows(d.ui, "Pays your own accounts only", "which is said");
|
||||
Tap(d, "bar.back");
|
||||
Tap(d, "nav.accounts");
|
||||
}
|
||||
|
||||
// A link that asks for a payment, as a website's pay button opens one. It fills in the pay form and does no more:
|
||||
// whoever wrote it chose the payee and the amount, so nothing is sent before the user presses the form's button
|
||||
// and the system's password dialog has said, in nostrod's own words, what is paid to whom.
|
||||
void Linking(Driver& d, Fake::Bus& bus, Fake::Bunq& bunq) {
|
||||
// One the app cannot read is said to be so over wherever the user is, with why, in the app's own words.
|
||||
Check(d.app.Open("payto://iban/NL00MARK?message=MARK"), "a link that cannot be read is taken all the same");
|
||||
Build(d);
|
||||
Equal(d.app.Screen(), std::string("accounts+link"), "and said to be one, over the accounts");
|
||||
Shows(d.ui, "This link cannot be opened", "by name");
|
||||
Shows(d.ui, "The IBAN in it is not a valid one.", "with why");
|
||||
Hides(d.ui, "MARK", "and with nothing of the link itself");
|
||||
TapBeside(d);
|
||||
Equal(d.app.Screen(), std::string("accounts"), "a tap beside it closes it");
|
||||
Check(d.app.Navigate("cards"), "the cards");
|
||||
Settle(d);
|
||||
Check(d.app.Open("https://example.org/pay"), "any other address is no payment");
|
||||
Build(d);
|
||||
Equal(d.app.Screen(), std::string("cards+link"), "which is said over the place the user is at: nothing is gone to for it");
|
||||
Shows(d.ui, "It is not a link to pay an IBAN", "with why");
|
||||
Tap(d, "link.close");
|
||||
Equal(d.app.Screen(), std::string("cards"), "and closed again");
|
||||
|
||||
// A link that can be read, from a page gone into: the pay form, filled in, and nothing asked or sent. Which
|
||||
// account pays is asked first, over the form, with the one chosen for pay links to start from as what the
|
||||
// form holds: Main, since the settings were gone through, which is not the account the bank lists first.
|
||||
Tap(d, "nav.settings");
|
||||
Tap(d, "settings.checkout");
|
||||
Equal(d.app.Screen(), std::string("checkout"), "a page of the settings");
|
||||
const std::size_t posts = bunq.Count("POST", "/user/");
|
||||
const std::size_t changes = Changes(bus);
|
||||
Check(d.app.Open(shopLink), "a link is taken from wherever the user is");
|
||||
Build(d);
|
||||
Equal(d.app.Screen(), std::string("pay+accounts"), "and opens the pay form, asking first which account pays");
|
||||
Shows(d.ui, "Choose an account", "in a list of the accounts");
|
||||
Check(Has(d, std::format("pick.{}", aliceMain)) && Has(d, std::format("pick.{}", aliceSavings)) && Has(d, std::format("pick.{}", carolIban)), "every one of them, whichever connection it is of");
|
||||
Shows(d.ui, "A link filled this in, not you.", "the form under it says that a link filled it in");
|
||||
for(const std::string_view said : {std::string_view(bobIban), std::string_view("Shop BV"), std::string_view("12.50"), std::string_view("Order 1234")}) {
|
||||
Shows(d.ui, said, "with what the link said, in the form's own fields");
|
||||
}
|
||||
// The question covers the form, as any sheet covers its page: the form's button cannot be pressed through it,
|
||||
// by a finger or by a key.
|
||||
d.ui.KeyDown(Key::Enter, {});
|
||||
d.ui.KeyDown(Key::Space, {});
|
||||
Check(!d.ui.Tap("pay.submit") && !d.ui.Tap("bar.back") && !d.ui.Tap("pay.to"), "the form is out of reach until the account is settled");
|
||||
Settle(d);
|
||||
Check(d.app.Screen() == "pay+accounts" && bunq.Count("POST", "/user/") == posts && Changes(bus) == changes && !d.app.Changing(), "nothing is sent, and the user is asked for no password: a link fills in a form");
|
||||
d.ui.KeyDown(Key::Escape, {});
|
||||
Build(d);
|
||||
Equal(d.app.Screen(), std::string("pay"), "Escape leaves the question");
|
||||
Shows(d.ui, "Main", "and the form paying from the account chosen for pay links to start from");
|
||||
Hides(d.ui, "Savings", "not from the first one");
|
||||
Bottom(d);
|
||||
Equal(d.ui.Find("pay.submit")->label, std::string("Pay"), "its button pays, as any pay form's does");
|
||||
|
||||
// The system's password dialog is where it is confirmed. Closed, nothing is paid, and the form is still the link's.
|
||||
SetPolkit(bus, Fake::Polkit::Dismiss, Bus::actionPay);
|
||||
Press(d, "pay.submit");
|
||||
Equal(d.app.Screen(), std::string("pay+problem"), "the button sends it to that dialog, with no question of the app's own before it");
|
||||
Shows(d.ui, "Not confirmed", "and a dialog closed is a payment not made");
|
||||
Equal(bunq.Count("POST", "/user/"), posts, "of which the bank hears nothing");
|
||||
Equal(Summary(bus), std::format("pay €12.50 to {} (Shop BV) from {} (Main)", bobIban, aliceMain), "the dialog said what the link asks for in nostrod's own words: the amount, the address before the name, and the account the form showed");
|
||||
Press(d, "problem.close");
|
||||
Top(d);
|
||||
Shows(d.ui, "A link filled this in, not you.", "the form is still said to be a link's");
|
||||
Shows(d.ui, "Order 1234", "and is as the link filled it in");
|
||||
SetPolkit(bus, Fake::Polkit::Password, Bus::actionPay);
|
||||
Bottom(d);
|
||||
Press(d, "pay.submit");
|
||||
Shows(d.ui, "Paid €12.50 to Shop BV", "confirmed there, it is paid");
|
||||
Equal(Action(bus), std::string(Bus::actionPay), "after the password for paying");
|
||||
Equal(bunq.Count("POST", "/user/"), posts + 1, "once");
|
||||
const std::string sent = LastPayment(bunq);
|
||||
Check(sent.contains(bobIban) && sent.contains("Shop BV") && sent.contains("12.50") && sent.contains("Order 1234"), "and the bank is sent what the form showed");
|
||||
Press(d, "done.close");
|
||||
Equal(d.app.Screen(), std::string("accounts"), "which leads to the accounts");
|
||||
Tap(d, "home.pay");
|
||||
Hides(d.ui, "A link filled this in", "the next pay form is nobody's but the user's");
|
||||
Hides(d.ui, "Order 1234", "and empty");
|
||||
Tap(d, "bar.back");
|
||||
|
||||
// An account picked from the choice a link opens with is the one that pays: the form shows it, and the
|
||||
// system's dialog names it. A tap beside the choice, like Escape, keeps the one the form started from.
|
||||
Check(d.app.Open(shopLink), "the link again");
|
||||
Tap(d, std::format("pick.{}", aliceSavings));
|
||||
Equal(d.app.Screen(), std::string("pay"), "an account picked there closes the choice");
|
||||
Shows(d.ui, "Savings", "and is the one the form pays from");
|
||||
Hides(d.ui, "Main", "in place of the one it started from");
|
||||
Shows(d.ui, "A link filled this in, not you.", "which leaves the form a link's");
|
||||
SetPolkit(bus, Fake::Polkit::Dismiss, Bus::actionPay);
|
||||
Bottom(d);
|
||||
Press(d, "pay.submit");
|
||||
Equal(Summary(bus), std::format("pay €12.50 to {} (Shop BV) from {} (Savings)", bobIban, aliceSavings), "the dialog names the account that was picked");
|
||||
SetPolkit(bus, Fake::Polkit::Password, Bus::actionPay);
|
||||
Press(d, "problem.close");
|
||||
Tap(d, "bar.back");
|
||||
Check(d.app.Open(shopLink), "and again");
|
||||
TapBeside(d);
|
||||
Equal(d.app.Screen(), std::string("pay"), "a tap beside the choice closes it too");
|
||||
Shows(d.ui, "Main", "with the account the form started from");
|
||||
Tap(d, "bar.back");
|
||||
|
||||
// A link that says no more than who is paid: the rest is the user's to fill in, and the form is checked as any.
|
||||
Check(d.app.Open(std::format("payto://iban/{}", bobIban)), "a link with an IBAN alone");
|
||||
TapBeside(d);
|
||||
Shows(d.ui, bobIban, "fills in who is paid");
|
||||
Bottom(d);
|
||||
Tap(d, "pay.submit");
|
||||
Top(d);
|
||||
Shows(d.ui, "The name of the account's holder", "and its form still lacks a name");
|
||||
Shows(d.ui, "Enter an amount", "and an amount");
|
||||
Check(!d.app.Changing() && bunq.Count("POST", "/user/") == posts + 1, "so nothing is sent");
|
||||
Tap(d, "bar.back");
|
||||
|
||||
// A name with an & in it, which the system's dialog does not show as it is: the form and the bank have the
|
||||
// link's name, and the dialog has it the way nostrod makes any name fit to show there, after the IBAN.
|
||||
Check(d.app.Open(std::format("payto://iban/{}?amount=EUR:1&receiver-name=Fish%20%26%20Chips", bobIban)), "a link whose name has an &");
|
||||
TapBeside(d);
|
||||
Shows(d.ui, "Fish & Chips", "has that name on its form as the link has it");
|
||||
Bottom(d);
|
||||
Press(d, "pay.submit");
|
||||
Shows(d.ui, "Paid €1.00 to Fish & Chips", "and is paid under it");
|
||||
Equal(Summary(bus), std::format("pay €1.00 to {} (Fish + Chips) from {} (Main)", bobIban, aliceMain), "the dialog showed the name in nostrod's way, after the IBAN it shows whole");
|
||||
Check(LastPayment(bunq).contains("Fish & Chips"), "and the bank is sent the name as the form had it");
|
||||
Press(d, "done.close");
|
||||
|
||||
// From an account whose connection pays between the user's own accounts only, what a link asks for is saved as
|
||||
// a draft, as anything paid to someone else from there is. The choice a link opens with offers that account
|
||||
// too, as the form's own does.
|
||||
Check(d.app.Open(shopLink), "the link again");
|
||||
Tap(d, std::format("pick.{}", carolIban));
|
||||
Shows(d.ui, "A payment to anyone else", "the form says what becomes of it from such an account");
|
||||
Bottom(d);
|
||||
Equal(d.ui.Find("pay.submit")->label, std::string("Save as draft"), "and its button that it saves a draft");
|
||||
Press(d, "pay.submit");
|
||||
Shows(d.ui, "Drafted €12.50 to Shop BV", "which it does");
|
||||
Equal(Action(bus), std::string(Bus::actionChange), "as a change that moves no money");
|
||||
Press(d, "done.close");
|
||||
|
||||
// A wide window has the app's places beside every page. A link's form left sideways is not opened again by
|
||||
// itself, and when the user goes back to it, what it holds is still said to be a link's.
|
||||
d.size = {0, 0, 1280, 800};
|
||||
Check(d.app.Open(shopLink), "the link in a wide window");
|
||||
Build(d);
|
||||
Equal(d.app.Screen(), std::string("pay+accounts"), "opens its form there too, under the same question");
|
||||
Check(!d.ui.Tap("nav.accounts") && !d.ui.Tap("pay.submit"), "which covers the places beside the form as well as the form");
|
||||
TapBeside(d);
|
||||
Equal(d.app.Screen(), std::string("pay"), "and is left by a tap beside it");
|
||||
Press(d, "nav.accounts");
|
||||
Press(d, "bar.refresh");
|
||||
Equal(d.app.Screen(), std::string("accounts"), "the accounts read again do not bring it back");
|
||||
Hides(d.ui, "A link asks for a payment", "and nothing waits");
|
||||
Tap(d, "home.pay");
|
||||
Shows(d.ui, "A link filled this in, not you.", "gone back to, the form is still said to be a link's");
|
||||
Shows(d.ui, "Order 1234", "for as long as it holds what the link said");
|
||||
Tap(d, "bar.back");
|
||||
Tap(d, "home.pay");
|
||||
Hides(d.ui, "A link filled this in", "which the way back empties it of");
|
||||
Tap(d, "bar.back");
|
||||
d.size = {0, 0, 400, 800};
|
||||
Build(d);
|
||||
}
|
||||
|
||||
// A link the app is started with is read before anything of the accounts is known: its form waits for them, and for
|
||||
// which of them pay links start from, and the accounts' page says that it does.
|
||||
void LinkWaiting(Fake::Bus& bus, sd_event* loop) {
|
||||
{
|
||||
Driver d(bus, loop);
|
||||
d.app.Start();
|
||||
Check(d.app.Open(shopLink), "a link is taken before the accounts are known");
|
||||
Build(d);
|
||||
Check(d.app.Busy() && d.app.Screen() == "accounts", "and waits for them, on the page they will be on");
|
||||
Shows(d.ui, "A link asks for a payment.", "which says that it does");
|
||||
Hides(d.ui, "Shop BV", "and nothing of what the link asks, which the form is for");
|
||||
Settle(d);
|
||||
Equal(d.app.Screen(), std::string("pay+accounts"), "its form opens once they are known, asking which of them pays");
|
||||
Shows(d.ui, "A link filled this in, not you.", "as a link's");
|
||||
Shows(d.ui, "Order 1234", "filled in");
|
||||
TapBeside(d);
|
||||
Equal(d.app.Screen(), std::string("pay"), "a tap beside the question leaves the form");
|
||||
Shows(d.ui, "Main", "paying from the account pay links start from");
|
||||
Hides(d.ui, "Savings", "which is not the first one");
|
||||
Tap(d, "bar.back");
|
||||
Hides(d.ui, "A link asks for a payment", "and the accounts' page has no more to say of it");
|
||||
}
|
||||
{
|
||||
// The accounts known, and which of them pay links start from not: that is read first.
|
||||
Driver d(bus, loop);
|
||||
d.app.Start();
|
||||
Settle(d);
|
||||
Check(d.app.Open(shopLink), "a link is taken once the accounts are known");
|
||||
Build(d);
|
||||
Check(d.app.Busy() && d.app.Screen() == "accounts", "and waits to hear which of them pay links start from");
|
||||
Shows(d.ui, "A link asks for a payment.", "saying so above the accounts");
|
||||
Shows(d.ui, "Savings", "which are listed meanwhile");
|
||||
Settle(d);
|
||||
Equal(d.app.Screen(), std::string("pay+accounts"), "and then opens its form, with the question over it");
|
||||
TapBeside(d);
|
||||
Shows(d.ui, "Main", "which pays from that account when it is left as it is");
|
||||
Hides(d.ui, "Savings", "and from no other");
|
||||
}
|
||||
{
|
||||
// No system bus: the link waits until the accounts can be read, which is tried again by hand.
|
||||
Driver d(bus, loop);
|
||||
d.noBus = true;
|
||||
d.app.Start();
|
||||
Check(d.app.Open(shopLink), "a link is taken without a system bus");
|
||||
Build(d);
|
||||
Shows(d.ui, "The system bus cannot be reached", "which is said as ever");
|
||||
Shows(d.ui, "A link asks for a payment.", "above the link that waits");
|
||||
d.noBus = false;
|
||||
Press(d, "overview.action");
|
||||
Equal(d.app.Screen(), std::string("pay+accounts"), "a link whose accounts could not be read opens when they can be");
|
||||
Shows(d.ui, "Order 1234", "as the link filled it in");
|
||||
TapBeside(d);
|
||||
Shows(d.ui, "Main", "from the account pay links start from, which is read with them");
|
||||
Hides(d.ui, "Savings", "and not from the first");
|
||||
}
|
||||
{
|
||||
// The user gone elsewhere while the accounts are read: what they are doing is not taken from them.
|
||||
Driver d(bus, loop);
|
||||
d.app.Start();
|
||||
Check(d.app.Open(shopLink), "a link is taken");
|
||||
Tap(d, "nav.cards");
|
||||
Settle(d);
|
||||
Equal(d.app.Screen(), std::string("cards"), "a user who went to another place meanwhile stays there");
|
||||
Shows(d.ui, "The link's payment was not opened", "and is told that the link was not opened");
|
||||
Tap(d, "nav.accounts");
|
||||
Hides(d.ui, "A link asks for a payment", "the link is dropped");
|
||||
Tap(d, "home.pay");
|
||||
Hides(d.ui, "A link filled this in", "and nothing of it is in the pay form");
|
||||
Hides(d.ui, "Order 1234", "which is empty");
|
||||
}
|
||||
{
|
||||
// The user being told something when the accounts arrive: the form is not opened over that either.
|
||||
Driver d(bus, loop);
|
||||
d.app.Start();
|
||||
Check(d.app.Open(shopLink) && d.app.Open("payto://iban/NL00MARK"), "a link that cannot be read, after one that waits");
|
||||
Settle(d);
|
||||
Equal(d.app.Screen(), std::string("accounts+link"), "is said to be one, and stays said");
|
||||
Shows(d.ui, "This link cannot be opened", "by name");
|
||||
Tap(d, "link.close");
|
||||
Equal(d.app.Screen(), std::string("accounts"), "and the link that waited is not opened under it");
|
||||
Tap(d, "home.pay");
|
||||
Hides(d.ui, "Order 1234", "nor left in the pay form");
|
||||
}
|
||||
{
|
||||
// The accounts known, and the system bus gone by the time the link comes: the reading of the account pay
|
||||
// links start from fails at once, inside the call that opens the link. The form opens all the same, once.
|
||||
Driver d(bus, loop);
|
||||
d.app.Start();
|
||||
Settle(d);
|
||||
d.noBus = true;
|
||||
bus.DisconnectOwn();
|
||||
RunUntil(d.loop, [] { return false; }, std::chrono::seconds(1));
|
||||
Check(d.app.Open(shopLink), "a link is taken with the accounts known and the system bus gone");
|
||||
Build(d);
|
||||
Equal(d.app.Screen(), std::string("pay+accounts"), "and opens its form from the accounts as they were known");
|
||||
Hides(d.ui, "The link's payment was not opened", "which is not said to be unopened over its own form");
|
||||
TapBeside(d);
|
||||
Shows(d.ui, "Order 1234", "and is filled in as the link has it");
|
||||
}
|
||||
{
|
||||
// Another user of the machine, who chose no account for pay links to start from, and whose first connection
|
||||
// pays between their own accounts only: the form starts from the first account that pays anybody, which is
|
||||
// their second connection's.
|
||||
{
|
||||
std::lock_guard lock(bus.mutex);
|
||||
bus.clientUid = erinUid;
|
||||
bus.logindNames[erinUid] = "erin";
|
||||
}
|
||||
Client erin = Client::System();
|
||||
erin.AddBunqOAuth("production", "fake-client", "fake-secret", "http://127.0.0.1/cb", "code-carol-erin");
|
||||
erin.AddBunq(daveKey, "*", "");
|
||||
Driver d(bus, loop);
|
||||
d.app.Start();
|
||||
Check(d.app.Open(shopLink), "a link for a user who chose no account to start from");
|
||||
Settle(d);
|
||||
Equal(d.app.Screen(), std::string("pay+accounts"), "opens its form under the choice of their accounts");
|
||||
Check(Has(d, std::format("pick.{}", carolIban)) && Has(d, std::format("pick.{}", daveIban)), "both of them");
|
||||
TapBeside(d);
|
||||
Shows(d.ui, "Play money", "and starts from the first account that pays anybody");
|
||||
Hides(d.ui, "Shared", "which is not their first account: that one's connection pays their own accounts only");
|
||||
{
|
||||
std::lock_guard lock(bus.mutex);
|
||||
bus.clientUid = uid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// An account that goes while the app is looking at it: nostrod no longer knows it, and the app looks again.
|
||||
void Vanishing(Driver& d, Fake::Bus& bus, Fake::Bunq& bunq) {
|
||||
Client other = Client::System();
|
||||
|
|
@ -1648,7 +2013,7 @@ namespace {
|
|||
Tap(d, "bar.back");
|
||||
Tap(d, "nav.accounts");
|
||||
Shows(d.ui, "No answer yet", "where it is said too");
|
||||
// The settings while the account that pays at checkout cannot be read.
|
||||
// The settings while the account pay links start from cannot be read.
|
||||
SetPolkit(bus, Fake::Polkit::Deny, Bus::actionView);
|
||||
Check(d.app.Navigate("settings"), "the settings");
|
||||
Build(d);
|
||||
|
|
@ -1857,6 +2222,7 @@ int main(int argc, char* argv[]) {
|
|||
const std::uint64_t carol = bunq.AddPerson("Carol", "key-carol");
|
||||
bunq.AddAccount(carol, carolIban, "Shared", 500);
|
||||
bunq.AddGrant(carol, "code-carol", "token-carol");
|
||||
bunq.AddGrant(carol, "code-carol-erin", "token-carol-erin");
|
||||
const std::uint64_t dave = bunq.AddPerson("Dave", daveKey);
|
||||
bunq.AddAccount(dave, daveIban, "Play money", 12345);
|
||||
bunq.AddAccount(bunq.AddPerson("Alice", "key-alice-two"), otherAliceIban, "Other", 100);
|
||||
|
|
@ -1877,11 +2243,13 @@ int main(int argc, char* argv[]) {
|
|||
Cards(d, bus, bunq, alice);
|
||||
Settings(d, bus, bunq);
|
||||
OAuth(d, bus, bunq);
|
||||
Linking(d, bus, bunq);
|
||||
Vanishing(d, bus, bunq);
|
||||
Sizes(d);
|
||||
Routes(d);
|
||||
Late(bus, loop);
|
||||
Bare(bus, loop);
|
||||
LinkWaiting(bus, loop);
|
||||
Reconnecting(bus, loop);
|
||||
Gone(d, bus, nostrod);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@
|
|||
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
// Currencies and amounts (Nostro:Currency) and the text helpers (Nostro:Utils): every parse with what it refuses,
|
||||
// every format, and the local-time helpers with a fixed time zone so the expectations hold anywhere.
|
||||
// every format, the local-time helpers with a fixed time zone so the expectations hold anywhere, and which characters
|
||||
// draw nothing or are a space.
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
|
@ -93,6 +94,35 @@ namespace {
|
|||
Check(!QueryParameter(url, "missing"), "a parameter that is not there");
|
||||
Check(!QueryParameter("https://example.com/cb", "code"), "a URL without a query");
|
||||
}
|
||||
|
||||
using Range = std::pair<std::uint32_t, std::uint32_t>;
|
||||
|
||||
// What a password dialog is kept free of, written out again: a change to the library's list shows here.
|
||||
constexpr std::array<Range, 31> unshown = {{
|
||||
{0x0000, 0x001F}, {0x007F, 0x009F}, {0x00AD, 0x00AD}, {0x034F, 0x034F}, {0x0600, 0x0605}, {0x061C, 0x061C}, {0x06DD, 0x06DD}, {0x070F, 0x070F},
|
||||
{0x0890, 0x0891}, {0x08E2, 0x08E2}, {0x115F, 0x1160}, {0x17B4, 0x17B5}, {0x180B, 0x180F}, {0x200B, 0x200F}, {0x2028, 0x202E}, {0x2060, 0x206F},
|
||||
{0x3164, 0x3164}, {0xD800, 0xF8FF}, {0xFDD0, 0xFDEF}, {0xFE00, 0xFE0F}, {0xFEFF, 0xFEFF}, {0xFFA0, 0xFFA0}, {0xFFF0, 0xFFFC}, {0xFFFE, 0xFFFF},
|
||||
{0x110BD, 0x110BD}, {0x110CD, 0x110CD}, {0x13430, 0x1343F}, {0x1BCA0, 0x1BCA3}, {0x1D173, 0x1D17A}, {0xE0000, 0xE0FFF}, {0xF0000, 0xFFFFFFFF},
|
||||
}};
|
||||
constexpr std::array<Range, 8> blank = {{
|
||||
{0x0020, 0x0020}, {0x00A0, 0x00A0}, {0x1680, 0x1680}, {0x2000, 0x200A}, {0x202F, 0x202F}, {0x205F, 0x205F}, {0x2800, 0x2800}, {0x3000, 0x3000},
|
||||
}};
|
||||
|
||||
// Each range at both of its ends, and not what lies just outside it.
|
||||
void Characters() {
|
||||
for(const Range& range : unshown) {
|
||||
Check(Unshown(range.first) && Unshown(range.second), std::format("U+{:04X} to U+{:04X} draw nothing", range.first, range.second));
|
||||
Check((range.first == 0 || !Unshown(range.first - 1)) && (range.second == 0xFFFFFFFF || !Unshown(range.second + 1)), std::format("and what is beside U+{:04X} to U+{:04X} is drawn", range.first, range.second));
|
||||
}
|
||||
for(const std::uint32_t drawn : {0x41U, 0xE9U, 0x20ACU, 0xFFFDU, 0x1F600U}) {
|
||||
Check(!Unshown(drawn), std::format("U+{:04X} is drawn", drawn));
|
||||
}
|
||||
for(const Range& range : blank) {
|
||||
Check(Blank(range.first) && Blank(range.second), std::format("U+{:04X} to U+{:04X} are spaces", range.first, range.second));
|
||||
Check(!Blank(range.first - 1) && !Blank(range.second + 1), std::format("and what is beside U+{:04X} to U+{:04X} is none", range.first, range.second));
|
||||
}
|
||||
Check(!Blank('a') && !Blank(0x200B), "a letter is no space, and neither is a space without a width, which draws nothing");
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
|
@ -102,5 +132,6 @@ int main() {
|
|||
Timestamps();
|
||||
LocalTime();
|
||||
Urls();
|
||||
Characters();
|
||||
return Test::Result();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -264,9 +264,10 @@ namespace {
|
|||
Fails({"cards", "freeze"}, "card id not provided");
|
||||
}
|
||||
|
||||
void Checkouts() {
|
||||
Works({"checkout", "account"}, "no account pays at checkout: `nostro checkout account <account>` chooses one");
|
||||
Works({"checkout", "account", annIban}, std::format("checkouts pay from Main\tBUNQNL2A {}\t€", annIban));
|
||||
// The account a pay link's form starts from in the app, which the command line can choose too.
|
||||
void PayLinkAccount() {
|
||||
Works({"checkout", "account"}, "no account is chosen for pay links to start from: `nostro checkout account <account>` chooses one");
|
||||
Works({"checkout", "account", annIban}, std::format("pay links start from Main\tBUNQNL2A {}\t€", annIban));
|
||||
Works({"checkout", "account"}, std::format("Main\tBUNQNL2A {}", annIban));
|
||||
Fails({"checkout", "account", std::string(carolIban)}, "is reached through OAuth, which pays only your own accounts");
|
||||
Fails({"checkout", "accounts"}, "unknown checkout command 'accounts'");
|
||||
|
|
@ -337,11 +338,10 @@ int main(int argc, char* argv[]) {
|
|||
Paying(bunq);
|
||||
Requesting();
|
||||
Cards(bunq, ann);
|
||||
Checkouts();
|
||||
PayLinkAccount();
|
||||
Removing(bunq);
|
||||
|
||||
bus.Disconnect("net.catcrafts.Nostro1");
|
||||
Equal(Fake::Wait(nostrod), 0, "nostrod ends when the bus goes");
|
||||
Check(bus.WaitForName("net.catcrafts.Nostro1.Checkout", false), "and its checkout with it");
|
||||
return Test::Result();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@
|
|||
|
||||
// nostrod on a fake system bus (tests/Support/FakeBus.inc) in front of a fake bunq (tests/Support/FakeBunq.inc): the
|
||||
// daemon and its workers are this executable again (nostrod's main is compiled in), every call goes through
|
||||
// Nostro::Client or Nostro::Checkout, and the bus plays each user by the uid it gives a connection. Users kept apart, a
|
||||
// uid handed to a new user, every polkit answer and what the dialog is told, calls that wait on each other or do not,
|
||||
// checkouts and their retries, workers that die, idle exits, and how each error reaches the client.
|
||||
// Nostro::Client, and the bus plays each user by the uid it gives a connection. Users kept apart, a uid handed to a new
|
||||
// user, every polkit answer and what the dialog is told, calls that wait on each other or do not, the account pay
|
||||
// links start from, workers that die, idle exits, and how each error reaches the client.
|
||||
|
||||
#include "../../lib/json.hpp"
|
||||
#include <poll.h>
|
||||
|
|
@ -22,7 +22,6 @@
|
|||
|
||||
import std;
|
||||
import Nostro;
|
||||
import Nostro.Checkout;
|
||||
import Crafter.Network;
|
||||
|
||||
#define main NostrodMain
|
||||
|
|
@ -46,6 +45,7 @@ namespace {
|
|||
constexpr std::uint32_t aliceUid = 4242;
|
||||
constexpr std::uint32_t bobUid = 4343;
|
||||
constexpr std::string_view name = "net.catcrafts.Nostro1";
|
||||
// The second name nostrod had until 2026-11-22, for a checkout over D-Bus that is gone.
|
||||
constexpr std::string_view checkoutName = "net.catcrafts.Nostro1.Checkout";
|
||||
const std::string aliceMain = "NL23BUNQ2025123456";
|
||||
const std::string aliceOther = "NL46BUNQ2025111111";
|
||||
|
|
@ -76,8 +76,6 @@ namespace {
|
|||
call();
|
||||
} catch(const DaemonError& e) {
|
||||
return Failure{e.name, e.what()};
|
||||
} catch(const Checkout::Error& e) {
|
||||
return Failure{e.name, e.what()};
|
||||
} catch(const std::exception& e) {
|
||||
return Failure{"exception", e.what()};
|
||||
}
|
||||
|
|
@ -203,22 +201,25 @@ namespace {
|
|||
return served;
|
||||
}
|
||||
|
||||
// The published contract: packaging/dbus/net.catcrafts.Nostro1.xml and net.catcrafts.Nostro1.Checkout.xml are the
|
||||
// interfaces nostrod serves, each under its own name alone, and the polkit policy declares every action nostrod asks
|
||||
// about and no other, each owned by the user nostrod runs as, with a dialog that uses no detail nostrod does not set,
|
||||
// and each but seeing asking for the user's password as it is shipped.
|
||||
// The published contract: packaging/dbus/net.catcrafts.Nostro1.xml is the interface nostrod serves, under the one
|
||||
// name it has, and the polkit policy declares every action nostrod asks about and no other, each owned by the user
|
||||
// nostrod runs as, with a dialog that uses no detail nostrod does not set, and each but seeing asking for the
|
||||
// user's password as it is shipped.
|
||||
void Contract(Fake::Bus& bus) {
|
||||
const std::string served = Introspect(bus, name);
|
||||
Check(Interface(served, name) == Interface(Slurp("packaging/dbus/net.catcrafts.Nostro1.xml"), name), std::format("packaging/dbus/net.catcrafts.Nostro1.xml is the interface nostrod serves, which is:\n{}", served));
|
||||
const std::string checkout = Introspect(bus, checkoutName);
|
||||
Check(Interface(checkout, checkoutName) == Interface(Slurp("packaging/dbus/net.catcrafts.Nostro1.Checkout.xml"), checkoutName), std::format("packaging/dbus/net.catcrafts.Nostro1.Checkout.xml is the checkout nostrod serves, which is:\n{}", checkout));
|
||||
// An app allowed to talk to the checkout's name reaches nothing else through it.
|
||||
Check(Interface(served, checkoutName).empty() && Interface(checkout, name).empty(), "each name serves its own interface alone");
|
||||
Check(!Raw(bus, checkoutName, name, "Connectors", true, [](sd_bus_message*) {}).empty(), "the checkout's name answers no other method");
|
||||
const std::string payHere = Raw(bus, name, checkoutName, "Pay", true, [](sd_bus_message* call) {
|
||||
// nostrod has no checkout: the interface that paid an app's order is gone, with its name. What a shop wants
|
||||
// paid reaches the user as a link, which only the app shows, and only as a form.
|
||||
const auto order = [](sd_bus_message* call) {
|
||||
sd_bus_message_append(call, "ssxssa{sv}", shopIban.c_str(), "Shop", std::int64_t{100}, "EUR", "1", 0u);
|
||||
});
|
||||
Check(!payHere.empty(), "and the other name pays no checkout");
|
||||
};
|
||||
Check(Interface(served, checkoutName).empty() && !fs::exists("packaging/dbus/net.catcrafts.Nostro1.Checkout.xml"), "nostrod serves no checkout, and none is published");
|
||||
Equal(Raw(bus, checkoutName, checkoutName, "Pay", true, order), std::string(SD_BUS_ERROR_SERVICE_UNKNOWN), "nobody owns the name a checkout had");
|
||||
Check(!Raw(bus, name, checkoutName, "Pay", true, order).empty() && !Raw(bus, name, name, "Pay", true, order).empty(), "and nostrod's own name pays no order");
|
||||
// The bus's policy still lets nostrod own that name: the nostrod of 0.0.0 asks for it when it starts, and the
|
||||
// system files may be newer than the Flatpak it runs from. It lets nobody call it.
|
||||
const std::string busPolicy = Slurp("packaging/system/net.catcrafts.Nostro1.conf");
|
||||
Check(busPolicy.contains(std::format("<allow own=\"{}\"/>", checkoutName)) && !busPolicy.contains(std::format("send_destination=\"{}\"", checkoutName)), "the bus's policy lets an older nostrod own the name it had, and lets nobody call it");
|
||||
|
||||
const std::string policy = Slurp("packaging/system/net.catcrafts.Nostro1.policy");
|
||||
std::vector<std::string> declared;
|
||||
|
|
@ -235,7 +236,7 @@ namespace {
|
|||
Check(action.substr(key).starts_with("$(summary)"), std::format("{} shows only details nostrod sets", declared.back()));
|
||||
}
|
||||
}
|
||||
const std::vector<std::string> asked = {std::string(Bus::actionView), std::string(Bus::actionChange), std::string(Bus::actionPay), std::string(Bus::actionUnfreezeCard), std::string(Bus::actionBlockCard), std::string(Bus::actionConnectors), std::string(Bus::actionCheckout)};
|
||||
const std::vector<std::string> asked = {std::string(Bus::actionView), std::string(Bus::actionChange), std::string(Bus::actionPay), std::string(Bus::actionUnfreezeCard), std::string(Bus::actionBlockCard), std::string(Bus::actionConnectors)};
|
||||
Check(std::ranges::is_permutation(declared, asked), "the policy declares the actions nostrod asks about, and no other");
|
||||
}
|
||||
|
||||
|
|
@ -458,7 +459,7 @@ namespace {
|
|||
{"answering a request", [&alice] { alice.RespondToRequest(aliceMain, 1, true); }, "see your incoming requests for money"},
|
||||
{"answering a draft", [&alice] { alice.RespondToDraftPayment(aliceMain, 1, false); }, "see your draft payments"},
|
||||
{"a card's status", [&alice] { alice.SetCardStatus(1, "LOST"); }, "see your cards"},
|
||||
{"the account that pays at checkout", [&alice] { alice.SetDefaultCheckoutAccount("Nope"); }, accounts},
|
||||
{"the account pay links start from", [&alice] { alice.SetDefaultCheckoutAccount("Nope"); }, accounts},
|
||||
{"removing a connector", [&alice] { alice.RemoveConnector("Nobody"); }, "see your bank connectors"},
|
||||
{"the transactions of an account nobody has", [&alice] { alice.Transactions("Nope", {}); }, "see your transactions"},
|
||||
{"a listing of one", [&alice] { alice.Requests("Nope"); }, "see your requests for money"},
|
||||
|
|
@ -602,216 +603,26 @@ namespace {
|
|||
Equal(unknown, std::string(), "a query key nostrod does not know");
|
||||
}
|
||||
|
||||
// A stand-in for nostrod's checkout, for answers nostrod never gives, chosen by the order's reference: "extra", a
|
||||
// result the client does not know; "shape", an answer of another shape; "odd", an error of another name; "bare", an
|
||||
// error without a message; anything else, no answer at all. A plain object rather than a vtable, whose answers sd-bus would hold to its signature.
|
||||
class FakeCheckout {
|
||||
public:
|
||||
FakeCheckout() {
|
||||
sd_bus_open_system(&bus);
|
||||
sd_bus_add_object(bus, nullptr, "/net/catcrafts/Nostro1", OnCall, nullptr);
|
||||
sd_bus_request_name(bus, "net.catcrafts.Nostro1.Checkout", 0);
|
||||
thread = std::thread([this] {
|
||||
while(!stop) {
|
||||
while(sd_bus_process(bus, nullptr) > 0) {
|
||||
}
|
||||
sd_bus_wait(bus, 20000);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
FakeCheckout(const FakeCheckout&) = delete;
|
||||
FakeCheckout& operator=(const FakeCheckout&) = delete;
|
||||
|
||||
~FakeCheckout() {
|
||||
stop = true;
|
||||
thread.join();
|
||||
sd_bus_flush_close_unref(bus);
|
||||
}
|
||||
|
||||
private:
|
||||
static std::int32_t OnCall(sd_bus_message* call, void*, sd_bus_error*) {
|
||||
if(!sd_bus_message_is_method_call(call, "net.catcrafts.Nostro1.Checkout", "Pay")) {
|
||||
return 0;
|
||||
}
|
||||
sd_bus_message_skip(call, "ssxs");
|
||||
// sd-bus hands strings out as C strings.
|
||||
// lint-disable-next-line no-char-pointer
|
||||
const char* reference = nullptr;
|
||||
sd_bus_message_read_basic(call, 's', &reference);
|
||||
const std::string_view kind(reference);
|
||||
if(kind == "extra") {
|
||||
return sd_bus_reply_method_return(call, "ta{sv}", std::uint64_t{7}, 2u, "colour", "s", "blue", "repeated", "b", 1);
|
||||
}
|
||||
if(kind == "shape") {
|
||||
return sd_bus_reply_method_return(call, "s", "nonsense");
|
||||
}
|
||||
if(kind == "odd") {
|
||||
return sd_bus_reply_method_errorf(call, "org.example.Odd", "an error of another name");
|
||||
}
|
||||
if(kind == "bare") {
|
||||
const sd_bus_error bare = {"org.example.Bare", nullptr, 0};
|
||||
return sd_bus_reply_method_error(call, &bare);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
sd_bus* bus = nullptr;
|
||||
std::thread thread;
|
||||
std::atomic<bool> stop{false};
|
||||
};
|
||||
|
||||
// Nostro.Checkout's own side: with no nostro on the bus, and against a stand-in for nostrod's checkout.
|
||||
void CheckoutClient(Fake::Bus& bus) {
|
||||
Checkout::Order order{.payeeIban = shopIban, .payeeName = "Shop", .amount = 1250, .reference = "1"};
|
||||
const Failure missing = FailureOf([&order] { Checkout::Pay(order); });
|
||||
Check(missing.name == SD_BUS_ERROR_SERVICE_UNKNOWN && missing.message.contains("nostro is not installed"), std::format("a checkout without nostro: {}", missing.message));
|
||||
Throws<std::invalid_argument>([] { Checkout::Pay({.payeeIban = "\xFF", .amount = 1, .reference = "1"}); }, "not UTF-8", "an order that is not UTF-8");
|
||||
|
||||
const auto pay = [&order](std::string_view reference, std::chrono::seconds timeout) {
|
||||
order.reference = std::string(reference);
|
||||
return Checkout::Pay(order, timeout);
|
||||
};
|
||||
{
|
||||
const FakeCheckout stand;
|
||||
Check(bus.WaitForName(checkoutName), "a stand-in for nostrod's checkout");
|
||||
const Checkout::Paid extra = pay("extra", std::chrono::seconds(20));
|
||||
Check(extra.paymentId == 7 && extra.repeated, "results the client does not know are skipped");
|
||||
Throws<std::system_error>([&pay] { pay("shape", std::chrono::seconds(20)); }, "cannot read nostrod's answer", "an answer of another shape");
|
||||
const Failure odd = FailureOf([&pay] { pay("odd", std::chrono::seconds(20)); });
|
||||
Check(odd.name == "org.example.Odd" && odd.message == "an error of another name", "an error of another name, as it came");
|
||||
const Failure bare = FailureOf([&pay] { pay("bare", std::chrono::seconds(20)); });
|
||||
Check(bare.name == "org.example.Bare" && bare.message.empty(), "and one without a message");
|
||||
const Failure late = FailureOf([&pay] { pay("silent", std::chrono::seconds(1)); });
|
||||
Check(late.name == SD_BUS_ERROR_TIMEOUT && late.message.contains("the order may have been paid"), std::format("no answer in time: {}", late.message));
|
||||
}
|
||||
Check(bus.WaitForName(checkoutName, false), "and the stand-in gone");
|
||||
}
|
||||
|
||||
// nostrod's side of a checkout: the account that pays, the prompt, the record that answers a retry, and every way an
|
||||
// order is refused.
|
||||
void Checkouts(Fake::Bus& bus, Fake::Bunq& bunq, const Bank& bank) {
|
||||
// The account a pay link's form starts from in the app, which nostrod keeps for the user and pays nothing from by
|
||||
// itself: none until one is chosen, never one that could pay no shop, chosen with the password that changing the
|
||||
// connections takes, and no longer chosen once the account is gone.
|
||||
void CheckoutAccount(Fake::Bus& bus, Fake::Bunq& bunq, const Bank& bank) {
|
||||
Client alice = As(bus, aliceUid);
|
||||
const auto pay = [&bus](const Checkout::Order& order) {
|
||||
{
|
||||
std::lock_guard lock(bus.mutex);
|
||||
bus.clientUid = aliceUid;
|
||||
}
|
||||
return Checkout::Pay(order);
|
||||
};
|
||||
const auto checks = [&bus](std::string_view reference) {
|
||||
std::lock_guard lock(bus.mutex);
|
||||
return std::ranges::count_if(bus.checks, [reference](const Fake::PolkitCheck& check) { return check.details.contains("reference") && check.details.at("reference") == reference; });
|
||||
};
|
||||
const std::string payments = std::format("/user/{}/monetary-account/{}/payment", bank.alice, bank.aliceMainId);
|
||||
const Checkout::Order order{.payeeIban = shopIban, .payeeName = "Shop", .amount = 1250, .reference = "order-1"};
|
||||
|
||||
Check(!alice.DefaultCheckoutAccount().has_value() && Summary(bus) == "see which account pays at checkout", "no account pays at checkout until one is chosen");
|
||||
Throws<Checkout::NoCheckoutAccount>([&pay, &order] { pay(order); }, "no account is chosen to pay checkouts from", "a checkout before an account is chosen");
|
||||
Check(!alice.DefaultCheckoutAccount().has_value() && Summary(bus) == "see which account pay links start from", "no account is the one pay links start from until one is chosen");
|
||||
Throws<std::invalid_argument>([&alice] { alice.SetDefaultCheckoutAccount(carolIban); }, "is reached through OAuth, which pays only your own accounts", "an account that could pay no shop");
|
||||
const Account chosen = alice.SetDefaultCheckoutAccount(aliceMain);
|
||||
Check(chosen.iban == aliceMain && chosen.name == "Main", "an account chosen, and shown");
|
||||
Check(bus.LastCheck().action == "net.catcrafts.Nostro1.Connectors" && Summary(bus) == std::format("let apps ask you to pay from {} (Main) at checkout", aliceMain), "choosing it is a change to the connections");
|
||||
Equal(alice.DefaultCheckoutAccount().value_or(Account{}).iban, aliceMain, "the account checkouts pay from");
|
||||
|
||||
const std::size_t before = bunq.Count("POST", payments);
|
||||
const Checkout::Paid paid = pay(order);
|
||||
Check(paid.paymentId != 0 && !paid.repeated, "an order paid");
|
||||
const Fake::PolkitCheck check = bus.LastCheck();
|
||||
Equal(check.action, std::string("net.catcrafts.Nostro1.Checkout"), "paying at checkout is an action of its own");
|
||||
Equal(check.details.at("summary"), std::format("pay €12.50 to {} (Shop) from {} (Main), as an app asks at checkout, reference order-1", shopIban, aliceMain), "the dialog shows the order, and the account that pays it");
|
||||
Check(check.details.at("reference") == "order-1" && check.details.at("amount_minor") == "1250" && check.details.at("account_iban") == aliceMain && check.details.at("counterparty") == shopIban, "and gives polkit rules the details");
|
||||
Equal(bunq.Count("POST", payments), before + 1, "one payment");
|
||||
Check(check.action == "net.catcrafts.Nostro1.Connectors" && Summary(bus) == std::format("have pay links start from {} (Main)", aliceMain), "choosing it is a change to the connections, and the dialog says what is chosen");
|
||||
Check(check.details.at("account_iban") == aliceMain && check.details.at("environment") == "production", "with the details a rule can test");
|
||||
Equal(alice.DefaultCheckoutAccount().value_or(Account{}).iban, aliceMain, "the account pay links start from");
|
||||
|
||||
const Checkout::Paid again = pay(order);
|
||||
Check(again.paymentId == paid.paymentId && again.repeated, "the same order again answers with its payment");
|
||||
Check(checks("order-1") == 1 && bunq.Count("POST", payments) == before + 1, "without asking, or paying, again");
|
||||
|
||||
const auto refused = [&pay](Checkout::Order changed, std::string_view part, std::string_view what) {
|
||||
const Failure failure = FailureOf([&pay, &changed] { pay(changed); });
|
||||
Check(failure.name == Checkout::errorInvalidArgument && failure.message.contains(part), std::format("{}: {}", what, failure.message));
|
||||
};
|
||||
Checkout::Order changed = order;
|
||||
changed.amount = 1300;
|
||||
refused(changed, "reference order-1 to NL91ABNA0417164300 is an order of another amount than €13.00", "a reference paid for another amount");
|
||||
// Which amount it was paid for is not said: whoever knows an order's payee and reference could ask for it.
|
||||
const Failure other = FailureOf([&pay, &changed] { pay(changed); });
|
||||
Check(!other.message.contains("12.50") && !other.message.contains("1250"), std::format("and not for which amount: {}", other.message));
|
||||
changed = order;
|
||||
changed.payeeIban = "shop@example.com";
|
||||
refused(changed, "checkout pays an IBAN, and 'shop@example.com' is none", "a payee that is no IBAN");
|
||||
changed.payeeIban = "NL00BUNQ0000000000";
|
||||
refused(changed, "is not a valid IBAN", "an IBAN with a typo");
|
||||
changed = order;
|
||||
changed.amount = 0;
|
||||
refused(changed, "more than zero", "nothing to pay");
|
||||
changed = order;
|
||||
changed.currency = "USD";
|
||||
refused(changed, "unsupported currency 'USD'", "a currency nostro does not pay in");
|
||||
changed = order;
|
||||
changed.reference = "";
|
||||
refused(changed, "an order needs a reference", "an order without a reference");
|
||||
|
||||
// bunq refusing it before doing anything: the order was not paid, and is paid when asked again.
|
||||
Checkout::Order refusedOrder = order;
|
||||
refusedOrder.reference = "order-2";
|
||||
bunq.Fail(Fault{.method = "POST", .path = "/user/", .status = 400, .body = R"({"Error":[{"error_description":"Not enough money."}]})"});
|
||||
const Failure poor = FailureOf([&pay, &refusedOrder] { pay(refusedOrder); });
|
||||
Check(poor.name == Checkout::errorBank && poor.message.contains("bunq: Not enough money. (400)"), std::format("bunq's refusal: {}", poor.message));
|
||||
// The app is told what the bank said, and not which call it said it to: that names the user and the account.
|
||||
const auto namesNoAccount = [](const Failure& failure) {
|
||||
return !failure.message.contains("/user/") && !failure.message.contains("monetary-account") && !failure.message.contains(aliceMain);
|
||||
};
|
||||
Check(namesNoAccount(poor), std::format("without the user or the account at the bank: {}", poor.message));
|
||||
Check(!pay(refusedOrder).repeated, "and the order paid when asked again");
|
||||
|
||||
// bunq's answer lost: the order may have been paid, and is not paid again.
|
||||
Checkout::Order lostOrder = order;
|
||||
lostOrder.reference = "order-3";
|
||||
bunq.Fail(Fault{.method = "POST", .path = "/user/", .status = 500, .body = R"({"Error":[{"error_description":"Hiccup."}]})"});
|
||||
const Failure hiccup = FailureOf([&pay, &lostOrder] { pay(lostOrder); });
|
||||
Check(hiccup.name == Checkout::errorBank && hiccup.message.contains("may have been carried out") && namesNoAccount(hiccup), std::format("an answer that may hide a payment, also without the account: {}", hiccup.message));
|
||||
const Failure lost = FailureOf([&pay, &lostOrder] { pay(lostOrder); });
|
||||
Check(lost.name == Checkout::errorFailed && lost.message.contains("order order-3 to NL91ABNA0417164300 may have been paid already") && !lost.message.contains(aliceMain), std::format("such an order asked again, without the account: {}", lost.message));
|
||||
|
||||
Checkout::Order unconfirmed = order;
|
||||
unconfirmed.reference = "order-4";
|
||||
SetPolkit(bus, Fake::Polkit::Dismiss, Bus::actionCheckout);
|
||||
Throws<Checkout::Cancelled>([&pay, &unconfirmed] { pay(unconfirmed); }, "you did not authenticate", "an order the user did not confirm");
|
||||
|
||||
// Asked again while the user is still at the prompt: the second call waits for the first, and gets its answer.
|
||||
SetPolkit(bus, Fake::Polkit::Slow, Bus::actionCheckout);
|
||||
Checkout::Paid first;
|
||||
std::thread paying([&pay, &unconfirmed, &first] { first = pay(unconfirmed); });
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(300));
|
||||
changed = unconfirmed;
|
||||
changed.amount = 99;
|
||||
refused(changed, "is an order of another amount than €0.99", "another amount while the order is being paid");
|
||||
const Checkout::Paid waited = pay(unconfirmed);
|
||||
paying.join();
|
||||
Check(first.paymentId != 0 && waited.paymentId == first.paymentId && !first.repeated && waited.repeated, "a retry while the first call is at the prompt gets the first call's payment");
|
||||
Equal(checks("order-4"), std::ptrdiff_t{2}, "and the user is asked once for it, after the dismissed dialog");
|
||||
|
||||
SetPolkit(bus, Fake::Polkit::Silent, Bus::actionCheckout);
|
||||
Checkout::Order unanswered = order;
|
||||
unanswered.reference = "order-5";
|
||||
Failure gaveUp;
|
||||
std::thread asking([&pay, &unanswered, &gaveUp] { gaveUp = FailureOf([&pay, &unanswered] { pay(unanswered); }); });
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(300));
|
||||
const Failure alsoGaveUp = FailureOf([&pay, &unanswered] { pay(unanswered); });
|
||||
asking.join();
|
||||
Check(gaveUp.name == SD_BUS_ERROR_ACCESS_DENIED && alsoGaveUp.name == gaveUp.name && alsoGaveUp.message == gaveUp.message, "and the first call's refusal, when it is refused");
|
||||
SetPolkit(bus, Fake::Polkit::Allow);
|
||||
|
||||
// An account chosen and since closed pays no checkout.
|
||||
// An account chosen and since closed is chosen no more.
|
||||
const std::uint64_t brief = bunq.AddAccount(bank.alice, briefIban, "Brief", 1000);
|
||||
Equal(alice.SetDefaultCheckoutAccount(briefIban).iban, briefIban, "an account opened since");
|
||||
bunq.ChangeAccount(brief, json{{"status", "CANCELLED"}});
|
||||
alice.Accounts();
|
||||
Check(!alice.DefaultCheckoutAccount().has_value(), "a closed account pays at checkout no more");
|
||||
Checkout::Order orphan = order;
|
||||
orphan.reference = "order-6";
|
||||
Throws<Checkout::NoCheckoutAccount>([&pay, &orphan] { pay(orphan); }, "or it is gone", "nor does a checkout pay from it");
|
||||
Check(!alice.DefaultCheckoutAccount().has_value(), "a closed account is the one pay links start from no more");
|
||||
alice.SetDefaultCheckoutAccount(aliceMain);
|
||||
}
|
||||
|
||||
|
|
@ -872,7 +683,7 @@ namespace {
|
|||
Fake::Limit(limited, RLIMIT_NPROC, processes);
|
||||
bus.Disconnect(name);
|
||||
Equal(Fake::Wait(limited), 0, "it ends with the bus");
|
||||
Check(bus.WaitForName(name, false) && bus.WaitForName(checkoutName, false), "and lets go of its names");
|
||||
Check(bus.WaitForName(name, false), "and lets go of its name");
|
||||
}
|
||||
|
||||
void Idle(Fake::Bus& bus, const fs::path& state) {
|
||||
|
|
@ -922,7 +733,6 @@ int main(int argc, char* argv[]) {
|
|||
bunq.AddAccount(bunq.AddPerson("Dave", "key-dave"), daveIban, "Dave's", 100);
|
||||
|
||||
NotRunning(bus);
|
||||
CheckoutClient(bus);
|
||||
const pid_t nostrod = Fake::StartNostrod({"--state", state.string(), "--idle", "60", "--prompt-timeout", "2"});
|
||||
Check(bus.WaitForName(name), "nostrod owns its name");
|
||||
Contract(bus);
|
||||
|
|
@ -933,12 +743,12 @@ int main(int argc, char* argv[]) {
|
|||
Lookups(bus, bunq, nostrod);
|
||||
Concurrency(bus, bunq, bank);
|
||||
Errors(bus, bunq, bank, state);
|
||||
Checkouts(bus, bunq, bank);
|
||||
CheckoutAccount(bus, bunq, bank);
|
||||
Workers(bus, nostrod);
|
||||
Notes(bus, bunq);
|
||||
bus.Disconnect(name);
|
||||
Equal(Fake::Wait(nostrod), 0, "nostrod ends when the bus goes, after its workers");
|
||||
Check(bus.WaitForName(name, false) && bus.WaitForName(checkoutName, false), "and lets go of its names");
|
||||
Check(bus.WaitForName(name, false), "and lets go of its name");
|
||||
|
||||
SpawnFailure(bus, state);
|
||||
Idle(bus, state);
|
||||
|
|
|
|||
|
|
@ -2,8 +2,9 @@
|
|||
// 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 every error
|
||||
// nostrod can answer with is explained as, and what the app knows of each bank it can connect.
|
||||
// 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>
|
||||
|
|
@ -228,6 +229,182 @@ namespace {
|
|||
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;
|
||||
|
|
@ -428,6 +605,7 @@ int main() {
|
|||
Words();
|
||||
Reading();
|
||||
Paying();
|
||||
Linking();
|
||||
Asking();
|
||||
Filtering();
|
||||
Connecting();
|
||||
|
|
|
|||
Loading…
Reference in a new issue