fix: close what the security review before the first release found

A review of the tree and its history before they are published found no
key and no bank data in them. It did find these, each closed here.

The password dialog could be emptied (daemon). Shown(), which makes a
payee's name fit for polkit's dialog, let an & through. GNOME's older
agent (polkit-gnome) and MATE's put the message into Pango markup
unescaped, where a bare & fails to parse and leaves the dialog without
a message: paying "Tom & Jerry", or an order an app names so at
checkout, asked for the password and showed no amount and no payee.
Line and paragraph separators passed too. Shown() now shows & as +,
leaves out what draws nothing or places text (control and format
characters, the separators, what Unicode ignores by default, private
use) and makes any run of spaces one space. An address is held to it
instead of made fit: an e-mail address the dialog could not show
unchanged is refused before anyone is asked, since "a&b@..." shown as
"a+b@..." is somebody else's address.

A refused caller could look (daemon). A call that names an account, a
card, a request, a draft or a connector had it looked up, at the bank
where that takes it, before polkit was asked. So a caller polkit
refused was told whether it was there ("no account is called ..."),
and had the bank asked. Such a call now asks for View first
(HandleLookup), a call that only sees looks its account up after its
yes, and the connectors are read, which refreshes the accounts at the
bank, on the first yes instead of on the first call.

An app at checkout was told too much (checkout). The refusal of an
order's reference with another amount named the amount on record, and
a refusal by the bank carried the call it answered, whose path has the
user's and the account's ids at bunq. Neither does now.

A key typed by hand could be read off the screen (app). The line under
a key field showed how the key begins and its last four characters,
which is every character of it as it is typed. It shows how the key
begins and how long it is.

Every change asks for the password (packaging, app). Change, the
action for what changes something and pays nobody, passed without a
password in an active session, so any program of the user's could
cancel a scheduled payment, ask for money in their name or freeze a
card. It asks now (auth_self), a draft saved and a card frozen
included: only View passes as shipped, and loosening is an
administrator's rule, of which the README has an example. The app says
of every change where it is confirmed (AsksPassword is gone), and the
request form sends on its button as the pay form does: its review
sheet would be a second confirmation of what the dialog confirms.

What is built is what was tested (build). Crafter.Network, Crafter.DB
and Crafter.LintRules are named at the commits the tests ran against.
Crafter.Thread still follows its branch, which Crafter.Network's own
project file names, and so does Crafter.Network in the app's debug
build, where Crafter.Debug names it too and crafter-build refuses a
module built twice. lib/json.hpp was nlohmann/json's develop branch at
95e9a593 less its last newline, and called 3.12.0: it is that file
byte for byte now, and called what it is.

The published contract changes with this, before any release (design
rule 10): an e-mail address the dialog cannot show as it is is
refused, a call that looks something up needs View as well as its own
action, the checkout's errors say less, and the policy asks for the
password for Change. The XML, the policy and ShouldServeEveryUser,
which now holds the policy to its defaults, change together.

Reproduced and verified on the fake bus and the fake bunq. The new
checks of ShouldServeEveryUser fail on the worker of before (50 of
them: the & shown, the lookups answered, the bank asked) and pass now.
crafter-build test (17 tests), lint for the library, the app and the
fake system, and tests/coverage.sh (every line, function and region)
pass. Looked at on the made-up system, 360x760 dp at scale 2, dark, on
KDE Wayland: the key form with a key typed, the request form with its
wait and its result, a card frozen, and About. No picture in the
README shows a screen that changed.

Not tried: bunq's sandbox, a real polkit agent, the Flatpak builds.
The README's example rule ran against a stand-in for polkit's rule
engine only.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
This commit is contained in:
Jorijn van der Graaf 2026-11-19 16:09:48 +01:00
commit 2e3739ff7a
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
23 changed files with 488 additions and 209 deletions

View file

