Write a boundary test that keeps a platform limit proved
A limit is proved when N−1 fails and N passes, on a macOS version you’ve written down, with the exact error you saw. Anything less is a claim. Keep the test in your repo and make it fail if the limit moves, so it stays proved.
I learned this by getting it wrong. I’d recorded Apple’s .aea password minimum as
32 characters and called it “confirmed”. One run of the test below shows that a
31-character password works on the versions I tried.
The test
This checks both ends of Apple’s .aea password range. It fails if either end has
moved. Save it as check-aea-limit.sh:
#!/bin/bash
# Fails if the boundary moves. MIN and MAX are what you expect to be true.
MIN=${MIN:-20}
MAX=${MAX:-256}
set -u
sw_vers
work=$(mktemp -d)
mkdir -p "$work/d" && echo hi > "$work/d/f"
cd "$work"
status=0
check() {
local n=$1 want=$2 p got err
p=$(printf 'a%.0s' $(seq 1 "$n"))
rm -f "p$n.aea"
if aa archive -D d -o "p$n.aea" -password-value "$p" 2>"e$n.txt" && [ -s "p$n.aea" ]; then
got=pass
else
got=fail
fi
err=$(tr '\n' ' ' < "e$n.txt")
echo "len=$n want=$want got=$got err=$err"
[ "$got" = "$want" ] || status=1
}
check $((MIN - 1)) fail
check "$MIN" pass
check "$MAX" pass
check $((MAX + 1)) fail
exit "$status"The passwords are throwaway strings of a. Passing a real password with
-password-value would expose it to anything that can read the process list.
Here’s the output on macOS 27.2, trimmed a little:
ProductVersion: 27.2
BuildVersion: 26B123
len=19 want=fail got=fail err=Error preparing encryption context Error creating output stream archive failedError 0xb9076000 Password is too short
len=20 want=pass got=pass err=
len=256 want=pass got=pass err=
len=257 want=fail got=fail err=Password too long archive failedIt exited 0. Here’s the check that matters, running it with the number I’d believed:
MIN=32 bash check-aea-limit.shlen=31 want=fail got=pass err=
len=32 want=pass got=pass err=
len=256 want=pass got=pass err=
len=257 want=fail got=fail err=Password too long archive failedThat exits 1, because 31 passed when it shouldn’t have. That’s the boundary check I should have had in May. Always try your test with a wrong value once. A test that can’t fail doesn’t prove anything.
Rules I now follow
Test both sides of the line. A test that only uses a good value proves very little. The passwords my original tests accepted were 35 and 36 characters, which pass whether the minimum is 20 or 32.
Search before you assert. If you don’t know the limit yet, start with a wide, coarse list. My first run used 8, 16, 19, 20, 21, 24, 31, 32, 64, 128, 256 and 257. Only then pin N−1 and N. A narrow test around the number you believe can only tell you you’re wrong, not what’s right.
Read why it failed. On macOS 27.2 the exit code gave the right answer each time, but checking that a file exists wouldn’t:
| Length | Exit code | Output file | Error |
|---|---|---|---|
| 19 | 1 | 0 bytes | Password is too short |
| 20 | 0 | 19,456 bytes | None |
| 256 | 0 | 19,456 bytes | None |
| 257 | 1 | None | Password too long |
A rejected short password leaves an empty file behind, so a check that the file
exists would pass. The script checks the size as a second signal. It doesn’t check
the reason: want=fail got=fail passes for any error, so it prints the message and
you need to read it. The 0x number differs between macOS versions, so don’t match
on it.
Write down the version and the exact error. Record the version and build from
sw_vers, where it ran, and the text you saw:
| macOS | Build | Where | 19 | 20 | 256 | 257 |
|---|---|---|---|---|---|---|
| 14.8.9 | 23J631 | GitHub runner | Password is too short | Pass | Pass | Password too long |
| 15.8.2 | 24H232 | GitHub runner | Password is too short | Pass | Pass | Password too long |
| 26.6.2 | 25G83 | UTM VM | Password is too short | Pass | Pass | archive failed |
| 27.2 | 26B123 | MacBook Pro | Password is too short | Pass | Pass | Password too long |
The 26.6.2 cell shows why this matters. It says “archive failed” because my command
that day piped through tail -1 and kept only the last line, so I didn’t capture
the reason. It failed, but I can’t tell you the message. Keep the whole error.
An error text needs care in another way. My old commit quoted “Invalid password” as
proof of the 32 minimum. On macOS 27.2, aea prints that for 1 to 7, 257 and 400,
and Password is too short at 8, 9 and 19. aa says too short at every short
length I tried. A real error message doesn’t prove the number attached to it, and two
tools can word the same limit differently. Test the tool you name.
Know what your values measure. My test passwords are ASCII, so characters and
bytes are the same thing. On macOS 27.2, I tried a 2-byte character: nine é (18
bytes) was too short and ten é (20 bytes) worked. At the top, 128 é (256 bytes)
worked and 129 (258 bytes) was too long. So both limits count bytes there. I only
tried that on 27.2.
Check the other direction too. A limit can pass on every version and still leave
files that won’t travel. A 20-character .aea made on 27.2 opened on 14.8.9, 15.8.2
and 26.6.2, and one made on 26.6.2 opened on 27.2. I didn’t test files made on 14 or
15 opening elsewhere.
Word it as narrowly as you tested it. “20 to 256 ASCII characters with aa, at
these lengths, on these four versions” is what this test shows. Apple doesn’t publish the
numbers that I could find. Its SDK header only mentions an internal size range, so
any version I haven’t run could differ, and a future update could change it.
Keep it proved
- Put the test in the repo and run it where the app’s other tests run, so a change in a new macOS shows up as a red build and not as a user’s bug report.
- Run it on each new macOS you support, and add a row to the table.
- Don’t write “confirmed” or “verified” in a commit or a doc unless a test backs it. If you find those words on an old claim, test it before you build on it.
Related
- Test on GitHub’s macOS runners, to run this on several versions
- Run older macOS in a UTM VM, for versions GitHub doesn’t offer
- Encrypt with Apple Encrypted Archive