Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 39 additions & 5 deletions .github/scripts/test-deploy-checks.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ const requiredKeys = (() => {

const script = runBody(body)

// Optional-key names the step includes only when configured: `if [ -n "${NAME:-}" ]; then`.
const optionalKeys = (() => {
return script
.split('\n')
.map((line) => line.match(/if \[ -n "\$\{([A-Za-z0-9_]+):-\}" \]/))
.filter(Boolean)
.map((match) => match[1])
})()

const SECRET_VALUE = 'test-value-not-a-real-secret'

const sandboxes = []
Expand Down Expand Up @@ -111,11 +120,36 @@ describe(`${STEP_NAME} step`, () => {
)
})

it('fail-closes on every secret it injects', () => {
assert.deepEqual(
[...requiredKeys].sort(),
Object.keys(declaredSecrets).sort(),
'every injected secret must be validated, and every validated secret injected'
it('fail-closes on required secrets and conditionally writes optional secrets', () => {
// Every fail-closed (required) secret must come from the repository secret of the same name.
for (const name of requiredKeys) {
assert.ok(
Object.hasOwn(declaredSecrets, name),
`required secret ${name} must be injected from a repository secret of the same name`
)
}
// Every injected secret is either fail-closed (required) or conditionally written (optional).
for (const name of Object.keys(declaredSecrets)) {
assert.ok(
requiredKeys.includes(name) || optionalKeys.includes(name),
`injected secret ${name} must be either fail-closed (required) or conditionally written (optional)`
)
}
// Every optional secret must be injected and written through the `if [ -n ... ]` block, never fail-closed.
for (const name of optionalKeys) {
assert.ok(
Object.hasOwn(declaredSecrets, name),
`optional secret ${name} must be injected from a repository secret of the same name`
)
assert.ok(
!requiredKeys.includes(name),
`optional secret ${name} must not be fail-closed in the required for loop`
)
}
// WAKER_SIGNING_KEY stays optional: unset -> official Cron, truthy -> waker, `false` -> no schedule.
assert.ok(
optionalKeys.includes('WAKER_SIGNING_KEY'),
'WAKER_SIGNING_KEY must be conditionally written, never fail-closed'
)
})

Expand Down