T13.9 follow-up 2: name PEM keys, forgive missing braces and double encoding, give a length hint (D23)

This commit is contained in:
2026-10-16 16:24:05 -07:00
parent 5cf6355a01
commit 5f8ebab5b2
3 changed files with 43 additions and 5 deletions

View File

@@ -200,11 +200,28 @@ for label, raw in variants.items():
chk(f"forgiven: {label}", isinstance(f.verified, dict) and f.user_calls == 1)
except OktaSyncError as e:
chk(f"forgiven: {label}", False, str(e))
# fields copied without the outer braces, and a value encoded twice, are forgiven
inner = json.dumps(rsa_jwk)[1:-1]
for label, raw in [("fields without braces (text)", inner),
("fields without braces (base64)", base64.b64encode(inner.encode()).decode()),
("encoded twice", base64.b64encode(b64.encode()).decode())]:
os.environ["OKTA_SYNC_PRIVATE_KEY"] = raw
try:
f = FakeOkta(rsa_pub)
okta_sync.fetch_users(http=f.client())
chk(f"forgiven: {label}", isinstance(f.verified, dict))
except OktaSyncError as e:
chk(f"forgiven: {label}", False, str(e))
pem = "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkq\n-----END PRIVATE KEY-----"
for label, raw in [("PEM text", pem), ("PEM in base64", base64.b64encode(pem.encode()).decode())]:
os.environ["OKTA_SYNC_PRIVATE_KEY"] = raw
err = fetch_err(FakeOkta()) or ""
chk(f"PEM is named: {label}", "PEM" in err and "MIIEvQ" not in err, err)
os.environ["OKTA_SYNC_PRIVATE_KEY"] = json.dumps({"keys": [rsa_jwk, rsa_jwk]})
chk("a key set with two keys is refused", "more than one key" in (fetch_err(FakeOkta()) or ""))
for label, raw, want in [
("garbage characters", "!!!not*base64!!!", "not valid base64"),
("base64 of non-JSON", base64.b64encode(b"hello world").decode(), "not JSON after decoding base64"),
("base64 of non-JSON", base64.b64encode(b"hello world").decode(), "not JSON after decoding base64 (11 characters, starts with a letter or digit)"),
("base64 of bytes that are not text", base64.b64encode(b"\xff\xfe\xfd\xfc").decode(), "not text"),
("broken JSON", "{ not json", "not JSON"),
]: