fix: secure and verify native agent deployment
Heimdall Gitea / Detect CI scope (pull_request) Successful in 6s
Heimdall Gitea / Build and tests (pull_request) Failing after 14m15s
Heimdall Gitea / Build and scan server image (pull_request) Skipped
Heimdall Gitea / Build and scan agent image (pull_request) Skipped
Heimdall Gitea / Build and scan NVIDIA Agent image (pull_request) Skipped
Heimdall Gitea / Publish versioned installer release (pull_request) Skipped
Heimdall Gitea / CI policy (pull_request) Failing after 2s

This commit is contained in:
arnaud.dartois committed 2026-11-13 17:32:25 +01:00
1 parent 04b3279d1f
commit 923f9e7a55
18 files changed
+390 -113

No files matched your search

@@ -9,6 +9,26 @@ namespace Heimdall.Web.Tests.Controllers;
public sealed class UpdatesControllerRetryTests
{
[Fact]
public async Task FetchBoundedReleaseAssetAsync_allowsMissingForgejoDigestForSignedMetadata()
{
using var client = new HttpClient(new StaticResponseHandler("verified-by-release-signature"));
var result = await FetchAssetAsync("https://forgejo.example/attachments/release-key", digest: null, client);
Assert.Equal("verified-by-release-signature", Encoding.UTF8.GetString(result!));
}
[Fact]
public async Task FetchBoundedReleaseAssetAsync_rejectsCrossOriginUrls()
{
var handler = new StaticResponseHandler("unexpected");
using var client = new HttpClient(handler);
var result = await FetchAssetAsync("https://other.example/asset", digest: null, client);
Assert.Null(result);
Assert.Equal(0, handler.RequestCount);
}
[Theory]
[InlineData("<html><title>Proxy error</title></html>")]
[InlineData("{not-json")]
@@ -63,6 +83,40 @@ public sealed class UpdatesControllerRetryTests
return task.GetType().GetProperty("Result")?.GetValue(task);
}
private static async Task<byte[]?> FetchAssetAsync(string url, string? digest, HttpClient client)
{
var assetType = typeof(UpdatesController).GetNestedType("ForgejoAsset", BindingFlags.NonPublic);
Assert.NotNull(assetType);
var asset = Activator.CreateInstance(assetType)!;
assetType.GetProperty("Name")!.SetValue(asset, "agent-release-public.pem");
assetType.GetProperty("BrowserDownloadUrl")!.SetValue(asset, url);
assetType.GetProperty("Digest")!.SetValue(asset, digest);
var listType = typeof(List<>).MakeGenericType(assetType);
var assets = (System.Collections.IList)Activator.CreateInstance(listType)!;
assets.Add(asset);
var method = typeof(UpdatesController).GetMethod("FetchBoundedReleaseAssetAsync",
BindingFlags.NonPublic | BindingFlags.Static);
Assert.NotNull(method);
var task = (Task<byte[]?>)method.Invoke(null,
[assets, "agent-release-public.pem", client, 4096, new Uri("https://forgejo.example/api/v1/releases/latest"), CancellationToken.None])!;
return await task;
}
private sealed class StaticResponseHandler(string body) : HttpMessageHandler
{
public int RequestCount { get; private set; }
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
RequestCount++;
return Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
{
RequestMessage = request,
Content = new StringContent(body, Encoding.UTF8),
});
}
}
[Theory]
[InlineData(HttpStatusCode.RequestTimeout, true)]
[InlineData(HttpStatusCode.TooManyRequests, true)]