use of net.codestory.http.payload.Payload in project datashare by ICIJ.
the class LocalUserFilterTest method test_adds_cookie.
@Test
public void test_adds_cookie() throws Exception {
LocalUserFilter localUserFilter = new LocalUserFilter(new PropertiesProvider());
Payload payload = localUserFilter.apply("url", context, nextFilter);
assertThat(payload.cookies().size()).isEqualTo(1);
assertThat(payload.cookies().get(0).name()).isEqualTo("_ds_session_id");
assertThat(payload.cookies().get(0).value()).contains("\"login\":\"local\"");
}
use of net.codestory.http.payload.Payload in project datashare by ICIJ.
the class TaskResource method getTaskResult.
/**
* gets task result with its id
*
* @param id
* @return 200 and the result,
* 204 if there is no result
* 404 if the tasks doesn't exist
* 403 if the task is not belonging to current user
*
* Example :
* $(curl localhost:8080/api/task/21148262/result)
*/
@Get("/:id/result")
public Payload getTaskResult(String id, Context context) {
TaskView<?> task = forbiddenIfNotSameUser(context, notFoundIfNull(taskManager.get(id)));
Object result = task.getResult();
if (result instanceof File) {
final Path appPath = ((File) result).isAbsolute() ? get(System.getProperty("user.dir")).resolve(context.env().appFolder()) : get(context.env().appFolder());
Path resultPath = appPath.relativize(((File) result).toPath());
return new Payload(resultPath).withHeader("Content-Disposition", "attachment;filename=\"" + resultPath.getFileName() + "\"");
}
return result == null ? new Payload(204) : new Payload(result);
}
use of net.codestory.http.payload.Payload in project datashare by ICIJ.
the class ApiKeyFilterTest method test_unauthorized_if_type_is_not_bearer.
@Test
public void test_unauthorized_if_type_is_not_bearer() throws Exception {
when(context.header("authorization")).thenReturn("Basic session_id");
Payload payload = apiKeyFilter.apply("url", context, nextFilter);
assertThat(payload.code()).isEqualTo(401);
}
use of net.codestory.http.payload.Payload in project datashare by ICIJ.
the class ApiKeyFilterTest method test_does_nothing_if_there_is_datashare_cookie.
@Test
public void test_does_nothing_if_there_is_datashare_cookie() throws Exception {
when(context.cookies()).thenReturn(new SimpleCookies() {
{
put("_ds_session_id", new NewCookie("_ds_session_id", "cookie value"));
}
});
Payload payload = apiKeyFilter.apply("url", context, nextFilter);
assertThat(payload).isSameAs(next);
}
use of net.codestory.http.payload.Payload in project datashare by ICIJ.
the class ApiKeyFilterTest method test_unauthorized_if_no_type.
@Test
public void test_unauthorized_if_no_type() throws Exception {
when(context.header("authorization")).thenReturn("session_id");
Payload payload = apiKeyFilter.apply("url", context, nextFilter);
assertThat(payload.code()).isEqualTo(401);
}
Aggregations