test(packaging): cover malformed manifests with a valid hash

Invalid JSON, missing or null required fields, an unknown format version, an
unsafe product name and an empty component list are all reported as corrupt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-02 10:26:21 +00:00
1 parent 6555549e0c
commit ee1ba9a4ad
2 files changed
+17 -2

No files matched your search

@@ -109,10 +109,12 @@ internal sealed class PackagingFixture(TestContext context)
BinaryPrimitives.ReadInt32LittleEndian(image.AsSpan(0x3C)) + 4 + 20 + 112 + 4 * 8;
/// <summary>Assembles an installer by hand from a manifest and data region, bypassing the writer's checks.</summary>
public string Craft(PayloadManifest manifest, byte[] data, string name = "crafted.exe")
public string Craft(PayloadManifest manifest, byte[] data, string name = "crafted.exe") => Craft(manifest.ToJsonBytes(), data, name);
/// <summary>Same with raw manifest bytes, which need not be valid JSON; the footer hash always matches them.</summary>
public string Craft(byte[] json, byte[] data, string name = "crafted.exe")
{
var stub = CraftStub;
var json = manifest.ToJsonBytes();
using var ms = new MemoryStream();
ms.Write(stub);
ms.Write(json);
@@ -142,6 +142,19 @@ public sealed class PayloadIntegrityTests(TestContext context)
Assert.Equal(PayloadError.UnsafePath, Assert.Throws<PayloadException>(() => PayloadReader.Open(installer)).Error);
}
[Theory]
[Case("not json at all")]
[Case("{\"formatVersion\":1,\"version\":\"1.0\"}")]
[Case("{\"formatVersion\":1,\"product\":null,\"version\":\"1.0\"}")]
[Case("{\"formatVersion\":2,\"product\":\"Titano\",\"version\":\"1.0\",\"components\":[{\"id\":\"Titano\",\"displayName\":\"Titano\"}]}")]
[Case("{\"formatVersion\":1,\"product\":\"..\",\"version\":\"1.0\",\"components\":[{\"id\":\"Titano\",\"displayName\":\"Titano\"}]}")]
[Case("{\"formatVersion\":1,\"product\":\"Titano\",\"version\":\"1.0\",\"components\":[]}")]
public void MalformedManifestWithMatchingHashIsCorrupt(string json)
{
var installer = _fx.Craft(System.Text.Encoding.UTF8.GetBytes(json), []);
Assert.Equal(PayloadError.Corrupt, Assert.Throws<PayloadException>(() => PayloadReader.Open(installer)).Error);
}
[Test]
public void DeclaredSizeBeyondTheDeflateLimitIsRejectedUpFront()
{