diff --git a/test/Core.Test/Utilities/StrictEmailAddressListAttributeTests.cs b/test/Core.Test/Utilities/StrictEmailAddressListAttributeTests.cs new file mode 100644 index 0000000000..2280fbb6c7 --- /dev/null +++ b/test/Core.Test/Utilities/StrictEmailAddressListAttributeTests.cs @@ -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 EmailList => new() + { + new object[] { new List { "test@domain.com", "test@sub.domain.com", "hello@world.planet.com" }, true }, + new object[] { new List { "/hello@world.com", "hello@##world.pla net.com", "''thello@world.com" }, false }, + new object[] { new List { "/hello.com", "test@domain.com", "''thello@world.com" }, false }, + new object[] { new List { "héllö@world.com", "hello@world.planet.com", "hello@world.planet.com" }, false }, + new object[] { new List { }, false }, + new object[] { new List + { + "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 + { + "test1domaincomtest2domaincomtest3domaincomtest4domaincomtest5domaincomtest6domaincomtest7domaincomtest8domaincomtest9domaincomtest10domaincomtest1domaincomtest2domaincomtest3domaincomtest4domaincomtest5domaincomtest6domaincomtest7domaincomtest8domaincomtest9domaincomtest10domaincom@test.com", + "test@domain.com" + }, false } // > 256 character email + + }; + + [Theory] + [MemberData(nameof(EmailList))] + public void IsListValid_ReturnsTrue_WhenValid(List 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); + } + } +}