also looking at this
feat: own runtime firmware candidates
#49
24 files
+1245
-92
| @@ -0,0 +1,43 @@ | ||
| 1 | import { afterEach, expect, test } from 'bun:test' | |
| 2 | import { command } from '@stacksjs/testing' | |
| 3 | import { mkdtemp, readFile, rm } from 'node:fs/promises' | |
| 4 | import { tmpdir } from 'node:os' | |
| 5 | import { join } from 'node:path' | |
| 6 | import { enrollRuntimeTrust } from '../../resources/functions/drone/updates/enrollment' | |
| 7 | import { createRuntimeTrustStore } from '../../resources/functions/drone/updates/store' | |
| 8 | import { platform, repository, target } from '../fixtures/updates/repository' | |
| 9 | ||
| 10 | const roots: string[] = [] | |
| 11 | afterEach(async () => { for (const root of roots.splice(0)) await rm(root, { recursive: true, force: true }) }) | |
| 12 | ||
| 13 | test('native candidate commands require pinned trust and clock, retain identity and preserve explicit retirement semantics', async () => { | |
| 14 | const root = await mkdtemp(join(tmpdir(), 'drone-owned-candidate-cli-')); roots.push(root) | |
| 15 | const source = join(root, 'repo'), fixture = await repository(source, { custom: { releaseSequence: 9 } }) | |
| 16 | const enrollment = join(root, 'enrollment'), directory = join(root, 'store') | |
| 17 | const enrolled = enrollRuntimeTrust({ target, platform, trustedRootSha256: fixture.rootSha256, minimumReleaseSequence: 7, trustedRoot: fixture.rootPath, output: enrollment }) | |
| 18 | const created = await createRuntimeTrustStore({ enrollmentDirectory: enrollment, enrollmentSha256: enrolled.enrollmentSha256, output: directory }) | |
| 19 | const flags = ['--enrollment', enrollment, '--enrollment-sha256', enrolled.enrollmentSha256, '--store-sha256', created.storeSha256] | |
| 20 | const reserve = await command(['updates:reserve', directory, ...flags, '--repository', source, '--trusted-system-clock-source', 'operator-managed-test-clock']).withTimeout(20000) | |
| 21 | expect(reserve.exitCode).toBe(0) | |
| 22 | const value = JSON.parse(reserve.stdout) | |
| 23 | expect(value.candidate.phase).toBe('prepared') | |
| 24 | expect(value.candidate.integrity).toBe('recorded-bytes-match') | |
| 25 | expect(value.candidate.currentTrustValidated).toBe(false) | |
| 26 | expect(value.store.releaseFloor).toBe(9) | |
| 27 | expect(value.physicalDeploymentAllowed).toBe(false) | |
| 28 | const status = await command(['updates:candidates', directory, ...flags]).withTimeout(20000) | |
| 29 | expect(status.exitCode).toBe(0) | |
| 30 | expect(JSON.parse(status.stdout)).toEqual(value) | |
| 31 | const missingClock = await command(['updates:reserve', directory, ...flags, '--repository', source]).withTimeout(20000) | |
| 32 | expect(missingClock.exitCode).toBe(1) | |
| 33 | expect(missingClock.stdout).toBe('') | |
| 34 | expect(missingClock.stderr).toBe('Runtime update store unavailable: invalid trust, clock, state or storage failure\n') | |
| 35 | const wrong = await command(['updates:retire', directory, ...flags, '--candidate', '0'.repeat(32)]).withTimeout(20000) | |
| 36 | expect(wrong.exitCode).toBe(1) | |
| 37 | expect(wrong.stdout).toBe('') | |
| 38 | const retired = await command(['updates:retire', directory, ...flags, '--candidate', value.candidate.id]).withTimeout(20000) | |
| 39 | expect(retired.exitCode).toBe(0) | |
| 40 | expect(JSON.parse(retired.stdout).candidate).toBeNull() | |
| 41 | expect(JSON.parse(retired.stdout).store.releaseFloor).toBe(9) | |
| 42 | expect(await readFile(join(value.candidate.directory, 'image.bin'))).toEqual(fixture.image) | |
| 43 | }, 120000) | |