Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing --enableAuth param when tested locally #4211

Merged
merged 8 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading