Search in sources :

Example 11 with RequestLine

use of com.artipie.http.rq.RequestLine in project artipie by artipie.

the class DockerRoutingSlice method response.

@Override
public Response response(final String line, final Iterable<Map.Entry<String, String>> headers, final Publisher<ByteBuffer> body) {
    final RequestLineFrom req = new RequestLineFrom(line);
    final String path = req.uri().getPath();
    final Matcher matcher = PTN_PATH.matcher(path);
    final Response rsp;
    if (matcher.matches()) {
        final String group = matcher.group(1);
        if (group.isEmpty() || group.equals("/")) {
            rsp = new AsyncResponse(this.settings.auth().thenApply(auth -> new BasicAuthSlice(new BaseEntity(), auth, user -> !user.equals(Permissions.ANY_USER)).response(line, headers, body)));
        } else {
            rsp = this.origin.response(new RequestLine(req.method().toString(), new URIBuilder(req.uri()).setPath(group).toString(), req.version()).toString(), new Headers.From(headers, DockerRoutingSlice.HDR_REAL_PATH, path), body);
        }
    } else {
        rsp = this.origin.response(line, headers, body);
    }
    return rsp;
}
Also used : AsyncResponse(com.artipie.http.async.AsyncResponse) BasicAuthSlice(com.artipie.http.auth.BasicAuthSlice) RequestLine(com.artipie.http.rq.RequestLine) Matcher(java.util.regex.Matcher) BaseEntity(com.artipie.docker.http.BaseEntity) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) AsyncResponse(com.artipie.http.async.AsyncResponse) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 12 with RequestLine

use of com.artipie.http.rq.RequestLine in project maven-adapter by artipie.

the class CachedProxySliceTest method loadsOriginIfCacheNotFound.

@Test
void loadsOriginIfCacheNotFound() {
    final byte[] data = "remote".getBytes();
    MatcherAssert.assertThat(new CachedProxySlice((line, headers, body) -> new RsWithBody(ByteBuffer.wrap(data)), (key, supplier, control) -> supplier.get()), new SliceHasResponse(Matchers.allOf(new RsHasStatus(RsStatus.OK), new RsHasBody(data)), new RequestLine(RqMethod.GET, "/bar")));
}
Also used : RqMethod(com.artipie.http.rq.RqMethod) RsWithStatus(com.artipie.http.rs.RsWithStatus) SliceHasResponse(com.artipie.http.hm.SliceHasResponse) RsHasBody(com.artipie.http.hm.RsHasBody) RsStatus(com.artipie.http.rs.RsStatus) Matchers(org.hamcrest.Matchers) CompletableFuture(java.util.concurrent.CompletableFuture) Content(com.artipie.asto.Content) RsHasStatus(com.artipie.http.hm.RsHasStatus) RsWithBody(com.artipie.http.rs.RsWithBody) FailedCompletionStage(com.artipie.asto.FailedCompletionStage) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.jupiter.api.Test) RequestLine(com.artipie.http.rq.RequestLine) MatcherAssert(org.hamcrest.MatcherAssert) SliceSimple(com.artipie.http.slice.SliceSimple) Optional(java.util.Optional) RequestLine(com.artipie.http.rq.RequestLine) SliceHasResponse(com.artipie.http.hm.SliceHasResponse) RsHasStatus(com.artipie.http.hm.RsHasStatus) RsHasBody(com.artipie.http.hm.RsHasBody) RsWithBody(com.artipie.http.rs.RsWithBody) Test(org.junit.jupiter.api.Test)

Example 13 with RequestLine

use of com.artipie.http.rq.RequestLine in project maven-adapter by artipie.

the class HeadProxySliceTest method passesStatusAndHeadersFromResponse.

@Test
void passesStatusAndHeadersFromResponse() {
    final RsStatus status = RsStatus.CREATED;
    final Headers.From headers = new Headers.From("abc", "123");
    MatcherAssert.assertThat(new HeadProxySlice(new SliceSimple(new RsWithHeaders(new RsWithStatus(status), headers))), new SliceHasResponse(Matchers.allOf(new RsHasStatus(status), new RsHasHeaders(headers)), new RequestLine(RqMethod.HEAD, "/")));
}
Also used : RequestLine(com.artipie.http.rq.RequestLine) SliceHasResponse(com.artipie.http.hm.SliceHasResponse) RsWithStatus(com.artipie.http.rs.RsWithStatus) RsHasStatus(com.artipie.http.hm.RsHasStatus) RsWithHeaders(com.artipie.http.rs.RsWithHeaders) RsHasHeaders(com.artipie.http.hm.RsHasHeaders) Headers(com.artipie.http.Headers) RsWithHeaders(com.artipie.http.rs.RsWithHeaders) RsStatus(com.artipie.http.rs.RsStatus) RsHasHeaders(com.artipie.http.hm.RsHasHeaders) SliceSimple(com.artipie.http.slice.SliceSimple) Test(org.junit.jupiter.api.Test)

Example 14 with RequestLine

use of com.artipie.http.rq.RequestLine in project maven-adapter by artipie.

