Skip to content

Commit 208362c

Browse files
authored
Fixing --enableAuth param when tested locally (#4211)
* fixing enableAuth param * adding tests for enableAuth * Consolidating tests * trying out change to exclude dotnetZip vulnerability * trying to parse out dontetzip * changing where object * changing check vulnerabilities back
1 parent 6f1f4ad commit 208362c

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

Diff for: src/Azure.Functions.Cli/Actions/HostActions/Startup.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
7474
.AddScheme<ArmAuthenticationOptions, CliAuthenticationHandler<ArmAuthenticationOptions>>(ArmAuthenticationDefaults.AuthenticationScheme, _ => { });
7575
}
7676

77-
services.AddSingleton<IAuthorizationHandler, CoreToolsAuthorizationHandler>();
77+
// Only set up authorization handler which bypasses all local auth if enableAuth param is not set
78+
if (!_enableAuth)
79+
{
80+
services.AddSingleton<IAuthorizationHandler, CoreToolsAuthorizationHandler>();
81+
}
7882

7983
services.AddWebJobsScriptHostAuthorization();
8084

Diff for: test/Azure.Functions.Cli.Tests/E2E/StartTests.cs

+46
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,52 @@ await CliTester.Run(new RunConfiguration[]
392392
}, _output);
393393
}
394394

395+
[Theory]
396+
[InlineData("function", false, "Welcome to Azure Functions!", "response from default function should be 'Welcome to Azure Functions!'", "Selected out-of-process host.")]
397+
[InlineData("anonymous", true, "Welcome to Azure Functions!", "response from default function should be 'Welcome to Azure Functions!'", "Selected out-of-process host.")]
398+
[InlineData("anonymous", true, "", "the call to the function is unauthorized", "\"status\": \"401\"")]
399+
public async Task Start_DotnetIsolated_Test_EnableAuthFeature(string authLevel, bool enableAuth, string resultOfFunctionCall, string becauseResult, string testOutputHelperValue)
400+
{
401+
string templateCommand = $"new --template Httptrigger --name HttpTrigger --authlevel ${authLevel}";
402+
string startCommand = enableAuth ? $"start --build --port {_funcHostPort} --verbose --enableAuth" : $"start --build --port {_funcHostPort} --verbose";
403+
await CliTester.Run(new RunConfiguration[]
404+
{
405+
new RunConfiguration
406+
{
407+
Commands = new[]
408+
{
409+
"init . --worker-runtime dotnet-isolated",
410+
templateCommand,
411+
},
412+
},
413+
new RunConfiguration
414+
{
415+
Commands = new[]
416+
{
417+
startCommand,
418+
},
419+
ExpectExit = false,
420+
Test = async (workingDir, p, _) =>
421+
{
422+
using (var client = new HttpClient() { BaseAddress = new Uri($"http://localhost:{_funcHostPort}") })
423+
{
424+
(await WaitUntilReady(client)).Should().BeTrue(because: _serverNotReady);
425+
var response = await client.GetAsync("/api/HttpTrigger?name=Test");
426+
var result = await response.Content.ReadAsStringAsync();
427+
p.Kill();
428+
result.Should().Be(resultOfFunctionCall, because: becauseResult);
429+
430+
if (_output is Xunit.Sdk.TestOutputHelper testOutputHelper)
431+
{
432+
testOutputHelper.Output.Should().Contain(testOutputHelperValue);
433+
}
434+
}
435+
},
436+
CommandTimeout = TimeSpan.FromSeconds(300)
437+
}
438+
}, _output);
439+
}
440+
395441
[Fact]
396442
public async Task Start_WithInspect_DebuggerIsStarted()
397443
{

0 commit comments

Comments
 (0)