Fix LDAP integration test: use GLAuth test credentials and runtime availability check

- Password "admin" → "password" (matches GLAuth config.toml)
- Replace hard Skip attribute with TCP connectivity check (test runs when GLAuth available)
- Add LdapSearchBase + AllowInsecureLdap to appsettings.Central.json for dev
This commit is contained in:
Joseph Doherty
2026-03-16 19:56:05 -04:00
parent dab8b061b5
commit 84ad6bb77d
2 changed files with 26 additions and 3 deletions

View File

@@ -24,6 +24,8 @@
"LdapServer": "localhost",
"LdapPort": 3893,
"LdapUseTls": false,
"AllowInsecureLdap": true,
"LdapSearchBase": "dc=scadalink,dc=local",
"JwtSigningKey": "CHANGE-ME-development-signing-key-at-least-32-chars",
"JwtExpiryMinutes": 15,
"IdleTimeoutMinutes": 30

View File

@@ -103,10 +103,17 @@ public class AuthFlowTests : IClassFixture<ScadaLinkWebApplicationFactory>
}
[Trait("Category", "Integration")]
[Fact(Skip = "Requires running GLAuth LDAP server (Docker). Run with: docker compose -f infra/docker-compose.yml up -d glauth")]
[Fact]
public async Task LoginEndpoint_WithValidLdapCredentials_SetsCookieAndRedirects()
{
// This test requires the GLAuth test LDAP server running on localhost:3893
// Requires GLAuth test LDAP server: docker compose -f infra/docker-compose.yml up -d glauth
// GLAuth runs on localhost:3893, baseDN dc=scadalink,dc=local, all passwords "password"
if (!await IsLdapAvailableAsync())
{
// Skip gracefully if GLAuth not running — not a test failure
return;
}
var client = _factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions
{
AllowAutoRedirect = false
@@ -115,7 +122,7 @@ public class AuthFlowTests : IClassFixture<ScadaLinkWebApplicationFactory>
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("username", "admin"),
new KeyValuePair<string, string>("password", "admin")
new KeyValuePair<string, string>("password", "password")
});
var response = await client.PostAsync("/auth/login", content);
@@ -129,4 +136,18 @@ public class AuthFlowTests : IClassFixture<ScadaLinkWebApplicationFactory>
Assert.NotNull(setCookieHeader);
Assert.Contains(CookieAuthenticationStateProvider.AuthCookieName, setCookieHeader);
}
private static async Task<bool> IsLdapAvailableAsync()
{
try
{
using var tcp = new System.Net.Sockets.TcpClient();
await tcp.ConnectAsync("localhost", 3893).WaitAsync(TimeSpan.FromSeconds(2));
return true;
}
catch
{
return false;
}
}
}