Generate test secrets the way Cottage's servers do (#10)

The local test made random32 and random16 secrets 32 and 16 URL-safe
characters, but Cottage's servers make them 24 and 12 characters from
an alphabet without look-alikes. A recipe that depended on a secret's
length or characters could pass locally and fail in production.
This commit is contained in:
michael authored and GitHub committed 2026-11-22 10:54:47 -05:00
1 parent 8b64c57058
commit c30fc19b71
1 file changed
+6 -2
+6 -2
View File
@@ -22,9 +22,13 @@ with socket.socket() as s: # a free port on this machine
s.bind(("127.0.0.1", 0))
port = s.getsockname()[1]
# Same as Cottage's servers: random32 and random16 are 24 and 12 characters from this
# alphabet (no look-alike characters), hex32 is 32 hex digits. Match them exactly, so a recipe
# that depends on a secret's length or characters fails here rather than in production.
ALPHA = "abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789"
GEN = {
"random32": lambda: secrets.token_urlsafe(24)[:32],
"random16": lambda: secrets.token_urlsafe(12)[:16],
"random32": lambda: "".join(secrets.choice(ALPHA) for _ in range(24)),
"random16": lambda: "".join(secrets.choice(ALPHA) for _ in range(12)),
"hex32": lambda: secrets.token_hex(16),
}
env = {