public async Task ChangeMachineTenantAsync_WhenMachineNotFound_ThrowsNotFoundException() { _machineRepositoryMock.SetupCreateItemQuery(); var request = new ChangeMachineTenantRequest { Id = Guid.NewGuid(), TenantId = Guid.NewGuid(), SettingProfileId = Guid.NewGuid() }; await Assert.ThrowsAsync <NotFoundException>(() => _controller.ChangeMachineTenantAsync(request, null)); }
private async Task <object> ChangeMachineTenantAsync(dynamic input, CancellationToken cancellationToken) { ChangeMachineTenantRequest request; try { request = this.Bind <ChangeMachineTenantRequest>(); } catch (Exception ex) { Logger.Info("Binding failed while attempting to update a Machine resource", ex); return(Response.BadRequestBindingException()); } // We need to make sure that this route is NOT in the default policy document. // Only the SuperAdmin group should have access to this route. // The permissions logic for this method is extremely messy because there are source // and target tenants involved. The user needs to have access to both of them. I think // that the "tenantAccess" condition needs to be expanded to include whether or not // the user can impersonate a particular tenant as well if the tenant claim on the // principal doesn't match the tenant of the resource in question. await RequiresAccess() .ExecuteAsync(cancellationToken); try { return(await _machinesController.ChangeMachineTenantAsync(request, NullableTenantId, cancellationToken)); } catch (RouteExecutionEarlyExitException) { throw; } catch (ValidationFailedException ex) { Logger.Debug("Validation failed for ChangeMachineTenant", ex); return(Response.BadRequestValidationFailed(ex.Errors)); } catch (NotFoundException) { return(Response.NotFound(ResponseReasons.NotFoundMachine)); } catch (Exception ex) { Logger.Error("Unhandled exception encountered while attempting to Change Machine Tenant", ex); return(Response.InternalServerError(ResponseReasons.InternalServerErrorUpdateMachine)); } }