io.netty.handler.codec.socksx.v4.DefaultSocks4CommandResponse #com.linecorp.armeria.common.AggregatedHttpResponse源码实例Demo

下面列出了 io.netty.handler.codec.socksx.v4.DefaultSocks4CommandResponse #com.linecorp.armeria.common.AggregatedHttpResponse 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: armeria   文件: HttpServerTest.java
@ParameterizedTest
@ArgumentsSource(ClientAndProtocolProvider.class)
void testTimeoutAfterPartialContent(WebClient client) throws Exception {
    serverRequestTimeoutMillis = 1000L;
    final CompletableFuture<AggregatedHttpResponse> f = client.get("/content_delay/2000").aggregate();

    // Because the service has written out the content partially, there's no way for the service
    // to reply with '503 Service Unavailable', so it will just close the stream.

    final Class<? extends Throwable> expectedCauseType =
            client.scheme().sessionProtocol().isMultiplex() ?
            ClosedStreamException.class : ClosedSessionException.class;

    assertThatThrownBy(f::get).isInstanceOf(ExecutionException.class)
                              .hasCauseInstanceOf(expectedCauseType);
}
 
源代码2 项目: armeria   文件: ServiceBindingTest.java
@Test
void routeService() throws InterruptedException {
    final WebClient client = WebClient.of(server.httpUri());
    AggregatedHttpResponse res = client.get("/greet/armeria").aggregate().join();
    propertyCheckLatch.await();
    assertThat(res.status()).isSameAs(HttpStatus.OK);
    assertThat(res.contentUtf8()).isEqualTo("armeria");

    res = client.post("/greet", "armeria").aggregate().join();
    assertThat(res.status()).isSameAs(HttpStatus.OK);
    assertThat(res.contentUtf8()).isEqualTo("armeria");

    res = client.put("/greet/armeria", "armeria").aggregate().join();
    assertThat(res.status()).isSameAs(HttpStatus.METHOD_NOT_ALLOWED);

    res = client.put("/greet", "armeria").aggregate().join();
    assertThat(res.status()).isSameAs(HttpStatus.METHOD_NOT_ALLOWED);
}
 
源代码3 项目: armeria   文件: ProxyClientIntegrationTest.java
@Test
void testProxy_protocolUpgrade_notSharableExceptionNotThrown() throws Exception {
    DYNAMIC_HANDLER.setWriteCustomizer((ctx, msg, promise) -> {
        ctx.write(new DefaultSocks4CommandResponse(Socks4CommandStatus.REJECTED_OR_FAILED), promise);
    });
    final ClientFactory clientFactory = ClientFactory.builder().proxyConfig(
            ProxyConfig.socks4(socksProxyServer.address())).build();
    final WebClient webClient = WebClient.builder(SessionProtocol.HTTP, backendServer.httpEndpoint())
                                         .factory(clientFactory)
                                         .decorator(LoggingClient.newDecorator())
                                         .build();
    final CompletableFuture<AggregatedHttpResponse> responseFuture =
            webClient.get(PROXY_PATH).aggregate();
    assertThatThrownBy(responseFuture::join).isInstanceOf(CompletionException.class)
                                            .hasCauseInstanceOf(UnprocessedRequestException.class)
                                            .hasRootCauseInstanceOf(ProxyConnectException.class);
    clientFactory.close();
}
 
源代码4 项目: armeria   文件: WebAppContainerTest.java
@Test
public void https() throws Exception {
    final WebClient client = WebClient.builder(server().uri(SessionProtocol.HTTPS))
                                      .factory(ClientFactory.insecure())
                                      .build();
    final AggregatedHttpResponse response = client.get("/jsp/index.jsp").aggregate().get();
    final String actualContent = CR_OR_LF.matcher(response.contentUtf8())
                                         .replaceAll("");
    assertThat(actualContent).isEqualTo(
            "<html><body>" +
            "<p>Hello, Armerian World!</p>" +
            "<p>Have you heard about the class 'org.slf4j.Logger'?</p>" +
            "<p>Context path: </p>" + // ROOT context path
            "<p>Request URI: /index.jsp</p>" +
            "<p>Scheme: https</p>" +
            "</body></html>");
}
 
