Skip to content
zit Artifact [6d1644e546]
Login

Artifact [6d1644e546]

Artifact 6d1644e54662da7bf94062ec1616121e5cae7f5b89ad901a0f6f15577b533c1c:


//! The `credential-command` setting: ask a program the operator names for a
//! remote's login, over git's credential-helper protocol, so a tool that
//! already holds the credential (a password manager, a forge client) can
//! answer for every checkout instead of priming them one at a time.
//!
//! The protocol is git's (git-credential(1), gitcredentials(7)), designed by
//! Jeff King for git's credential API (git's credential.c): `key=value` lines
//! on the helper's stdin describing the remote, the same lines back on its
//! stdout, and three actions, `get`, `store` and `erase`. A helper written for
//! git answers here unchanged.
//!
//! How the command runs. The value is a shell command line; zit appends one
//! space and the action and hands the whole string to `/bin/sh -c`, which is
//! how git runs a helper value that begins with `!`. A leading `!` is accepted
//! and dropped, so a git `credential.helper = !...` value pastes over. Git's
//! other forms (a bare NAME meaning `git credential-NAME`) have no zit
//! counterpart and are not imitated: a bare word here is a command the shell
//! looks up on PATH.
//!
//! What crosses. The password reaches the helper only on its stdin (for
//! `store` and `erase`) and comes back only on its stdout, into a fixed buffer
//! the caller scrubs. Nothing is put in argv or in the helper's environment,
//! and the helper's stderr is its own terminal's, as under git. The answer is
//! bounded in size and the helper in time; one that fails in any way is as if
//! no helper were set.

const std = @import("std");
const builtin = @import("builtin");
const zit = @import("zit");
const posix = std.posix;

/// The longest command value honoured. Longer is ignored as unset: a
/// truncated command line would run a different program.
pub const max_command_len: usize = 4096;

/// The most a `get` answer may hold. A login is two short lines; anything
/// near this is not a credential answer, and the helper is treated as failed.
pub const max_answer_len: usize = 16 * 1024;

/// How long a helper may take, end to end. Generous because a helper may
/// unlock a password manager and wait on the person at the keyboard; bounded
/// because an autosync must not hang for ever on a stuck one.
const default_timeout_ns: i96 = 120 * std.time.ns_per_s;

/// The remote, described the way git describes it to a helper.
pub const Attributes = struct {
    /// The URL scheme: `https`, `http`.
    protocol: []const u8,
    /// The host, with `:port` when the URL names one (git's shape).
    host: []const u8,
    /// The path without its leading `/`, empty for the root.
    path: []const u8,
    username: ?[]const u8 = null,
};

/// The attributes for `url`, or null when it has no `scheme://host` or a
/// value would carry a newline or NUL (git refuses those too: a value with a
/// newline in it would forge a second attribute line). The URL's userinfo is
/// never an attribute; the caller passes the user it settled on.
pub fn describe(url: []const u8, username: ?[]const u8) ?Attributes {
    const scheme_end = std.mem.indexOf(u8, url, "://") orelse return null;
    const protocol = url[0..scheme_end];
    const rest = url[scheme_end + 3 ..];
    const authority_end = std.mem.indexOfAny(u8, rest, "/?#") orelse rest.len;
    const authority = rest[0..authority_end];
    const host = if (std.mem.lastIndexOfScalar(u8, authority, '@')) |at| authority[at + 1 ..] else authority;
    var path = rest[authority_end..];
    if (std.mem.indexOfAny(u8, path, "?#")) |q| path = path[0..q];
    if (std.mem.startsWith(u8, path, "/")) path = path[1..];
    if (protocol.len == 0 or host.len == 0) return null;
    const out: Attributes = .{ .protocol = protocol, .host = host, .path = path, .username = username };
    if (!valueOk(protocol) or !valueOk(host) or !valueOk(path)) return null;
    if (username) |u| if (!valueOk(u)) return null;
    return out;
}

fn valueOk(v: []const u8) bool {
    return std.mem.indexOfAny(u8, v, "\n\x00") == null;
}

