Skip to content

Commit a105cb4

Browse files
committed
Fixing issue with host ID trailing dash removal
1 parent c54adb7 commit a105cb4

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
@@ -1172,8 +1172,7 @@ internal static string GetDefaultHostId(ScriptSettingsManager settingsManager, S
11721172
else if (!string.IsNullOrEmpty(settingsManager.AzureWebsiteUniqueSlotName))
11731173
{
11741174
// If running on Azure Web App, derive the host ID from unique site slot name
1175-
// Trim any trailing - as they can cause problems with queue names
1176-
hostId = settingsManager.AzureWebsiteUniqueSlotName.TrimEnd('-');
1175+
hostId = settingsManager.AzureWebsiteUniqueSlotName;
11771176
}
11781177

11791178
if (!string.IsNullOrEmpty(hostId))
@@ -1185,7 +1184,8 @@ internal static string GetDefaultHostId(ScriptSettingsManager settingsManager, S
11851184
}
11861185
}
11871186

1188-
return hostId?.ToLowerInvariant();
1187+
// Lowercase and trim any trailing '-' as they can cause problems with queue names
1188+
return hostId?.ToLowerInvariant().TrimEnd('-');
11891189
}
11901190

11911191
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
@@ -1055,20 +1055,19 @@ public void GetDefaultHostId_SelfHost_ReturnsExpectedResult()
10551055
Assert.Equal($"{sanitizedMachineName}-789851553", hostId);
10561056
}
10571057

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

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

10741073
public class AssemblyMock : Assembly

0 commit comments

Comments
 (0)