use of spark.Request in project searchcode-server by boyter.
the class ApiRouteServiceTest method testRepoAddAuthInvalidSigned.
public void testRepoAddAuthInvalidSigned() {
Request mockRequest = mock(Request.class);
SQLiteRepo mockSQLiteRepo = mock(SQLiteRepo.class);
ApiService mockApiService = mock(ApiService.class);
when(mockApiService.validateRequest("test", "test", "pub=test&reponame=test&repourl=test&repotype=test&repousername=test&repopassword=test&reposource=test&repobranch=test", ApiService.HmacType.SHA1)).thenReturn(false);
ApiRouteService apiRouteService = new ApiRouteService(mockApiService, null, mockSQLiteRepo, null, null, null, new Helpers(), new LoggerWrapper());
apiRouteService.apiEnabled = true;
apiRouteService.apiAuth = true;
when(mockRequest.queryParams("reponame")).thenReturn("test");
when(mockRequest.queryParams("repourl")).thenReturn("test");
when(mockRequest.queryParams("repotype")).thenReturn("test");
when(mockRequest.queryParams("repousername")).thenReturn("test");
when(mockRequest.queryParams("repopassword")).thenReturn("test");
when(mockRequest.queryParams("reposource")).thenReturn("test");
when(mockRequest.queryParams("repobranch")).thenReturn("test");
when(mockRequest.queryParams("pub")).thenReturn("test");
when(mockRequest.queryParams("sig")).thenReturn("test");
ApiResponse apiResponse = apiRouteService.repoAdd(mockRequest, null);
assertThat(apiResponse.getMessage()).isEqualTo("invalid signed url");
assertThat(apiResponse.isSucessful()).isFalse();
}
use of spark.Request in project searchcode-server by boyter.
the class ApiRouteServiceTest method testRepoAddMissingRepoSource.
public void testRepoAddMissingRepoSource() {
Request mockRequest = mock(Request.class);
SQLiteRepo mockSQLiteRepo = mock(SQLiteRepo.class);
ApiRouteService apiRouteService = new ApiRouteService(null, null, mockSQLiteRepo, null, null, null, new Helpers(), new LoggerWrapper());
apiRouteService.apiEnabled = true;
apiRouteService.apiAuth = false;
when(mockRequest.queryParams("reponame")).thenReturn("test");
when(mockRequest.queryParams("repourl")).thenReturn("test");
when(mockRequest.queryParams("repotype")).thenReturn("test");
when(mockRequest.queryParams("repousername")).thenReturn("test");
when(mockRequest.queryParams("repopassword")).thenReturn("test");
ApiResponse apiResponse = apiRouteService.repoAdd(mockRequest, null);
assertThat(apiResponse.getMessage()).isEqualTo("reposource is a required parameter");
assertThat(apiResponse.isSucessful()).isFalse();
}
use of spark.Request in project searchcode-server by boyter.
the class ApiRouteServiceTest method testGetIndexTime.
public void testGetIndexTime() {
Request mockRequest = mock(Request.class);
SQLiteRepo SQLiteRepoMock = mock(SQLiteRepo.class);
when(mockRequest.queryParams("reponame")).thenReturn("somename");
when(mockRequest.queryParams()).thenReturn((new HashMap<String, String>() {
{
put("reponame", "reponame");
}
}).keySet());
when(SQLiteRepoMock.getRepoByName("somename")).thenReturn(Optional.of(new RepoResult().setRowId(0).setName("name").setScm("scm").setUrl("url").setUsername("username").setPassword("password").setSource("source").setBranch("branch").setData("{\"rowId\":1,\"name\":\"test\",\"scm\":\"git\",\"url\":\"/test/\",\"username\":\"\",\"password\":\"\",\"source\":\"\",\"branch\":\"master\",\"data\":{\"averageIndexTimeSeconds\":9,\"indexStatus\":\"success\",\"jobRunTime\":{\"seconds\":1496356541,\"nanos\":188000000}}}")));
ApiRouteService apiRouteService = new ApiRouteService(null, null, SQLiteRepoMock, null, null, null, new Helpers(), new LoggerWrapper());
String averageIndexTimeSeconds = apiRouteService.getIndexTime(mockRequest, null);
assertThat(averageIndexTimeSeconds).contains("years ago");
}
use of spark.Request in project waltz by khartec.
the class AttestationInstanceEndpoint method register.
@Override
public void register() {
String attestInstancePath = mkPath(BASE_URL, "attest", ":id");
String attestEntityForUserPath = mkPath(BASE_URL, "attest-entity");
String findByEntityRefPath = mkPath(BASE_URL, "entity", ":kind", ":id");
String findByRunIdPath = mkPath(BASE_URL, "run", ":id");
String findUnattestedByUserPath = mkPath(BASE_URL, "unattested", "user");
String findAllByUserPath = mkPath(BASE_URL, "all", "user");
String findHistoricalForPendingByUserPath = mkPath(BASE_URL, "historical", "user");
String findPersonsByInstancePath = mkPath(BASE_URL, ":id", "person");
String findBySelectorPath = mkPath(BASE_URL, "selector");
String findLatestMeasurableAttestationsPath = mkPath(BASE_URL, "latest", "measurable-category", "entity", ":kind", ":id");
String findApplicationAttestationInstancesForKindAndSelectorPath = mkPath(BASE_URL, "applications", "attested-entity", ":kind", ":id");
String findApplicationAttestationSummaryForSelectorPath = mkPath(BASE_URL, "app-summary");
String cleanupOrphansPath = mkPath(BASE_URL, "cleanup-orphans");
String reassignRecipientsPath = mkPath(BASE_URL, "reassign-recipients");
String getCountsOfRecipientsToReassignPath = mkPath(BASE_URL, "reassign-counts");
DatumRoute<Boolean> attestInstanceRoute = (req, res) -> attestationInstanceService.attestInstance(getId(req), getUsername(req));
ListRoute<AttestationInstance> findByEntityRefRoute = (req, res) -> attestationInstanceService.findByEntityReference(getEntityReference(req));
ListRoute<AttestationInstance> findUnattestedByRecipientRoute = (req, res) -> attestationInstanceService.findByRecipient(getUsername(req), true);
ListRoute<AttestationInstance> findAllByRecipientRoute = (req, res) -> attestationInstanceService.findByRecipient(getUsername(req), false);
ListRoute<AttestationInstance> findHistoricalForPendingByRecipientRoute = (req, res) -> attestationInstanceService.findHistoricalForPendingByUserId(getUsername(req));
ListRoute<AttestationInstance> findByRunIdRoute = (req, res) -> attestationInstanceService.findByRunId(getId(req));
ListRoute<Person> findPersonsByInstanceRoute = (request, response) -> {
long id = Long.valueOf(request.params("id"));
return attestationInstanceService.findPersonsByInstanceId(id);
};
ListRoute<AttestationInstance> findBySelectorRoute = ((request, response) -> attestationInstanceService.findByIdSelector(readIdSelectionOptionsFromBody(request)));
ListRoute<LatestMeasurableAttestationInfo> findLatestMeasurableAttestationsRoute = ((request, response) -> attestationInstanceService.findLatestMeasurableAttestations(getEntityReference(request)));
ListRoute<ApplicationAttestationInstanceSummary> findApplicationAttestationInstancesForKindAndSelectorRoute = ((request, response) -> {
EntityKind attestedKind = getKind(request);
Long attestedId = StringUtilities.parseLong(request.params("id"), null);
ApplicationAttestationInstanceInfo applicationAttestationInstanceInfo = readBody(request, ApplicationAttestationInstanceInfo.class);
return attestationInstanceService.findApplicationAttestationInstancesForKindAndSelector(attestedKind, attestedId, applicationAttestationInstanceInfo);
});
ListRoute<ApplicationAttestationSummaryCounts> findApplicationAttestationSummaryForSelectorRoute = ((request, response) -> attestationInstanceService.findAttestationInstanceSummaryForSelector(readBody(request, ApplicationAttestationInstanceInfo.class)));
DatumRoute<Boolean> attestEntityForUserRoute = (req, res) -> attestationInstanceService.attestForEntity(getUsername(req), readCreateCommand(req));
postForDatum(attestInstancePath, attestInstanceRoute);
postForDatum(attestEntityForUserPath, attestEntityForUserRoute);
getForList(findByEntityRefPath, findByEntityRefRoute);
getForList(findUnattestedByUserPath, findUnattestedByRecipientRoute);
getForList(findAllByUserPath, findAllByRecipientRoute);
getForList(findHistoricalForPendingByUserPath, findHistoricalForPendingByRecipientRoute);
getForList(findByRunIdPath, findByRunIdRoute);
getForList(findPersonsByInstancePath, findPersonsByInstanceRoute);
getForList(findLatestMeasurableAttestationsPath, findLatestMeasurableAttestationsRoute);
postForList(findBySelectorPath, findBySelectorRoute);
postForList(findApplicationAttestationInstancesForKindAndSelectorPath, findApplicationAttestationInstancesForKindAndSelectorRoute);
postForList(findApplicationAttestationSummaryForSelectorPath, findApplicationAttestationSummaryForSelectorRoute);
getForDatum(cleanupOrphansPath, this::cleanupOrphansRoute);
postForDatum(reassignRecipientsPath, this::reassignRecipientsRoute);
getForDatum(getCountsOfRecipientsToReassignPath, this::getCountsOfRecipientsToReassign);
}
use of spark.Request in project gocd by gocd.
the class EnvironmentsControllerV3 method partialUpdate.
public String partialUpdate(Request request, Response response) {
JsonReader jsonReader = GsonTransformer.getInstance().jsonReaderFrom(request.body());
PatchEnvironmentRequest req = PatchEnvironmentRequestRepresenter.fromJSON(jsonReader);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
String environmentName = request.params("name");
EnvironmentConfig environmentConfig = fetchEntityFromConfig(environmentName);
Optional<EnvironmentVariableConfig> parsingErrors = req.getEnvironmentVariablesToAdd().stream().filter(envVar -> !envVar.errors().isEmpty()).findFirst();
if (parsingErrors.isPresent()) {
EnvironmentVariablesConfig configs = new EnvironmentVariablesConfig(req.getEnvironmentVariablesToAdd());
response.status(422);
return MessageJson.create("Error parsing patch request", writer -> toJSONArray(writer, "environment_variables", configs));
}
environmentConfigService.patchEnvironment(environmentConfig, req.getPipelineToAdd(), req.getPipelineToRemove(), req.getEnvironmentVariablesToAdd(), req.getEnvironmentVariablesToRemove(), currentUsername(), result);
EnvironmentConfig updateConfigElement = fetchEntityFromConfig(environmentName);
setEtagHeader(updateConfigElement, response);
return handleCreateOrUpdateResponse(request, response, updateConfigElement, result);
}
Aggregations