up
Some checks failed
api-governance / spectral-lint (push) Has been cancelled
Docs CI / lint-and-preview (push) Has been cancelled
oas-ci / oas-validate (push) Has been cancelled
SDK Publish & Sign / sdk-publish (push) Has been cancelled
Policy Lint & Smoke / policy-lint (push) Has been cancelled
Policy Simulation / policy-simulate (push) Has been cancelled
devportal-offline / build-offline (push) Has been cancelled
Some checks failed
api-governance / spectral-lint (push) Has been cancelled
Docs CI / lint-and-preview (push) Has been cancelled
oas-ci / oas-validate (push) Has been cancelled
SDK Publish & Sign / sdk-publish (push) Has been cancelled
Policy Lint & Smoke / policy-lint (push) Has been cancelled
Policy Simulation / policy-simulate (push) Has been cancelled
devportal-offline / build-offline (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
using System.Threading.Tasks;
|
||||
using StellaOps.Scanner.WebService.Contracts;
|
||||
using Xunit;
|
||||
|
||||
namespace StellaOps.Scanner.WebService.Tests;
|
||||
|
||||
public sealed partial class ScansEndpointsTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task EntropyEndpoint_AttachesSnapshot_AndSurfacesInStatus()
|
||||
{
|
||||
using var secrets = new TestSurfaceSecretsScope();
|
||||
using var factory = new ScannerApplicationFactory(cfg =>
|
||||
{
|
||||
cfg["scanner:authority:enabled"] = "false";
|
||||
cfg["scanner:authority:allowAnonymousFallback"] = "true";
|
||||
});
|
||||
|
||||
using var client = factory.CreateClient();
|
||||
|
||||
var submitResponse = await client.PostAsJsonAsync("/api/v1/scans", new
|
||||
{
|
||||
image = new { digest = "sha256:image-demo" }
|
||||
});
|
||||
submitResponse.EnsureSuccessStatusCode();
|
||||
|
||||
var submit = await submitResponse.Content.ReadFromJsonAsync<ScanSubmitResponse>();
|
||||
Assert.NotNull(submit);
|
||||
|
||||
var entropyPayload = new EntropyIngestRequest(
|
||||
ImageOpaqueRatio: 0.42,
|
||||
Layers: new[]
|
||||
{
|
||||
new EntropyLayerRequest("sha256:layer-demo", 0.35, 3500, 10_000)
|
||||
});
|
||||
|
||||
var attachResponse = await client.PostAsJsonAsync($"/api/v1/scans/{submit!.ScanId}/entropy", entropyPayload);
|
||||
Assert.Equal(HttpStatusCode.Accepted, attachResponse.StatusCode);
|
||||
|
||||
var status = await client.GetFromJsonAsync<ScanStatusResponse>($"/api/v1/scans/{submit.ScanId}");
|
||||
Assert.NotNull(status);
|
||||
Assert.NotNull(status!.Entropy);
|
||||
Assert.Equal(0.42, status.Entropy!.ImageOpaqueRatio, 3);
|
||||
Assert.Single(status.Entropy!.Layers);
|
||||
var layer = status.Entropy!.Layers[0];
|
||||
Assert.Equal("sha256:layer-demo", layer.LayerDigest);
|
||||
Assert.Equal(0.35, layer.OpaqueRatio, 3);
|
||||
Assert.Equal(3500, layer.OpaqueBytes);
|
||||
Assert.Equal(10_000, layer.TotalBytes);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user