fix(desktop): narrow publisher metadata parse recovery
This commit is contained in:
1 parent
046df1b122
commit
3fd0c6683d
3 files changed
+23
-6
No files matched your search
@@ -62,10 +62,11 @@ function same(left: DesktopObjectDigest | null, right: DesktopObjectDigest | nul
|
||||
}
|
||||
|
||||
function version(contents: string, remote = false): string {
|
||||
let parsed: { version: string } | undefined
|
||||
try {
|
||||
const parsed = z.object({ version: z.string() }).parse(load(contents))
|
||||
if (valid(parsed.version) !== null) return parsed.version
|
||||
} catch (_error) { /* Discard parser error details, which may include raw remote YAML. */ }
|
||||
parsed = z.object({ version: z.string() }).parse(load(contents))
|
||||
} catch (_parseError) { /* Discard parser error details, which may include raw remote YAML. */ }
|
||||
if (parsed !== undefined && valid(parsed.version) !== null) return parsed.version
|
||||
throw new DesktopPublishError(remote ? 'verification-failed' : 'invalid-plan',
|
||||
`desktop publish: invalid ${remote ? 'remote' : 'planned'} channel version`)
|
||||
}
|
||||
|
||||
@@ -127,3 +127,22 @@ it('classifies corrupted remote channel metadata separately from an invalid loca
|
||||
await expect(publishDesktopRelease(f.plan, f.operations)).rejects.toMatchObject({ code: 'verification-failed' })
|
||||
expect(f.writes).toEqual([])
|
||||
})
|
||||
|
||||
it.each(['version: [private-feed', 'version: 42\n', 'version: invalid-private-version\n'])(
|
||||
'rejects invalid channel metadata without exposing its contents: %s', async (contents) => {
|
||||
for (const remote of [false, true]) {
|
||||
const f = fixture()
|
||||
const plan: DesktopUploadPlan = remote ? f.plan : {
|
||||
...f.plan,
|
||||
artifacts: f.plan.artifacts.map(artifact => artifact.channelMetadata ? { ...artifact, contents } : artifact),
|
||||
}
|
||||
if (remote) f.objects.set('feed/nightly.yml', observed(contents))
|
||||
await expect(publishDesktopRelease(plan, f.operations)).rejects.toMatchObject({
|
||||
code: remote ? 'verification-failed' : 'invalid-plan',
|
||||
message: `desktop publish: invalid ${remote ? 'remote' : 'planned'} channel version`,
|
||||
})
|
||||
expect(f.writes).toEqual([])
|
||||
expect(f.tags()).toBe(0)
|
||||
}
|
||||
},
|
||||
)
|
||||
@@ -2,9 +2,6 @@
|
||||
"apps/cli/tests/built-bin.e2e.ts": {
|
||||
"cf101add035f69891416d7350e9a824c2de6c0d1b7a253de6a73da923023b073": 1
|
||||
},
|
||||
"apps/desktop/scripts/desktop-publish.ts": {
|
||||
"d37e8639087921e2491d45d40d63b44e72b30a516ad3a5f3155f467c7f5c3ac7": 1
|
||||
},
|
||||
"apps/desktop/src/client/WelcomePage.tsx": {
|
||||
"10ea16f7e56fe8d9176f54f90b2c2137b20e2c60e3f5cb45d6dc09fe23c52eae": 1
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user