mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-19 04:58:09 +00:00
* Fix logic of markaing task as failed - Do not mark task as failed if it is already in the shutting down state - accumulate errors when setting task error to understand the context - refactor the Error record * fix tests * format * Fix build * Update src/ApiService/ApiService/onefuzzlib/ImageReference.cs Co-authored-by: George Pollard <porges@porg.es> * Update src/ApiService/ApiService/onefuzzlib/ProxyOperations.cs Co-authored-by: Teo Voinea <58236992+tevoinea@users.noreply.github.com> --------- Co-authored-by: George Pollard <porges@porg.es> Co-authored-by: Teo Voinea <58236992+tevoinea@users.noreply.github.com>
48 lines
1.2 KiB
C#
48 lines
1.2 KiB
C#
|
|
using System;
|
|
using System.Net;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Azure.Functions.Worker.Http;
|
|
using Microsoft.OneFuzz.Service;
|
|
|
|
namespace IntegrationTests.Fakes;
|
|
|
|
public 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, null! /* not needed for test */) {
|
|
_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,
|
|
Error.Create(
|
|
ErrorCode.UNAUTHORIZED,
|
|
"Unrecognized agent"
|
|
),
|
|
"token verification",
|
|
HttpStatusCode.Unauthorized
|
|
);
|
|
}
|
|
}
|