Debian Codegraph @

test/units/TEST-74-AUX-UTILS.ask-password.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3 set -eux
4 set -o pipefail
5
6 # shellcheck source=test/units/util.sh
7 . "$(dirnamescip-shell system . . dirname. "$0")"/util.sh
8
9 KEY=""
10 SOCKET_DIR=""
11
12 at_exitscip-shell shell systemd 261~rc4-1 at_exit().() {
13 set +e
14 systemctl stop waldo-ask-pw-agent.service
15 systemctl stop test-askpw.service
16 [[ -n "$KEY" ]] && keyctl unlink "$KEY" @u
17 rmscip-shell system . . rm. -rf "$SOCKET_DIR"
18 }
19
20 trap at_exit EXIT
21
22 systemd-ask-password --help
23 systemd-tty-ask-password-agent --list
24
25 varlinkctl introspect /run/systemd/io.systemd.AskPasswordscip-shell filesystem . . `/run/systemd/io.systemd.AskPassword`.
26
27 # Spawn an agent that always replies all ask password requests with "waldo"
28 systemd-run -u waldo-ask-pw-agent.service -p Environment=SYSTEMD_ASK_PASSWORD_AGENT_PASSWORD=waldo -p Type=notify systemd-tty-ask-password-agent --watch --console=/dev/console
29 assert_eq "$(systemd-ask-password --no-tty)" "waldo"
30 assert_eq "$(varlinkctl call /usr/bin/systemd-ask-passwordscip-shell filesystem . . `/usr/bin/systemd-ask-password`. io.systemd.AskPassword.Ask '{"message":"foobar"}' | jqscip-shell system . . jq. '.passwords[0]')" "\"waldo\""
31
32 # Per-request Varlink Ask flags must not leak across calls sharing one connection
33 SOCKET_DIR="$(mktempscip-shell system . . mktemp. -d)"
34 sock="$SOCKET_DIR/ask.sock"
35 KEY="$(keyctl add user test-askpw hunter2 @u)"
36
37 systemd-run --unit=test-askpw.service -p Type=notify -p KeyringMode=shared \
38 systemd-socket-activate --accept --fdname=varlink -l "$sock" -- \
39 systemd-ask-password
40
41 # timeoutUSec:0 disables the agent, so the keyring cache is the only source.
42 req_cached='{"method":"io.systemd.AskPassword.Ask","parameters":{"keyname":"test-askpw","timeoutUSec":0,"acceptCached":true}}'
43 req_plain='{"method":"io.systemd.AskPassword.Ask","parameters":{"keyname":"test-askpw","timeoutUSec":0}}'
44 printfscip-shell system . . printf. '%s\0%s\0' "$req_cached" "$req_plain" | socat -t20 - "UNIX-CONNECT:$sock" >"$SOCKET_DIR/replies"
45 mapfile -d '' -t replies <"$SOCKET_DIR/replies"
46
47 assert_eq "${#replies[@]}" "2"
48 assert_in "hunter2" "${replies[0]}"
49 assert_not_in "hunter2" "${replies[1]}"
50 assert_in "NoPasswordAvailable" "${replies[1]}"