源代码5 项目: centraldogma   文件: ContentServiceV1Test.java
@Test
void deleteFile() throws IOException {
    final WebClient client = dogma.httpClient();
    addFooJson(client);
    addBarTxt(client);

    final String body =
            '{' +
            "   \"path\": \"/foo.json\"," +
            "   \"type\": \"REMOVE\"," +
            "   \"commitMessage\" : {" +
            "       \"summary\" : \"Delete foo.json\"" +
            "   }" +
            '}';
    final RequestHeaders headers = RequestHeaders.of(HttpMethod.POST, CONTENTS_PREFIX,
                                                     HttpHeaderNames.CONTENT_TYPE, MediaType.JSON);
    final AggregatedHttpResponse res1 = client.execute(headers, body).aggregate().join();
    assertThat(ResponseHeaders.of(res1.headers()).status()).isEqualTo(HttpStatus.OK);

    final AggregatedHttpResponse res2 = client.get(CONTENTS_PREFIX + "/**").aggregate().join();
    // /a directory and /a/bar.txt file are left
    assertThat(Jackson.readTree(res2.contentUtf8()).size()).isEqualTo(2);
}
 
@Test
public void multipleObjectPublisherBasedResponseConverter() throws Exception {
    final WebClient client = WebClient.of(rule.httpUri() + "/publish/multi");

    AggregatedHttpResponse res;

    res = aggregated(client.get("/string"));
    assertThat(res.contentType()).isEqualTo(MediaType.JSON_UTF_8);
    assertThatJson(res.contentUtf8())
            .isArray().ofLength(3)
            .thatContains("a").thatContains("b").thatContains("c");

    res = aggregated(client.get("/jsonNode"));
    assertThat(res.contentType()).isEqualTo(MediaType.JSON_UTF_8);
    assertThatJson(res.contentUtf8())
            .isEqualTo("[{\"a\":\"1\"},{\"b\":\"2\"},{\"c\":\"3\"}]");
}
 
源代码7 项目: centraldogma   文件: ArmeriaCentralDogma.java
/**
 * Parses the content of the specified {@link AggregatedHttpResponse} into a {@link JsonNode}.
 */
private static JsonNode toJson(AggregatedHttpResponse res, @Nullable JsonNodeType expectedNodeType) {
    final String content = toString(res);
    final JsonNode node;
    try {
        node = Jackson.readTree(content);
    } catch (JsonParseException e) {
        throw new CentralDogmaException("failed to parse the response JSON", e);
    }

    if (expectedNodeType != null && node.getNodeType() != expectedNodeType) {
        throw new CentralDogmaException(
                "invalid server response; expected: " + expectedNodeType +
                ", actual: " + node.getNodeType() + ", content: " + content);
    }
    return node;
}
 
源代码8 项目: centraldogma   文件: ContentServiceV1Test.java
@Test
void editFileWithJsonPatch() throws IOException {
    final WebClient client = dogma.httpClient();
    addFooJson(client);
    final AggregatedHttpResponse res1 = editFooJson(client);
    final String expectedJson =
            '{' +
            "   \"revision\": 3," +
            "   \"pushedAt\": \"${json-unit.ignore}\"" +
            '}';
    final String actualJson = res1.contentUtf8();
    assertThatJson(actualJson).isEqualTo(expectedJson);

    final AggregatedHttpResponse res2 = client.get(CONTENTS_PREFIX + "/foo.json").aggregate().join();
    assertThat(Jackson.readTree(res2.contentUtf8()).get("content").get("a").textValue())
            .isEqualToIgnoringCase("baz");
}
 
@Test
void testDefaultRequestConverter_text() throws Exception {
    final WebClient client = WebClient.of(server.httpUri());

    AggregatedHttpResponse response;

    final byte[] utf8 = "¥".getBytes(StandardCharsets.UTF_8);
    response = client.execute(AggregatedHttpRequest.of(HttpMethod.POST, "/2/default/text",
                                                       MediaType.PLAIN_TEXT_UTF_8, utf8))
                     .aggregate().join();
    assertThat(response.status()).isEqualTo(HttpStatus.OK);
    assertThat(response.content().array()).isEqualTo(utf8);

    final MediaType textPlain = MediaType.create("text", "plain");
    response = client.execute(AggregatedHttpRequest.of(HttpMethod.POST, "/2/default/text",
                                                       textPlain, utf8))
                     .aggregate().join();
    assertThat(response.status()).isEqualTo(HttpStatus.OK);
    // Response is encoded as UTF-8.
    assertThat(response.content().array()).isEqualTo(utf8);
}
 
