Example usage for org.openqa.selenium Cookie getValue

List of usage examples for org.openqa.selenium Cookie getValue

Introduction

In this page you can find the example usage for org.openqa.selenium Cookie getValue.

Prototype

public String getValue() 

Source Link

Usage

From source file:net.continuumsecurity.steps.WebApplicationSteps.java

License:Open Source License

@Then("the value of the session cookie issued after authentication should be different from that of the previously noted session ID")
public void compareSessionIds() {
    for (String name : Config.getInstance().getSessionIDs()) {
        Cookie initialSessionCookie = findCookieByName(sessionIds, name);
        if (initialSessionCookie != null) {
            String existingCookieValue = findCookieByName(sessionIds, name).getValue();
            assertThat(app.getCookieByName(name).getValue(), not(initialSessionCookie.getValue()));
        } else if (app.getCookieByName(name).getValue() == null) {
            throw new RuntimeException("No session IDs found after login with name: " + name);
        }/*from  www.  j  a  v  a 2 s.co m*/
    }
}

From source file:net.continuumsecurity.steps.WebApplicationSteps.java

License:Open Source License

@Then("the string: <sensitiveData> should not be present in any of the HTTP responses")
public void checkNoAccessToResource(@Named("sensitiveData") String sensitiveData) {
    if (methodProxyMap == null || methodProxyMap.get(methodName).size() == 0)
        throw new ConfigurationException("No HTTP messages were recorded for the method: " + methodName);
    boolean accessible = false;
    findAndSetSessionIds();/*  w  w w.  j a  v  a  2  s  . co m*/
    for (HarEntry entry : methodProxyMap.get(methodName)) {
        if (entry.getResponse().getBodySize() > 0) {
            Map<String, String> cookieMap = new HashMap<String, String>();
            for (Cookie cookie : sessionIds) {
                cookieMap.put(cookie.getName(), cookie.getValue());
            }
            HarRequest manual = null;
            try {
                manual = Utils.replaceCookies(entry.getRequest(), cookieMap);
            } catch (Exception e) {
                e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
                throw new RuntimeException("Could not copy Har request");
            }
            getProxy().clear();
            List<HarEntry> results = getProxy().makeRequest(manual, true);
            results = getProxy().findInResponseHistory(sensitiveData);
            accessible = results != null && results.size() > 0;
            if (accessible)
                break;
        }
    }
    if (!accessible) {
        log.debug("User: " + credentials.getUsername() + " has no access to resource: " + methodName);
    }
    assertThat(accessible, equalTo(false));
}

From source file:net.continuumsecurity.web.steps.WebApplicationSteps.java

License:Open Source License

@Then("the session cookies after authentication should be different from those issued before")
public void compareSessionIds() {
    Config.instance();/*from  ww  w . ja va  2s  .  com*/
    for (String name : Config.getSessionIDs()) {
        Cookie initialSessionCookie = findCookieByName(sessionIds, name);
        if (initialSessionCookie != null) {
            String existingCookieValue = findCookieByName(sessionIds, name).getValue();
            assertThat(app.getCookieByName(name).getValue(), not(initialSessionCookie.getValue()));
        } else if (app.getCookieByName(name).getValue() == null) {
            throw new RuntimeException("No session IDs found after login with name: " + name);
        }
    }
}

From source file:net.continuumsecurity.web.steps.WebApplicationSteps.java

License:Open Source License

@Then("they should not see the word <verifyString> when accessing the restricted resource <method>")
public void checkNoAccessToResource(@Named("verifyString") String verifyString,
        @Named("method") String method) {
    if (methodProxyMap == null || methodProxyMap.get(method).size() == 0)
        throw new ConfigurationException("No HTTP messages were recorded for the method: " + method);
    Pattern pattern = Pattern.compile(verifyString);
    boolean accessible = false;
    getSessionIds();//ww w.j  a  va  2  s.c om
    for (HttpMessage message : methodProxyMap.get(method)) {
        if (!"".equals(message.getResponseBody())) {
            log.debug("Original request:\n" + message.getRequestAsString());
            log.debug("Original response:\n" + message.getResponseAsString());
            Map<String, String> cookieMap = new HashMap<String, String>();
            for (Cookie cookie : sessionIds) {
                cookieMap.put(cookie.getName(), cookie.getValue());
            }
            HttpMessage manual = new HttpMessage(message);
            manual.replaceCookies(cookieMap);
            log.debug("Replaced request: " + manual.getRequestAsString());
            manual = burp.makeRequest(manual);
            log.debug("Response: " + manual.getResponseAsString());

            if (pattern.matcher(manual.getResponseAsString()).find()) {
                log.debug("Found regex: " + verifyString);
                accessible = true;
                break;
            } else {
                log.debug("Did not find regex: " + verifyString);
            }
        }
    }
    Assert.assertThat("Resource: " + method + " can be accessed.", accessible, equalTo(false));
}

From source file:net.continuumsecurity.web.TeamMentorWSTest.java

License:Open Source License

