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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user