Search in sources :

Example 26 with Key

use of com.artipie.asto.Key in project maven-adapter by artipie.

the class AstoValidUploadTest method returnsFalseWhenMetadataIsNotValid.

@Test
void returnsFalseWhenMetadataIsNotValid() throws InterruptedException {
    final Key upload = new Key.From(".upload/com/test/logger");
    final Key artifact = new Key.From("com/test/logger");
    final Key jar = new Key.From("com/test/logger/1.0/my-package.jar");
    final byte[] bytes = "artifact".getBytes();
    this.bsto.save(jar, bytes);
    new MetadataXml("com.test", "jogger").addXmlToStorage(this.storage, new Key.From(upload, PutMetadataSlice.SUB_META, "maven-metadata.xml"), new MetadataXml.VersionTags("1.0", "1.0", "1.0"));
    this.addMetadata(artifact);
    this.bsto.save(jar, bytes);
    new RepositoryChecksums(this.storage).generate(jar).toCompletableFuture().join();
    MatcherAssert.assertThat(this.validupload.validate(upload, artifact).toCompletableFuture().join(), new IsEqual<>(false));
}
Also used : MetadataXml(com.artipie.maven.MetadataXml) Key(com.artipie.asto.Key) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 27 with Key

use of com.artipie.asto.Key in project maven-adapter by artipie.

the class AstoValidUploadTest method returnsTrueWhenUploadIsValid.

@Test
void returnsTrueWhenUploadIsValid() throws InterruptedException {
    final Key upload = new Key.From(".upload/com/test");
    final Key artifact = new Key.From("com/test");
    final Key jar = new Key.From(upload, "1.0/my-package.jar");
    final Key war = new Key.From(upload, "1.0/my-package.war");
    final byte[] jbytes = "jar artifact".getBytes();
    final byte[] wbytes = "war artifact".getBytes();
    this.bsto.save(jar, jbytes);
    this.bsto.save(war, wbytes);
    this.addMetadata(upload);
    this.addMetadata(artifact);
    this.bsto.save(jar, jbytes);
    this.bsto.save(war, wbytes);
    new RepositoryChecksums(this.storage).generate(jar).toCompletableFuture().join();
    new RepositoryChecksums(this.storage).generate(war).toCompletableFuture().join();
    MatcherAssert.assertThat(this.validupload.validate(upload, artifact).toCompletableFuture().join(), new IsEqual<>(true));
}
Also used : Key(com.artipie.asto.Key) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 28 with Key

use of com.artipie.asto.Key in project maven-adapter by artipie.

the class AstoValidUploadTest method returnsFalseWhenNotAllChecksumsAreValid.

@Test
void returnsFalseWhenNotAllChecksumsAreValid() throws InterruptedException {
    final Key key = new Key.From("org/example");
    final Key jar = new Key.From("org/example/1.0/my-package.jar");
    final Key war = new Key.From("org/example/1.0/my-package.war");
    final byte[] bytes = "artifact".getBytes();
    this.bsto.save(jar, bytes);
    this.bsto.save(war, "war artifact".getBytes());
    this.bsto.save(new Key.From(String.format("%s.sha256", war.string())), "123".getBytes());
    this.addMetadata(key);
    this.bsto.save(jar, bytes);
    new RepositoryChecksums(this.storage).generate(jar).toCompletableFuture().join();
    MatcherAssert.assertThat(this.validupload.validate(key, key).toCompletableFuture().join(), new IsEqual<>(false));
}
Also used : Key(com.artipie.asto.Key) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 29 with Key

use of com.artipie.asto.Key in project maven-adapter by artipie.

the class ArtifactHeadResponseTest method noBodyIfExists.

@Test
void noBodyIfExists() throws Exception {
    final Storage storage = new InMemoryStorage();
    final Key key = new Key.From("repo/artifact2.jar");
    new BlockingStorage(storage).save(key, "data".getBytes(StandardCharsets.UTF_8));
    MatcherAssert.assertThat(new ArtifactHeadResponse(storage, key), new RsHasBody(new byte[0]));
}
Also used : InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) BlockingStorage(com.artipie.asto.blocking.BlockingStorage) Storage(com.artipie.asto.Storage) InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) BlockingStorage(com.artipie.asto.blocking.BlockingStorage) RsHasBody(com.artipie.http.hm.RsHasBody) Key(com.artipie.asto.Key) Test(org.junit.jupiter.api.Test)