源代码10 项目: centraldogma   文件: ContentCompressionTest.java
@Test
void http() throws Exception {
    final WebClient client =
            WebClient.builder("http://127.0.0.1:" + dogma.serverAddress().getPort())
                     .setHttpHeader(HttpHeaderNames.AUTHORIZATION, "Bearer " + CsrfToken.ANONYMOUS)
                     .setHttpHeader(HttpHeaderNames.ACCEPT_ENCODING, "deflate")
                     .build();

    final String contentPath = HttpApiV1Constants.PROJECTS_PREFIX + '/' + PROJ +
                               HttpApiV1Constants.REPOS + '/' + REPO +
                               "/contents" + PATH;

    final AggregatedHttpResponse compressedResponse = client.get(contentPath).aggregate().join();
    assertThat(compressedResponse.status()).isEqualTo(HttpStatus.OK);

    final HttpData content = compressedResponse.content();
    try (Reader in = new InputStreamReader(new InflaterInputStream(new ByteArrayInputStream(
            content.array(), 0, content.length())), StandardCharsets.UTF_8)) {

        assertThat(CharStreams.toString(in)).contains(CONTENT);
    }
}
 
源代码11 项目: armeria   文件: RedirectServiceTest.java
@Test
public void testMisconfiguredPathParams3() throws Exception {
    serverRule2c.start();

    final WebClient client = WebClient.of(serverRule2c.httpUri());
    AggregatedHttpResponse res = client.get("/test1a/qwe/asd/zxc").aggregate().get();
    assertThat(res.status()).isEqualTo(HttpStatus.TEMPORARY_REDIRECT);

    final String newLocation = res.headers().get(HttpHeaderNames.LOCATION);
    assertThat(newLocation).isEqualTo("/new1/null/new1/null/new1/null");

    res = client.get(newLocation).aggregate().get();
    assertThat(res.status()).isEqualTo(HttpStatus.NOT_FOUND);

    serverRule2c.stop();
}
 
源代码12 项目: armeria   文件: ArmeriaAutoConfigurationTest.java
@Test
public void testThriftServiceRegistrationBean() throws Exception {
    final HelloService.Iface client = Clients.newClient(newUrl("tbinary+h1c") + "/thrift",
                                                        HelloService.Iface.class);
    assertThat(client.hello("world")).isEqualTo("hello world");

    final WebClient webClient = WebClient.of(newUrl("h1c"));
    final HttpResponse response = webClient.get("/internal/docs/specification.json");

    final AggregatedHttpResponse res = response.aggregate().get();
    assertThat(res.status()).isEqualTo(HttpStatus.OK);
    assertThatJson(res.contentUtf8()).node("services[2].name").isStringEqualTo(
            "com.linecorp.armeria.spring.test.thrift.main.HelloService");
    assertThatJson(res.contentUtf8())
            .node("services[2].exampleHttpHeaders[0].x-additional-header").isStringEqualTo("headerVal");
    assertThatJson(res.contentUtf8())
            .node("services[0].methods[0].exampleHttpHeaders[0].x-additional-header")
            .isStringEqualTo("headerVal");
}
 
@Test
void requestConverterOrder() throws Exception {
    final String body = "{\"foo\":\"bar\"}";
    final AggregatedHttpRequest aReq = AggregatedHttpRequest.of(
            HttpMethod.POST, "/1/requestConverterOrder", MediaType.JSON, body);

    final AggregatedHttpResponse aRes = executeRequest(aReq);

    assertThat(aRes.status()).isEqualTo(HttpStatus.OK);
    // Converted from the default converter which is JacksonRequestConverterFunction.
    assertThat(aRes.contentUtf8()).isEqualTo(body);

    // parameter level(+1) -> method level(+1) -> class level(+1) -> service level(+1) -> server level(+1)
    // -> default
    assertThat(requestCounter.get()).isEqualTo(5);
}
 
