Resolve SGU staff addresses and provision local student user
This commit is contained in:
@@ -228,6 +228,65 @@ public sealed class SguProfileParserTests
|
||||
Assert.Null(profile.Email);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolvesAdministrativeAddressFromPageMethodIdentifiers()
|
||||
{
|
||||
const string html = """
|
||||
<html><body>
|
||||
<input id='ctl00_contenedor_txtCalle' value='RETORNO 1, SUR 16' />
|
||||
<input id='ctl00_contenedor_txtNoExt' value='74' />
|
||||
<input id='ctl00_contenedor_txtNoInt' value='' />
|
||||
<input id='ctl00_contenedor_txtCP' value='08500' />
|
||||
<select id='ctl00_contenedor_ddlEstado'>
|
||||
<option selected='selected' value='0'>Seleccione...</option>
|
||||
<option value='09'>CIUDAD DE MÉXICO</option>
|
||||
</select>
|
||||
<select id='ctl00_contenedor_ddlLocalidad'>
|
||||
<option selected='selected' value='0'>Seleccione alguna localidad...</option>
|
||||
</select>
|
||||
<select id='ctl00_contenedor_ddlColonia'>
|
||||
<option selected='selected' value='0,0'>Seleccione alguna colonia...</option>
|
||||
</select>
|
||||
</body></html>
|
||||
""";
|
||||
const string directionJson = """
|
||||
{"d":[{"p_IdCP":"091263","p_IdEstado":"09","p_NombreEstado":"","p_IdMunicipio":"006","p_NombreMunicipio":"","p_NombreColonia":"","p_Cp":"08500"}]}
|
||||
""";
|
||||
const string localitiesJson = """
|
||||
{"d":[{"ID_Estado":"09","Id_Municipio":"002","Nombre":"AZCAPOTZALCO"},{"ID_Estado":"09","Id_Municipio":"006","Nombre":"IZTACALCO"}]}
|
||||
""";
|
||||
const string neighborhoodsJson = """
|
||||
{"d":[{"p_IdCP":"091263","p_Nombre":"AGRÍCOLA ORIENTAL","p_Cp":"08500"}]}
|
||||
""";
|
||||
|
||||
SguAdministrativeLocationSelection? selection =
|
||||
SguProfileParser.ParseAdministrativeLocationSelection(directionJson, "08500");
|
||||
InstitutionalProfile? profile = SguProfileParser.ParseAdministrativeLocation(
|
||||
html,
|
||||
selection,
|
||||
localitiesJson,
|
||||
neighborhoodsJson);
|
||||
|
||||
Assert.NotNull(selection);
|
||||
Assert.Equal("09", selection.StateId);
|
||||
Assert.Equal("006", selection.MunicipalityId);
|
||||
Assert.Equal("091263", selection.NeighborhoodId);
|
||||
Assert.NotNull(profile);
|
||||
Assert.Equal("Retorno 1, Sur 16 74\r\nAgrícola Oriental", profile.StreetAddress);
|
||||
Assert.Equal("Iztacalco", profile.City);
|
||||
Assert.Equal("Ciudad de México", profile.State);
|
||||
Assert.Equal("08500", profile.PostalCode);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("not-json")]
|
||||
[InlineData("{\"d\":{}}")]
|
||||
[InlineData("{\"d\":[]}")]
|
||||
public void RejectsUnexpectedAdministrativeLocationPayloads(string json)
|
||||
{
|
||||
Assert.Null(SguProfileParser.ParseAdministrativeLocationSelection(json, "08500"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AdministrativePagesOverlayTheVerifiedIncidentsProfile()
|
||||
{
|
||||
|
||||
@@ -145,14 +145,24 @@ public sealed class NtlmCredentialValidatorTests
|
||||
<input id="ctl00_contenedor_txtNoExt" value="15" />
|
||||
<input id="ctl00_contenedor_txtCP" value="01000" />
|
||||
<select id="ctl00_contenedor_ddlEstado">
|
||||
<option selected="selected">CIUDAD DE MÉXICO</option>
|
||||
<option selected="selected" value="0">Seleccione...</option>
|
||||
<option value="09">CIUDAD DE MÉXICO</option>
|
||||
</select>
|
||||
<select id="ctl00_contenedor_ddlLocalidad">
|
||||
<option selected="selected">ÁLVARO OBREGÓN</option>
|
||||
<option selected="selected" value="0">Seleccione alguna localidad...</option>
|
||||
</select>
|
||||
<select id="ctl00_contenedor_ddlColonia">
|
||||
<option>FLORIDA</option>
|
||||
<option selected="selected" value="0,0">Seleccione alguna colonia...</option>
|
||||
</select>
|
||||
"""),
|
||||
JsonResponse("""
|
||||
{"d":[{"p_IdCP":"090001","p_IdEstado":"09","p_NombreEstado":"","p_IdMunicipio":"010","p_NombreMunicipio":"","p_NombreColonia":"FLORIDA","p_Cp":"01000"}]}
|
||||
"""),
|
||||
JsonResponse("""
|
||||
{"d":[{"ID_Estado":"09","Id_Municipio":"010","Nombre":"ÁLVARO OBREGÓN"}]}
|
||||
"""),
|
||||
JsonResponse("""
|
||||
{"d":[{"p_IdCP":"090001","p_Nombre":"FLORIDA","p_Cp":"01000"}]}
|
||||
"""));
|
||||
NtlmCredentialValidator validator = CreateValidator(handler);
|
||||
|
||||
@@ -180,9 +190,17 @@ public sealed class NtlmCredentialValidatorTests
|
||||
"/psulsa/",
|
||||
"/psulsa/gadmon/capitalhumano/controlincidencias/incidencias.aspx",
|
||||
"/psulsa/gadmon/capitalhumano/datos/personales.aspx",
|
||||
"/psulsa/gadmon/capitalhumano/datos/ubicacion.aspx"
|
||||
"/psulsa/gadmon/capitalhumano/datos/ubicacion.aspx",
|
||||
"/psulsa/gadmon/capitalhumano/datos/ubicacion.aspx/GetDireccion",
|
||||
"/psulsa/gadmon/capitalhumano/datos/ubicacion.aspx/GetLocalidadListado",
|
||||
"/psulsa/gadmon/capitalhumano/datos/ubicacion.aspx/GetColoniasListado"
|
||||
],
|
||||
handler.RequestPaths);
|
||||
Assert.Equal("{\"CodigoPostal\":\"01000\"}", handler.RequestBodies[5]);
|
||||
Assert.Equal("{\"pIdEstado\":\"09\"}", handler.RequestBodies[6]);
|
||||
Assert.Equal(
|
||||
"{\"pIdEstado\":\"\",\"pLocalidad\":\"\",\"CodigoPostal\":\"01000\"}",
|
||||
handler.RequestBodies[7]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -242,14 +260,24 @@ public sealed class NtlmCredentialValidatorTests
|
||||
<input id="ctl00_contenedor_txtNoExt" value="15" />
|
||||
<input id="ctl00_contenedor_txtCP" value="01000" />
|
||||
<select id="ctl00_contenedor_ddlEstado">
|
||||
<option selected="selected">CIUDAD DE MÉXICO</option>
|
||||
<option selected="selected" value="0">Seleccione...</option>
|
||||
<option value="09">CIUDAD DE MÉXICO</option>
|
||||
</select>
|
||||
<select id="ctl00_contenedor_ddlLocalidad">
|
||||
<option selected="selected">ÁLVARO OBREGÓN</option>
|
||||
<option selected="selected" value="0">Seleccione alguna localidad...</option>
|
||||
</select>
|
||||
<select id="ctl00_contenedor_ddlColonia">
|
||||
<option selected="selected">FLORIDA</option>
|
||||
<option selected="selected" value="0,0">Seleccione alguna colonia...</option>
|
||||
</select>
|
||||
"""),
|
||||
JsonResponse("""
|
||||
{"d":[{"p_IdCP":"090001","p_IdEstado":"09","p_NombreEstado":"","p_IdMunicipio":"010","p_NombreMunicipio":"","p_NombreColonia":"FLORIDA","p_Cp":"01000"}]}
|
||||
"""),
|
||||
JsonResponse("""
|
||||
{"d":[{"ID_Estado":"09","Id_Municipio":"010","Nombre":"ÁLVARO OBREGÓN"}]}
|
||||
"""),
|
||||
JsonResponse("""
|
||||
{"d":[{"p_IdCP":"090001","p_Nombre":"FLORIDA","p_Cp":"01000"}]}
|
||||
"""));
|
||||
NtlmCredentialValidator validator = CreateValidator(handler);
|
||||
|
||||
@@ -280,7 +308,10 @@ public sealed class NtlmCredentialValidatorTests
|
||||
"/psulsa/menu.aspx",
|
||||
"/psulsa/gadmon/nomina/consultanomina.aspx",
|
||||
"/psulsa/gadmon/capitalhumano/datos/personales.aspx",
|
||||
"/psulsa/gadmon/capitalhumano/datos/ubicacion.aspx"
|
||||
"/psulsa/gadmon/capitalhumano/datos/ubicacion.aspx",
|
||||
"/psulsa/gadmon/capitalhumano/datos/ubicacion.aspx/GetDireccion",
|
||||
"/psulsa/gadmon/capitalhumano/datos/ubicacion.aspx/GetLocalidadListado",
|
||||
"/psulsa/gadmon/capitalhumano/datos/ubicacion.aspx/GetColoniasListado"
|
||||
],
|
||||
handler.RequestPaths);
|
||||
}
|
||||
@@ -363,18 +394,29 @@ public sealed class NtlmCredentialValidatorTests
|
||||
Content = new StringContent(content)
|
||||
};
|
||||
|
||||
private static HttpResponseMessage JsonResponse(string content) =>
|
||||
new(HttpStatusCode.OK)
|
||||
{
|
||||
Content = new StringContent(content, null, "application/json")
|
||||
};
|
||||
|
||||
private sealed class SequenceHandler(params HttpResponseMessage[] responses) : HttpMessageHandler
|
||||
{
|
||||
private readonly Queue<HttpResponseMessage> responses = new(responses);
|
||||
|
||||
public List<string> RequestPaths { get; } = [];
|
||||
|
||||
public List<string?> RequestBodies { get; } = [];
|
||||
|
||||
protected override Task<HttpResponseMessage> SendAsync(
|
||||
HttpRequestMessage request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
RequestPaths.Add(request.RequestUri!.AbsolutePath);
|
||||
RequestBodies.Add(request.Content is null
|
||||
? null
|
||||
: request.Content.ReadAsStringAsync(cancellationToken).GetAwaiter().GetResult());
|
||||
if (responses.Count == 0)
|
||||
{
|
||||
throw new InvalidOperationException("The validator sent more requests than expected.");
|
||||
|
||||
Reference in New Issue
Block a user