mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-25 07:13:50 +00:00
Fixed signing in to mailboxes with characters beyond ASCII in the username or password (#1224)
Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
This commit is contained in:
1 parent
f6a4348820
commit
c72a1948b3
27 files changed
+1052
-30
No files matched your search
@@ -55,6 +55,8 @@ public sealed class ImapMailboxConnectorTests
|
||||
{
|
||||
yield return Case("unknown transport security", MAILBOX with { TransportSecurity = MailboxTransportSecurity.UNKNOWN }, PASSWORD);
|
||||
yield return Case("unknown auth method", MAILBOX with { AuthMethod = MailboxAuthMethod.UNKNOWN }, PASSWORD);
|
||||
yield return Case("unknown password encoding", MAILBOX with { PasswordEncoding = MailboxPasswordEncoding.FromName("EBCDIC") }, PASSWORD);
|
||||
yield return Case("password encoding which changes ASCII", MAILBOX with { PasswordEncoding = MailboxPasswordEncoding.FromName("utf-16") }, PASSWORD);
|
||||
yield return Case("no host", MAILBOX with { Host = " " }, PASSWORD);
|
||||
yield return Case("a URL as host", MAILBOX with { Host = "imaps://imap.example.org" }, PASSWORD);
|
||||
yield return Case("port 0", MAILBOX with { Port = 0 }, PASSWORD);
|
||||
@@ -107,11 +109,59 @@ public sealed class ImapMailboxConnectorTests
|
||||
// a network failure instead of this one.
|
||||
//
|
||||
await using var connector = new ImapMailboxConnector();
|
||||
var policy = new MailServerPolicy(true, ["imap.intra.example.org"]);
|
||||
var policy = new MailServerPolicy(true, [new("imap.intra.example.org", null)]);
|
||||
var exception = await Assert.ThrowsAsync<MailboxConnectionException>(() => connector.ConnectAsync(MAILBOX, PASSWORD, policy, CancellationToken.None));
|
||||
Assert.That(exception?.Failure, Is.EqualTo(MailboxConnectionFailure.SERVER_NOT_ALLOWED));
|
||||
}
|
||||
|
||||
private static IEnumerable<TestCaseData> SignInPreparations()
|
||||
{
|
||||
const string UTF8 = "utf-8";
|
||||
const string WINDOWS_1252 = "windows-1252";
|
||||
|
||||
yield return Case("ASCII", UTF8, "someone", "Sommer-2026!", true, true);
|
||||
yield return Case("umlaut in the password", UTF8, "someone", "Grüße-2026", true, true);
|
||||
yield return Case("umlaut in the username", WINDOWS_1252, @"FIRMA\müller", "Sommer-2026!", true, true);
|
||||
yield return Case("Windows-1252 with umlaut and euro sign", WINDOWS_1252, "someone", "Grüße-100€", true, true);
|
||||
yield return Case("UTF-8 with Turkish and Japanese", UTF8, "kişi", "şifre-日本", true, true);
|
||||
yield return Case("Windows-1254 with Turkish", "windows-1254", "kişi", "şifre-2026", true, true);
|
||||
yield return Case("Shift-JIS with Japanese", "shift_jis", "利用者", "日本-2026", true, true);
|
||||
|
||||
// Windows-1252 lacks the capital sharp s and the Turkish s with cedilla, and AI Studio never switches to UTF-8 on its own:
|
||||
yield return Case("capital sharp s in Windows-1252", WINDOWS_1252, "someone", "STRAẞE", true, false);
|
||||
yield return Case("Turkish s in Windows-1252", WINDOWS_1252, "kişi", "Sommer-2026!", true, false);
|
||||
|
||||
// Without PLAIN, MailKit sends the LOGIN command in UTF-8, whatever it is handed:
|
||||
yield return Case("umlaut without PLAIN in UTF-8", UTF8, "someone", "Grüße-2026", false, true);
|
||||
yield return Case("umlaut without PLAIN in Windows-1252", WINDOWS_1252, "someone", "Grüße-2026", false, false);
|
||||
yield return Case("ASCII without PLAIN in Windows-1252", WINDOWS_1252, "someone", "Sommer-2026!", false, true);
|
||||
|
||||
// No encoding has a lone surrogate:
|
||||
yield return Case("lone surrogate", UTF8, "someone", "abc\uD800", true, false);
|
||||
yield break;
|
||||
|
||||
static TestCaseData Case(string name, string encoding, string username, string password, bool offersPlain, bool expected) => new TestCaseData(encoding, username, password, offersPlain).Returns(expected).SetArgDisplayNames(name);
|
||||
}
|
||||
|
||||
[TestCaseSource(nameof(SignInPreparations))]
|
||||
public bool ASignInGoesAheadOnlyWhenTheEncodingCarriesTheUsernameAndThePassword(string encoding, string username, string password, bool offersPlain)
|
||||
{
|
||||
return ImapMailboxConnector.TryPrepareSignIn(MailboxPasswordEncodingTests.GetKnownEncoding(encoding), username, password, offersPlain, out _, out _);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void APreparedSignInComposesADecomposedUmlautForWindows1252()
|
||||
{
|
||||
// An a followed by a combining diaeresis, as some password managers deliver an ä:
|
||||
const string DECOMPOSED = "Ka\u0308se";
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(ImapMailboxConnector.TryPrepareSignIn(MailboxPasswordEncodingTests.GetKnownEncoding("windows-1252"), "müller", DECOMPOSED, true, out var username, out var password), Is.True);
|
||||
Assert.That(username, Is.EqualTo("müller"));
|
||||
Assert.That(password, Is.EqualTo("Käse"));
|
||||
}
|
||||
}
|
||||
|
||||
[TestCase("Projects", '/', ExpectedResult = true)]
|
||||
[TestCase("Projekte 2026", '.', ExpectedResult = true)]
|
||||
[TestCase("Ablage/Alt", '.', ExpectedResult = true)]
|
||||
|
||||
Reference in new issue
Block a user