/// The request git writes to a helper: the attributes as `key=value` lines,
/// the password too for `store` and `erase`, then a blank line. Null when it
/// does not fit `buf` or the password carries a newline or NUL.
pub fn formatRequest(buf: []u8, a: Attributes, password: ?[]const u8) ?[]const u8 {
    var w: std.Io.Writer = .fixed(buf);
    w.print("protocol={s}\nhost={s}\npath={s}\n", .{ a.protocol, a.host, a.path }) catch return null;
    if (a.username) |u| w.print("username={s}\n", .{u}) catch return null;
    if (password) |p| {
        if (!valueOk(p)) return null;
        w.print("password={s}\n", .{p}) catch return null;
    }
    w.writeAll("\n") catch return null;
    return w.buffered();
}

/// What a helper answered. Both borrow the answer text.
pub const Answer = struct {
    username: ?[]const u8 = null,
    password: ?[]const u8 = null,
};

/// Read a helper's answer as git's `credential_read` does: `key=value` lines
/// up to the end or a blank line, the last value of a key winning, keys zit
/// has no use for (`quit`, `password_expiry_utc`, `oauth_refresh_token`,
/// `capability[]`, ...) ignored. A line with no `=` makes the whole answer
/// invalid, as git rejects it, and null is returned. An empty value is no
/// value.
pub fn parseAnswer(text: []const u8) ?Answer {
    var out: Answer = .{};
    var it = std.mem.splitScalar(u8, text, '\n');
    while (it.next()) |line| {
        if (line.len == 0) break;
        const eq = std.mem.indexOfScalar(u8, line, '=') orelse return null;
        const key = line[0..eq];
        const value = line[eq + 1 ..];
        const slot: *?[]const u8 = if (std.mem.eql(u8, key, "username"))
            &out.username
        else if (std.mem.eql(u8, key, "password"))
            &out.password
        else
            continue;
        slot.* = if (value.len == 0) null else value;
    }
    return out;
}

/// The command `credential-command` resolves to, copied into `buf`, or null
/// when none is set. `$ZIT_CREDENTIAL_COMMAND`, then the global settings file;
/// the setting lives nowhere else.
pub fn configured(gpa: std.mem.Allocator, io: std.Io, environ: std.process.Environ, buf: *[max_command_len]u8) ?[]const u8 {
    var arena_state = std.heap.ArenaAllocator.init(gpa);
    defer arena_state.deinit();
    var c: zit.settings.Candidates = .{};
    const r = zit.repo_config.resolveSettingTiers(io, arena_state.allocator(), .{ .environ = environ }, .credential_command, &c, null) catch return null;
    var command = std.mem.trim(u8, r.value, " \t");
    if (std.mem.startsWith(u8, command, "!")) command = std.mem.trimStart(u8, command[1..], " \t");
    if (command.len == 0 or command.len > buf.len) return null;
    @memcpy(buf[0..command.len], command);
    return buf[0..command.len];
}

/// A login a helper supplied, borrowing the caller's buffers.
pub const Login = struct {
    user: []const u8,
    password: []const u8,
};

/// Ask the helper for `url`'s login (`get`). `username` is the user the
/// caller already settled on, if any: it is sent to the helper and kept even
/// when the helper names another, since the operator's choice wins. With no
/// username the helper must name one. The answer is copied into `user_buf`
/// and `pw_buf`; null, with nothing kept, when no helper is set, it cannot
/// run, it exits non-zero, it runs too long, its answer is too long or
/// malformed, or it names no password (or no user, when one was needed).
pub fn fill(
    gpa: std.mem.Allocator,
    io: std.Io,
    environ: std.process.Environ,
    url: []const u8,
    username: ?[]const u8,
    user_buf: []u8,
    pw_buf: []u8,
) ?Login {
    return fillWithin(gpa, io, environ, url, username, user_buf, pw_buf, default_timeout_ns);
}

/// `fill` with its deadline given, so a test can run a stuck helper out in
/// a second rather than two minutes.
fn fillWithin(
    gpa: std.mem.Allocator,
    io: std.Io,
    environ: std.process.Environ,
    url: []const u8,
    username: ?[]const u8,
    user_buf: []u8,
    pw_buf: []u8,
    timeout_ns: i96,
) ?Login {
    var cmd_buf: [max_command_len]u8 = undefined;
    const command = configured(gpa, io, environ, &cmd_buf) orelse return null;
    const attrs = describe(url, username) orelse return null;
    var req_buf: [4096]u8 = undefined;
    const request = formatRequest(&req_buf, attrs, null) orelse return null;
    var answer_buf: [max_answer_len + 1]u8 = undefined;
    defer std.crypto.secureZero(u8, &answer_buf);
    const n = exchange(gpa, io, environ, command, "get", request, &answer_buf, timeout_ns) orelse return null;
    const answer = parseAnswer(answer_buf[0..n]) orelse return null;
    const password = answer.password orelse return null;
    const user = username orelse answer.username orelse return null;
    if (password.len > pw_buf.len or user.len > user_buf.len) return null;
    if (zit.sync.containsFossilWhitespace(user)) return null;
    @memcpy(user_buf[0..user.len], user);
    @memcpy(pw_buf[0..password.len], password);
    return .{ .user = user_buf[0..user.len], .password = pw_buf[0..password.len] };
}

