public async Async.Task RequiresAdmin(string method) { // config must be found await Context.InsertAll( new InstanceConfig(Context.ServiceConfiguration.OneFuzzInstanceName !)); // must be a user to auth var auth = new TestEndpointAuthorization(RequestType.User, Logger, Context); // override the found user credentials var userInfo = new UserInfo(ApplicationId: Guid.NewGuid(), ObjectId: Guid.NewGuid(), "upn"); Context.UserCredentials = new TestUserCredentials(Logger, Context.ConfigOperations, OneFuzzResult <UserInfo> .Ok(userInfo)); var req = new NodeGet(MachineId: _machineId); var func = new NodeFunction(Logger, auth, Context); var result = await func.Run(TestHttpRequestData.FromJson(method, req)); Assert.Equal(HttpStatusCode.BadRequest, result.StatusCode); var err = BodyAs <Error>(result); Assert.Equal(ErrorCode.UNAUTHORIZED, err.Code); Assert.Contains("pool modification disabled", err.Errors?.Single()); }
public async Async.Task Search_SpecificNode_NotFound_ReturnsNotFound() { var auth = new TestEndpointAuthorization(RequestType.User, Logger, Context); var req = new NodeSearch(MachineId: _machineId); var func = new NodeFunction(Logger, auth, Context); var result = await func.Run(TestHttpRequestData.FromJson("GET", req)); Assert.Equal(HttpStatusCode.BadRequest, result.StatusCode); }
public async Async.Task Search_MultipleNodes_CanFindNone() { var auth = new TestEndpointAuthorization(RequestType.User, Logger, Context); var req = new NodeSearch(); var func = new NodeFunction(Logger, auth, Context); var result = await func.Run(TestHttpRequestData.FromJson("GET", req)); Assert.Equal(HttpStatusCode.OK, result.StatusCode); Assert.Equal("[]", BodyAsString(result)); }
public async Async.Task Search_SpecificNode_Found_ReturnsOk() { await Context.InsertAll( new Node(_poolName, _machineId, null, _version)); var auth = new TestEndpointAuthorization(RequestType.User, Logger, Context); var req = new NodeSearch(MachineId: _machineId); var func = new NodeFunction(Logger, auth, Context); var result = await func.Run(TestHttpRequestData.FromJson("GET", req)); Assert.Equal(HttpStatusCode.OK, result.StatusCode); // make sure we got the data from the table var deserialized = BodyAs <NodeSearchResult>(result); Assert.Equal(_version, deserialized.Version); }
public async Async.Task Search_MultipleNodes_ByPoolName() { await Context.InsertAll( new Node(PoolName.Parse("otherPool"), Guid.NewGuid(), null, _version), new Node(_poolName, Guid.NewGuid(), null, _version), new Node(_poolName, Guid.NewGuid(), null, _version)); var req = new NodeSearch(PoolName: _poolName); var auth = new TestEndpointAuthorization(RequestType.User, Logger, Context); var func = new NodeFunction(Logger, auth, Context); var result = await func.Run(TestHttpRequestData.FromJson("GET", req)); Assert.Equal(HttpStatusCode.OK, result.StatusCode); // make sure we got the data from the table var deserialized = BodyAs <NodeSearchResult[]>(result); Assert.Equal(2, deserialized.Length); }