Files
ExecuteR/tests/Agent.Tests/ServerDownloadsTests.cs
Alphaeus Mote 739547e46c
CI / build-test (push) Successful in 25m31s
CI / images (push) Successful in 7m35s
CI / build-test (pull_request) Successful in 10m52s
CI / images (pull_request) Has been skipped
feat(server): the built-in store gives out real S3 presigned URLs
Like an external store's, and checked by the store itself; the server only passes
on one signed object. They are signed for a fixed name the server gives the store,
so they hold at any address. An external store's URLs lead straight to it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 20:19:52 -05:00

38 lines
1.6 KiB
C#

using Agent.Files;
using Shared.Infrastructure.Routing;
using Xunit;
namespace Agent.Tests;
public sealed class ServerDownloadsTests
{
private static readonly ServerUrl Server = ServerUrl.Parse("https://control.example.com/executer");
[Theory]
[InlineData("/api/s3/store/executer/a/b.zip?X-Amz-Expires=900&X-Amz-Signature=x", "https://control.example.com/executer/api/s3/store/executer/a/b.zip?X-Amz-Expires=900&X-Amz-Signature=x")]
[InlineData("https://s3.example.com/bucket/a.zip?X-Amz-Signature=x", "https://s3.example.com/bucket/a.zip?X-Amz-Signature=x")]
[InlineData("http://minio.local:9000/a.zip", "http://minio.local:9000/a.zip")]
public void A_server_path_goes_to_this_agents_server_and_an_absolute_url_stays(string url, string expected)
=> Assert.Equal(expected, ServerDownloads.Resolve(url, Server)?.AbsoluteUri);
[Theory]
[InlineData("")]
[InlineData("//elsewhere.example.com/a.zip")]
[InlineData("ftp://example.com/a.zip")]
[InlineData("file:///c:/windows/system32/config/sam")]
[InlineData("a.zip")]
public void Anything_else_is_refused(string url)
=> Assert.Null(ServerDownloads.Resolve(url, Server));
[Fact]
public void A_path_needs_a_server_to_go_to()
=> Assert.Null(ServerDownloads.Resolve("/api/s3/store/executer/a", null));
[Fact]
public void A_refused_link_does_not_put_its_signature_in_the_job_output()
{
var problem = Assert.Throws<InvalidOperationException>(() => new ServerDownloads(null, false).Resolve("/api/s3/store/executer/a?X-Amz-Signature=secret"));
Assert.DoesNotContain("secret", problem.Message);
}
}