Example usage for org.openqa.selenium Cookie getName

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

Introduction

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

Prototype

public String getName() 

Source Link

Usage

From source file:io.vertigo.ui.FileDownloader4Tests.java

License:Apache License

/**
 * Load in all the cookies WebDriver currently knows about so that we can mimic the browser cookie state
 *
 * @param seleniumCookieSet/*from  w  w  w  . j a v  a  2  s  . c o  m*/
 * @return BasicCookieStore
 */
private static BasicCookieStore mimicCookieState(final Set<Cookie> seleniumCookieSet) {
    final BasicCookieStore mimicWebDriverCookieStore = new BasicCookieStore();
    for (final Cookie seleniumCookie : seleniumCookieSet) {
        final BasicClientCookie duplicateCookie = new BasicClientCookie(seleniumCookie.getName(),
                seleniumCookie.getValue());
        duplicateCookie.setDomain(seleniumCookie.getDomain());
        duplicateCookie.setSecure(seleniumCookie.isSecure());
        duplicateCookie.setExpiryDate(seleniumCookie.getExpiry());
        duplicateCookie.setPath(seleniumCookie.getPath());
        mimicWebDriverCookieStore.addCookie(duplicateCookie);
    }

    return mimicWebDriverCookieStore;
}

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();//from w  w w  . j av  a 2s.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.steps.WebApplicationSteps.java

License:Open Source License

private Cookie findCookieByName(List<Cookie> cookies, String name) {
    if (cookies.size() == 0)
        return null;
    for (Cookie cookie : cookies) {
        if (cookie == null)
            return null;
        if (cookie.getName().equalsIgnoreCase(name))
            return cookie;
    }/*from w  ww  . ja  v  a 2 s. c  o m*/
    return null;
}

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();/*from  www.  j  a  v a  2s .c o m*/
    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;/*  w w  w .  j a  va  2s.com*/

    // 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   ww w. j a  v a  2  s  .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.client.SeleniumBrowserDriver.java

License:Apache License

public void setCookie(Cookie cookie) {
    getDriver().manage().deleteCookieNamed(cookie.getName());
    getDriver().manage().addCookie(cookie);
}

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);
    }/*www  .  j  av  a 2 s  .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 w w . ja v a2  s  . c  o m
    return mimicWebDriverCookieState;
}