Add Gitea deploy workflow, compose stack and health endpoint
Build and deploy / build (push) Successful in 1m52s
Build and deploy / deploy (push) Successful in 30s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
TomandClaude Opus 5.5 committed 2026-11-14 14:32:25 +01:00
1 parent 7c39cb5562
commit e9758499ff
13 files changed
+421 -2

No files matched your search

@@ -6,6 +6,7 @@
<ItemGroup>
<PackageReference Include="coverlet.collector" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NSubstitute" />
<PackageReference Include="Shouldly" />
@@ -16,6 +17,7 @@
<ItemGroup>
<ProjectReference Include="..\..\src\Flypaper.Http\Flypaper.Http.csproj" />
<ProjectReference Include="..\..\src\Flypaper.Storage\Flypaper.Storage.csproj" />
<ProjectReference Include="..\..\src\Flypaper.Web\Flypaper.Web.csproj" />
</ItemGroup>
<ItemGroup>
@@ -0,0 +1,80 @@
using System.Net;
using Flypaper.Core;
using Flypaper.Core.Abstractions;
using Flypaper.Http;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using NSubstitute;
using Shouldly;
namespace Flypaper.Tests.Http;
public sealed class HealthProbeTests
{
[Theory]
[InlineData("172.19.0.7")]
[InlineData("127.0.0.1")]
[InlineData("192.168.1.20")]
[InlineData("::1")]
public async Task Lets_health_probe_from_private_network_pass_with_unknown_host(string remoteIp)
{
var (reachedApp, status) = await SendAsync(IPAddress.Parse(remoteIp), "/health");
reachedApp.ShouldBeTrue();
status.ShouldBe(StatusCodes.Status200OK);
}
[Fact]
public async Task Traps_health_path_from_public_ip()
{
var (reachedApp, status) = await SendAsync(IPAddress.Parse("203.0.113.9"), "/health");
reachedApp.ShouldBeFalse();
status.ShouldBe(StatusCodes.Status404NotFound);
}
[Fact]
public async Task Traps_other_paths_from_private_network_with_unknown_host()
{
var (reachedApp, _) = await SendAsync(IPAddress.Parse("172.19.0.7"), "/status");
reachedApp.ShouldBeFalse();
}
private static async Task<(bool ReachedApp, int Status)> SendAsync(IPAddress remoteIp, string path)
{
var configuration = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string?>
{
["Flypaper:MaxConnections"] = "0",
["Flypaper:Http:KnownHosts:0"] = "dashboard.lan"
})
.Build();
var services = new ServiceCollection()
.AddLogging()
.AddSingleton(Substitute.For<ITrapEventSink>())
.AddFlypaperCore(configuration)
.AddFlypaperHttp(configuration)
.BuildServiceProvider();
var reachedApp = false;
var app = new ApplicationBuilder(services);
app.UseFlypaper();
app.Run(_ =>
{
reachedApp = true;
return Task.CompletedTask;
});
var httpContext = new DefaultHttpContext { RequestServices = services };
httpContext.Connection.RemoteIpAddress = remoteIp;
httpContext.Request.Host = new HostString("flypaper:8080");
httpContext.Request.Path = path;
await app.Build()(httpContext);
return (reachedApp, httpContext.Response.StatusCode);
}
}
@@ -0,0 +1,53 @@
using System.Net;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Data.Sqlite;
using Shouldly;
namespace Flypaper.Tests.Web;
public sealed class HealthEndpointTests : IDisposable
{
private readonly string _dbPath = Path.Combine(Path.GetTempPath(), $"flypaper-health-{Guid.NewGuid():N}.db");
private readonly WebApplicationFactory<Program> _factory;
public HealthEndpointTests()
{
_factory = new WebApplicationFactory<Program>().WithWebHostBuilder(builder =>
{
builder.UseSetting("ConnectionStrings:Flypaper", $"Data Source={_dbPath}");
builder.UseSetting("Flypaper:Http:KnownHosts:0", "localhost");
});
}
[Fact]
public async Task Reports_healthy_without_login()
{
using var client = _factory.CreateClient(new WebApplicationFactoryClientOptions { AllowAutoRedirect = false });
var response = await client.GetAsync("/health");
response.StatusCode.ShouldBe(HttpStatusCode.OK);
(await response.Content.ReadAsStringAsync()).ShouldBe("healthy");
}
[Fact]
public async Task Keeps_dashboard_behind_login()
{
using var client = _factory.CreateClient(new WebApplicationFactoryClientOptions { AllowAutoRedirect = false });
var response = await client.GetAsync("/");
response.StatusCode.ShouldBe(HttpStatusCode.Redirect);
response.Headers.Location!.OriginalString.ShouldStartWith("http://localhost/login");
}
public void Dispose()
{
_factory.Dispose();
SqliteConnection.ClearAllPools();
foreach (var suffix in new[] { "", "-wal", "-shm" })
{
File.Delete(_dbPath + suffix);
}
}
}