/// Tell the helper the login it gave worked (`store`) or was refused
/// (`erase`), as git does after a request. Best-effort and silent: a helper
/// that fails here changes nothing about the verb's result.
pub fn settle(
    gpa: std.mem.Allocator,
    io: std.Io,
    environ: std.process.Environ,
    url: []const u8,
    login: Login,
    accepted: bool,
) void {
    var cmd_buf: [max_command_len]u8 = undefined;
    const command = configured(gpa, io, environ, &cmd_buf) orelse return;
    const attrs = describe(url, login.user) orelse return;
    var req_buf: [4096]u8 = undefined;
    defer std.crypto.secureZero(u8, &req_buf);
    const request = formatRequest(&req_buf, attrs, login.password) orelse return;
    _ = exchange(gpa, io, environ, command, if (accepted) "store" else "erase", request, null, default_timeout_ns);
}

/// Tell the helper a login it holds for `url` as `user` was refused
/// (`erase`), when zit has no password to name: a saved login keeps only a
/// derived secret. Git's helpers match an erase on the attributes given, so
/// the user and the remote are enough. Best-effort and silent.
pub fn erase(gpa: std.mem.Allocator, io: std.Io, environ: std.process.Environ, url: []const u8, user: []const u8) void {
    var cmd_buf: [max_command_len]u8 = undefined;
    const command = configured(gpa, io, environ, &cmd_buf) orelse return;
    const attrs = describe(url, user) orelse return;
    var req_buf: [4096]u8 = undefined;
    const request = formatRequest(&req_buf, attrs, null) orelse return;
    _ = exchange(gpa, io, environ, command, "erase", request, null, default_timeout_ns);
}

/// Run `command action` through the shell with `request` on its stdin. With
/// `answer` the helper's stdout is read into it and the byte count returned;
/// without, stdout is discarded and 0 returned. Null when the helper cannot
/// be started, overruns the deadline or the buffer, or does not exit 0.
fn exchange(
    gpa: std.mem.Allocator,
    io: std.Io,
    environ: std.process.Environ,
    command: []const u8,
    action: []const u8,
    request: []const u8,
    answer: ?[]u8,
    timeout_ns: i96,
) ?usize {
    var script_buf: [max_command_len + 8]u8 = undefined;
    const script = std.fmt.bufPrint(&script_buf, "{s} {s}", .{ command, action }) catch return null;
    var env_map = environ.createMap(gpa) catch return null;
    defer env_map.deinit();
    var child = std.process.spawn(io, .{
        .argv = &.{ "/bin/sh", "-c", script },
        .environ_map = &env_map,
        .stdin = .pipe,
        .stdout = if (answer != null) .pipe else .ignore,
        .stderr = .inherit,
    }) catch return null;
    // A no-op once the helper has been reaped below. Otherwise it overran or
    // failed: SIGKILL first, since `kill` sends only SIGTERM and then blocks
    // until the helper exits, which one that ignores SIGTERM never would.
    defer {
        if (child.id) |pid| posix.kill(pid, .KILL) catch {};
        child.kill(io);
    }
    const deadline = nowNs(io) + timeout_ns;

    // A helper that exits without reading its stdin breaks the pipe; zit
    // ignores SIGPIPE, so that is a failed write, and its answer still counts.
    if (child.stdin) |f| {
        f.writeStreamingAll(io, request) catch {};
        f.close(io);
        child.stdin = null;
    }

    var n: usize = 0;
    if (answer) |buf| {
        const fd = child.stdout.?.handle;
        while (true) {
            const left = deadline - nowNs(io);
            if (left <= 0) return null;
            var fds = [_]posix.pollfd{.{ .fd = fd, .events = posix.POLL.IN, .revents = 0 }};
            const ms: i32 = @intCast(@min(@divFloor(left, std.time.ns_per_ms) + 1, 1000));
            const ready = posix.poll(&fds, ms) catch return null;
            if (ready == 0) continue;
            if (n == buf.len) return null; // longer than any answer can be
            const got = posix.read(fd, buf[n..]) catch return null;
            if (got == 0) break;
            n += got;
        }
        // The caller's buffer is one longer than the largest answer, so a
        // full one means the helper said too much.
        if (n == buf.len) return null;
    }

    const status = reapBy(&child, deadline, io) orelse return null;
    return if (status == 0) n else null;
}

