Skip to content

Commit

Permalink
Fixing --enableAuth param when tested locally (#4211)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
aishwaryabh authored Jan 7, 2025
1 parent 6f1f4ad commit 208362c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Azure.Functions.Cli/Actions/HostActions/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
.AddScheme<ArmAuthenticationOptions, CliAuthenticationHandler<ArmAuthenticationOptions>>(ArmAuthenticationDefaults.AuthenticationScheme, _ => { });
}

services.AddSingleton<IAuthorizationHandler, CoreToolsAuthorizationHandler>();
// Only set up authorization handler which bypasses all local auth if enableAuth param is not set
if (!_enableAuth)
{
services.AddSingleton<IAuthorizationHandler, CoreToolsAuthorizationHandler>();
}

services.AddWebJobsScriptHostAuthorization();

Expand Down
46 changes: 46 additions & 0 deletions test/Azure.Functions.Cli.Tests/E2E/StartTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,52 @@ await CliTester.Run(new RunConfiguration[]
}, _output);
}

[Theory]
[InlineData("function", false, "Welcome to Azure Functions!", "response from default function should be 'Welcome to Azure Functions!'", "Selected out-of-process host.")]
[InlineData("anonymous", true, "Welcome to Azure Functions!", "response from default function should be 'Welcome to Azure Functions!'", "Selected out-of-process host.")]
[InlineData("anonymous", true, "", "the call to the function is unauthorized", "\"status\": \"401\"")]
public async Task Start_DotnetIsolated_Test_EnableAuthFeature(string authLevel, bool enableAuth, string resultOfFunctionCall, string becauseResult, string testOutputHelperValue)
{
string templateCommand = $"new --template Httptrigger --name HttpTrigger --authlevel ${authLevel}";
string startCommand = enableAuth ? $"start --build --port {_funcHostPort} --verbose --enableAuth" : $"start --build --port {_funcHostPort} --verbose";
await CliTester.Run(new RunConfiguration[]
{
new RunConfiguration
{
Commands = new[]
{
"init . --worker-runtime dotnet-isolated",
templateCommand,
},
},
new RunConfiguration
{
Commands = new[]
{
startCommand,
},
ExpectExit = false,
Test = async (workingDir, p, _) =>
{
using (var client = new HttpClient() { BaseAddress = new Uri($"http://localhost:{_funcHostPort}") })
{
(await WaitUntilReady(client)).Should().BeTrue(because: _serverNotReady);
var response = await client.GetAsync("/api/HttpTrigger?name=Test");
var result = await response.Content.ReadAsStringAsync();
p.Kill();
result.Should().Be(resultOfFunctionCall, because: becauseResult);

if (_output is Xunit.Sdk.TestOutputHelper testOutputHelper)
{
testOutputHelper.Output.Should().Contain(testOutputHelperValue);
}
}
},
CommandTimeout = TimeSpan.FromSeconds(300)
}
}, _output);
}

[Fact]
public async Task Start_WithInspect_DebuggerIsStarted()
{
Expand Down

0 comments on commit 208362c

Please sign in to comment.