public Cookie getCookieByName(String name) {
    Client client = ClientProxy.getClient(port);
    client.getEndpoint().getOutInterceptors().add(new SoapActionInterceptor());
    HTTPConduit http = (HTTPConduit) client.getConduit();
    if (http.getCookies() == null || http.getCookies().size() == 0)
        return null;
    org.apache.cxf.transport.http.Cookie cookie = http.getCookies().get(name);
    Cookie returnCookie = new Cookie(cookie.getName(), cookie.getValue(), cookie.getPath());
    return returnCookie;
}

From source file:net.sourceforge.jwebunit.webdriver.WebDriverTestingEngineImpl.java

License:Open Source License

public void beginAt(URL aInitialURL, TestContext aTestContext) throws TestingEngineResponseException {
    this.setTestContext(aTestContext);
    // start the proxy
    Proxy proxy = startBrowserMobProxy();

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.PROXY, proxy);
    capabilities.setCapability(CapabilityType.SUPPORTS_JAVASCRIPT, jsEnabled);
    capabilities.setBrowserName("htmlunit");
    capabilities.setVersion("firefox");

    driver = new HtmlUnitDriver(capabilities);

    // Reset form
    formIdent = null;/*from   w ww.jav a  2  s . co  m*/

    // Deal with cookies
    for (javax.servlet.http.Cookie c : aTestContext.getCookies()) {
        // FIXME Hack for BrowserMob
        String domain = c.getDomain();
        if ("localhost".equals(domain)) {
            domain = null;
        }
        if ("".equals(domain)) {
            domain = null;
        }
        Date expiry = null;
        if (c.getMaxAge() != -1) {
            Calendar cal = Calendar.getInstance();
            cal.add(Calendar.SECOND, c.getMaxAge());
            expiry = cal.getTime();
        }
        driver.manage().addCookie(new org.openqa.selenium.Cookie(c.getName(), c.getValue(), domain,
                c.getPath() != null ? c.getPath() : "", expiry, c.getSecure()));
    }
    gotoPage(aInitialURL);
}

From source file:net.sourceforge.jwebunit.webdriver.WebDriverTestingEngineImpl.java

License:Open Source License

public List<javax.servlet.http.Cookie> getCookies() {
    List<javax.servlet.http.Cookie> result = new LinkedList<javax.servlet.http.Cookie>();
    Set<Cookie> cookies = driver.manage().getCookies();
    for (Cookie cookie : cookies) {
        javax.servlet.http.Cookie c = new javax.servlet.http.Cookie(cookie.getName(), cookie.getValue());
        c.setDomain(cookie.getDomain());
        Date expire = cookie.getExpiry();
        if (expire == null) {
            c.setMaxAge(-1);/*from   www .  ja v  a 2s  . c o m*/
        } else {
            Date now = Calendar.getInstance().getTime();
            // Convert milli-second to second
            Long second = Long.valueOf((expire.getTime() - now.getTime()) / 1000);
            c.setMaxAge(second.intValue());
        }
        c.setPath(cookie.getPath());
        c.setSecure(cookie.isSecure());
        result.add(c);
    }
    return result;
}

From source file:nz.co.testamation.core.reader.pdf.BrowserCookieHttpContextProvider.java

License:Apache License

@Override
public HttpContext get() {
    BasicHttpContext localContext = new BasicHttpContext();
    Set<Cookie> cookies = browserDriver.getAllCookies();
    BasicCookieStore cookieStore = new BasicCookieStore();

    for (Cookie cookie : cookies) {
        BasicClientCookie clientCookie = new BasicClientCookie(cookie.getName(), cookie.getValue());
        clientCookie.setDomain(cookie.getDomain());
        clientCookie.setPath(cookie.getPath());
        clientCookie.setExpiryDate(cookie.getExpiry());
        cookieStore.addCookie(clientCookie);
    }/*  w  w w  .  j av  a2s .  c o m*/
    localContext.setAttribute(HttpClientContext.COOKIE_STORE, cookieStore);
    return localContext;
}

From source file:org.ado.picasa.FileDownloader.java

License:Apache License

private HttpState mimicCookieState(Set<org.openqa.selenium.Cookie> seleniumCookieSet) {
    HttpState mimicWebDriverCookieState = new HttpState();
    for (org.openqa.selenium.Cookie seleniumCookie : seleniumCookieSet) {
        Cookie httpClientCookie = new Cookie(seleniumCookie.getDomain(), seleniumCookie.getName(),
                seleniumCookie.getValue(), seleniumCookie.getPath(), seleniumCookie.getExpiry(),
                seleniumCookie.isSecure());
        mimicWebDriverCookieState.addCookie(httpClientCookie);
    }/*from w  ww  .  ja va 2 s  .  c  om*/
    return mimicWebDriverCookieState;
}

From source file:org.alfresco.po.Page.java

License:Open Source License

/**
 * Gets the browser session id from a cookie.
 * /*from  w w w.j a v a  2  s.com*/
 * @return String JSESSIONID and value
 */
public String getSessionId() {
    Cookie cookie = getCookie("JSESSIONID");
    if (cookie != null) {
        return String.format("%s = %s%n", cookie.getName(), cookie.getValue());
    }
    return "";
}