mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 15:42:48 -05:00
Add support for international domain names (IDN) in email addresses (#1512)
* Adjust email address checking to handle unicode * ASCII only in local part * allow unicode in second-level and top-level domain * Add PunyEncoding/Decoding methods and tests * Use PunyEncoding for outbound email recipients * Use MailKit for punycode, handle edge cases * Punyencode all email addresses in mailServices * Remove punyencoding from HandlebarsMailService * Add to punyencoding tests * Use more inclusive e-mail error * Fix comment wording * Apply StrictEmail checking to emergency access invite * Remove punyDecode helper
This commit is contained in:
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Bit.Core.Utilities;
|
||||
using Xunit;
|
||||
using MimeKit;
|
||||
|
||||
namespace Bit.Core.Test.Utilities
|
||||
{
|
||||
@ -216,5 +217,20 @@ namespace Bit.Core.Test.Utilities
|
||||
// Assert
|
||||
Assert.Equal(startingUri, newUri.ToString());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("bücher.com", "xn--bcher-kva.com")]
|
||||
[InlineData("bücher.cömé", "xn--bcher-kva.xn--cm-cja4c")]
|
||||
[InlineData("hello@bücher.com", "hello@xn--bcher-kva.com")]
|
||||
[InlineData("hello@world.cömé", "hello@world.xn--cm-cja4c")]
|
||||
[InlineData("hello@bücher.cömé", "hello@xn--bcher-kva.xn--cm-cja4c")]
|
||||
[InlineData("ascii.com", "ascii.com")]
|
||||
[InlineData("", "")]
|
||||
[InlineData(null, null)]
|
||||
public void PunyEncode_Success(string text, string expected)
|
||||
{
|
||||
var actual = CoreHelpers.PunyEncode(text);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ namespace Bit.Core.Test.Utilities
|
||||
[InlineData("hello@world.planet.com")] // subdomain
|
||||
[InlineData("hello+1@world.com")] // alias
|
||||
[InlineData("hello.there@world.com")] // period in local-part
|
||||
[InlineData("hello@wörldé.com")] // unicode domain
|
||||
[InlineData("hello@world.cömé")] // unicode top-level domain
|
||||
public void IsValid_ReturnsTrueWhenValid(string email)
|
||||
{
|
||||
var sut = new StrictEmailAddressAttribute();
|
||||
@ -43,6 +45,7 @@ namespace Bit.Core.Test.Utilities
|
||||
[InlineData("hellothere@.worldcom")] // domain beginning with dot
|
||||
[InlineData("hellothere@worldcom.")] // domain ending in dot
|
||||
[InlineData("hellothere@world.com-")] // domain ending in hyphen
|
||||
[InlineData("héllö@world.com")] // unicode in local-part
|
||||
public void IsValid_ReturnsFalseWhenInvalid(string email)
|
||||
{
|
||||
var sut = new StrictEmailAddressAttribute();
|
||||
|
Reference in New Issue
Block a user