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));
}
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));
}
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));
}
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]));
}
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;
}
Aggregations