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:
@@ -24,6 +24,8 @@
|
|||||||
"LdapServer": "localhost",
|
"LdapServer": "localhost",
|
||||||
"LdapPort": 3893,
|
"LdapPort": 3893,
|
||||||
"LdapUseTls": false,
|
"LdapUseTls": false,
|
||||||
|
"AllowInsecureLdap": true,
|
||||||
|
"LdapSearchBase": "dc=scadalink,dc=local",
|
||||||
"JwtSigningKey": "CHANGE-ME-development-signing-key-at-least-32-chars",
|
"JwtSigningKey": "CHANGE-ME-development-signing-key-at-least-32-chars",
|
||||||
"JwtExpiryMinutes": 15,
|
"JwtExpiryMinutes": 15,
|
||||||
"IdleTimeoutMinutes": 30
|
"IdleTimeoutMinutes": 30
|
||||||
|
|||||||
@@ -103,10 +103,17 @@ public class AuthFlowTests : IClassFixture<ScadaLinkWebApplicationFactory>
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Trait("Category", "Integration")]
|
[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()
|
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
|
var client = _factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions
|
||||||
{
|
{
|
||||||
AllowAutoRedirect = false
|
AllowAutoRedirect = false
|
||||||
@@ -115,7 +122,7 @@ public class AuthFlowTests : IClassFixture<ScadaLinkWebApplicationFactory>
|
|||||||
var content = new FormUrlEncodedContent(new[]
|
var content = new FormUrlEncodedContent(new[]
|
||||||
{
|
{
|
||||||
new KeyValuePair<string, string>("username", "admin"),
|
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);
|
var response = await client.PostAsync("/auth/login", content);
|
||||||
@@ -129,4 +136,18 @@ public class AuthFlowTests : IClassFixture<ScadaLinkWebApplicationFactory>
|
|||||||
Assert.NotNull(setCookieHeader);
|
Assert.NotNull(setCookieHeader);
|
||||||
Assert.Contains(CookieAuthenticationStateProvider.AuthCookieName, 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user