using OpenWaf.Domain.Engine;
using OpenWaf.Domain.Responses;
using Xunit;
namespace OpenWaf.Tests.Unit;
///
/// The refusal as a page (OPEN-57). Two things are worth pinning here: which
/// clients get the page, and what the page is allowed to contain. Both are
/// rules about behaviour, not about looks — a page that leaks the operator's
/// note, quotes a rule pattern, or fetches a stylesheet is a different product
/// from the one this file describes.
///
public sealed class BlockPageTests
{
private static readonly DateTimeOffset T0 = new(2026, 10, 4, 12, 0, 0, TimeSpan.Zero);
[Theory]
// A browser: text/html named explicitly.
[InlineData("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", true)]
[InlineData("text/html", true)]
[InlineData("application/xhtml+xml;q=0.9", true)]
[InlineData("TEXT/HTML", true)]
[InlineData("text/plain;q=1, text/html;q=0.2", true)]
// Not a browser. `*/*` is "I did not think about it", and it is what curl,
// monitors, SDKs and scrapers send — the clients that parse the body.
[InlineData("*/*", false)]
[InlineData("", false)]
[InlineData(null, false)]
[InlineData("application/json", false)]
[InlineData("application/json;q=1,*/*;q=0.5", false)]
// Named, then refused.
[InlineData("text/html;q=0", false)]
[InlineData("text/html;q=0.0", false)]
public void Only_a_client_that_named_html_gets_the_page(string? accept, bool wantsHtml)
=> Assert.Equal(wantsHtml, BlockPage.PrefersHtml(accept));
[Fact]
public void Each_refusal_says_what_it_is_in_words()
{
Assert.Contains("You are asking too often.",
BlockPage.Render(EdgeVerdict.BlockRate, "rate_3_of_2", null, 12, T0));
Assert.Contains("This site blocked your address.",
BlockPage.Render(EdgeVerdict.BlockEngine, "3 consecutive refusals", null, 0, T0));
Assert.Contains("This path is refused on this site.",
BlockPage.Render(EdgeVerdict.BlockRule, "rule_12", null, 0, T0));
Assert.Contains("not available from your region",
BlockPage.Render(EdgeVerdict.GeoReject, "country_denied_DE", null, 0, T0));
Assert.Contains("added your address to a list",
BlockPage.Render(EdgeVerdict.BlockOperator, null, null, 0, T0));
}
[Fact]
public void The_reference_the_json_carries_is_the_reference_the_page_shows()
{
var page = BlockPage.Render(EdgeVerdict.BlockRule, "rule_12", null, 0, T0);
Assert.Contains("rule_12", page);
Assert.Contains("Reference:", page);
}
[Fact]
public void A_reference_is_text_and_never_becomes_an_element()
{
var page = BlockPage.Render(EdgeVerdict.BlockEngine,
"