feat(auth): 0.5.0 passwordless group lookup ILdapGroupLookup (ScadaBridge#46)
ILdapGroupLookup.GetUserGroupsAsync(username, ct) re-reads a known user's groups with the service account: same extraction, canonicalisation, endpoint walk (FallbackServers), timeouts and TLS policy as AuthenticateAsync, via one shared WalkEndpoints<T>. Explicit statuses: Found, UserNotFound, UserDisabled (AD userAccountControl), AmbiguousUser, DirectoryUnavailable, NotSupported (BindMode=User / no service account / foreign ILdapAuthService), ProviderDisabled. AddZbLdapAuth registers it as the same singleton. 0.5.0 is the first published version carrying 0.4.2-0.4.4; scadaproj#51 was live-verified against the NAM AD (24/24, identity check mutation-proven). Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
This commit is contained in:
+44
@@ -161,3 +161,47 @@ public class ServiceCollectionExtensionsTests
|
||||
Assert.False(options.AcceptDomainQualifiedNames);
|
||||
}
|
||||
}
|
||||
|
||||
public class LdapGroupLookupRegistrationTests
|
||||
{
|
||||
private static IConfiguration Config() =>
|
||||
new ConfigurationBuilder()
|
||||
.AddInMemoryCollection(new Dictionary<string, string?>
|
||||
{
|
||||
["Auth:Ldap:Server"] = "ldap.example.com",
|
||||
["Auth:Ldap:SearchBase"] = "dc=example,dc=com",
|
||||
["Auth:Ldap:ServiceAccountDn"] = "cn=svc,dc=example,dc=com",
|
||||
})
|
||||
.Build();
|
||||
|
||||
[Fact]
|
||||
public void AddZbLdapAuth_ResolvesGroupLookup_AsTheSameInstanceAsTheAuthService()
|
||||
{
|
||||
var services = new ServiceCollection().AddZbLdapAuth(Config(), "Auth:Ldap");
|
||||
using var provider = services.BuildServiceProvider();
|
||||
|
||||
var lookup = provider.GetRequiredService<ILdapGroupLookup>();
|
||||
|
||||
Assert.IsType<LdapAuthService>(lookup);
|
||||
Assert.Same(provider.GetRequiredService<ILdapAuthService>(), lookup);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AddZbLdapAuth_WithAForeignAuthService_ResolvesANotSupportedLookup()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton<ILdapAuthService, StubAuth>();
|
||||
services.AddZbLdapAuth(Config(), "Auth:Ldap");
|
||||
using var provider = services.BuildServiceProvider();
|
||||
|
||||
var result = await provider.GetRequiredService<ILdapGroupLookup>().GetUserGroupsAsync("alice", CancellationToken.None);
|
||||
|
||||
Assert.Equal(LdapGroupLookupStatus.NotSupported, result.Status);
|
||||
}
|
||||
|
||||
private sealed class StubAuth : ILdapAuthService
|
||||
{
|
||||
public Task<LdapAuthResult> AuthenticateAsync(string username, string password, CancellationToken ct)
|
||||
=> Task.FromResult(LdapAuthResult.Fail(LdapAuthFailure.Disabled));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user