Example 30 with Key

use of com.artipie.asto.Key in project maven-adapter by artipie.

the class PutMetadataChecksumSlice method response.

@Override
public Response response(final String line, final Iterable<Map.Entry<String, String>> headers, final Publisher<ByteBuffer> body) {
    final Matcher matcher = PutMetadataChecksumSlice.PTN.matcher(new RequestLineFrom(line).uri().getPath());
    final Response res;
    if (matcher.matches()) {
        final String alg = matcher.group("alg");
        final String pkg = matcher.group("pkg");
        res = new AsyncResponse(this.findAndSave(body, alg, pkg).thenCompose(key -> {
            final CompletionStage<Response> resp;
            if (key.isPresent() && key.get().parent().isPresent() && key.get().parent().get().parent().isPresent()) {
                final Key location = key.get().parent().get().parent().get();
                // @checkstyle NestedIfDepthCheck (10 lines)
                resp = this.valid.ready(location).thenCompose(ready -> {
                    final CompletionStage<Response> action;
                    if (ready) {
                        action = this.validateAndUpdate(pkg, location);
                    } else {
                        action = CompletableFuture.completedFuture(new RsWithStatus(RsStatus.CREATED));
                    }
                    return action;
                });
            } else {
                resp = CompletableFuture.completedFuture(PutMetadataChecksumSlice.BAD_REQUEST);
            }
            return resp;
        }));
    } else {
        res = new RsWithStatus(RsStatus.BAD_REQUEST);
    }
    return res;
}
Also used : Response(com.artipie.http.Response) AsyncResponse(com.artipie.http.async.AsyncResponse) ContentDigest(com.artipie.asto.ext.ContentDigest) Slice(com.artipie.http.Slice) CompletableFuture(java.util.concurrent.CompletableFuture) Single(io.reactivex.Single) ByteBuffer(java.nio.ByteBuffer) Digests(com.artipie.asto.ext.Digests) Matcher(java.util.regex.Matcher) Storage(com.artipie.asto.Storage) Locale(java.util.Locale) Map(java.util.Map) Observable(io.reactivex.Observable) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) Maven(com.artipie.maven.Maven) RsWithStatus(com.artipie.http.rs.RsWithStatus) Publisher(org.reactivestreams.Publisher) Response(com.artipie.http.Response) RsStatus(com.artipie.http.rs.RsStatus) Content(com.artipie.asto.Content) Key(com.artipie.asto.Key) StandardCharsets(java.nio.charset.StandardCharsets) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) SingleInterop(hu.akarnokd.rxjava2.interop.SingleInterop) ValidUpload(com.artipie.maven.ValidUpload) PublisherAs(com.artipie.asto.ext.PublisherAs) CompletionStage(java.util.concurrent.CompletionStage) RxStorageWrapper(com.artipie.asto.rx.RxStorageWrapper) AsyncResponse(com.artipie.http.async.AsyncResponse) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) RsWithStatus(com.artipie.http.rs.RsWithStatus) Matcher(java.util.regex.Matcher) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) AsyncResponse(com.artipie.http.async.AsyncResponse) Key(com.artipie.asto.Key) CompletionStage(java.util.concurrent.CompletionStage)

Aggregations

Key (com.artipie.asto.Key)37 Test (org.junit.jupiter.api.Test)17 Storage (com.artipie.asto.Storage)16 BlockingStorage (com.artipie.asto.blocking.BlockingStorage)13 InMemoryStorage (com.artipie.asto.memory.InMemoryStorage)9 Content (com.artipie.asto.Content)8 Optional (java.util.Optional)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 YamlMapping (com.amihaiemil.eoyaml.YamlMapping)6 PublisherAs (com.artipie.asto.ext.PublisherAs)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 Matcher (java.util.regex.Matcher)6 Pattern (java.util.regex.Pattern)6 Collectors (java.util.stream.Collectors)5 TestResource (com.artipie.asto.test.TestResource)4 Response (com.artipie.http.Response)4 Slice (com.artipie.http.Slice)4 AsyncResponse (com.artipie.http.async.AsyncResponse)4 RequestLineFrom (com.artipie.http.rq.RequestLineFrom)4 CompletionStage (java.util.concurrent.CompletionStage)4