Enrich AD users from SGU profile metadata

This commit is contained in:
2026-09-01 07:34:00 -06:00
parent 289a67e371
commit 3d0897316d
16 changed files with 563 additions and 22 deletions
@@ -1,6 +1,7 @@
using SGU.AuthBroker.Core.Authentication;
using SGU.AuthBroker.Core.Directory;
using SGU.AuthBroker.Core.Identity;
using SGU.AuthBroker.Core.Profiles;
using Xunit;
namespace SGU.AuthBroker.Core.Tests;
@@ -11,7 +12,13 @@ public sealed class AuthenticationWorkflowTests
public async Task PassesTheExactOriginalPasswordToNtlmAndActiveDirectory()
{
const string original = "Árbol-Exacto-🔐-NoDerivar-27!";
CapturingNtlmValidator ntlm = new(NtlmValidationResult.Valid());
InstitutionalProfile profile = new(
EmployeeNumber: "123456",
DisplayName: "Persona de Prueba",
Email: "persona@lasalle.mx",
JobTitle: "DOCENTE",
Department: "FACULTAD DE PRUEBA");
CapturingNtlmValidator ntlm = new(NtlmValidationResult.Valid(profile));
CapturingDirectorySynchronizer directory = new();
AuthenticationWorkflow workflow = new(ntlm, directory);
@@ -23,8 +30,9 @@ public sealed class AuthenticationWorkflowTests
Assert.Equal(AuthenticationFlowOutcome.Authorized, result.Outcome);
Assert.Same(original, ntlm.Password);
Assert.Same(original, directory.Password);
Assert.Equal("DO123456", ntlm.UserName);
Assert.Equal("DO123456", ntlm.Identity?.UserName);
Assert.Equal(InstitutionalRole.Professor, directory.Identity?.Role);
Assert.Same(profile, directory.Profile);
}
[Fact]
@@ -63,13 +71,16 @@ public sealed class AuthenticationWorkflowTests
private sealed class CapturingNtlmValidator(NtlmValidationResult result) : INtlmCredentialValidator
{
public string? UserName { get; private set; }
public UserIdentity? Identity { get; private set; }
public string? Password { get; private set; }
public Task<NtlmValidationResult> ValidateAsync(string userName, string password, CancellationToken cancellationToken)
public Task<NtlmValidationResult> ValidateAsync(
UserIdentity identity,
string password,
CancellationToken cancellationToken)
{
UserName = userName;
Identity = identity;
Password = password;
return Task.FromResult(result);
}
@@ -81,12 +92,16 @@ public sealed class AuthenticationWorkflowTests
public string? Password { get; private set; }
public InstitutionalProfile? Profile { get; private set; }
public Task<DirectorySyncResult> SynchronizeAsync(
UserIdentity identity,
InstitutionalProfile? profile,
string password,
CancellationToken cancellationToken)
{
Identity = identity;
Profile = profile;
Password = password;
return Task.FromResult(new DirectorySyncResult(
"LCI",