T13.9 follow-up: forgive paste damage in OKTA_SYNC_PRIVATE_KEY and name the failing step (D23)
This commit is contained in:
@@ -178,6 +178,41 @@ os.environ["OKTA_SYNC_CLIENT_ID"] = "0oaCLIENT"
|
||||
os.environ.pop("OKTA_SYNC_PRIVATE_KEY")
|
||||
chk("no key: not configured", okta_sync.auth_method() == "")
|
||||
|
||||
# 4b. Copy and paste damage is forgiven, and the messages say which step failed
|
||||
good = json.dumps(rsa_jwk)
|
||||
b64 = base64.b64encode(good.encode()).decode()
|
||||
variants = {
|
||||
"double quotes around base64": '"' + b64 + '"',
|
||||
"single quotes around base64": "'" + b64 + "'",
|
||||
"line breaks every 76 characters": "\n".join(b64[i:i + 76] for i in range(0, len(b64), 76)),
|
||||
"spaces and a trailing newline": " " + b64[:50] + " " + b64[50:] + " \r\n",
|
||||
"padding removed": b64.rstrip("="),
|
||||
"URL-safe alphabet": base64.urlsafe_b64encode(good.encode()).decode(),
|
||||
"byte-order mark in the file": base64.b64encode(b"\xef\xbb\xbf" + good.encode()).decode(),
|
||||
"JWK set with one key (JSON)": json.dumps({"keys": [rsa_jwk]}),
|
||||
"JWK set with one key (base64)": base64.b64encode(json.dumps({"keys": [rsa_jwk]}).encode()).decode(),
|
||||
}
|
||||
for label, raw in variants.items():
|
||||
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) and f.user_calls == 1)
|
||||
except OktaSyncError as e:
|
||||
chk(f"forgiven: {label}", False, str(e))
|
||||
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 bytes that are not text", base64.b64encode(b"\xff\xfe\xfd\xfc").decode(), "not text"),
|
||||
("broken JSON", "{ not json", "not JSON"),
|
||||
]:
|
||||
os.environ["OKTA_SYNC_PRIVATE_KEY"] = raw
|
||||
err = fetch_err(FakeOkta()) or ""
|
||||
chk(f"clear message: {label}", want in err, err)
|
||||
chk(f"no key text in message: {label}", raw[:8] not in err.replace("OKTA_SYNC_PRIVATE_KEY", ""), err)
|
||||
|
||||
# 5. An SSWS token still works and wins
|
||||
setenv(rsa_jwk)
|
||||
os.environ["OKTA_API_TOKEN"] = "ssws-token-value"
|
||||
|
||||
Reference in New Issue
Block a user