Search in sources :

Example 1 with RequestLine

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

the class DockerProxyTest method shouldBuildFromConfig.

@ParameterizedTest
@MethodSource("goodConfigs")
void shouldBuildFromConfig(final String yaml) throws Exception {
    final Slice slice = dockerProxy(yaml);
    MatcherAssert.assertThat(slice.response(new RequestLine(RqMethod.GET, "/").toString(), Headers.EMPTY, Flowable.empty()), new RsHasStatus(new IsNot<>(new CustomMatcher<>("is server error") {

        @Override
        public boolean matches(final Object item) {
            return ((RsStatus) item).serverError();
        }
    })));
}
Also used : RequestLine(com.artipie.http.rq.RequestLine) IsNot(org.hamcrest.core.IsNot) RsHasStatus(com.artipie.http.hm.RsHasStatus) Slice(com.artipie.http.Slice) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with RequestLine

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

the class DockerProxyTest method shouldFailBuildFromBadConfig.

@ParameterizedTest
@MethodSource("badConfigs")
void shouldFailBuildFromBadConfig(final String yaml) throws Exception {
    final Slice slice = dockerProxy(yaml);
    Assertions.assertThrows(RuntimeException.class, () -> slice.response(new RequestLine(RqMethod.GET, "/").toString(), Headers.EMPTY, Flowable.empty()).send((status, headers, body) -> CompletableFuture.allOf()).toCompletableFuture().join());
}
Also used : RqMethod(com.artipie.http.rq.RqMethod) RepoConfig(com.artipie.repo.RepoConfig) Headers(com.artipie.http.Headers) IsNot(org.hamcrest.core.IsNot) Slice(com.artipie.http.Slice) Permissions(com.artipie.http.auth.Permissions) CustomMatcher(org.hamcrest.CustomMatcher) RsStatus(com.artipie.http.rs.RsStatus) IOException(java.io.IOException) CompletableFuture(java.util.concurrent.CompletableFuture) Key(com.artipie.asto.Key) Yaml(com.amihaiemil.eoyaml.Yaml) RsHasStatus(com.artipie.http.hm.RsHasStatus) RequestLine(com.artipie.http.rq.RequestLine) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Stream(java.util.stream.Stream) MatcherAssert(org.hamcrest.MatcherAssert) Flowable(io.reactivex.Flowable) ClientSlices(com.artipie.http.client.ClientSlices) JettyClientSlices(com.artipie.http.client.jetty.JettyClientSlices) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) MethodSource(org.junit.jupiter.params.provider.MethodSource) RequestLine(com.artipie.http.rq.RequestLine) Slice(com.artipie.http.Slice) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with RequestLine

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

the class AuthAndPermissionsTest method johnCanDelete.

@Test
void johnCanDelete() throws IOException {
    final RsStatus status = RsStatus.NO_CONTENT;
    MatcherAssert.assertThat(new BasicAuthSlice(new SliceSimple(new RsWithStatus(status)), new AuthFromYaml(this.credentials()), new Permission.ByName("delete", this.permissions())).response(new RequestLine("PUT", "/foo", "HTTP/1.2").toString(), new ListOf<Map.Entry<String, String>>(new Authorization(String.format("Basic %s", new Base64Encoded("john:123").asString()))), Flowable.empty()), new RsHasStatus(status));
}
Also used : RsHasStatus(com.artipie.http.hm.RsHasStatus) RsStatus(com.artipie.http.rs.RsStatus) Authorization(com.artipie.http.headers.Authorization) BasicAuthSlice(com.artipie.http.auth.BasicAuthSlice) RequestLine(com.artipie.http.rq.RequestLine) RsWithStatus(com.artipie.http.rs.RsWithStatus) Permission(com.artipie.http.auth.Permission) ListOf(org.cactoos.list.ListOf) Base64Encoded(org.cactoos.text.Base64Encoded) Map(java.util.Map) SliceSimple(com.artipie.http.slice.SliceSimple) Test(org.junit.jupiter.api.Test)

Example 4 with RequestLine

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

the class AuthAndPermissionsTest method publicRepoWorksWithAuth.

@Test
void publicRepoWorksWithAuth() throws IOException {
    final RsStatus status = RsStatus.OK;
    MatcherAssert.assertThat(new BasicAuthSlice(new SliceSimple(new RsWithStatus(status)), new AuthFromYaml(this.credentials()), new Permission.ByName("delete", this.allAllowedPermissions())).response(new RequestLine("GET", "/foo", "HTTP/1.2").toString(), new ListOf<Map.Entry<String, String>>(new Authorization(String.format("Basic %s", new Base64Encoded("admin:abc").asString()))), Flowable.empty()), new RsHasStatus(status));
}
Also used : RsHasStatus(com.artipie.http.hm.RsHasStatus) RsStatus(com.artipie.http.rs.RsStatus) Authorization(com.artipie.http.headers.Authorization) BasicAuthSlice(com.artipie.http.auth.BasicAuthSlice) RequestLine(com.artipie.http.rq.RequestLine) RsWithStatus(com.artipie.http.rs.RsWithStatus) Permission(com.artipie.http.auth.Permission) ListOf(org.cactoos.list.ListOf) Base64Encoded(org.cactoos.text.Base64Encoded) Map(java.util.Map) SliceSimple(com.artipie.http.slice.SliceSimple) Test(org.junit.jupiter.api.Test)

Example 5 with RequestLine

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

the class AuthAndPermissionsTest method authIsNotRequiredForPublicRepo.

@Test
void authIsNotRequiredForPublicRepo() {
    final RsStatus status = RsStatus.ACCEPTED;
    MatcherAssert.assertThat(new BasicAuthSlice(new SliceSimple(new RsWithStatus(status)), new AuthFromYaml(this.credentials()), new Permission.ByName("install", this.allAllowedPermissions())).response(new RequestLine("GET", "/foo", "HTTP/1.2").toString(), Collections.emptyList(), Flowable.empty()), new RsHasStatus(status));
}
Also used : BasicAuthSlice(com.artipie.http.auth.BasicAuthSlice) RequestLine(com.artipie.http.rq.RequestLine) RsWithStatus(com.artipie.http.rs.RsWithStatus) RsHasStatus(com.artipie.http.hm.RsHasStatus) Permission(com.artipie.http.auth.Permission) RsStatus(com.artipie.http.rs.RsStatus) SliceSimple(com.artipie.http.slice.SliceSimple) 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