Example usage for org.apache.http.cookie SetCookie getPorts

List of usage examples for org.apache.http.cookie SetCookie getPorts

Introduction

In this page you can find the example usage for org.apache.http.cookie SetCookie getPorts.

Prototype

int[] getPorts();

Source Link

Document

Get the Port attribute.

Usage

From source file:org.sonatype.nexus.testsuite.security.SimpleSessionCookieIT.java

/**
 * Validate standard session cookie properties
 */// w  w w  .j a v a 2 s .c  o m
private void assertCommonSessionCookieAttributes(final URL baseUrl, final SetCookie serverCookie,
        final String headerText) {
    assertThat(serverCookie, notNullValue());
    assertThat("cookie value must be present", serverCookie.getValue(), notNullValue());
    assertThat("cookie name mismatch", serverCookie.getName(), equalTo(DEFAULT_SESSION_COOKIE_NAME));
    assertThat("not expecting to get ports since they are generally ignored", serverCookie.getPorts(),
            nullValue());
    assertThat(
            "session cookie does not currently set the domain leaving it to the Browser to do the right thing",
            headerText, not(containsString("; Domain=")));
    assertThat("browser should interpret domain as same as origin", serverCookie.getDomain(),
            equalTo(baseUrl.getHost()));
    assertThat("cookie path should match Nexus context path", serverCookie.getPath(),
            equalTo(cookiePath(baseUrl)));
    if (baseUrl.getProtocol().equalsIgnoreCase("https")) {
        assertThat("session cookie should be marked Secure when cookies are served by https URLs", headerText,
                containsString("; Secure"));
    } else {
        assertThat("session cookie should not be marked Secure when cookies are served by http URLs",
                headerText, not(containsString("; Secure")));
    }
}