XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESystem

【Rust】XFE系统,基于Rust和汇编

公开
关注 0 Fork 0 Star 0
UTF-8
using System.Security.Cryptography;
using System.Text.Json;

namespace XFESystem.Platform.Tests;

public sealed class ProvenanceTests
{
    [Fact]
    public void VendoredLunarFontSourcesMatchPinnedOfficialBytesAndRetainLicense()
    {
        var root = new DirectoryInfo(AppContext.BaseDirectory);
        while (root is not null && !Directory.Exists(Path.Combine(root.FullName, "Source", "XFESystem.Platform"))) root = root.Parent;
        Assert.NotNull(root);
        string directory = Path.Combine(root.FullName, "Source", "XFESystem.Platform", "ThirdParty", "LunarFonts");
        using var manifest = JsonDocument.Parse(File.ReadAllBytes(Path.Combine(directory, "SourceManifest.json")));
        Assert.Equal("6501f54cc1a943a1cea304c6a382724cdc7e2146", manifest.RootElement.GetProperty("Commit").GetString());
        Assert.Equal("Copyright (c) 2018 Sérgio Flores", manifest.RootElement.GetProperty("Copyright").GetString());
        foreach (var file in manifest.RootElement.GetProperty("Files").EnumerateArray())
        {
            string path = Path.Combine(directory, file.GetProperty("SnapshotPath").GetString()!);
            Assert.Equal(file.GetProperty("Sha256").GetString(), Convert.ToHexStringLower(SHA256.HashData(File.ReadAllBytes(path))));
            Assert.True(file.GetProperty("Verbatim").GetBoolean());
        }
        Assert.Contains("Copyright (c) 2018 Sérgio Flores", File.ReadAllText(Path.Combine(directory, "LICENSE")));
        var build = manifest.RootElement.GetProperty("PrivateBuild");
        byte[] upstream = File.ReadAllBytes(Path.Combine(directory, build.GetProperty("UpstreamSnapshotPath").GetString()!));
        byte[] compiled = File.ReadAllBytes(Path.Combine(directory, build.GetProperty("SnapshotPath").GetString()!));
        Assert.Equal(build.GetProperty("UpstreamSha256").GetString(), Convert.ToHexStringLower(SHA256.HashData(upstream)));
        Assert.Equal(build.GetProperty("Sha256").GetString(), Convert.ToHexStringLower(SHA256.HashData(compiled)));
        // Provenance contract: retain the exact upstream snapshot and prove
        // the private copy changes no raster algorithm or unrelated byte.
        string quiet = System.Text.Encoding.UTF8.GetString(upstream).Replace(
            "                                Console.WriteLine(\"Sorted \" + curr.ey + \" with \" + prox.ey);\r\n", "", StringComparison.Ordinal);
        Assert.Equal(System.Text.Encoding.UTF8.GetBytes(quiet), compiled);
    }
}