mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-19 13:03:44 +00:00
Integration tests project (#2083)
Move integration tests into their own project. This makes it easier to run unit tests if you don't want to (or don't have) `azurite` running, since you can `dotnet test` just that directory. Also add a check into the `AzuriteStorage` class that will abort the entire test run if `azurite` is not running, which is simpler than reading lots of socket exceptions.
This commit is contained in:
@ -0,0 +1,44 @@
|
||||
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Azure.Functions.Worker.Http;
|
||||
using Microsoft.OneFuzz.Service;
|
||||
|
||||
enum RequestType {
|
||||
NoAuthorization,
|
||||
User,
|
||||
Agent,
|
||||
}
|
||||
|
||||
sealed class TestEndpointAuthorization : EndpointAuthorization {
|
||||
private readonly RequestType _type;
|
||||
private readonly IOnefuzzContext _context;
|
||||
|
||||
public TestEndpointAuthorization(RequestType type, ILogTracer log, IOnefuzzContext context) : base(context, log) {
|
||||
_type = type;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public override Task<HttpResponseData> CallIf(
|
||||
HttpRequestData req,
|
||||
Func<HttpRequestData, Task<HttpResponseData>> method,
|
||||
bool allowUser = false,
|
||||
bool allowAgent = false) {
|
||||
|
||||
if ((_type == RequestType.User && allowUser) ||
|
||||
(_type == RequestType.Agent && allowAgent)) {
|
||||
return method(req);
|
||||
}
|
||||
|
||||
return _context.RequestHandling.NotOk(
|
||||
req,
|
||||
new Error(
|
||||
ErrorCode.UNAUTHORIZED,
|
||||
new string[] { "Unrecognized agent" }
|
||||
),
|
||||
"token verification",
|
||||
HttpStatusCode.Unauthorized
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user