the class PutMetadataChecksumSliceTest method foundsCorrespondingMetadataAndSavesChecksum.

@ParameterizedTest
@ValueSource(strings = { "md5", "sha1", "sha256", "sha512" })
void foundsCorrespondingMetadataAndSavesChecksum(final String alg) {
    final byte[] xml = new MetadataXml("com.example", "abc").get(new MetadataXml.VersionTags("0.1")).getBytes(StandardCharsets.UTF_8);
    this.asto.save(new Key.From(UploadSlice.TEMP, "com/example/abc/0.1/meta/maven-metadata.xml"), new Content.From(xml)).join();
    this.asto.save(new Key.From(UploadSlice.TEMP, "com/example/abc/0.2/meta/maven-metadata.xml"), new Content.From("any".getBytes())).join();
    final byte[] mdfive = new ContentDigest(new Content.From(xml), Digests.valueOf(alg.toUpperCase(Locale.US))).hex().toCompletableFuture().join().getBytes(StandardCharsets.US_ASCII);
    final Maven.Fake mvn = new Maven.Fake();
    MatcherAssert.assertThat("Incorrect response status, CREATED is expected", new PutMetadataChecksumSlice(this.asto, new ValidUpload.Dummy(), mvn), new SliceHasResponse(new RsHasStatus(RsStatus.CREATED), new RequestLine(RqMethod.PUT, String.format("/com/example/abc/maven-metadata.xml.%s", alg)), Headers.EMPTY, new Content.From(mdfive)));
    MatcherAssert.assertThat("Incorrect content was saved to storage", this.asto.value(new Key.From(String.format(".upload/com/example/abc/0.1/meta/maven-metadata.xml.%s", alg))).join(), new ContentIs(mdfive));
    MatcherAssert.assertThat("Repository update was not started", mvn.wasUpdated(), new IsEqual<>(true));
}
Also used : Maven(com.artipie.maven.Maven) SliceHasResponse(com.artipie.http.hm.SliceHasResponse) RsHasStatus(com.artipie.http.hm.RsHasStatus) ContentIs(com.artipie.asto.test.ContentIs) ContentDigest(com.artipie.asto.ext.ContentDigest) RequestLine(com.artipie.http.rq.RequestLine) MetadataXml(com.artipie.maven.MetadataXml) Content(com.artipie.asto.Content) Key(com.artipie.asto.Key) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 15 with RequestLine

use of com.artipie.http.rq.RequestLine in project maven-adapter by artipie.

the class PutMetadataSliceTest method returnsCreatedAndSavesMetadata.

@Test
void returnsCreatedAndSavesMetadata() {
    final byte[] xml = new MetadataXml("com.example", "any").get(new MetadataXml.VersionTags("0.1", "0.2", new ListOf<String>("0.1", "0.2"))).getBytes(StandardCharsets.UTF_8);
    MatcherAssert.assertThat("Incorrect response status, CREATED is expected", this.pms, new SliceHasResponse(new RsHasStatus(RsStatus.CREATED), new RequestLine(RqMethod.PUT, "/com/example/any/maven-metadata.xml"), new Headers.From(new ContentLength(xml.length)), new Content.OneTime(new Content.From(xml))));
    MatcherAssert.assertThat("Metadata file was not saved to storage", this.asto.value(new Key.From(".upload/com/example/any/0.2/meta/maven-metadata.xml")).join(), new ContentIs(xml));
}
Also used : SliceHasResponse(com.artipie.http.hm.SliceHasResponse) RsHasStatus(com.artipie.http.hm.RsHasStatus) ContentIs(com.artipie.asto.test.ContentIs) RequestLine(com.artipie.http.rq.RequestLine) MetadataXml(com.artipie.maven.MetadataXml) Content(com.artipie.asto.Content) ContentLength(com.artipie.http.headers.ContentLength) Key(com.artipie.asto.Key) Test(org.junit.jupiter.api.Test)

Aggregations

RequestLine (com.artipie.http.rq.RequestLine)26 RsHasStatus (com.artipie.http.hm.RsHasStatus)21 Test (org.junit.jupiter.api.Test)21 SliceHasResponse (com.artipie.http.hm.SliceHasResponse)16 RsStatus (com.artipie.http.rs.RsStatus)11 Content (com.artipie.asto.Content)9 Key (com.artipie.asto.Key)8 RsWithStatus (com.artipie.http.rs.RsWithStatus)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 SliceSimple (com.artipie.http.slice.SliceSimple)7 ContentIs (com.artipie.asto.test.ContentIs)6 RsHasBody (com.artipie.http.hm.RsHasBody)6 MetadataXml (com.artipie.maven.MetadataXml)6 BasicAuthSlice (com.artipie.http.auth.BasicAuthSlice)5 Authorization (com.artipie.http.headers.Authorization)5 RqMethod (com.artipie.http.rq.RqMethod)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 MatcherAssert (org.hamcrest.MatcherAssert)5 Permission (com.artipie.http.auth.Permission)4 Header (com.artipie.http.headers.Header)4