Path: redb-identity/tests/redb.Identity.Web.Tests/CsrfProtectionTests.cs Snapshot: redb-identity, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-identity Page: https://redbase.app/src/dev-2026-12-06/redb-identity/tests/redb.Identity.Web.Tests/CsrfProtectionTests.cs ---- using System.Net; using System.Net.Http; using AwesomeAssertions; using Microsoft.AspNetCore.Mvc.Testing; using Xunit; namespace redb.Identity.Web.Tests; /// /// F-1.1 regression test: /api/auth/login must reject form POSTs that are /// missing the antiforgery token, even with valid-looking credentials. /// public sealed class CsrfProtectionTests : IClassFixture { private readonly WebHostFixture _factory; public CsrfProtectionTests(WebHostFixture factory) { _factory = factory; } [Fact] public async Task Post_login_without_antiforgery_token_is_rejected() { var client = _factory.CreateClient(new WebApplicationFactoryClientOptions { AllowAutoRedirect = false }); var form = new FormUrlEncodedContent(new[] { new KeyValuePair("username", "anyone"), new KeyValuePair("password", "anything"), }); var resp = await client.PostAsync("/api/auth/login", form); // ASP.NET Core antiforgery returns 400 BadRequest when the token is absent // or invalid on a [FromForm] minimal API endpoint. resp.StatusCode.Should().Be(HttpStatusCode.BadRequest); } }