Skip to content

Commit 5160920

Browse files
authored
StartupContextProvider should expand path environment variable (#5687)
1 parent 20bb914 commit 5160920

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/WebJobs.Script.WebHost/StartupContextProvider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ private StartupContext GetStartupContextOrNull()
104104
{
105105
try
106106
{
107+
contextPath = Environment.ExpandEnvironmentVariables(contextPath);
107108
_logger.LogDebug($"Loading startup context from {contextPath}");
108109
string content = File.ReadAllText(contextPath);
109110

test/WebJobs.Script.Tests/StartupContextProviderTests.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,15 @@ public void GetContext_InvalidPath_ReturnsNull()
141141
VerifyLastLog(LogLevel.Error, "Failed to load startup context");
142142
}
143143

144+
[Fact]
145+
public void GetContext_ExpandsEnvironmentVariables()
146+
{
147+
string path = Path.Combine("%TEMP%", $"{Guid.NewGuid()}.txt");
148+
WriteStartupContext(path: path);
149+
150+
Assert.NotNull(_startupContextProvider.Context);
151+
}
152+
144153
[Fact]
145154
public void GetContext_EnvVarNotSet_ReturnsNull()
146155
{
@@ -193,9 +202,10 @@ public void SetContext_AppliesHostAssignmentContext()
193202
Assert.Equal(_secrets.Host.System, secrets.SystemKeys);
194203
}
195204

196-
private string WriteStartupContext(string context = null)
205+
private string WriteStartupContext(string context = null, string path = null)
197206
{
198-
var path = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid()}.txt");
207+
path = path ?? Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid()}.txt");
208+
path = Environment.ExpandEnvironmentVariables(path);
199209
_environment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteStartupContextCache, path);
200210

201211
if (context == null)

0 commit comments

Comments
 (0)