Skip to content

Commit a78720e

Browse files
committed
test and fix
1 parent 0b4c9a5 commit a78720e

File tree

3 files changed

+26
-32
lines changed

3 files changed

+26
-32
lines changed

src/Servers/IIS/AspNetCoreModuleV2/AspNetCore/ShimOptions.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ ShimOptions::ShimOptions(const ConfigurationSource &configurationSource) :
5454
.value_or(environmentVariables[CS_ASPNETCORE_ENVIRONMENT]);
5555
const auto dotnetEnvironment = Environment::GetEnvironmentVariableValue(CS_DOTNET_ENVIRONMENT)
5656
.value_or(environmentVariables[CS_DOTNET_ENVIRONMENT]);
57+
// We prefer the environment variables for LAUNCHER_PATH and LAUNCHER_ARGS
58+
m_strProcessPath = Environment::GetEnvironmentVariableValue(CS_ANCM_LAUNCHER_PATH)
59+
.value_or(m_strProcessPath);
60+
m_strArguments = Environment::GetEnvironmentVariableValue(CS_ANCM_LAUNCHER_ARGS)
61+
.value_or(m_strArguments);
5762

5863
auto detailedErrorsEnabled = equals_ignore_case(L"1", detailedErrors) || equals_ignore_case(L"true", detailedErrors);
5964
auto aspnetCoreEnvironmentEnabled = equals_ignore_case(L"Development", aspnetCoreEnvironment);

src/Servers/IIS/AspNetCoreModuleV2/RequestHandlerLib/requesthandler_config.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ REQUESTHANDLER_CONFIG::Populate(
102102
BSTR bstrBasicAuthSection = NULL;
103103
BSTR bstrAnonymousAuthSection = NULL;
104104
BSTR bstrAspNetCoreSection = NULL;
105-
auto launcherPathEnv = Environment::GetEnvironmentVariableValue(CS_ANCM_LAUNCHER_PATH);
106-
auto launcherArgsEnv = Environment::GetEnvironmentVariableValue(CS_ANCM_LAUNCHER_ARGS);
105+
std::optional<std::wstring> launcherPathEnv;
106+
std::optional<std::wstring> launcherArgsEnv;
107107

108108
pAdminManager = pHttpServer->GetAdminManager();
109109
try
@@ -252,13 +252,20 @@ REQUESTHANDLER_CONFIG::Populate(
252252
}
253253

254254
// We prefer the environment variables for LAUNCHER_PATH and LAUNCHER_ARGS
255+
try
256+
{
257+
launcherPathEnv = Environment::GetEnvironmentVariableValue(CS_ANCM_LAUNCHER_PATH);
258+
launcherArgsEnv = Environment::GetEnvironmentVariableValue(CS_ANCM_LAUNCHER_ARGS);
259+
}
260+
catch(...)
261+
{
262+
FINISHED_IF_FAILED(E_FAIL);
263+
}
264+
255265
if (launcherPathEnv.has_value())
256266
{
257267
hr = m_struProcessPath.Copy(launcherPathEnv.value().c_str());
258-
if (FAILED(hr))
259-
{
260-
goto Finished;
261-
}
268+
FINISHED_IF_FAILED(hr);
262269
}
263270
else
264271
{
@@ -274,10 +281,7 @@ REQUESTHANDLER_CONFIG::Populate(
274281
if (launcherArgsEnv.has_value())
275282
{
276283
hr = m_struArguments.Copy(launcherArgsEnv.value().c_str());
277-
if (FAILED(hr))
278-
{
279-
goto Finished;
280-
}
284+
FINISHED_IF_FAILED(hr);
281285
}
282286
else
283287
{

src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/StartupTests.cs

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -890,18 +890,10 @@ public async Task EnvironmentVariableForLauncherPathIsPreferred(HostingModel hos
890890
{
891891
var deploymentParameters = Fixture.GetBaseDeploymentParameters(hostingModel);
892892

893-
deploymentParameters.EnvironmentVariables["ANCM_LAUNCHER_PATH"] = "nope";
894-
var result = await DeployAsync(deploymentParameters);
895-
var response = await result.HttpClient.GetAsync("/");
893+
deploymentParameters.EnvironmentVariables["ANCM_LAUNCHER_PATH"] = _dotnetLocation;
894+
deploymentParameters.WebConfigActionList.Add(WebConfigHelpers.AddOrModifyAspNetCoreSection("processPath", "nope"));
896895

897-
if (hostingModel == HostingModel.InProcess)
898-
{
899-
Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
900-
}
901-
else
902-
{
903-
Assert.Equal(HttpStatusCode.BadGateway, response.StatusCode);
904-
}
896+
await StartAsync(deploymentParameters);
905897
}
906898

907899
[ConditionalTheory]
@@ -913,19 +905,12 @@ public async Task EnvironmentVariableForLauncherPathIsPreferred(HostingModel hos
913905
public async Task EnvironmentVariableForLauncherArgsIsPreferred(HostingModel hostingModel)
914906
{
915907
var deploymentParameters = Fixture.GetBaseDeploymentParameters(hostingModel);
908+
using var publishedApp = await deploymentParameters.ApplicationPublisher.Publish(deploymentParameters, LoggerFactory.CreateLogger("test"));
916909

917-
deploymentParameters.EnvironmentVariables["ANCM_LAUNCHER_ARGS"] = "fail";
918-
var result = await DeployAsync(deploymentParameters);
919-
var response = await result.HttpClient.GetAsync("/");
910+
deploymentParameters.EnvironmentVariables["ANCM_LAUNCHER_ARGS"] = Path.ChangeExtension(Path.Combine(publishedApp.Path, deploymentParameters.ApplicationPublisher.ApplicationPath), ".dll");
911+
deploymentParameters.WebConfigActionList.Add(WebConfigHelpers.AddOrModifyAspNetCoreSection("arguments", "nope"));
920912

921-
if (hostingModel == HostingModel.InProcess)
922-
{
923-
Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
924-
}
925-
else
926-
{
927-
Assert.Equal(HttpStatusCode.BadGateway, response.StatusCode);
928-
}
913+
await StartAsync(deploymentParameters);
929914
}
930915

931916
private static void VerifyDotnetRuntimeEventLog(IISDeploymentResult deploymentResult)

0 commit comments

Comments
 (0)