Improve SGU logon resilience and client UX
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
using System.Text;
|
||||
using SGU.AuthBroker.Core.Profiles;
|
||||
using Xunit;
|
||||
|
||||
namespace SGU.AuthBroker.Core.Tests;
|
||||
|
||||
public sealed class SguHtmlDecoderTests
|
||||
{
|
||||
[Fact]
|
||||
public void DecodesWindows1252WhenSguOmitsACharset()
|
||||
{
|
||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||
byte[] bytes = Encoding.GetEncoding(1252).GetBytes(
|
||||
"<span>ANALISTA DE INMERSIÓN — FACULTAD DE INGENIERÍA</span>");
|
||||
|
||||
string decoded = SguHtmlDecoder.Decode(bytes);
|
||||
|
||||
Assert.Contains("INMERSIÓN", decoded, StringComparison.Ordinal);
|
||||
Assert.Contains("INGENIERÍA", decoded, StringComparison.Ordinal);
|
||||
Assert.Contains('—', decoded);
|
||||
Assert.DoesNotContain('\uFFFD', decoded);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FallsBackWhenTheDeclaredUtf8CharsetIsIncorrect()
|
||||
{
|
||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||
byte[] bytes = Encoding.GetEncoding(1252).GetBytes("JESÚS GONZÁLEZ");
|
||||
|
||||
string decoded = SguHtmlDecoder.Decode(bytes, "utf-8");
|
||||
|
||||
Assert.Equal("JESÚS GONZÁLEZ", decoded);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HonorsValidUtf8WithoutADeclaration()
|
||||
{
|
||||
byte[] bytes = Encoding.UTF8.GetBytes("María del Carmen 🔐");
|
||||
|
||||
string decoded = SguHtmlDecoder.Decode(bytes);
|
||||
|
||||
Assert.Equal("María del Carmen 🔐", decoded);
|
||||
}
|
||||
}
|
||||
@@ -38,11 +38,11 @@ public sealed class SguProfileParserTests
|
||||
|
||||
Assert.NotNull(profile);
|
||||
Assert.Equal("017045", profile.EmployeeNumber);
|
||||
Assert.Equal("JESÚS ALEJANDRO ROSALES GONZÁLEZ", profile.DisplayName);
|
||||
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);
|
||||
Assert.Equal("Sindicalizado quincenal (activo)", profile.EmployeeType);
|
||||
Assert.Equal("Analista de Proyectos", profile.JobTitle);
|
||||
Assert.Equal("Facultad de Ingeniería", profile.Department);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -68,12 +68,44 @@ public sealed class SguProfileParserTests
|
||||
InstitutionalProfile? profile = SguProfileParser.ParseMenu(html);
|
||||
|
||||
Assert.NotNull(profile);
|
||||
Assert.Equal("MARÍA & JOSÉ", profile.DisplayName);
|
||||
Assert.Equal("María & José", profile.DisplayName);
|
||||
Assert.Null(profile.Email);
|
||||
Assert.Null(profile.JobTitle);
|
||||
Assert.Null(profile.Department);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("MARÍA DEL CARMEN", "María del Carmen")]
|
||||
[InlineData("MIGUEL DE CERVANTES", "Miguel de Cervantes")]
|
||||
[InlineData("CARLOS DE LA FUENTE", "Carlos de la Fuente")]
|
||||
[InlineData("MARÍA-JOSÉ O'CONNOR", "María-José O'Connor")]
|
||||
public void PreservesSpanishNameParticlesAndAccents(string source, string expected)
|
||||
{
|
||||
const string marker = "ctl00_lblNombreUsuario";
|
||||
|
||||
InstitutionalProfile? profile = SguProfileParser.ParseMenu(
|
||||
$"<span id=\"{marker}\">{source}</span>");
|
||||
|
||||
Assert.NotNull(profile);
|
||||
Assert.Equal(expected, profile.DisplayName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RejectsReplacementCharactersInsteadOfWritingCorruptMetadata()
|
||||
{
|
||||
const string html = """
|
||||
<span id="ctl00_contenedor_decEncabezado_lblNombre">017045 - JES�S ROSALES</span>
|
||||
<span id="ctl00_contenedor_decEncabezado_lblPuesto">ANALISTA DE INMERSI�N</span>
|
||||
""";
|
||||
|
||||
InstitutionalProfile? profile = SguProfileParser.ParseAdministrative(html, "017045");
|
||||
|
||||
Assert.NotNull(profile);
|
||||
Assert.Null(profile.DisplayName);
|
||||
Assert.Null(profile.JobTitle);
|
||||
Assert.Equal("017045", profile.EmployeeNumber);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MissingKnownFieldsProducesNoProfile()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user