1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-05 05:00:19 -05:00

Added unit tests for StrictEmailAddressListAttribute in Bit.Core.Utilities (#1652)

* Added unit tests for StrictEmailAddressListAttribute in Bit.Core.Utilities

* Fixed list format; added a null test on StrictEmailAddressListAttribute in Utilities
This commit is contained in:
SudoEvan 2021-10-29 12:24:53 -04:00 committed by GitHub
parent 114f58aa8e
commit dcc11e3819
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,55 @@
using System.Collections.Generic;
using Bit.Core.Utilities;
using Xunit;
namespace Bit.Core.Test.Utilities
{
public class StrictEmailAddressListAttributeTests
{
public static List<object[]> EmailList => new()
{
new object[] { new List<string> { "test@domain.com", "test@sub.domain.com", "hello@world.planet.com" }, true },
new object[] { new List<string> { "/hello@world.com", "hello@##world.pla net.com", "''thello@world.com" }, false },
new object[] { new List<string> { "/hello.com", "test@domain.com", "''thello@world.com" }, false },
new object[] { new List<string> { "héllö@world.com", "hello@world.planet.com", "hello@world.planet.com" }, false },
new object[] { new List<string> { }, false },
new object[] { new List<string>
{
"test1@domain.com", "test2@domain.com", "test3@domain.com", "test4@domain.com", "test5@domain.com",
"test6@domain.com", "test7@domain.com", "test8@domain.com", "test9@domain.com", "test10@domain.com",
"test11@domain.com", "test12@domain.com", "test13@domain.com", "test14@domain.com", "test15@domain.com",
"test16@domain.com", "test17@domain.com", "test18@domain.com", "test19@domain.com", "test20@domain.com",
"test21@domain.com", "test22@domain.com", "test23@domain.com", "test24@domain.com", "test25@domain.com",
}, false },
new object[] { new List<string>
{
"test1domaincomtest2domaincomtest3domaincomtest4domaincomtest5domaincomtest6domaincomtest7domaincomtest8domaincomtest9domaincomtest10domaincomtest1domaincomtest2domaincomtest3domaincomtest4domaincomtest5domaincomtest6domaincomtest7domaincomtest8domaincomtest9domaincomtest10domaincom@test.com",
"test@domain.com"
}, false } // > 256 character email
};
[Theory]
[MemberData(nameof(EmailList))]
public void IsListValid_ReturnsTrue_WhenValid(List<string> emailList, bool valid)
{
var sut = new StrictEmailAddressListAttribute();
var actual = sut.IsValid(emailList);
Assert.Equal(actual, valid);
}
[Theory]
[InlineData("single@email.com", false)]
[InlineData(null, false)]
public void IsValid_ReturnsTrue_WhenValid(string email, bool valid)
{
var sut = new StrictEmailAddressListAttribute();
var actual = sut.IsValid(email);
Assert.Equal(actual, valid);
}
}
}