@Test
public void metaAnnotations() {
    final AggregatedHttpResponse msg =
            WebClient.of(rule.httpUri())
                     .execute(RequestHeaders.of(HttpMethod.POST, "/hello",
                                                HttpHeaderNames.CONTENT_TYPE,
                                                MediaType.PLAIN_TEXT_UTF_8,
                                                HttpHeaderNames.ACCEPT, "text/*"),
                              HttpData.ofUtf8("Armeria"))
                     .aggregate().join();
    assertThat(msg.status()).isEqualTo(HttpStatus.CREATED);
    assertThat(msg.contentType()).isEqualTo(MediaType.PLAIN_TEXT_UTF_8);
    assertThat(msg.headers().get(HttpHeaderNames.of("x-foo"))).isEqualTo("foo");
    assertThat(msg.headers().get(HttpHeaderNames.of("x-bar"))).isEqualTo("bar");
    assertThat(msg.contentUtf8())
            .isEqualTo("Hello, Armeria (decorated-1) (decorated-2) (decorated-3)!");
    assertThat(msg.trailers().get(HttpHeaderNames.of("x-baz"))).isEqualTo("baz");
    assertThat(msg.trailers().get(HttpHeaderNames.of("x-qux"))).isEqualTo("qux");
}
 
源代码15 项目: centraldogma   文件: MergeFileTest.java
@Test
void exceptionWhenOnlyOptionalFilesAndDoNotExist() {
    final WebClient client = dogma.httpClient();
    addFilesForMergeJson(client);
    final String queryString = "optional_path=/no_exist1.json" + '&' +
                               "optional_path=/no_exist2.json";

    final AggregatedHttpResponse aRes = client.get("/api/v1/projects/myPro/repos/myRepo/merge?" +
                                                   queryString).aggregate().join();
    assertThat(aRes.status()).isEqualTo(HttpStatus.NOT_FOUND);
    final String expectedJson =
            '{' +
            "     \"exception\": \"com.linecorp.centraldogma.common.EntryNotFoundException\"," +
            "     \"message\": \"Entry '/no_exist1.json,/no_exist2.json (revision: 4)' does not exist.\"" +
            '}';
    assertThatJson(aRes.contentUtf8()).isEqualTo(expectedJson);
}
 
@Test
void maybe() {
    final WebClient client = WebClient.of(server.httpUri() + "/maybe");

    AggregatedHttpResponse res;

    res = client.get("/string").aggregate().join();
    assertThat(res.contentType()).isEqualTo(MediaType.PLAIN_TEXT_UTF_8);
    assertThat(res.contentUtf8()).isEqualTo("a");

    res = client.get("/json").aggregate().join();
    assertThat(res.contentType()).isEqualTo(MediaType.JSON_UTF_8);
    assertThatJson(res.contentUtf8()).isStringEqualTo("a");

    res = client.get("/empty").aggregate().join();
    assertThat(res.status()).isEqualTo(HttpStatus.OK);
    assertThat(res.content().isEmpty()).isTrue();

    res = client.get("/error").aggregate().join();
    assertThat(res.status()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);

    res = client.get("/http-response").aggregate().join();
    assertThat(res.contentType()).isEqualTo(MediaType.PLAIN_TEXT_UTF_8);
    assertThat(res.contentUtf8()).isEqualTo("a");
}
 
源代码17 项目: armeria   文件: HttpServerTest.java
@ParameterizedTest
@ArgumentsSource(ClientAndProtocolProvider.class)
void testStrings_acceptEncodingDeflate(WebClient client) throws Exception {
    final RequestHeaders req = RequestHeaders.of(HttpMethod.GET, "/strings",
                                                 HttpHeaderNames.ACCEPT_ENCODING, "deflate");
    final CompletableFuture<AggregatedHttpResponse> f = client.execute(req).aggregate();

    final AggregatedHttpResponse res = f.get();

    assertThat(res.status()).isEqualTo(HttpStatus.OK);
    assertThat(res.headers().get(HttpHeaderNames.CONTENT_ENCODING)).isEqualTo("deflate");
    assertThat(res.headers().get(HttpHeaderNames.VARY)).isEqualTo("accept-encoding");

    final byte[] decoded;
    try (InflaterInputStream unzipper =
                 new InflaterInputStream(new ByteArrayInputStream(res.content().array()))) {
        decoded = ByteStreams.toByteArray(unzipper);
    }
    assertThat(new String(decoded, StandardCharsets.UTF_8)).isEqualTo("Armeria is awesome!");
}
 
