Skip to content

Commit a0d2c07

Browse files
[Blueprint] Fix blueprint assignment name validation regex (Azure#19888)
* Fix blueprint assignment name validation regex * Update ChangeLog.md Co-authored-by: Yabo Hu <yabhu@microsoft.com>
1 parent 94146b5 commit a0d2c07

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/Blueprint/Blueprint.Test/ScenarioTests/BlueprintAssignmentTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Microsoft.Azure.Commands.Blueprint.Common;
1516
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17+
using System;
1618
using Xunit;
1719

1820
namespace Microsoft.Azure.Commands.Blueprint.Test.ScenarioTests
@@ -58,5 +60,15 @@ public void TestRemoveBlueprintAssignment()
5860
TestRunner.RunTestScript("Test-RemoveBlueprintAssignment");
5961
}
6062

63+
64+
[Fact]
65+
[Trait(Category.AcceptanceType, Category.CheckIn)]
66+
public void TestResourceNameValidation()
67+
{
68+
Assert.Null(Record.Exception(() => Utils.ValidateName("Valid-resourceId")));
69+
Assert.Null(Record.Exception(() => Utils.ValidateName("60b96b66-0ead-4cfc-831c-801616145b9c")));
70+
Assert.Null(Record.Exception(() => Utils.ValidateName("H_-e.l(1)o۳৭﹏dž")));
71+
Assert.Throws<ArgumentException>(() => Utils.ValidateName("trailing."));
72+
}
6173
}
6274
}

src/Blueprint/Blueprint/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Fixed blueprint assignment name validation
2122

2223
## Version 0.4.0
2324
* Fix custom delegating handler to only apply to Blueprint requests

src/Blueprint/Blueprint/Common/Utils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static string GetScopeForSubscription(string subscriptionId)
5757

5858
public static void ValidateName(string name)
5959
{
60-
var regex = @"^[0-9a-zA-Z_-]*$";
60+
var regex = @"^[-\w\._\(\)]+(?<!\.)$";
6161

6262
Match match = Regex.Match(name, regex, RegexOptions.CultureInvariant);
6363

0 commit comments

Comments
 (0)