diff --git a/src/ServiceManagement/Common/Commands.ScenarioTest/Commands.ScenarioTest.csproj b/src/ServiceManagement/Common/Commands.ScenarioTest/Commands.ScenarioTest.csproj
index ad81f675f239..df37c366081e 100644
--- a/src/ServiceManagement/Common/Commands.ScenarioTest/Commands.ScenarioTest.csproj
+++ b/src/ServiceManagement/Common/Commands.ScenarioTest/Commands.ScenarioTest.csproj
@@ -380,6 +380,7 @@
+
diff --git a/src/ServiceManagement/Common/Commands.ScenarioTest/ServiceManagement/UnitTests.cs b/src/ServiceManagement/Common/Commands.ScenarioTest/ServiceManagement/UnitTests.cs
new file mode 100644
index 000000000000..6d82aa4103de
--- /dev/null
+++ b/src/ServiceManagement/Common/Commands.ScenarioTest/ServiceManagement/UnitTests.cs
@@ -0,0 +1,76 @@
+// ----------------------------------------------------------------------------------
+//
+// Copyright Microsoft Corporation
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+// http://www.apache.org/licenses/LICENSE-2.0
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+// ----------------------------------------------------------------------------------
+
+using Microsoft.WindowsAzure.Commands.ServiceManagement.Extensions;
+using System;
+using Xunit;
+
+namespace Microsoft.WindowsAzure.Commands.ScenarioTest
+{
+ public partial class ServiceManagementTests
+ {
+ [Fact]
+ [Trait(Category.Service, Category.ServiceManagement)]
+ [Trait(Category.AcceptanceType, Category.CheckIn)]
+ [Trait(Category.AcceptanceType, Category.BVT)]
+ public void TestExtensionRoleNames()
+ {
+ var roleNames = new string[]
+ {
+ "test Role Name",
+ "!!!!! _____ test Role Name ~~~",
+ "testRoleName",
+ " testRoleName",
+ "testRoleName ",
+ " testRoleName"
+ };
+ var expectedPrefixName = "testRoleName";
+ var expectedExtensionId = "testRoleName-test-test-Ext-0";
+ foreach (var roleName in roleNames)
+ {
+ ExtensionRole er = new ExtensionRole(roleName);
+ Assert.Equal(er.PrefixName, expectedPrefixName);
+ Assert.Equal(er.GetExtensionId("test", "test", 0), expectedExtensionId);
+ }
+
+ var longRoleNames = new string[]
+ {
+ "A123456789B123456789C123456789D123456789E123456789F123456789G123456789H123456789",
+ " A123456789B123456789C123456789D123456789E123456789F123456789G123456789H123456789 ~~~"
+ };
+
+ // Extenion ID's Max Length 60 = 43 + 1 + 4 + 1 + 4 + 1 + 5
+ // i.e. 'A123...E123' + '-' + 'test' + '-' + 'test' + '-' + 'Ext-0'
+ // L=43 L=1 L=4 L=1 L=4 L=1 L=5
+ expectedPrefixName = longRoleNames[0];
+ expectedExtensionId = "A123456789B123456789C123456789D123456789E123-test-test-Ext-0";
+ foreach (var roleName in longRoleNames)
+ {
+ ExtensionRole er = new ExtensionRole(roleName);
+ Assert.Equal(er.PrefixName, expectedPrefixName);
+ Assert.Equal(er.GetExtensionId("test", "test", 0), expectedExtensionId);
+ }
+
+
+ var longExtensionNames = longRoleNames;
+ expectedExtensionId = "D-A123456789B123456789C123456789D123456789E123456-test-Ext-1";
+ foreach (var extensionName in longExtensionNames)
+ {
+ ExtensionRole er = new ExtensionRole();
+ Assert.Equal(er.PrefixName, "Default");
+ Assert.Equal(er.GetExtensionId(extensionName, "test", 1), expectedExtensionId);
+ }
+ }
+ }
+}
diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/Common/ExtensionRole.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/Common/ExtensionRole.cs
index 772144feb5cd..e417e42e913c 100644
--- a/src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/Common/ExtensionRole.cs
+++ b/src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/Common/ExtensionRole.cs
@@ -23,6 +23,7 @@ public class ExtensionRole
protected const string DefaultExtensionIdPrefixStr = "Default";
protected const string ExtensionIdSuffixTemplate = "-{0}-{1}-Ext-{2}";
protected const int MaxExtensionIdLength = 60;
+ protected const int MaxSuffixLength = MaxExtensionIdLength - 1;
public string RoleName { get; private set; }
public string PrefixName { get; private set; }
@@ -81,6 +82,12 @@ public string GetExtensionId(string extensionName, string slot, int index)
var suffix = new StringBuilder();
suffix.AppendFormat(ExtensionIdSuffixTemplate, normalizedExtName, slot, index);
+ if (suffix.Length > MaxSuffixLength)
+ {
+ int lenDiff = suffix.Length - MaxSuffixLength;
+ int startIndex = 1; // Suffix starts with '-'
+ suffix.Remove(startIndex + normalizedExtName.Length - lenDiff, lenDiff);
+ }
int prefixSubStrLen = Math.Min(Math.Max(MaxExtensionIdLength - suffix.Length, 0), PrefixName.Length);