Existing coverage was one integration test and zero e2e tests. Adds the thin, high-value integration/e2e layer unit tests can't reach (real Postgres wire contract, real browser flows) and wires it as a post-deploy smoke gate. - Seed a deterministic dev/QA admin user and fixed Development env key so HTTP-only tests can authenticate without per-run registration. - Expand the API integration suite: disabled-flag, unauthorized access, environment-document bootstrap, identity-override precedence, and auth login scenarios, reusing the existing black-box HTTP+Npgsql harness. - Add a Playwright suite for the admin SPA: login, nav, project/environment context selection, and feature create/toggle, against the real API. - Bind QA Postgres to 127.0.0.1 for direct seeding, add smoke-qa.sh and an ensure_node() bootstrap (the qa runner has no Node today), and wire a new smoke-qa CI job after deploy-qa.
56 lines
2.3 KiB
C#
56 lines
2.3 KiB
C#
using MicCheck.Api.Tests.Integration.Common;
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
namespace MicCheck.Api.Tests.Integration.Auth;
|
|
|
|
/// <summary>
|
|
/// A stand-in for the real API's <c>User</c> type: <see cref="PasswordHasher{TUser}"/> only uses
|
|
/// it as a type parameter (it doesn't inspect the instance), so any reference type works. Keeps
|
|
/// this project a true black box with no <c>ProjectReference</c> to the API.
|
|
/// </summary>
|
|
public class HashedUser;
|
|
|
|
public sealed record AuthSeed(int OrganizationId, int UserId, string Email, string Password)
|
|
{
|
|
public static async Task<AuthSeed> InsertAsync(TestDatabase db, string testRunTag, string password)
|
|
{
|
|
var rawUnique = $"{testRunTag}-{Guid.NewGuid():N}";
|
|
var unique = rawUnique[..Math.Min(rawUnique.Length, 40)];
|
|
var email = $"{unique}@integration.test";
|
|
var now = DateTimeOffset.UtcNow;
|
|
|
|
var passwordHash = new PasswordHasher<HashedUser>().HashPassword(new HashedUser(), password);
|
|
|
|
var organizationId = await db.ExecuteScalarAsync<int>(
|
|
"INSERT INTO \"Organizations\" (\"Name\", \"CreatedAt\") VALUES (@name, @createdAt) RETURNING \"Id\"",
|
|
("name", $"org_{unique}"),
|
|
("createdAt", now));
|
|
|
|
var userId = await db.ExecuteScalarAsync<int>(
|
|
"""
|
|
INSERT INTO "Users" ("Email", "PasswordHash", "FirstName", "LastName", "IsActive", "IsTwoFactorEnabled", "CreatedAt")
|
|
VALUES (@email, @passwordHash, 'Integration', 'Test', true, false, @createdAt)
|
|
RETURNING "Id"
|
|
""",
|
|
("email", email),
|
|
("passwordHash", passwordHash),
|
|
("createdAt", now));
|
|
|
|
await db.ExecuteAsync(
|
|
"""
|
|
INSERT INTO "OrganizationUsers" ("OrganizationId", "UserId", "Role", "IsPrimary")
|
|
VALUES (@orgId, @userId, 1, true)
|
|
""",
|
|
("orgId", organizationId),
|
|
("userId", userId));
|
|
|
|
return new AuthSeed(organizationId, userId, email, password);
|
|
}
|
|
|
|
public async Task CleanupAsync(TestDatabase db)
|
|
{
|
|
await db.ExecuteAsync("DELETE FROM \"Users\" WHERE \"Id\" = @userId", ("userId", UserId));
|
|
await db.ExecuteAsync("DELETE FROM \"Organizations\" WHERE \"Id\" = @orgId", ("orgId", OrganizationId));
|
|
}
|
|
}
|