MdpPushKitTests.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System.IO.Compression;
  2. using System.Text.Json;
  3. using Admin.NET.Plugin.AiDOP.DataPlatform.UnifiedIngress;
  4. using Xunit;
  5. namespace Admin.NET.Plugin.AiDOP.Tests.DataPlatform;
  6. public sealed class MdpPushKitTests
  7. {
  8. [Theory]
  9. [InlineData("https://localhost:5443", true)]
  10. [InlineData("http://localhost:5443", false)]
  11. [InlineData("https://localhost:5443/other", false)]
  12. public void KitUsesPublishedMappingAndOnlyExportsApprovedHttpsOrigin(string origin, bool approved)
  13. {
  14. using var data = JsonDocument.Parse("""
  15. {"datasetKey":"lab.purchase.v1","schemaVersion":"po-test","schemaJson":"{}",
  16. "rowSchema":{"type":"object","required":["VendorPoNo"]},
  17. "endpoint":"/api/v1/ingest/lab.purchase.v1",
  18. "batchStatusEndpoint":"/api/v1/ingest/lab.purchase.v1/batches/{batchId}",
  19. "samples":{"json":"{}","ndjson":"{\"VendorPoNo\":\"PO-1\"}\n"},
  20. "signatureVector":{"exampleKeyBase64":"example"}}
  21. """);
  22. using var zip = new ZipArchive(new MemoryStream(MdpPushKit.Build(data.RootElement, "801", origin)));
  23. using var openapi = JsonDocument.Parse(Read("openapi.json"));
  24. Assert.Equal(approved ? 1 : 0, openapi.RootElement.GetProperty("servers").GetArrayLength());
  25. Assert.True(openapi.RootElement.GetProperty("paths").TryGetProperty("/api/v1/ingest/lab.purchase.v1", out _));
  26. Assert.Contains("VendorPoNo", Read("row.schema.json"));
  27. Assert.Equal("{\"VendorPoNo\":\"PO-1\"}\n", Read("sample.ndjson"));
  28. Assert.DoesNotContain("SIGNING_KEY_BASE64=", Read("client.env"));
  29. Assert.All(new[] { "push.py", "push.mjs", "Push.cs", "Push.java" }, name => Assert.Contains("Idempotency-Key", Read(name)));
  30. string Read(string name)
  31. {
  32. using var reader = new StreamReader(zip.GetEntry(name)!.Open());
  33. return reader.ReadToEnd();
  34. }
  35. }
  36. }