Migrate Playwright suite to .NET UI tests and deprecate TS project
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using System.Net;
|
||||
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;
|
||||
|
||||
public class AuthApiSmokeTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", "RequiresDockerHost")]
|
||||
public async Task AuthApi_Login_WorksAgainstDockerHost()
|
||||
{
|
||||
var cookies = new CookieContainer();
|
||||
using var handler = new HttpClientHandler { CookieContainer = cookies };
|
||||
using var client = new HttpClient(handler) { BaseAddress = new Uri(UiTestSettings.BaseUrl) };
|
||||
|
||||
var key = await client.GetFromJsonAsync<PublicKeyResponse>("api/auth/public-key");
|
||||
Assert.NotNull(key);
|
||||
Assert.Contains("BEGIN PUBLIC KEY", key!.PublicKeyPem);
|
||||
|
||||
var 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);
|
||||
|
||||
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