From 84ad6bb77d965d17072a0027b0bfc7b1bc27629f Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Mon, 16 Mar 2026 19:56:05 -0400 Subject: [PATCH] Fix LDAP integration test: use GLAuth test credentials and runtime availability check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- src/ScadaLink.Host/appsettings.Central.json | 2 ++ .../AuthFlowTests.cs | 27 ++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/ScadaLink.Host/appsettings.Central.json b/src/ScadaLink.Host/appsettings.Central.json index d21a051..2c888a3 100644 --- a/src/ScadaLink.Host/appsettings.Central.json +++ b/src/ScadaLink.Host/appsettings.Central.json @@ -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 diff --git a/tests/ScadaLink.IntegrationTests/AuthFlowTests.cs b/tests/ScadaLink.IntegrationTests/AuthFlowTests.cs index ec2e3e1..591e6b7 100644 --- a/tests/ScadaLink.IntegrationTests/AuthFlowTests.cs +++ b/tests/ScadaLink.IntegrationTests/AuthFlowTests.cs @@ -103,10 +103,17 @@ public class AuthFlowTests : IClassFixture } [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 var content = new FormUrlEncodedContent(new[] { new KeyValuePair("username", "admin"), - new KeyValuePair("password", "admin") + new KeyValuePair("password", "password") }); var response = await client.PostAsync("/auth/login", content); @@ -129,4 +136,18 @@ public class AuthFlowTests : IClassFixture Assert.NotNull(setCookieHeader); Assert.Contains(CookieAuthenticationStateProvider.AuthCookieName, setCookieHeader); } + + private static async Task IsLdapAvailableAsync() + { + try + { + using var tcp = new System.Net.Sockets.TcpClient(); + await tcp.ConnectAsync("localhost", 3893).WaitAsync(TimeSpan.FromSeconds(2)); + return true; + } + catch + { + return false; + } + } }