mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-19 13:03:44 +00:00
Add correct routes and auth to "agents" Functions (#2109)
The routes and auth were missing from the "agents" functions.
This commit is contained in:
52
src/ApiService/IntegrationTests/AgentCommandsTests.cs
Normal file
52
src/ApiService/IntegrationTests/AgentCommandsTests.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using System.Net;
|
||||
using IntegrationTests.Fakes;
|
||||
using Microsoft.OneFuzz.Service;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
using Async = System.Threading.Tasks;
|
||||
|
||||
namespace IntegrationTests;
|
||||
|
||||
[Trait("Category", "Live")]
|
||||
public class AzureStorageAgentCommandsTest : AgentCommandsTestsBase {
|
||||
public AzureStorageAgentCommandsTest(ITestOutputHelper output)
|
||||
: base(output, Integration.AzureStorage.FromEnvironment()) { }
|
||||
}
|
||||
|
||||
public class AzuriteAgentCommandsTest : AgentEventsTestsBase {
|
||||
public AzuriteAgentCommandsTest(ITestOutputHelper output)
|
||||
: base(output, new Integration.AzuriteStorage()) { }
|
||||
}
|
||||
|
||||
public abstract class AgentCommandsTestsBase : FunctionTestBase {
|
||||
public AgentCommandsTestsBase(ITestOutputHelper output, IStorage storage)
|
||||
: base(output, storage) { }
|
||||
|
||||
|
||||
[Fact]
|
||||
public async Async.Task Authorization_IsRequired() {
|
||||
var auth = new TestEndpointAuthorization(RequestType.NoAuthorization, Logger, Context);
|
||||
var func = new AgentCommands(Logger, auth, Context);
|
||||
|
||||
var result = await func.Run(TestHttpRequestData.Empty("GET"));
|
||||
Assert.Equal(HttpStatusCode.Unauthorized, result.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Async.Task UserAuthorization_IsNotPermitted() {
|
||||
var auth = new TestEndpointAuthorization(RequestType.User, Logger, Context);
|
||||
var func = new AgentCommands(Logger, auth, Context);
|
||||
|
||||
var result = await func.Run(TestHttpRequestData.Empty("GET"));
|
||||
Assert.Equal(HttpStatusCode.Unauthorized, result.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Async.Task AgentAuthorization_IsAccepted() {
|
||||
var auth = new TestEndpointAuthorization(RequestType.Agent, Logger, Context);
|
||||
var func = new AgentCommands(Logger, auth, Context);
|
||||
|
||||
var result = await func.Run(TestHttpRequestData.Empty("GET"));
|
||||
Assert.Equal(HttpStatusCode.BadRequest, result.StatusCode); // BadRequest due to no body, not Unauthorized
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user