Files
jobtrackingapp/JobTrackerApi.Tests/RateLimitPartitionKeysTests.cs
T
cesnimda 8ef8b098c8
CI and Deploy / test (pull_request) Failing after 5m23s
CI and Deploy / deploy (pull_request) Has been skipped
fix(security): harden public CV edges
2026-08-15 20:53:16 +02:00

30 lines
1.1 KiB
C#

using System.Net;
using JobTrackerApi.Services;
using Microsoft.AspNetCore.Http;
using Xunit;
namespace JobTrackerApi.Tests;
public sealed class RateLimitPartitionKeysTests
{
[Fact]
public void Public_pdf_partition_isolated_by_client_and_slug()
{
var first = Context("203.0.113.10", "shared-slug");
var second = Context("203.0.113.11", "shared-slug");
var otherSlug = Context("203.0.113.10", "other-slug");
Assert.NotEqual(RateLimitPartitionKeys.PublicPdf(first), RateLimitPartitionKeys.PublicPdf(second));
Assert.NotEqual(RateLimitPartitionKeys.PublicPdf(first), RateLimitPartitionKeys.PublicPdf(otherSlug));
Assert.Equal(RateLimitPartitionKeys.PublicPdf(first), RateLimitPartitionKeys.PublicPdf(Context("203.0.113.10", "shared-slug")));
}
private static DefaultHttpContext Context(string address, string slug)
{
var context = new DefaultHttpContext();
context.Connection.RemoteIpAddress = IPAddress.Parse(address);
context.Request.RouteValues["slug"] = slug;
return context;
}
}