Skip to content

Fix Email validation util. Would currently flag mail addresses that s… #10019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/Sql/Sql.Test/UnitTests/AzureSqlUtilTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Microsoft.Azure.Commands.Sql.Services;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using System;
using System.Collections.Generic;
using System.Text;
using Xunit;

namespace Microsoft.Azure.Commands.Sql.Test.UnitTests
{
public class AzureSqlUtilTests
{
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void MailValidation()
{
Assert.True(Util.AreEmailAddressesInCorrectFormat(new[] {
"[email protected]",
"[email protected]",
"[email protected]"}), "Valid email addresses are flagged as invalid");
Assert.False(Util.AreEmailAddressesInCorrectFormat(new[] { "kuku" }), "Invalid mail address not detected");
Assert.False(Util.AreEmailAddressesInCorrectFormat(new[] { "kuku@microsoft" }), "Invalid mail address not detected");
Assert.False(Util.AreEmailAddressesInCorrectFormat(new[] { "@micorsoft.com", "[email protected]" }), "One fauly mail address should fail the lot");
}
}
}
1 change: 1 addition & 0 deletions src/Sql/Sql/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* Added vCore example to creating an elastic pool (New-AzSqlElasticPool).
* Remove the validation of EmailAddresses and the check that EmailAdmins is not false in case EmailAddresses is empty in Set-AzSqlServerAdvancedThreatProtectionPolicy and Set-AzSqlDatabaseAdvancedThreatProtectionPolicy
* Enabled removal of server/database auditing settings when multiple diagnostic settings that enable audit category exist.
* Fix email addresses validation in multiple Sql Vulnerability Assessment cmdlets (Update-AzSqlDatabaseVulnerabilityAssessmentSetting, Update-AzSqlServerVulnerabilityAssessmentSetting, Update-AzSqlInstanceDatabaseVulnerabilityAssessmentSetting and Update-AzSqlInstanceVulnerabilityAssessmentSetting).

## Version 1.14.1
* Update documentation of old Auditing cmdlets.
Expand Down
2 changes: 1 addition & 1 deletion src/Sql/Sql/Services/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static bool AreEmailAddressesInCorrectFormat(string[] emailAddresses)
new Regex(string.Format("{0}{1}",
@"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))",
@"(?(\[)(\[(\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]))$"));
return !emailAddresses.Any(e => !emailRegex.IsMatch(e));
return !emailAddresses.Any(e => !emailRegex.IsMatch(e.ToLower()));
}
}
}