using System.IO.Compression; using System.Text.Json; using Admin.NET.Plugin.AiDOP.DataPlatform.UnifiedIngress; using Xunit; namespace Admin.NET.Plugin.AiDOP.Tests.DataPlatform; public sealed class MdpPushKitTests { [Theory] [InlineData("https://localhost:5443", true)] [InlineData("http://localhost:5443", false)] [InlineData("https://localhost:5443/other", false)] public void KitUsesPublishedMappingAndOnlyExportsApprovedHttpsOrigin(string origin, bool approved) { using var data = JsonDocument.Parse(""" {"datasetKey":"lab.purchase.v1","schemaVersion":"po-test","schemaJson":"{}", "rowSchema":{"type":"object","required":["VendorPoNo"]}, "endpoint":"/api/v1/ingest/lab.purchase.v1", "batchStatusEndpoint":"/api/v1/ingest/lab.purchase.v1/batches/{batchId}", "samples":{"json":"{}","ndjson":"{\"VendorPoNo\":\"PO-1\"}\n"}, "signatureVector":{"exampleKeyBase64":"example"}} """); using var zip = new ZipArchive(new MemoryStream(MdpPushKit.Build(data.RootElement, "801", origin))); using var openapi = JsonDocument.Parse(Read("openapi.json")); Assert.Equal(approved ? 1 : 0, openapi.RootElement.GetProperty("servers").GetArrayLength()); Assert.True(openapi.RootElement.GetProperty("paths").TryGetProperty("/api/v1/ingest/lab.purchase.v1", out _)); Assert.Contains("VendorPoNo", Read("row.schema.json")); Assert.Equal("{\"VendorPoNo\":\"PO-1\"}\n", Read("sample.ndjson")); Assert.DoesNotContain("SIGNING_KEY_BASE64=", Read("client.env")); Assert.All(new[] { "push.py", "push.mjs", "Push.cs", "Push.java" }, name => Assert.Contains("Idempotency-Key", Read(name))); string Read(string name) { using var reader = new StreamReader(zip.GetEntry(name)!.Open()); return reader.ReadToEnd(); } } }