源代码18 项目: armeria   文件: ContentPreviewingClientTest.java
/**
 * Unlike {@link #decodedContentPreview()}, the content preview of this test is encoded data because
 * the previewing decorator is inserted before {@link DecodingClient}.
 */
@Test
void contentPreviewIsDecodedInPreviewer() {
    final WebClient client = WebClient.builder(server.httpUri())
                                      .decorator(decodingContentPreviewDecorator())
                                      .decorator(DecodingClient.newDecorator())
                                      .build();
    final RequestHeaders headers = RequestHeaders.of(HttpMethod.POST, "/",
                                                     HttpHeaderNames.CONTENT_TYPE,
                                                     MediaType.PLAIN_TEXT_UTF_8);

    final ClientRequestContext context;
    try (ClientRequestContextCaptor captor = Clients.newContextCaptor()) {
        final AggregatedHttpResponse res = client.execute(headers, "Armeria").aggregate().join();
        assertThat(res.contentUtf8()).isEqualTo("Hello Armeria!");
        assertThat(res.headers().get(HttpHeaderNames.CONTENT_ENCODING)).isEqualTo("gzip");
        context = captor.get();
    }

    final RequestLog requestLog = context.log().whenComplete().join();
    assertThat(requestLog.requestContentPreview()).isEqualTo("Armeria");
    assertThat(requestLog.responseContentPreview()).isEqualTo("Hello Armeria!");
}
 
@Test
public void throttle3() throws Exception {
    final WebClient client = WebClient.of(serverRule.httpUri());
    final AggregatedHttpResponse response1 = client.get("/http-throttle3").aggregate().get();
    assertThat(response1.status()).isEqualTo(HttpStatus.OK);

    assertThat(response1.headers().contains(HttpHeaderNames.RETRY_AFTER)).isFalse();
    assertThat(response1.headers().contains("RateLimit-Remaining")).isFalse();
    assertThat(response1.headers().contains("X-Rate-Limit-Remaining")).isFalse();
    assertThat(response1.headers().contains("X-RateLimit-Remaining")).isFalse();
    assertThat(response1.headers().contains("X-RateLimit-Reset")).isFalse();

    final AggregatedHttpResponse response2 = client.get("/http-throttle3").aggregate().get();
    assertThat(response2.status()).isEqualTo(HttpStatus.TOO_MANY_REQUESTS);

    assertThat(response2.headers().contains(HttpHeaderNames.RETRY_AFTER)).isTrue();
    final long retryAfter2 = Long.parseLong(response2.headers().get(HttpHeaderNames.RETRY_AFTER));
    assertThat(retryAfter2).isBetween(0L, 10L);
    assertThat(response2.headers().contains("RateLimit-Remaining")).isFalse();
    assertThat(response2.headers().contains("X-Rate-Limit-Remaining")).isFalse();
    assertThat(response2.headers().contains("X-RateLimit-Remaining")).isFalse();
    assertThat(response2.headers().contains("X-RateLimit-Reset")).isFalse();
}
 
源代码20 项目: armeria   文件: HealthCheckService.java
private static AggregatedHttpResponse clearCommonHeaders(AggregatedHttpResponse res) {
    return AggregatedHttpResponse.of(res.informationals(),
                                     res.headers().toBuilder()
                                        .removeAndThen(ARMERIA_LPHC)
                                        .build(),
                                     res.content(),
                                     res.trailers().toBuilder()
                                        .removeAndThen(ARMERIA_LPHC)
                                        .build());
}
 
