Search in sources :

Example 1 with Authorization

use of com.artipie.http.headers.Authorization 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 Authorization

use of com.artipie.http.headers.Authorization 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 Authorization

use of com.artipie.http.headers.Authorization 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)

Example 4 with Authorization

use of com.artipie.http.headers.Authorization in project artipie by artipie.

the class ResponseMetricsSliceTest method shouldReportBadAuthResponse.

@Test
public void shouldReportBadAuthResponse() {
    this.send(RqMethod.DELETE, new Headers.From(new Authorization("some value")), new RsWithStatus(RsStatus.UNAUTHORIZED));
    this.send(RqMethod.DELETE, new Headers.From(new Authorization("another value")), new RsWithStatus(RsStatus.UNAUTHORIZED));
    MatcherAssert.assertThat(this.metrics.counter("delete.error.bad-auth").value(), new IsEqual<>(2L));
}
Also used : Authorization(com.artipie.http.headers.Authorization) RsWithStatus(com.artipie.http.rs.RsWithStatus) Headers(com.artipie.http.Headers) Test(org.junit.jupiter.api.Test)

Aggregations

Authorization (com.artipie.http.headers.Authorization)4 RsWithStatus (com.artipie.http.rs.RsWithStatus)4 Test (org.junit.jupiter.api.Test)4 BasicAuthSlice (com.artipie.http.auth.BasicAuthSlice)3 Permission (com.artipie.http.auth.Permission)3 RsHasStatus (com.artipie.http.hm.RsHasStatus)3 RequestLine (com.artipie.http.rq.RequestLine)3 RsStatus (com.artipie.http.rs.RsStatus)3 SliceSimple (com.artipie.http.slice.SliceSimple)3 Map (java.util.Map)3 ListOf (org.cactoos.list.ListOf)3 Base64Encoded (org.cactoos.text.Base64Encoded)3 Headers (com.artipie.http.Headers)1