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
@@ -0,0 +1,85 @@
using SGU.AuthBroker.Core.Profiles;
using Xunit;
namespace SGU.AuthBroker.Core.Tests;
public sealed class SguProfileParserTests
{
[Fact]
public void ParsesOnlyTheRequiredAdministrativeFieldsFromTheInitialResponse()
{
const string html = """
<html><body>
<span id="ctl00_contenedor_decEncabezado_lblNombre">
017045 - JESÚS&nbsp;ALEJANDRO ROSALES GONZÁLEZ
</span>
<span id="ctl00_contenedor_decEncabezado_lblIndicadorValue">
SINDICALIZADO QUINCENAL (ACTIVO)
</span>
<span id="ctl00_contenedor_decEncabezado_lblCorreo">
<a href="mailto:persona@lasalle.mx">persona@lasalle.mx</a>
</span>
<div style="display:none">
<span id="ctl00_contenedor_decEncabezado_lblPuesto">
ANALISTA DE PROYECTOS
</span>
<span id="ctl00_contenedor_decEncabezado_lblDependencia">
FACULTAD DE INGENIERÍA
</span>
<span id="ctl00_contenedor_decEncabezado_lblJefeNombre">
ESTE CAMPO NO DEBE EXTRAERSE
</span>
</div>
<table id="incidencias"><tr><td>DATOS NO REQUERIDOS</td></tr></table>
</body></html>
""";
InstitutionalProfile? profile = SguProfileParser.ParseAdministrative(html, "017045");
Assert.NotNull(profile);
Assert.Equal("017045", profile.EmployeeNumber);
Assert.Equal("JESÚS ALEJANDRO ROSALES GONZÁLEZ", profile.DisplayName);
Assert.Equal("persona@lasalle.mx", profile.Email);
Assert.Equal("SINDICALIZADO QUINCENAL (ACTIVO)", profile.EmployeeType);
Assert.Equal("ANALISTA DE PROYECTOS", profile.JobTitle);
Assert.Equal("FACULTAD DE INGENIERÍA", profile.Department);
}
[Fact]
public void RejectsAdministrativeMetadataForADifferentEmployeeNumber()
{
const string html = """
<span id='ctl00_contenedor_decEncabezado_lblNombre'>017045 - PERSONA INCORRECTA</span>
<span id='ctl00_contenedor_decEncabezado_lblCorreo'>incorrecta@lasalle.mx</span>
""";
Assert.Null(SguProfileParser.ParseAdministrative(html, "999999"));
}
[Fact]
public void ParsesTheMenuNameAsAConservativeFallback()
{
const string html = """
<span class="usuario" id="ctl00_lblNombreUsuario">
MARÍA&nbsp;&amp;&nbsp;JOSÉ
</span>
""";
InstitutionalProfile? profile = SguProfileParser.ParseMenu(html);
Assert.NotNull(profile);
Assert.Equal("MARÍA & JOSÉ", profile.DisplayName);
Assert.Null(profile.Email);
Assert.Null(profile.JobTitle);
Assert.Null(profile.Department);
}
[Fact]
public void MissingKnownFieldsProducesNoProfile()
{
Assert.Null(SguProfileParser.ParseMenu("<html><body>Portal SGU</body></html>"));
Assert.Null(SguProfileParser.ParseAdministrative(
"<html><body>Portal SGU</body></html>",
"017045"));
}
}