Search in sources :

Example 1 with RsStatus

use of com.artipie.http.rs.RsStatus 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 2 with RsStatus

use of com.artipie.http.rs.RsStatus 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 3 with RsStatus

use of com.artipie.http.rs.RsStatus 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)

Example 4 with RsStatus

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

the class ResponseMetricsSliceTest method shouldForwardRequestUnmodified.

@Test
void shouldForwardRequestUnmodified() {
    final Header header = new Header("header1", "value1");
    final byte[] body = "some code".getBytes();
    final RsStatus status = RsStatus.CREATED;
    MatcherAssert.assertThat(new ResponseMetricsSlice((rsline, rsheaders, rsbody) -> new RsFull(status, rsheaders, rsbody), this.metrics).response(new RequestLine(RqMethod.POST, "/some_upload.war").toString(), new Headers.From(header), Flowable.just(ByteBuffer.wrap(body))), new ResponseMatcher(status, body, header));
}
Also used : RequestLine(com.artipie.http.rq.RequestLine) ResponseMatcher(com.artipie.http.hm.ResponseMatcher) RsFull(com.artipie.http.rs.RsFull) Header(com.artipie.http.headers.Header) RsStatus(com.artipie.http.rs.RsStatus) Test(org.junit.jupiter.api.Test)

Example 5 with RsStatus

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

the class AuthAndPermissionsTest method adminCanDeploy.

@Test
void adminCanDeploy() throws IOException {
    final RsStatus status = RsStatus.ACCEPTED;
    MatcherAssert.assertThat(new BasicAuthSlice(new SliceSimple(new RsWithStatus(status)), new AuthFromYaml(this.credentials()), new Permission.ByName("deploy", 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("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)

Aggregations

RequestLine (com.artipie.http.rq.RequestLine)7 RsStatus (com.artipie.http.rs.RsStatus)7 Test (org.junit.jupiter.api.Test)7 RsWithStatus (com.artipie.http.rs.RsWithStatus)6 RsHasStatus (com.artipie.http.hm.RsHasStatus)5 SliceSimple (com.artipie.http.slice.SliceSimple)5 BasicAuthSlice (com.artipie.http.auth.BasicAuthSlice)4 Permission (com.artipie.http.auth.Permission)4 Authorization (com.artipie.http.headers.Authorization)4 Map (java.util.Map)3 ListOf (org.cactoos.list.ListOf)3 Base64Encoded (org.cactoos.text.Base64Encoded)3 Headers (com.artipie.http.Headers)2 Header (com.artipie.http.headers.Header)2 ResponseMatcher (com.artipie.http.hm.ResponseMatcher)2 RsFull (com.artipie.http.rs.RsFull)2 Response (com.artipie.http.Response)1 RsHasHeaders (com.artipie.http.hm.RsHasHeaders)1 SliceHasResponse (com.artipie.http.hm.SliceHasResponse)1 RqMethod (com.artipie.http.rq.RqMethod)1