/// Wait for `child` until `deadline`, polling without blocking so a helper
/// that closed its stdout but keeps running is still bounded. Its exit status,
/// or null when it ran out of time or died by a signal (the caller's deferred
/// kill then ends it). Reaped here, the child's handles are released here.
fn reapBy(child: *std.process.Child, deadline: i96, io: std.Io) ?u8 {
    const pid = child.id orelse return null;
    while (nowNs(io) < deadline) {
        var status: if (builtin.link_libc) c_int else i32 = 0;
        const rc = posix.system.waitpid(pid, &status, posix.W.NOHANG);
        switch (posix.errno(rc)) {
            .SUCCESS => if (rc != 0) {
                if (child.stdout) |f| f.close(io);
                child.stdout = null;
                child.id = null;
                const s: u32 = @bitCast(status);
                return if (posix.W.IFEXITED(s)) posix.W.EXITSTATUS(s) else null;
            },
            .INTR => continue,
            else => return null,
        }
        io.sleep(.fromMilliseconds(10), .awake) catch return null;
    }
    return null;
}

fn nowNs(io: std.Io) i96 {
    return std.Io.Clock.awake.now(io).nanoseconds;
}

// ---------------------------------------------------------------------------

const testing = std.testing;

test "describe: git's attributes for a URL, port in host, path without its slash" {
    const a = describe("https://alice:[email protected]:8443/team/repo?x=1", null).?;
    try testing.expectEqualStrings("https", a.protocol);
    try testing.expectEqualStrings("forge.example:8443", a.host);
    try testing.expectEqualStrings("team/repo", a.path);
    try testing.expect(a.username == null);
    const root = describe("http://127.0.0.1:8080/", "bob").?;
    try testing.expectEqualStrings("127.0.0.1:8080", root.host);
    try testing.expectEqualStrings("", root.path);
    try testing.expectEqualStrings("bob", root.username.?);
    try testing.expectEqualStrings("", describe("https://h.example", null).?.path);
    try testing.expect(describe("not a url", null) == null);
    try testing.expect(describe("https:///path", null) == null);
    try testing.expect(describe("https://h.example/a\nb", null) == null);
    try testing.expect(describe("https://h.example/", "a\nusername=evil") == null);
}

test "formatRequest: key=value lines, the password only when given, then a blank line" {
    var buf: [256]u8 = undefined;
    const get = formatRequest(&buf, .{ .protocol = "https", .host = "h.example", .path = "r", .username = "alice" }, null).?;
    try testing.expectEqualStrings("protocol=https\nhost=h.example\npath=r\nusername=alice\n\n", get);
    var buf2: [256]u8 = undefined;
    const store = formatRequest(&buf2, .{ .protocol = "http", .host = "h:1", .path = "" }, "s3cret").?;
    try testing.expectEqualStrings("protocol=http\nhost=h:1\npath=\npassword=s3cret\n\n", store);
    try testing.expect(formatRequest(&buf2, .{ .protocol = "http", .host = "h", .path = "" }, "a\nb") == null);
    var tiny: [8]u8 = undefined;
    try testing.expect(formatRequest(&tiny, .{ .protocol = "https", .host = "h.example", .path = "" }, null) == null);
}