@ -404,7 +404,8 @@ namespace {
Shows(d.ui, "The API key, from the bunq app", "a form without a key says so");
Equal(d.app.Screen(), std::string("add:bunq:key"), "and asks nostrod nothing");
Type(d, "key.key", aliceKey);
Shows(d.ui, std::format("Typed: {}", Fingerprint(aliceKey)), "what was typed is told by how it begins and ends");
Shows(d.ui, std::format("Typed: {}", Fingerprint(aliceKey)), "what was typed is told by how it begins and how long it is");
Hides(d.ui, aliceKey.substr(aliceKey.size() - 4), "and not by how it ends, which is what was typed last");
Hides(d.ui, aliceKey, "and never shown");
Hides(d.ui, "The API key, from the bunq app", "the error goes once there is a key");
Check(!Has(d, "key.ips"), "the allowed addresses are tucked away");
@ -540,9 +541,20 @@ namespace {
Shows(d.ui, "Bob's", "and what is shown is what there is");
// And once more while they are read again: the reading gives up, and says so.
before = Answers(d, "Connectors ok");
const auto viewChecks = [&bus] {
std::lock_guard lock(bus.mutex);
return std::ranges::count_if(bus.checks, [](const Fake::PolkitCheck& check) { return check.action == Bus::actionView; });
};
const std::ptrdiff_t viewed = viewChecks();
Tap(d, "bar.refresh");
Check(RunUntil(d.loop, [&d, before] { return Answers(d, "Connectors ok") > before; }), "the connections are read");
// Removing a connection looks it up first, for which nostrod asks polkit whether the caller may see: that is
// answered at once here, once the app's reading of the accounts is at polkit, which answers that a second
// later whatever it is set to meanwhile.
Check(RunUntil(d.loop, [&viewChecks, viewed] { return viewChecks() >= viewed + 2; }), "and the accounts are being read");
SetPolkit(bus, Fake::Polkit::Allow, Bus::actionView);
other.RemoveConnector("Bob");
SetPolkit(bus, Fake::Polkit::Slow, Bus::actionView);
Check(RunUntil(d.loop, [&d, before] { return Answers(d, "Connectors ok") > before + 1; }), "and read again");
other.AddBunq("key-bob", "*", "");
Settle(d);
@ -839,7 +851,7 @@ namespace {
Equal(Action(bus), std::string(Bus::actionPay), "after the password for paying");
Press(d, "done.close");
// A draft: made now, paid once someone accepts it, and no password for making it.
// A draft: made now, paid once someone accepts it. Making one is a change, and is confirmed like any.
Tap(d, "home.pay");
Type(d, "pay.to", "+31612345678");
Shows(d.ui, "Phone number", "a phone number is known for one");
@ -849,8 +861,8 @@ namespace {
Bottom(d);
Equal(d.ui.Find("pay.submit")->label, std::string("Save as draft"), "and the button says that it saves one");
Tap(d, "pay.submit");
Shows(d.ui, "Saving a draft of €2.00 to +31612345678", "a draft is saved at once");
Shows(d.ui, "One moment.", "and needs no password, so the wait says nothing of one");
Shows(d.ui, "Saving a draft of €2.00 to +31612345678", "a draft is saved from the form's button, with no question of the app's before it");
Shows(d.ui, "Confirm it in your system's password dialog.", "and confirmed where every change is");
Settle(d);
Shows(d.ui, "Drafted €2.00 to +31612345678", "and is made");
Shows(d.ui, "It is paid once it is accepted", "with what that means");
@ -901,24 +913,30 @@ namespace {
const std::string page = std::format("account:{}", aliceMain);
Tap(d, "home.request");
Equal(d.app.Screen(), std::string("request"), "asking starts from the accounts");
Tap(d, "request.review");
Bottom(d);
Shows(d.ui, "Your bank asks them where it can reach them", "what asking does is said on the form");
const Region* submit = d.ui.Find("request.submit");
Check(submit != nullptr && submit->label == "Ask", "whose button is named for what it does");
Tap(d, "request.submit");
Shows(d.ui, "Enter an amount", "a form that is empty says what it lacks");
Equal(d.app.Screen(), std::string("request"), "and asks nostrod nothing");
Top(d);
Tap(d, "request.into");
Tap(d, std::format("pick.{}", aliceMain));
Type(d, "request.from", bobIban);
Tap(d, "request.review");
Tap(d, "request.submit");
Shows(d.ui, "The name of the account's holder", "an IBAN needs a name here too");
Type(d, "request.name", "Bob");
Type(d, "request.amount", "5");
Type(d, "request.description", "back");
Tap(d, "request.review");
Equal(d.app.Screen(), std::string("request+review"), "a request is reviewed");
Shows(d.ui, "Ask Bob for €5.00?", "as what it is");
Shows(d.ui, std::format("Main · {}", GroupIban(aliceMain)), "and into which account");
Hides(d.ui, "Your system asks for your password", "it needs no password");
Tap(d, "review.back");
Tap(d, "request.review");
Press(d, "review.confirm");
// The button sends what is filled in, as the pay form's does: there is no review of the app's own, since the
// system's password dialog is what confirms a request.
Bottom(d);
Tap(d, "request.submit");
Equal(d.app.Screen(), std::string("request+working"), "a request is sent by the form's button, with no question of the app's before it");
Shows(d.ui, "Asking Bob for €5.00", "the change under way is shown as what it is");
Shows(d.ui, "Confirm it in your system's password dialog.", "with where to confirm it");
Settle(d);
Shows(d.ui, "Asked Bob for €5.00", "the request is made");
Equal(Action(bus), std::string(Bus::actionChange), "as a change that moves no money");
Shows(d.ui, "https://bunq.me/t/", "with the link anyone can pay through");
@ -940,10 +958,11 @@ namespace {
Tap(d, "home.request");
Type(d, "request.from", "+31612345678");
Type(d, "request.amount", "3");
Tap(d, "request.review");
Shows(d.ui, "Ask +31612345678 for €3.00?", "someone asked by phone number is named by it");
bunq.Fail(Fault{.method = "POST", .path = "/user/", .status = 500, .body = R"({"Error":[{"error_description":"Hiccup."}]})"});
Press(d, "review.confirm");
Bottom(d);
Tap(d, "request.submit");
Shows(d.ui, "Asking +31612345678 for €3.00", "someone asked by phone number is named by it");
Settle(d);
Shows(d.ui, "It may have been done", "a request without a clear answer may have been made");
Check(Has(d, "problem.activity"), "and the account is a press away");
Press(d, "problem.close");
@ -976,6 +995,7 @@ namespace {
Tap(d, "detail.revoke");
Equal(d.app.Screen(), std::format("{}+confirm", page), "taking it back is asked about first");
Shows(d.ui, "Revoke the request to Bob?", "by name");
Shows(d.ui, "Your system asks for your password", "and with where it is confirmed: no change is made without the password");
Tap(d, "confirm.no");
Equal(d.app.Screen(), page, "and can be thought better of");
Tap(d, row);
@ -1023,7 +1043,7 @@ namespace {
Tap(d, Row(d, "incoming.", 1));
Tap(d, "detail.reject");
Shows(d.ui, "Reject the request from Dave?", "rejecting is asked about first");
Hides(d.ui, "Your system asks for your password", "and needs no password");
Shows(d.ui, "Your system asks for your password", "and needs the password too, as every change does");
Press(d, "confirm.yes");
Shows(d.ui, "Request rejected", "a request rejected is said");
Shows(d.ui, "Rejected · rent", "and listed as such");
@ -1166,7 +1186,7 @@ namespace {
Check(Has(d, "detail.freeze") && !Has(d, "detail.unfreeze") && Has(d, "detail.lost") && Has(d, "detail.stolen"), "a card in use can be frozen or reported");
Tap(d, "detail.freeze");
Shows(d.ui, "Freezing card •••• 1234", "freezing is under way at once");
Shows(d.ui, "One moment.", "without a password");
Shows(d.ui, "Confirm it in your system's password dialog.", "and is confirmed there, as unfreezing is: the app freezes no card by itself");
Settle(d);
Shows(d.ui, "Card •••• 1234 is now Deactivated", "a frozen card is said");
Equal(Action(bus), std::string(Bus::actionChange), "as a change");
@ -1417,7 +1437,7 @@ namespace {
Type(d, "oauth.client", "fake-client");
Type(d, "oauth.redirect", "http://127.0.0.1/cb");
Type(d, "oauth.secret", "fake-secret");
Shows(d.ui, "Typed: ••••", "the secret is told by nothing of itself");
Shows(d.ui, "Typed: 11 characters", "the secret is told by nothing of itself but how long it is");
Hides(d.ui, "fake-secret", "and never shown");
Bottom(d);
Tap(d, "oauth.environment.1");

View file

@ -108,6 +108,13 @@ namespace {
return check.details.contains("summary") ? check.details.at("summary") : std::string();
}
// How often polkit was asked about something that takes a password as shipped: everything but seeing, which a
// call that names an account or a card asks about first, and which an active session has without a dialog.
std::size_t Asked(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; }));
}
std::string Slurp(const fs::path& file) {
std::ifstream in(file);
return std::string(std::istreambuf_iterator<char>(in), std::istreambuf_iterator<char>());
@ -198,7 +205,8 @@ namespace {
// 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.
// 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));
@ -219,6 +227,10 @@ namespace {
const std::size_t id = action.find('"') + 1;
declared.emplace_back(action.substr(id, action.find('"', id) - id));
Check(action.contains("<annotate key=\"org.freedesktop.policykit.owner\">unix-user:nostro</annotate>"), std::format("{} is owned by the user nostrod runs as", declared.back()));
// Secure as shipped: in the user's own session only seeing passes without their password, everything else
// asks for it every time, and nothing passes from anywhere else. Loosening that is an administrator's rule.
const std::string_view inSession = declared.back() == Bus::actionView ? "<allow_active>yes</allow_active>" : "<allow_active>auth_self</allow_active>";
Check(action.contains(inSession) && action.contains("<allow_inactive>auth_self</allow_inactive>") && action.contains("<allow_any>auth_self</allow_any>"), std::format("{} asks for the user's password as shipped, unless it only looks, and keeps no authorization", declared.back()));
for(std::size_t key = action.find("$("); key != std::string_view::npos; key = action.find("$(", key + 1)) {
Check(action.substr(key).starts_with("$(summary)"), std::format("{} shows only details nostrod sets", declared.back()));
}
@ -283,10 +295,31 @@ namespace {
// markup or for polkit's $(…), at most 64 characters.
const std::string nasty = std::format("B\x01o\x7F" "b\xC2\x85\xE2\x80\x8B\xE2\x80\xAE\xE2\x81\xA6\xEF\xBB\xBF<i>$(amount_minor)</i>\xF0\x9F\x98\x80x{}", std::string(70, 'y'));
alice.Send(aliceMain, "x@y", nasty, 100, "");
Equal(Summary(bus), std::format("pay €1.00 to x@y (Bob‹i›$ (amount_minor)‹/i›😀x{}…) from {} (Main)", std::string(37, 'y'), aliceMain), "a name made safe to show");
Equal(Summary(bus), std::format("pay €1.00 to x@y (Bob‹i›$ (amount_minor)‹/i›😀x{}…) from {} (Main)", std::string(36, 'y'), aliceMain), "a name made safe to show");
// An agent that reads its message as markup shows nothing of one with a bare & in it, the amount included.
alice.Send(aliceMain, bobIban, "Tom & Jerry", 100, "");
Equal(Summary(bus), std::format("pay €1.00 to {} (Tom + Jerry) from {} (Main)", bobIban, aliceMain), "an & is shown as a +");
// Nothing starts a line of its own or leaves a gap: an em space first, then a soft hyphen, an Arabic letter
// mark, a space, a no-break space and a blank Braille pattern, a line and a paragraph separator, a tag, a
// private-use character and a variation selector, and two spaces last.
alice.Send(aliceMain, bobIban, "\xE2\x80\x83 Ann\xC2\xAD\xD8\x9C \xC2\xA0\xE2\xA0\x80Lee\xE2\x80\xA8\xE2\x80\xA9\xF3\xA0\x81\x81\xEE\x80\x80\xEF\xB8\x8F ", 100, "");
Equal(Summary(bus), std::format("pay €1.00 to {} (Ann Lee) from {} (Main)", bobIban, aliceMain), "what draws nothing is left out, and spaces of any kind are one space between words");
// D-Bus carries UTF-8 alone, so text that is not cannot even be sent.
Throws<std::invalid_argument>([&alice] { alice.Send(aliceMain, bobIban, "\xFF", 100, ""); }, "not UTF-8", "a name that is not UTF-8");
// An address decides where the money goes, so the dialog shows it whole and as it is, or nobody is asked: one
// with an & would read as one with a +, which is another address.
const std::size_t passwords = Asked(bus);
const std::string addressRefused = "the password dialog would not show that address as it is";
Throws<std::invalid_argument>([&alice] { alice.Send(aliceMain, "tom&jerry@example.com", "Tom", 100, ""); }, addressRefused, "an address with an &");
Throws<std::invalid_argument>([&alice] { alice.Request(aliceMain, "tom\xE2\x80\x8Bjerry@example.com", "Tom", 100, ""); }, addressRefused, "one with a character that draws nothing");
Throws<std::invalid_argument>([&alice] { alice.Draft(aliceMain, std::format("{}@example.com", std::string(250, 'a')), "Tom", 100, ""); }, addressRefused, "one longer than an address gets");
Throws<std::invalid_argument>([&alice, start = std::chrono::sys_days(std::chrono::year(2027) / 1 / 1)] { alice.Schedule(aliceMain, "<tom@example.com>", "Tom", 100, "", BunqSchedule{.start = start, .unit = "ONCE"}); }, addressRefused, "one in angle brackets");
Equal(Asked(bus), passwords, "and nobody is asked for a password for any of them");
const std::string longAddress = std::format("{}@example.com", std::string(70, 'a'));
alice.Send(aliceMain, longAddress, "Tom", 100, "");
Check(Summary(bus) == std::format("pay €1.00 to {} (Tom) from {} (Main)", longAddress, aliceMain) && bus.LastCheck().details.at("counterparty") == longAddress, "an address longer than a name may be is shown whole, and given to rules whole");
alice.Accounts();
Check(bus.LastCheck().action == "net.catcrafts.Nostro1.View" && Summary(bus) == "see your accounts and balances", "listing is the View action");
const std::size_t listed = alice.Transactions(aliceMain, {}).size();
@ -357,18 +390,14 @@ namespace {
Check(bus.LastCheck().action == "net.catcrafts.Nostro1.BlockCard" && Summary(bus) == "report card **** 1234 stolen, which blocks it for good", "and so does blocking one for good");
// A virtual card is not frozen or unfrozen: bunq would leave it as it is and answer as if it had been done. It
// is refused before anyone is asked for a password, and bunq is not asked at all.
// is refused before anyone is asked for a password, and bunq is not asked to change anything.
const std::uint64_t number = bunq.AddCard(bank.alice, "DEACTIVATED", json{{"order_status", "VIRTUAL_DELIVERY"}, {"primary_account_numbers", json::array({json{{"four_digit", "4321"}}})}});
const auto prompted = [&bus] {
std::lock_guard lock(bus.mutex);
return bus.checks.size();
};
const std::size_t prompts = prompted();
const std::size_t prompts = Asked(bus);
const std::size_t changes = bunq.Count("PUT", "/user/");
for(const std::string_view status : {"DEACTIVATED", "ACTIVE"}) {
Throws<std::invalid_argument>([&alice, number, status] { alice.SetCardStatus(number, status); }, std::format("card {} is a virtual card, which bunq does not freeze or unfreeze when asked", number), "a virtual card is not frozen or unfrozen");
}
Check(prompted() == prompts && bunq.Count("PUT", "/user/") == changes, "nobody is asked for a password for it, and bunq is not asked");
Check(Asked(bus) == prompts && bunq.Count("PUT", "/user/") == changes, "nobody is asked for a password for it, and bunq is not asked");
Equal(alice.SetCardStatus(number, "LOST").status, std::string("LOST"), "it is reported lost like any card");
Check(bus.LastCheck().action == "net.catcrafts.Nostro1.BlockCard" && Summary(bus) == "report card **** 4321 lost, which blocks it for good", "which blocks it for good, after the password for that");
}
@ -411,6 +440,67 @@ namespace {
Check(!quick.Connectors().empty(), "and the next call is answered");
}
// What a call names is looked up for a caller who may see the user's accounts, and for no other: one polkit
// refuses that is told nothing of what is there, and has the bank asked nothing.
void Lookups(Fake::Bus& bus, Fake::Bunq& bunq, pid_t nostrod) {
Client alice = As(bus, aliceUid);
const std::string_view accounts = "see your accounts and balances";
const BunqSchedule once{.start = std::chrono::sys_days(std::chrono::year(2027) / 1 / 1), .unit = "ONCE"};
// Each call, with something that is there or something that is not, and what polkit is asked to let it see.
const std::vector<std::tuple<std::string_view, std::function<void()>, std::string_view>> calls = {
{"a payment from an account nobody has", [&alice] { alice.Send("Nope", bobIban, "Bob", 100, ""); }, accounts},
{"a payment from an account there is", [&alice] { alice.Send(aliceMain, bobIban, "Bob", 100, ""); }, accounts},
{"a schedule", [&alice, &once] { alice.Schedule("Nope", bobIban, "Bob", 100, "", once); }, accounts},
{"a request for money", [&alice] { alice.Request("Nope", bobIban, "Bob", 100, ""); }, accounts},
{"a draft", [&alice] { alice.Draft("Nope", bobIban, "Bob", 100, ""); }, accounts},
{"revoking a request", [&alice] { alice.RevokeRequest("Nope", 1); }, accounts},
{"cancelling a schedule", [&alice] { alice.CancelScheduledPayment(aliceMain, 1); }, accounts},
{"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},
{"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"},
};
SetPolkit(bus, Fake::Polkit::Deny, Bus::actionView);
const std::size_t prompts = Asked(bus);
const std::size_t questions = bunq.Count("GET", "/user/");
for(const auto& [what, call, seen] : calls) {
const Failure refused = FailureOf(call);
Check(refused.name == SD_BUS_ERROR_ACCESS_DENIED && refused.message.contains("does not allow net.catcrafts.Nostro1.View"), std::format("{}, asked by a caller who may not see the accounts: {}", what, refused.message));
Check(bus.LastCheck().action == Bus::actionView && Summary(bus) == seen, std::format("{}: polkit is asked whether the caller may {}", what, seen));
}
Equal(Asked(bus), prompts, "nobody is asked for a password for any of it");
Equal(bunq.Count("GET", "/user/"), questions, "and the bank is asked nothing");
// Where seeing the accounts takes a password, a call that looks something up asks for it first.
SetPolkit(bus, Fake::Polkit::Dismiss, Bus::actionView);
Equal(FailureOf([&alice] { alice.Send(aliceMain, bobIban, "Bob", 100, ""); }).name, std::string(Bus::errorCancelled), "a password to look, not given");
SetPolkit(bus, Fake::Polkit::Password, Bus::actionView);
const std::string unasked = Raw(bus, name, name, "Send", false, [](sd_bus_message* call) {
sd_bus_message_append(call, "sssxs", aliceMain.c_str(), bobIban.c_str(), "Bob", std::int64_t{100}, "");
});
Equal(unasked, std::string(SD_BUS_ERROR_INTERACTIVE_AUTHORIZATION_REQUIRED), "or one the call did not let nostrod ask for");
Equal(Asked(bus), prompts, "and still nobody is asked about the payment itself");
Check(alice.Send(aliceMain, bobIban, "Bob", 100, "").id != 0, "given, the call goes on");
const std::pair<std::string, std::string> lastTwo = [&bus] {
std::lock_guard lock(bus.mutex);
return std::pair(bus.checks.at(bus.checks.size() - 2).action, bus.checks.back().action);
}();
Check(lastTwo.first == Bus::actionView && lastTwo.second == Bus::actionPay, "and asks twice: to look, and then to pay");
// A worker just started reads the user's connectors, which asks the bank, for the first caller polkit says
// yes to, and for none before.
KillWorkers(bus, nostrod);
SetPolkit(bus, Fake::Polkit::Deny, Bus::actionView);
const std::size_t before = bunq.Count("GET", "/user/");
Equal(FailureOf([&bus] { As(bus, aliceUid).Accounts(); }).name, std::string(SD_BUS_ERROR_ACCESS_DENIED), "a caller a new worker refuses");
Equal(bunq.Count("GET", "/user/"), before, "has the bank asked nothing either");
SetPolkit(bus, Fake::Polkit::Allow);
Check(!As(bus, aliceUid).Connectors().empty() && bunq.Count("GET", "/user/") > before, "the first caller polkit lets in has the connectors read");
}
void Concurrency(Fake::Bus& bus, Fake::Bunq& bunq, const Bank& bank) {
Client alice = As(bus, aliceUid);
Client again = As(bus, aliceUid);
@ -643,7 +733,10 @@ namespace {
};
Checkout::Order changed = order;
changed.amount = 1300;
refused(changed, "reference order-1 to NL91ABNA0417164300 is an order of €12.50, not of €13.00", "a reference paid for another amount");
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");
@ -664,7 +757,12 @@ namespace {
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("Not enough money."), "bunq's refusal");
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.
@ -672,7 +770,7 @@ namespace {
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"), std::format("an answer that may hide a payment: {}", hiccup.message));
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));
@ -688,7 +786,7 @@ namespace {
std::this_thread::sleep_for(std::chrono::milliseconds(300));
changed = unconfirmed;
changed.amount = 99;
refused(changed, "is an order of €12.50, not of €0.99", "another amount while the order is being paid");
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");
@ -832,6 +930,7 @@ int main(int argc, char* argv[]) {
Users(bus, state);
Prompts(bus, bunq, bank);
Outcomes(bus);
Lookups(bus, bunq, nostrod);
Concurrency(bus, bunq, bank);
Errors(bus, bunq, bank, state);
Checkouts(bus, bunq, bank);

View file

@ -97,10 +97,20 @@ namespace {
Equal(ScheduleLabel(schedule, now), std::format("Every {} from 3 Nov", word), "each unit bunq has");
}
Equal(Fingerprint("short"), std::string("••••"), "a short secret shows nothing of itself");
Equal(Fingerprint("sandbox_ab12cd34ef56gh78"), std::string("sandbox_…gh78"), "a key shows what it is for and how it ends");
Equal(Fingerprint("abcdefghijklmnopqrst"), std::string("abcd…qrst"), "one without a mark its first four");
Equal(Fingerprint("abcdefghijklmn_opqrst"), std::string("abcd…qrst"), "and so one whose mark comes late");
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() {
@ -313,21 +323,22 @@ namespace {
}
void Explaining() {
// What nostrod asks polkit for, per the policy nostro installs.
const std::array<std::tuple<Operation, std::string_view, bool, bool>, 17> operations = {{
{Operation::Load, Bus::actionView, false, false},
{Operation::Send, Bus::actionPay, true, true}, {Operation::Schedule, Bus::actionPay, true, true},
{Operation::PayRequest, Bus::actionPay, true, true}, {Operation::AcceptDraft, Bus::actionPay, true, true},
{Operation::Draft, Bus::actionChange, false, false}, {Operation::Request, Bus::actionChange, false, false},
{Operation::RevokeRequest, Bus::actionChange, false, false}, {Operation::RejectRequest, Bus::actionChange, false, false},
{Operation::CancelSchedule, Bus::actionChange, false, false}, {Operation::RejectDraft, Bus::actionChange, false, false},
{Operation::FreezeCard, Bus::actionChange, false, false},
{Operation::UnfreezeCard, Bus::actionUnfreezeCard, true, false}, {Operation::BlockCard, Bus::actionBlockCard, true, false},
{Operation::AddConnection, Bus::actionConnectors, true, false}, {Operation::RemoveConnection, Bus::actionConnectors, true, false},
{Operation::SetCheckoutAccount, Bus::actionConnectors, true, false},
// 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, password, money] : operations) {
Check(ActionOf(operation) == action && AsksPassword(operation) == password && MovesMoney(operation) == money, std::format("operation {} asks for {}", std::to_underlying(operation), action));
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);