use of cn.taketoday.http.client.ClientHttpResponse in project today-infrastructure by TAKETODAY.
the class AbstractServletWebServerFactoryTests method sessionCookieSameSiteAttributeCanBeConfiguredAndOnlyAffectsSessionCookies.
@ParameterizedTest
@EnumSource(SameSite.class)
void sessionCookieSameSiteAttributeCanBeConfiguredAndOnlyAffectsSessionCookies(SameSite sameSite) throws Exception {
AbstractServletWebServerFactory factory = getFactory();
factory.getSession().getCookie().setSameSite(sameSite);
factory.addInitializers(new ServletRegistrationBean<>(new CookieServlet(false), "/"));
this.webServer = factory.getWebServer();
this.webServer.start();
ClientHttpResponse clientResponse = getClientResponse(getLocalUrl("/"));
List<String> setCookieHeaders = clientResponse.getHeaders().get("Set-Cookie");
assertThat(setCookieHeaders).satisfiesExactlyInAnyOrder((header) -> assertThat(header).contains("JSESSIONID").contains("SameSite=" + sameSite.attributeValue()), (header) -> assertThat(header).contains("test=test").doesNotContain("SameSite"));
}
use of cn.taketoday.http.client.ClientHttpResponse in project today-infrastructure by TAKETODAY.
the class AbstractServletWebServerFactoryTests method cookieSameSiteSuppliers.
@Test
void cookieSameSiteSuppliers() throws Exception {
AbstractServletWebServerFactory factory = getFactory();
factory.addCookieSameSiteSuppliers(CookieSameSiteSupplier.ofLax().whenHasName("relaxed"));
factory.addCookieSameSiteSuppliers(CookieSameSiteSupplier.ofNone().whenHasName("empty"));
factory.addCookieSameSiteSuppliers(CookieSameSiteSupplier.ofStrict().whenHasName("controlled"));
factory.addInitializers(new ServletRegistrationBean<>(new CookieServlet(true), "/"));
this.webServer = factory.getWebServer();
this.webServer.start();
ClientHttpResponse clientResponse = getClientResponse(getLocalUrl("/"));
List<String> setCookieHeaders = clientResponse.getHeaders().get("Set-Cookie");
assertThat(setCookieHeaders).satisfiesExactlyInAnyOrder((header) -> assertThat(header).contains("JSESSIONID").doesNotContain("SameSite"), (header) -> assertThat(header).contains("test=test").doesNotContain("SameSite"), (header) -> assertThat(header).contains("relaxed=test").contains("SameSite=Lax"), (header) -> assertThat(header).contains("empty=test").contains("SameSite=None"), (header) -> assertThat(header).contains("controlled=test").contains("SameSite=Strict"));
}
use of cn.taketoday.http.client.ClientHttpResponse in project today-infrastructure by TAKETODAY.
the class AbstractServletWebServerFactoryTests method serverHeaderCanBeCustomizedWhenUsingSsl.
@Test
void serverHeaderCanBeCustomizedWhenUsingSsl() throws Exception {
AbstractServletWebServerFactory factory = getFactory();
factory.setServerHeader("MyServer");
factory.setSsl(getSsl(null, "password", "src/test/resources/test.jks"));
this.webServer = factory.getWebServer(new ServletRegistrationBean<>(new ExampleServlet(true, false), "/hello"));
this.webServer.start();
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build());
HttpClient httpClient = this.httpClientBuilder.get().setSSLSocketFactory(socketFactory).setRetryHandler(new DefaultHttpRequestRetryHandler(10, false)).build();
ClientHttpResponse response = getClientResponse(getLocalUrl("https", "/hello"), HttpMethod.GET, new HttpComponentsClientHttpRequestFactory(httpClient));
assertThat(response.getHeaders().get("Server")).containsExactly("MyServer");
}
use of cn.taketoday.http.client.ClientHttpResponse in project today-framework by TAKETODAY.
the class AbstractServletWebServerFactoryTests method serverHeaderIsDisabledByDefaultWhenUsingSsl.
@Test
void serverHeaderIsDisabledByDefaultWhenUsingSsl() throws Exception {
AbstractServletWebServerFactory factory = getFactory();
factory.setSsl(getSsl(null, "password", "src/test/resources/test.jks"));
this.webServer = factory.getWebServer(new ServletRegistrationBean<>(new ExampleServlet(true, false), "/hello"));
this.webServer.start();
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build());
HttpClient httpClient = this.httpClientBuilder.get().setSSLSocketFactory(socketFactory).build();
ClientHttpResponse response = getClientResponse(getLocalUrl("https", "/hello"), HttpMethod.GET, new HttpComponentsClientHttpRequestFactory(httpClient));
assertThat(response.getHeaders().get("Server")).isNullOrEmpty();
}
use of cn.taketoday.http.client.ClientHttpResponse in project today-framework by TAKETODAY.
the class AbstractServletWebServerFactoryTests method sessionCookieSameSiteAttributeCanBeConfiguredAndOnlyAffectsSessionCookies.
@ParameterizedTest
@EnumSource(SameSite.class)
void sessionCookieSameSiteAttributeCanBeConfiguredAndOnlyAffectsSessionCookies(SameSite sameSite) throws Exception {
AbstractServletWebServerFactory factory = getFactory();
factory.getSession().getCookie().setSameSite(sameSite);
factory.addInitializers(new ServletRegistrationBean<>(new CookieServlet(false), "/"));
this.webServer = factory.getWebServer();
this.webServer.start();
ClientHttpResponse clientResponse = getClientResponse(getLocalUrl("/"));
List<String> setCookieHeaders = clientResponse.getHeaders().get("Set-Cookie");
assertThat(setCookieHeaders).satisfiesExactlyInAnyOrder((header) -> assertThat(header).contains("JSESSIONID").contains("SameSite=" + sameSite.attributeValue()), (header) -> assertThat(header).contains("test=test").doesNotContain("SameSite"));
}
Aggregations