test "parseAnswer: git's reading rules" {
    const a = parseAnswer("username=alice\npassword=first\nquit=1\npassword_expiry_utc=99\npassword=last\n").?;
    try testing.expectEqualStrings("alice", a.username.?);
    try testing.expectEqualStrings("last", a.password.?);
    // A value keeps every byte after the first `=`, spaces and `=` included.
    try testing.expectEqualStrings(" a=b ", parseAnswer("password= a=b ").?.password.?);
    // A blank line ends the answer.
    try testing.expect(parseAnswer("username=a\n\npassword=p\n").?.password == null);
    // Empty values are no values; an empty answer is no answer.
    try testing.expect(parseAnswer("password=\n").?.password == null);
    try testing.expect(parseAnswer("").?.password == null);
    // A line without `=` invalidates the whole answer, as in git.
    try testing.expect(parseAnswer("password=p\ngarbage\n") == null);
}

/// A test environment whose only variables are `pairs`, as `KEY=VALUE`.
fn testEnviron(comptime pairs: []const [:0]const u8) std.process.Environ {
    const S = struct {
        const block: [pairs.len:null]?[*:0]const u8 = blk: {
            var b: [pairs.len:null]?[*:0]const u8 = undefined;
            for (pairs, 0..) |p, i| b[i] = p.ptr;
            break :blk b;
        };
    };
    return .{ .block = .{ .slice = &S.block } };
}

/// Write an executable helper script into `dir` and return its absolute path.
fn writeHelper(gpa: std.mem.Allocator, io: std.Io, dir: std.Io.Dir, name: []const u8, body: []const u8) ![]u8 {
    {
        var f = try dir.createFile(io, name, .{ .truncate = true, .permissions = .fromMode(0o755) });
        defer f.close(io);
        try f.writePositionalAll(io, body, 0);
    }
    var abs: [std.fs.max_path_bytes]u8 = undefined;
    const len = try dir.realPath(io, &abs);
    return std.fmt.allocPrint(gpa, "{s}/{s}", .{ abs[0..len], name });
}

test "fill runs the helper with the attributes on stdin and keeps its login" {
    if (builtin.os.tag == .windows) return error.SkipZigTest;
    const gpa = testing.allocator;
    const io = testing.io;
    var tmp = testing.tmpDir(.{});
    defer tmp.cleanup();
    var abs: [std.fs.max_path_bytes]u8 = undefined;
    const dir_len = try tmp.dir.realPath(io, &abs);
    const settings_path = try std.fmt.allocPrint(gpa, "{s}/settings", .{abs[0..dir_len]});
    defer gpa.free(settings_path);
    const helper = try writeHelper(gpa, io, tmp.dir, "helper.sh",
        \\#!/bin/sh
        \\d=$(dirname "$0")
        \\echo "$1" >> "$d/actions"
        \\cat > "$d/stdin-$1"
        \\[ "$1" = get ] && printf 'username=tester\npassword=t0p-s3cret\nquit=0\n'
        \\exit 0
        \\
    );
    defer gpa.free(helper);
    const line = try std.fmt.allocPrint(gpa, "credential-command {s}\n", .{helper});
    defer gpa.free(line);
    try tmp.dir.writeFile(io, .{ .sub_path = "settings", .data = line });
    const cfg = try std.fmt.allocPrintSentinel(gpa, "ZIT_CONFIG={s}", .{settings_path}, 0);
    defer gpa.free(cfg);
    var block = [_:null]?[*:0]const u8{cfg.ptr};
    const env: std.process.Environ = .{ .block = .{ .slice = &block } };

    var user_buf: [64]u8 = undefined;
    var pw_buf: [64]u8 = undefined;
    const got = fill(gpa, io, env, "http://127.0.0.1:9/repo", null, &user_buf, &pw_buf).?;
    try testing.expectEqualStrings("tester", got.user);
    try testing.expectEqualStrings("t0p-s3cret", got.password);
    const sent = try tmp.dir.readFileAlloc(io, "stdin-get", gpa, .limited(4096));
    defer gpa.free(sent);
    try testing.expectEqualStrings("protocol=http\nhost=127.0.0.1:9\npath=repo\n\n", sent);

    // A user the caller settled on is sent, and kept over the helper's.
    var user_buf2: [64]u8 = undefined;
    var pw_buf2: [64]u8 = undefined;
    const named = fill(gpa, io, env, "http://127.0.0.1:9/repo", "alice", &user_buf2, &pw_buf2).?;
    try testing.expectEqualStrings("alice", named.user);

    settle(gpa, io, env, "http://127.0.0.1:9/repo", got, true);
    settle(gpa, io, env, "http://127.0.0.1:9/repo", got, false);
    const stored = try tmp.dir.readFileAlloc(io, "stdin-store", gpa, .limited(4096));
    defer gpa.free(stored);
    try testing.expectEqualStrings("protocol=http\nhost=127.0.0.1:9\npath=repo\nusername=tester\npassword=t0p-s3cret\n\n", stored);
    const erased = try tmp.dir.readFileAlloc(io, "stdin-erase", gpa, .limited(4096));
    defer gpa.free(erased);
    try testing.expectEqualStrings(stored, erased);
    const actions = try tmp.dir.readFileAlloc(io, "actions", gpa, .limited(4096));
    defer gpa.free(actions);
    try testing.expectEqualStrings("get\nget\nstore\nerase\n", actions);
}

