Skip to content

Commit 27a9a66

Browse files
committed
Fixing issue with host ID trailing dash removal
1 parent 32a48fb commit 27a9a66

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

src/WebJobs.Script/Host/ScriptHost.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,8 +1093,7 @@ internal static string GetDefaultHostId(ScriptSettingsManager settingsManager, S
10931093
else if (!string.IsNullOrEmpty(settingsManager.AzureWebsiteUniqueSlotName))
10941094
{
10951095
// If running on Azure Web App, derive the host ID from unique site slot name
1096-
// Trim any trailing - as they can cause problems with queue names
1097-
hostId = settingsManager.AzureWebsiteUniqueSlotName.TrimEnd('-');
1096+
hostId = settingsManager.AzureWebsiteUniqueSlotName;
10981097
}
10991098

11001099
if (!string.IsNullOrEmpty(hostId))
@@ -1106,7 +1105,8 @@ internal static string GetDefaultHostId(ScriptSettingsManager settingsManager, S
11061105
}
11071106
}
11081107

1109-
return hostId?.ToLowerInvariant();
1108+
// Lowercase and trim any trailing '-' as they can cause problems with queue names
1109+
return hostId?.ToLowerInvariant().TrimEnd('-');
11101110
}
11111111

11121112
private void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)

test/WebJobs.Script.Tests/ScriptHostTests.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,20 +1054,19 @@ public void GetDefaultHostId_SelfHost_ReturnsExpectedResult()
10541054
Assert.Equal($"{sanitizedMachineName}-789851553", hostId);
10551055
}
10561056

1057-
[Fact]
1058-
public void GetDefaultHostId_AzureHost_ReturnsExpectedResult()
1057+
[Theory]
1058+
[InlineData("TEST-FUNCTIONS--", "test-functions")]
1059+
[InlineData("TEST-FUNCTIONS-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "test-functions-xxxxxxxxxxxxxxxxx")]
1060+
[InlineData("TEST-FUNCTIONS-XXXXXXXXXXXXXXXX-XXXX", "test-functions-xxxxxxxxxxxxxxxx")] /* 32nd character is a '-' */
1061+
[InlineData(null, null)]
1062+
public void GetDefaultHostId_AzureHost_ReturnsExpectedResult(string input, string expected)
10591063
{
10601064
var config = new ScriptHostConfiguration();
1061-
string subdomain = "TEST-FUNCTIONS--";
10621065
var scriptSettingsManagerMock = new Mock<ScriptSettingsManager>(MockBehavior.Strict);
1063-
scriptSettingsManagerMock.SetupGet(p => p.AzureWebsiteUniqueSlotName).Returns(() => subdomain);
1066+
scriptSettingsManagerMock.SetupGet(p => p.AzureWebsiteUniqueSlotName).Returns(() => input);
10641067

10651068
string hostId = ScriptHost.GetDefaultHostId(scriptSettingsManagerMock.Object, config);
1066-
Assert.Equal("test-functions", hostId);
1067-
1068-
subdomain = "TEST-FUNCTIONS-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
1069-
hostId = ScriptHost.GetDefaultHostId(scriptSettingsManagerMock.Object, config);
1070-
Assert.Equal("test-functions-xxxxxxxxxxxxxxxxx", hostId);
1069+
Assert.Equal(expected, hostId);
10711070
}
10721071

10731072
public class AssemblyMock : Assembly

0 commit comments

Comments
 (0)