源代码21 项目: armeria   文件: AnnotatedServiceDecorationTest.java
@Test
public void testDecoratingAnnotatedService() throws Exception {
    final WebClient client = WebClient.of(rule.httpUri());

    AggregatedHttpResponse response;

    response = client.execute(RequestHeaders.of(HttpMethod.GET, "/1/ok")).aggregate().get();
    assertThat(response.status()).isEqualTo(HttpStatus.OK);

    response = client.execute(RequestHeaders.of(HttpMethod.GET, "/1/tooManyRequests")).aggregate().get();
    assertThat(response.status()).isEqualTo(HttpStatus.TOO_MANY_REQUESTS);

    response = client.execute(RequestHeaders.of(HttpMethod.GET, "/1/locked")).aggregate().get();
    assertThat(response.status()).isEqualTo(HttpStatus.LOCKED);

    // Call inherited methods.
    response = client.execute(RequestHeaders.of(HttpMethod.GET, "/2/tooManyRequests")).aggregate().get();
    assertThat(response.status()).isEqualTo(HttpStatus.TOO_MANY_REQUESTS);

    response = client.execute(RequestHeaders.of(HttpMethod.GET, "/2/locked")).aggregate().get();
    assertThat(response.status()).isEqualTo(HttpStatus.LOCKED);

    // Call a new method.
    response = client.execute(RequestHeaders.of(HttpMethod.GET, "/2/added")).aggregate().get();
    assertThat(response.status()).isEqualTo(HttpStatus.OK);

    // Call an overriding method.
    response = client.execute(RequestHeaders.of(HttpMethod.GET, "/2/override")).aggregate().get();
    assertThat(response.status()).isEqualTo(HttpStatus.TOO_MANY_REQUESTS);

    // Respond by the class-level decorator.
    response = client.execute(RequestHeaders.of(HttpMethod.GET, "/3/tooManyRequests")).aggregate().get();
    assertThat(response.status()).isEqualTo(HttpStatus.TOO_MANY_REQUESTS);

    // Respond by the method-level decorator.
    response = client.execute(RequestHeaders.of(HttpMethod.GET, "/4/tooManyRequests")).aggregate().get();
    assertThat(response.status()).isEqualTo(HttpStatus.TOO_MANY_REQUESTS);
}
 
源代码22 项目: armeria   文件: ArmeriaAutoConfigurationTest.java
@Test
public void testAnnotatedServiceRegistrationBean() throws Exception {
    final WebClient client = WebClient.of(newUrl("h1c"));

    HttpResponse response = client.get("/annotated/get");

    AggregatedHttpResponse res = response.aggregate().get();
    assertThat(res.status()).isEqualTo(HttpStatus.OK);
    assertThat(res.contentUtf8()).isEqualTo("annotated");

    response = client.get("/annotated/get/2");
    res = response.aggregate().get();
    assertThat(res.status()).isEqualTo(HttpStatus.OK);
    assertThat(res.contentUtf8()).isEqualTo("exception");

    final RequestHeaders postJson = RequestHeaders.of(HttpMethod.POST, "/annotated/post",
                                                      HttpHeaderNames.CONTENT_TYPE, "application/json");
    response = client.execute(postJson, "{\"foo\":\"bar\"}");
    res = response.aggregate().join();
    assertThat(res.status()).isEqualTo(HttpStatus.OK);
    assertThatJson(res.contentUtf8()).node("foo").isEqualTo("bar");

    final WebClient webClient = WebClient.of(newUrl("h1c"));
    response = webClient.get("/internal/docs/specification.json");

    res = response.aggregate().get();
    assertThat(res.status()).isEqualTo(HttpStatus.OK);
    assertThatJson(res.contentUtf8()).node("services[0].name").isStringEqualTo(
            "com.linecorp.armeria.spring.ArmeriaAutoConfigurationTest$AnnotatedService");
    assertThatJson(res.contentUtf8())
            .node("services[0].methods[2].exampleRequests[0]").isStringEqualTo("{\"foo\":\"bar\"}");
    assertThatJson(res.contentUtf8())
            .node("services[0].exampleHttpHeaders[0].x-additional-header").isStringEqualTo("headerVal");
    assertThatJson(res.contentUtf8())
            .node("services[0].methods[0].exampleHttpHeaders[0].x-additional-header")
            .isStringEqualTo("headerVal");
}
 
源代码23 项目: armeria   文件: MainTest.java
@Test
void testFavicon() {
    // Download the favicon.
    final AggregatedHttpResponse res = client.get("/favicon.ico").aggregate().join();
    assertThat(res.status()).isEqualTo(HttpStatus.OK);
    assertThat(res.headers().contentType()).isEqualTo(MediaType.parse("image/x-icon"));
}
 