test "fill: a failing, silent, malformed or absent helper yields nothing" {
    if (builtin.os.tag == .windows) return error.SkipZigTest;
    const gpa = testing.allocator;
    const io = testing.io;
    var user_buf: [64]u8 = undefined;
    var pw_buf: [64]u8 = undefined;
    const cases = [_]std.process.Environ{
        // exits 1 after answering: the answer is not used
        testEnviron(&.{"ZIT_CREDENTIAL_COMMAND=printf 'username=u\\npassword=p\\n'; exit 1; :"}),
        // exits 0, says nothing
        testEnviron(&.{"ZIT_CREDENTIAL_COMMAND=true"}),
        // a user but no password
        testEnviron(&.{"ZIT_CREDENTIAL_COMMAND=printf 'username=u\\n'; :"}),
        // a line with no `=`
        testEnviron(&.{"ZIT_CREDENTIAL_COMMAND=printf 'password=p\\nnonsense\\n'; :"}),
        // cannot be run
        testEnviron(&.{"ZIT_CREDENTIAL_COMMAND=/nonexistent/zit-helper 2>/dev/null"}),
        // a password but no user, when none was settled on
        testEnviron(&.{"ZIT_CREDENTIAL_COMMAND=printf 'password=p\\n'; :"}),
        // no helper at all
        testEnviron(&.{}),
    };
    for (cases) |env| {
        try testing.expect(fill(gpa, io, env, "https://h.example/r", null, &user_buf, &pw_buf) == null);
    }
    // The last but one answers once a user is settled on.
    const ok = fill(gpa, io, cases[5], "https://h.example/r", "alice", &user_buf, &pw_buf).?;
    try testing.expectEqualStrings("p", ok.password);
    // A leading `!`, git's shell-snippet marker, is accepted.
    const bang = testEnviron(&.{"ZIT_CREDENTIAL_COMMAND=!printf 'password=q\\n'; :"});
    try testing.expectEqualStrings("q", fill(gpa, io, bang, "https://h.example/r", "alice", &user_buf, &pw_buf).?.password);
}

test "fill: an answer longer than any login is refused" {
    if (builtin.os.tag == .windows) return error.SkipZigTest;
    const gpa = testing.allocator;
    const io = testing.io;
    var user_buf: [64]u8 = undefined;
    var pw_buf: [64]u8 = undefined;
    const env = testEnviron(&.{"ZIT_CREDENTIAL_COMMAND=head -c 40000 /dev/zero | tr '\\0' x; printf '\\npassword=p\\n'; :"});
    try testing.expect(fill(gpa, io, env, "https://h.example/r", "alice", &user_buf, &pw_buf) == null);
}

test "fill: a helper that outlives its deadline is killed and yields nothing" {
    if (builtin.os.tag == .windows) return error.SkipZigTest;
    const gpa = testing.allocator;
    const io = testing.io;
    var user_buf: [64]u8 = undefined;
    var pw_buf: [64]u8 = undefined;
    // One answers then never exits; the other never closes its stdout.
    const cases = [_]std.process.Environ{
        testEnviron(&.{"ZIT_CREDENTIAL_COMMAND=printf 'password=p\\n'; exec sleep 30 >&-; :"}),
        testEnviron(&.{"ZIT_CREDENTIAL_COMMAND=exec sleep 30; :"}),
    };
    for (cases) |env| {
        const start = nowNs(io);
        try testing.expect(fillWithin(gpa, io, env, "https://h.example/r", "alice", &user_buf, &pw_buf, std.time.ns_per_s) == null);
        try testing.expect(nowNs(io) - start < 10 * std.time.ns_per_s);
    }
}