mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-19 04:58:09 +00:00
Closes #2098. This cleans up the authentication a bit; after this change we have two stages in the middleware pipeline: - `AuthenticationMiddleware` reads the JWT token (it does not validate it, this is done by the Azure Functions service) and stores it in `FunctionContext.Items["ONEFUZZ_USER_INFO"]` - `AuthorizationMiddleware` checks the user info against the `[Authorize]` attribute to see if the user has the required permissions - Functions can read the user info from the `FunctionContext` if needed The authorize attribute can be `[Authorize(Allow.User)]` or `Allow.Agent` or `Allow.Admin`. The `Admin` case is new and allows this to be declaratively specified rather than being checked in code. We have several functions which could be changed to use this (e.g. Pool POST/DELETE/PATCH, Scaleset POST/DELETE/PATCH), but I have only changed one so far (JinjaToScriban). One of the benefits here is that this simplifies the test code a lot: we can set the desired user info directly onto our `(Test)FunctionContext` rather than having to supply a fake that pretends to parse the token from the HTTP request. This will also have benefits when running the service locally for testing purposes (refer to internal issue). The other benefit is the ability to programmatically read the required authentication for each function, which may help with Swagger generation.
23 lines
734 B
C#
23 lines
734 B
C#
using Microsoft.OneFuzz.Service;
|
|
using Xunit;
|
|
using Xunit.Abstractions;
|
|
|
|
namespace IntegrationTests;
|
|
|
|
[Trait("Category", "Live")]
|
|
public class AzureStorageAgentCanScheduleTest : AgentCommandsTestsBase {
|
|
public AzureStorageAgentCanScheduleTest(ITestOutputHelper output)
|
|
: base(output, Integration.AzureStorage.FromEnvironment()) { }
|
|
}
|
|
|
|
public class AzuriteAgentCanScheduleTest : AgentEventsTestsBase {
|
|
public AzuriteAgentCanScheduleTest(ITestOutputHelper output)
|
|
: base(output, new Integration.AzuriteStorage()) { }
|
|
}
|
|
|
|
public abstract class AgentCanScheduleTestsBase : FunctionTestBase {
|
|
public AgentCanScheduleTestsBase(ITestOutputHelper output, IStorage storage)
|
|
: base(output, storage) { }
|
|
|
|
}
|