Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (push) Has been skipped
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (push) Has been skipped
Build ErsatzTV Image / Build & test (.NET) (push) Successful in 7m45s
Build ErsatzTV Image / Functional E2E (curl contracts) (push) Successful in 14m19s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (push) Successful in 18m27s
Build ErsatzTV Image / Build & push image (amd64) (push) Successful in 4m10s
Co-authored-by: Timothy <timothy.look@gmail.com> Co-committed-by: Timothy <timothy.look@gmail.com>
51 lines
1.5 KiB
C#
51 lines
1.5 KiB
C#
using ErsatzTV.Middleware;
|
|
using Microsoft.AspNetCore.Http;
|
|
using NUnit.Framework;
|
|
using Shouldly;
|
|
|
|
namespace ErsatzTV.Tests.Middleware;
|
|
|
|
[TestFixture]
|
|
public class RequestLogScrubberTests
|
|
{
|
|
private static HttpRequest RequestFor(string path, string queryString)
|
|
{
|
|
var context = new DefaultHttpContext();
|
|
context.Request.Path = path;
|
|
context.Request.QueryString = new QueryString(queryString);
|
|
return context.Request;
|
|
}
|
|
|
|
[Test]
|
|
public void Redacts_access_token_but_keeps_other_query_params()
|
|
{
|
|
HttpRequest request = RequestFor(
|
|
"/iptv/channel/1.m3u8",
|
|
"?mode=segmenter&access_token=eyJhbGciOiJIUzI1NiJ9.secret.sig");
|
|
|
|
string scrubbed = RequestLogScrubber.ScrubbedPath(request);
|
|
|
|
scrubbed.ShouldNotContain("secret");
|
|
scrubbed.ShouldNotContain("eyJhbGciOiJIUzI1NiJ9");
|
|
scrubbed.ShouldContain("access_token=***");
|
|
scrubbed.ShouldContain("mode=segmenter");
|
|
scrubbed.ShouldStartWith("/iptv/channel/1.m3u8?");
|
|
}
|
|
|
|
[Test]
|
|
public void Redaction_is_case_insensitive_on_the_key()
|
|
{
|
|
HttpRequest request = RequestFor("/iptv/xmltv.xml", "?Access_Token=secret");
|
|
|
|
RequestLogScrubber.ScrubbedPath(request).ShouldNotContain("secret");
|
|
}
|
|
|
|
[Test]
|
|
public void Path_without_query_is_returned_verbatim()
|
|
{
|
|
HttpRequest request = RequestFor("/app", string.Empty);
|
|
|
|
RequestLogScrubber.ScrubbedPath(request).ShouldBe("/app");
|
|
}
|
|
}
|