Migrate UI tests to Playwright dotta
This commit is contained in:
@@ -3,14 +3,31 @@ using System.Net.Http.Json;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using JdeScoping.Core.Models;
|
||||
using JdeScoping.Core.Models.Auth;
|
||||
using JdeScoping.Ui.Tests.Support;
|
||||
|
||||
namespace JdeScoping.Ui.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// API-level smoke tests for the authentication endpoint against the Docker host.
|
||||
/// Validates the RSA public-key exchange, encrypted login, and session cookie flow.
|
||||
/// Requires a running Docker host (Category: RequiresDockerHost).
|
||||
/// </summary>
|
||||
public class AuthApiSmokeTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Verifies the full login flow: fetch public key, encrypt credentials, POST login, and confirm session via /me.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Steps:
|
||||
/// <list type="number">
|
||||
/// <item>Create an HttpClient with a CookieContainer for session tracking.</item>
|
||||
/// <item>GET /api/auth/public-key and verify the PEM response.</item>
|
||||
/// <item>RSA-encrypt a test login payload using the returned public key.</item>
|
||||
/// <item>POST /api/auth/login with the encrypted payload and assert HTTP 200.</item>
|
||||
/// <item>GET /api/auth/me and assert HTTP 200 (session is authenticated).</item>
|
||||
/// </list>
|
||||
/// </remarks>
|
||||
[Fact]
|
||||
[Trait("Category", "RequiresDockerHost")]
|
||||
public async Task AuthApi_Login_WorksAgainstDockerHost()
|
||||
@@ -23,16 +40,17 @@ public class AuthApiSmokeTests
|
||||
Assert.NotNull(key);
|
||||
Assert.Contains("BEGIN PUBLIC KEY", key!.PublicKeyPem);
|
||||
|
||||
var payload = JsonSerializer.Serialize(new LoginModel { Username = "testuser", Password = "testpass" });
|
||||
string payload = JsonSerializer.Serialize(new LoginModel { Username = "testuser", Password = "testpass" });
|
||||
|
||||
using var rsa = RSA.Create();
|
||||
rsa.ImportFromPem(key.PublicKeyPem);
|
||||
var encrypted = rsa.Encrypt(Encoding.UTF8.GetBytes(payload), RSAEncryptionPadding.OaepSHA256);
|
||||
byte[] encrypted = rsa.Encrypt(Encoding.UTF8.GetBytes(payload), RSAEncryptionPadding.OaepSHA256);
|
||||
|
||||
var login = await client.PostAsJsonAsync("api/auth/login", new EncryptedLoginRequest(Convert.ToBase64String(encrypted)));
|
||||
var login = await client.PostAsJsonAsync("api/auth/login",
|
||||
new EncryptedLoginRequest(Convert.ToBase64String(encrypted)));
|
||||
Assert.Equal(HttpStatusCode.OK, login.StatusCode);
|
||||
|
||||
var me = await client.GetAsync("api/auth/me");
|
||||
Assert.Equal(HttpStatusCode.OK, me.StatusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user