Repository navigation
refactor(deploy_keys): validate the key's base64 blob with z.base64(), the published pattern held in lockstep - #565
Merged
Conversation
…z.base64() at parse time The deploy key line was accepted by one hand-written regex built from a hand-written base64 grammar, with a second instance for material GitHub returned, and the rejection helpers ran only after the regex failed, to name a reason. The parse is now one structured walk: the fields, the form checks, the side's algorithm rule, then the blob under zod's z.base64(), which covers the alphabet, the padding, and the multiple-of-four length. materialPattern(), STORED_KEY_PATTERN, declaredRejection(), and storedRejection() are gone; the hand-spelled grammar remains only inside PUBLIC_KEY_PATTERN, the published JSON Schema pattern for the key field, whose capture groups are now non-capturing since nothing reads them. zod's check takes the empty string too; the two-field check ahead of it makes an empty blob a missing field on both sides. zod's own published base64 pattern opens with ^$| and cannot sit inside a larger pattern, so the published grammar stays hand-spelled, and test/sections/deploy_keys/published-pattern.test.ts holds the published pattern and parsePublicKey to one verdict over the generators' keys, a seeded sweep over every axis of the line, and the hand-made invalid set (bad padding, a non-base64 character, an empty blob, a wrong length class). Differential check, the origin/main module against this one: 20,050 distinct key lines (45 hand-made, 5 from the e2e generators, 20,000 seeded random), parsePublicKey and parseStoredKey compared on verdict, message, and material: 0 mismatches. The published pattern against the new parsePublicKey: 0 mismatches. Blob-level control: zod's check and the hand grammar diverge on exactly one blob, the empty string. Every refusal message is unchanged.
Contributor
File size check0 over a hard cap (fails), 6 warning(s).
Split the file, wrap the line, shorten or exempt the comment, or list the path in 5 managed file(s) skipped; repo-platform owns them. |
There was a problem hiding this comment.
🟢 Approval recommended
The focused parser refactor and schema-agreement tests have no identified blocking defects.
No open issues 🎉
What changed in this PR
Refactors deploy-key parsing to validate the base64 field with z.base64(), while retaining a separate pattern for the published JSON Schema.
Changes:
- Replaces regex-driven parsing with structured field, form, algorithm, and base64 checks.
- Adds tests comparing the published schema pattern with parser verdicts across generated, randomized, and invalid keys.
- Updates the refusal-message test's constant list for the renamed base64 pattern.
| File | Description |
|---|---|
test/sections/refusal-messages.test.ts |
Updates the base64 constant name in the test allowlist. |
test/sections/deploy_keys/published-pattern.test.ts |
Adds schema-pattern and parser agreement tests. |
src/sections/deploy_keys/schema.ts |
Introduces structured parsing with Zod base64 validation. |
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
How
materialPattern,STORED_KEY_PATTERN, the regex-drivenparseMaterial,declaredRejection,storedRejection;parseMaterialnow yields the material or the reason.z.base64(), the schema library already in use;ajvin the test, already a devDependency.Proof
build:check14 files unchanged, fleet biome 0, member-shape 0, line cap.Technical details
BASE64_BLOBisBASE64_PATTERN(the refusal-messages constant table follows).src/sections/deploy_keys/schema.ts,test/sections/deploy_keys/published-pattern.test.ts(new),test/sections/refusal-messages.test.ts.