Skip to content

Commit b625f3d

Browse files
authored
Merge pull request Azure#10019 from Azure/fixEmailValidation
Fix Email validation util. Would currently flag mail addresses that s…
2 parents 8b1887a + 4b90ae8 commit b625f3d

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Microsoft.Azure.Commands.Sql.Services;
2+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Text;
6+
using Xunit;
7+
8+
namespace Microsoft.Azure.Commands.Sql.Test.UnitTests
9+
{
10+
public class AzureSqlUtilTests
11+
{
12+
[Fact]
13+
[Trait(Category.AcceptanceType, Category.CheckIn)]
14+
public void MailValidation()
15+
{
16+
Assert.True(Util.AreEmailAddressesInCorrectFormat(new[] {
17+
18+
19+
"[email protected]"}), "Valid email addresses are flagged as invalid");
20+
Assert.False(Util.AreEmailAddressesInCorrectFormat(new[] { "kuku" }), "Invalid mail address not detected");
21+
Assert.False(Util.AreEmailAddressesInCorrectFormat(new[] { "kuku@microsoft" }), "Invalid mail address not detected");
22+
Assert.False(Util.AreEmailAddressesInCorrectFormat(new[] { "@micorsoft.com", "[email protected]" }), "One fauly mail address should fail the lot");
23+
}
24+
}
25+
}

src/Sql/Sql/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* Added vCore example to creating an elastic pool (New-AzSqlElasticPool).
2323
* Remove the validation of EmailAddresses and the check that EmailAdmins is not false in case EmailAddresses is empty in Set-AzSqlServerAdvancedThreatProtectionPolicy and Set-AzSqlDatabaseAdvancedThreatProtectionPolicy
2424
* Enabled removal of server/database auditing settings when multiple diagnostic settings that enable audit category exist.
25+
* Fix email addresses validation in multiple Sql Vulnerability Assessment cmdlets (Update-AzSqlDatabaseVulnerabilityAssessmentSetting, Update-AzSqlServerVulnerabilityAssessmentSetting, Update-AzSqlInstanceDatabaseVulnerabilityAssessmentSetting and Update-AzSqlInstanceVulnerabilityAssessmentSetting).
2526

2627
## Version 1.14.1
2728
* Update documentation of old Auditing cmdlets.

src/Sql/Sql/Services/Util.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public static bool AreEmailAddressesInCorrectFormat(string[] emailAddresses)
9090
new Regex(string.Format("{0}{1}",
9191
@"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))",
9292
@"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$"));
93-
return !emailAddresses.Any(e => !emailRegex.IsMatch(e));
93+
return !emailAddresses.Any(e => !emailRegex.IsMatch(e.ToLower()));
9494
}
9595
}
9696
}

0 commit comments

Comments
 (0)