Search in sources :

Example 11 with RsWithStatus

use of com.artipie.http.rs.RsWithStatus in project maven-adapter by artipie.

the class HeadProxySlice method response.

@Override
public Response response(final String line, final Iterable<Map.Entry<String, String>> headers, final Publisher<ByteBuffer> body) {
    final CompletableFuture<Response> promise = new CompletableFuture<>();
    this.client.response(line, Headers.EMPTY, Content.EMPTY).send((status, rsheaders, rsbody) -> {
        promise.complete(new RsWithHeaders(new RsWithStatus(status), rsheaders));
        return CompletableFuture.allOf();
    });
    return new AsyncResponse(promise);
}
Also used : Response(com.artipie.http.Response) AsyncResponse(com.artipie.http.async.AsyncResponse) CompletableFuture(java.util.concurrent.CompletableFuture) RsWithStatus(com.artipie.http.rs.RsWithStatus) RsWithHeaders(com.artipie.http.rs.RsWithHeaders) AsyncResponse(com.artipie.http.async.AsyncResponse)

Example 12 with RsWithStatus

use of com.artipie.http.rs.RsWithStatus in project artipie by artipie.

the class ResponseMetricsSliceTest method shouldReportNoAuthResponse.

@Test
public void shouldReportNoAuthResponse() {
    this.send(RqMethod.PUT, new RsWithStatus(RsStatus.UNAUTHORIZED));
    this.send(RqMethod.PUT, new RsWithStatus(RsStatus.UNAUTHORIZED));
    MatcherAssert.assertThat(this.metrics.counter("put.error.no-auth").value(), new IsEqual<>(2L));
}
Also used : RsWithStatus(com.artipie.http.rs.RsWithStatus) Test(org.junit.jupiter.api.Test)

Example 13 with RsWithStatus

use of com.artipie.http.rs.RsWithStatus in project artipie by artipie.

the class ResponseMetricsSliceTest method shouldReportBadAuthResponse.

@Test
public void shouldReportBadAuthResponse() {
    this.send(RqMethod.DELETE, new Headers.From(new Authorization("some value")), new RsWithStatus(RsStatus.UNAUTHORIZED));
    this.send(RqMethod.DELETE, new Headers.From(new Authorization("another value")), new RsWithStatus(RsStatus.UNAUTHORIZED));
    MatcherAssert.assertThat(this.metrics.counter("delete.error.bad-auth").value(), new IsEqual<>(2L));
}
Also used : Authorization(com.artipie.http.headers.Authorization) RsWithStatus(com.artipie.http.rs.RsWithStatus) Headers(com.artipie.http.Headers) Test(org.junit.jupiter.api.Test)

Example 14 with RsWithStatus

use of com.artipie.http.rs.RsWithStatus in project artipie by artipie.

the class ContentLengthRestrictionTest method shouldPassRequestsWithinLimit.

@ParameterizedTest
@CsvSource({ "10,0", "10,not number", "10,1", "10,10" })
public void shouldPassRequestsWithinLimit(final int limit, final String value) {
    final Slice slice = new ContentLengthRestriction((line, headers, body) -> new RsWithStatus(RsStatus.OK), limit);
    final Response response = slice.response("", this.headers(value), Flowable.empty());
    MatcherAssert.assertThat(response, new RsHasStatus(RsStatus.OK));
}
Also used : Response(com.artipie.http.Response) RsWithStatus(com.artipie.http.rs.RsWithStatus) RsHasStatus(com.artipie.http.hm.RsHasStatus) Slice(com.artipie.http.Slice) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 15 with RsWithStatus

use of com.artipie.http.rs.RsWithStatus in project artipie by artipie.

the class ContentLengthRestrictionTest method shouldPassRequestsWithoutContentLength.

@Test
public void shouldPassRequestsWithoutContentLength() {
    final int limit = 10;
    final Slice slice = new ContentLengthRestriction((line, headers, body) -> new RsWithStatus(RsStatus.OK), limit);
    final Response response = slice.response("", Collections.emptySet(), Flowable.empty());
    MatcherAssert.assertThat(response, new RsHasStatus(RsStatus.OK));
}
Also used : Response(com.artipie.http.Response) RsWithStatus(com.artipie.http.rs.RsWithStatus) RsHasStatus(com.artipie.http.hm.RsHasStatus) Slice(com.artipie.http.Slice) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

RsWithStatus (com.artipie.http.rs.RsWithStatus)16 Test (org.junit.jupiter.api.Test)12 RsHasStatus (com.artipie.http.hm.RsHasStatus)8 RsStatus (com.artipie.http.rs.RsStatus)7 Response (com.artipie.http.Response)6 Slice (com.artipie.http.Slice)5 RequestLine (com.artipie.http.rq.RequestLine)5 SliceSimple (com.artipie.http.slice.SliceSimple)5 Map (java.util.Map)5 BasicAuthSlice (com.artipie.http.auth.BasicAuthSlice)4 Permission (com.artipie.http.auth.Permission)4 Authorization (com.artipie.http.headers.Authorization)4 AsyncResponse (com.artipie.http.async.AsyncResponse)3 ListOf (org.cactoos.list.ListOf)3 Base64Encoded (org.cactoos.text.Base64Encoded)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 Content (com.artipie.asto.Content)2 Key (com.artipie.asto.Key)2 Storage (com.artipie.asto.Storage)2 PublisherAs (com.artipie.asto.ext.PublisherAs)2