mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 21:36:40 -10:00
The stubs logged with echo "x $*" >> "$STUB_LOG", which bash can write
in pieces for a long line, so a stub running at the same time could put
its own line in the middle. Every stub now appends through
testdata/stubs/stub-log, a Perl script that writes the whole line with a
single syswrite to the file opened for appending: the call log and the
stubs' shared lists ($STUB_DIR/containers-made, unpacked, scripts,
tm-excluded). The stubs run it from their own folder (${0%/*}), and
stubtest.New links it too when it puts only the named stubs on PATH.
TestCallLinesWhole runs two open stubs at once with 100 KB arguments
while the test appends short lines of its own to the log, and checks
every call landed whole; it failed on every run with the old stubs.
TestStubsLogWithStubLog fails on any stub that appends to $STUB_LOG or
$STUB_DIR with the shell's >>.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
32 lines
1.2 KiB
Bash
Executable File
32 lines
1.2 KiB
Bash
Executable File
#!/bin/bash
|
|
# Stand-in for macOS security in tests, so they never touch the real
|
|
# Keychain: logs the call to $STUB_LOG (stdin isn't logged, as a value
|
|
# there is in no process's arguments). An item is the file
|
|
# $STUB_DIR/keychain/ACCOUNT. find-generic-password -a NAME … -w prints it,
|
|
# delete-generic-password -a NAME deletes it, each failing as security does
|
|
# for an item that isn't there (44); security -i reads
|
|
# add-generic-password … -a NAME … -w "VALUE" lines from stdin and saves
|
|
# them.
|
|
set -euo pipefail
|
|
"${0%/*}/stub-log" "$STUB_LOG" security "$@"
|
|
kc=$STUB_DIR/keychain
|
|
account=""
|
|
args=("$@")
|
|
for ((i = 0; i < ${#args[@]}; i++)); do [[ ${args[i]} != -a ]] || account=${args[i + 1]:-}; done
|
|
case ${1:-} in
|
|
find-generic-password)
|
|
[[ -n $account && -f $kc/$account ]] || exit 44
|
|
cat "$kc/$account" ;;
|
|
delete-generic-password)
|
|
[[ -n $account && -f $kc/$account ]] || exit 44
|
|
rm "$kc/$account" ;;
|
|
-i)
|
|
re='^add-generic-password .*-a "([^"]*)" .*-w "([^"]*)"$'
|
|
while IFS= read -r line; do
|
|
[[ $line =~ $re ]] || exit 1
|
|
mkdir -p "$kc"
|
|
printf '%s\n' "${BASH_REMATCH[2]}" > "$kc/${BASH_REMATCH[1]}"
|
|
done ;;
|
|
*) exit 1 ;;
|
|
esac
|