Installer payload appended to the setup program: JSON manifest (components, files with size/SHA-256/offsets/mtime, shortcuts, file types) plus deflate or stored entries and a 64-byte footer with the manifest hash. The reader finds the footer before an Authenticode table, validates every offset, rejects unsafe paths and bounds inflation by the declared size; the writer is deterministic, deduplicates identical content and strips a signed stub. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
61 lines
1.7 KiB
C#
61 lines
1.7 KiB
C#
using Titano.Core.Packaging;
|
|
using Titano.Testing;
|
|
|
|
namespace Titano.Core.Tests.Packaging;
|
|
|
|
public sealed class PayloadPathTests(TestContext context)
|
|
{
|
|
[Theory]
|
|
[Case("Titano.exe")]
|
|
[Case("lib/deep/file.dll")]
|
|
[Case("città/日本語 ✓.txt")]
|
|
[Case(".hidden")]
|
|
[Case("CONFIG.SYS")]
|
|
[Case("console.log")]
|
|
public void AcceptsCanonicalRelativePaths(string path) => Assert.True(PayloadPath.IsValid(path), path);
|
|
|
|
[Theory]
|
|
[Case("")]
|
|
[Case("..")]
|
|
[Case("../x")]
|
|
[Case("a/../b")]
|
|
[Case("a/./b")]
|
|
[Case("a//b")]
|
|
[Case("/rooted")]
|
|
[Case("trailing/")]
|
|
[Case("C:/x")]
|
|
[Case("a\\b")]
|
|
[Case("a:stream")]
|
|
[Case("con")]
|
|
[Case("aux.txt")]
|
|
[Case("COM1")]
|
|
[Case("lpt9.log")]
|
|
[Case("dot.")]
|
|
[Case("space ")]
|
|
[Case("tab\tname")]
|
|
[Case("star*")]
|
|
public void RejectsUnsafePaths(string path) => Assert.False(PayloadPath.IsValid(path), path);
|
|
|
|
[Test]
|
|
public void RejectsOverlongPaths()
|
|
{
|
|
Assert.False(PayloadPath.IsValid(new string('a', 256)));
|
|
Assert.False(PayloadPath.IsValid(string.Join('/', Enumerable.Repeat("abcdefghij", 100))));
|
|
}
|
|
|
|
[Test]
|
|
public void ResolveStaysInsideTheRoot()
|
|
{
|
|
var root = context.CreateTempDirectory();
|
|
Assert.Equal(Path.Combine(root, "a", "b.txt"), PayloadPath.Resolve(root, "a/b.txt"));
|
|
Assert.Equal(PayloadError.UnsafePath, Assert.Throws<PayloadException>(() => PayloadPath.Resolve(root, "../b.txt")).Error);
|
|
}
|
|
|
|
[Test]
|
|
public void ConvertsNativeSeparators()
|
|
{
|
|
Assert.Equal("a/b/c.txt", PayloadPath.FromRelative("a\\b\\c.txt"));
|
|
Assert.Throws<PayloadException>(() => PayloadPath.FromRelative("..\\c.txt"));
|
|
}
|
|
}
|