源代码24 项目: centraldogma   文件: ShiroLoginAndLogoutTest.java
private void loginAndLogout(AggregatedHttpResponse loginRes) throws Exception {
    assertThat(loginRes.status()).isEqualTo(HttpStatus.OK);

    // Ensure authorization works.
    final AccessToken accessToken = Jackson.readValue(loginRes.contentUtf8(), AccessToken.class);
    final String sessionId = accessToken.accessToken();

    assertThat(usersMe(client, sessionId).status()).isEqualTo(HttpStatus.OK);

    // Log out.
    assertThat(logout(client, sessionId).status()).isEqualTo(HttpStatus.OK);
    assertThat(usersMe(client, sessionId).status()).isEqualTo(HttpStatus.UNAUTHORIZED);
}
 
源代码25 项目: centraldogma   文件: TestAuthMessageUtil.java
public static AggregatedHttpResponse loginWithBasicAuth(WebClient client, String username,
                                                        String password) {
    return client.execute(
            RequestHeaders.of(HttpMethod.POST, "/api/v1/login",
                              HttpHeaderNames.AUTHORIZATION,
                              "basic " + encoder.encodeToString(
                                      (username + ':' + password).getBytes(StandardCharsets.US_ASCII))))
                 .aggregate().join();
}
 
源代码26 项目: armeria   文件: AbstractPooledHttpServiceTest.java
@ParameterizedTest
@EnumSource(value = HttpMethod.class, mode = Mode.EXCLUDE, names = {"CONNECT", "UNKNOWN"})
void implemented(HttpMethod method) {
    final AggregatedHttpResponse response = client.execute(HttpRequest.of(method, "/implemented"))
                                                  .aggregate().join();
    assertThat(response.status()).isEqualTo(HttpStatus.OK);
    // HEAD responses content stripped out by framework.
    if (method != HttpMethod.HEAD) {
        assertThat(response.contentUtf8()).isEqualTo(method.name().toLowerCase());
    }
}
 
源代码27 项目: armeria   文件: HttpServerAdditionalHeadersTest.java
@Test
void blacklistedHeadersAndTrailersMustBeFiltered() {
    final WebClient client = WebClient.of(server.httpUri());
    final AggregatedHttpResponse res = client.get("/headers_and_trailers").aggregate().join();
    assertThat(res.status()).isEqualTo(HttpStatus.OK);
    assertThat(res.headers().names()).doesNotContain(HttpHeaderNames.SCHEME,
                                                     HttpHeaderNames.METHOD,
                                                     HttpHeaderNames.PATH,
                                                     HttpHeaderNames.TRANSFER_ENCODING);
    assertThat(res.trailers().names()).doesNotContain(HttpHeaderNames.SCHEME,
                                                      HttpHeaderNames.STATUS,
                                                      HttpHeaderNames.METHOD,
                                                      HttpHeaderNames.PATH,
                                                      HttpHeaderNames.TRANSFER_ENCODING);
}
 
源代码28 项目: armeria   文件: HttpServerCorsTest.java
@Test
public void testNoCorsDecoratorForAnnotatedService() throws Exception {
    final WebClient client = client();
    final AggregatedHttpResponse response = preflightRequest(client, "/cors5/post", "http://example.com",
                                                             "POST");
    assertEquals(HttpStatus.FORBIDDEN, response.status());
}
 
private static AggregatedHttpResponse sendPostRequest(WebClient client) {
    final RequestHeaders requestHeaders =
            RequestHeaders.of(HttpMethod.POST, "/hello",
                              HttpHeaderNames.USER_AGENT, "test-agent/1.0.0",
                              HttpHeaderNames.ACCEPT_ENCODING, "gzip");
    return client.execute(requestHeaders, HttpData.wrap(POST_BODY.getBytes())).aggregate().join();
}
 
源代码30 项目: zipkin-aws   文件: AWSSignatureVersion4Test.java
@Test public void signsRequestsForRegionAndEsService() {
  MOCK_RESPONSE.set(AggregatedHttpResponse.of(HttpStatus.OK));

  client.get("/_template/zipkin_template").aggregate().join();

  AggregatedHttpRequest request = CAPTURED_REQUEST.get();
  assertThat(request.headers().get(HttpHeaderNames.AUTHORIZATION))
      .startsWith("AWS4-HMAC-SHA256 Credential=" + credentials.get().accessKey)
      .contains(region + "/es/aws4_request"); // for the region and service
}