use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class CookieManagerTest method cookieExpires_badDateFormat.
/**
* Test some formating errors.
* @throws Exception if the test fails
*/
@Test
@Alerts("fifth=5; first=1; fourth=4; second=2; sixth=6; third=3")
public void cookieExpires_badDateFormat() throws Exception {
final List<NameValuePair> responseHeader1 = new ArrayList<>();
responseHeader1.add(new NameValuePair("Set-Cookie", "first=1;expires=Thu 01-Dec-42 16:00:00 GMT"));
responseHeader1.add(new NameValuePair("Set-Cookie", "second=2;expires=Thu 01 Dec 42 16:00:00 GMT"));
responseHeader1.add(new NameValuePair("Set-Cookie", "third=3;expires=Thu, 01-Dec-42 16:00:00 GMT"));
responseHeader1.add(new NameValuePair("Set-Cookie", "fourth=4;expires=Thu, 01 Dec 42 16:00:00 GMT"));
responseHeader1.add(new NameValuePair("Set-Cookie", "fifth=5;expires=Thu,01-Dec-42 16:00:00 GMT"));
responseHeader1.add(new NameValuePair("Set-Cookie", "sixth=6;expires=Thu,01 Dec 42 16:00:00 GMT"));
getMockWebConnection().setResponse(URL_FIRST, HTML_ALERT_COOKIE, 200, "OK", MimeType.TEXT_HTML, responseHeader1);
loadPageWithAlerts2(URL_FIRST);
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class CookieManagerTest method setCookieSubPath.
/**
* Response to / sets cookie to /foo/blah.
* @throws Exception if the test fails
*/
@Test
@Alerts(DEFAULT = "first=1; second=2", IE = "first=1")
public void setCookieSubPath() throws Exception {
final List<NameValuePair> responseHeader1 = new ArrayList<>();
responseHeader1.add(new NameValuePair("Set-Cookie", "first=1;path=/foo/blah"));
responseHeader1.add(new NameValuePair("Set-Cookie", "second=2;path=/foo/blah/test"));
responseHeader1.add(new NameValuePair("Location", "/foo/blah/test"));
getMockWebConnection().setDefaultResponse(HTML_ALERT_COOKIE);
getMockWebConnection().setResponse(URL_FIRST, "", 302, "Moved", MimeType.TEXT_HTML, responseHeader1);
loadPageWithAlerts2(URL_FIRST);
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class CookieManagerTest method trailing_slash.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts({ "", "dog=dalmation" })
public void trailing_slash() throws Exception {
final String[] expectedAlerts = getExpectedAlerts();
final WebDriver driver = getWebDriver();
setExpectedAlerts(expectedAlerts[0]);
loadPageWithAlerts2(HTML_ALERT_COOKIE, URL_SECOND);
setExpectedAlerts(expectedAlerts[1]);
driver.manage().addCookie(new org.openqa.selenium.Cookie("dog", "dalmation", "/second/"));
loadPageWithAlerts2(HTML_ALERT_COOKIE, URL_SECOND);
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class DefaultCredentialsProvider2Test method basicAuthenticationUserFromUrlOverwrite.
/**
* @throws Exception if an error occurs
*/
@Test
@Alerts("SecRet")
public void basicAuthenticationUserFromUrlOverwrite() throws Exception {
final String html = "<html><body onload='alert(\"SecRet\")'></body></html>";
getMockWebConnection().setDefaultResponse(html);
getWebClient().getCredentialsProvider().clear();
try {
// no credentials
loadPage(html, URL_FIRST);
fail("Should not be authorized");
} catch (final FailingHttpStatusCodeException e) {
// success
}
final boolean urlWithCredentials = !getBrowserVersion().isIE();
try {
// now a url with credentials
final URL url = new URL("http://jetty:jetty@localhost:" + PORT + "/");
loadPageWithAlerts(url);
if (!urlWithCredentials) {
fail("Should not be authorized");
}
} catch (final FailingHttpStatusCodeException e) {
if (urlWithCredentials) {
throw e;
}
}
try {
// next step without credentials but the credentials are still known
loadPageWithAlerts(URL_FIRST);
if (!urlWithCredentials) {
fail("Should not be authorized");
}
} catch (final FailingHttpStatusCodeException e) {
if (urlWithCredentials) {
throw e;
}
}
try {
final URL url = new URL("http://jetty:wrong@localhost:" + PORT + "/");
loadPage(html, url);
fail("Should not be authorized");
} catch (final FailingHttpStatusCodeException e) {
// success
}
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class DefaultCredentialsProvider2Test method basicAuthenticationUserFromUrlOverwriteWrongDefaultCredentials.
/**
* @throws Exception if an error occurs
*/
@Test
@Alerts("SecRet")
public void basicAuthenticationUserFromUrlOverwriteWrongDefaultCredentials() throws Exception {
final String html = "<html><body onload='alert(\"SecRet\")'></body></html>";
getMockWebConnection().setDefaultResponse(html);
getWebClient().getCredentialsProvider().clear();
((DefaultCredentialsProvider) getWebClient().getCredentialsProvider()).addCredentials("joe", "hack");
// use default wrong credentials
try {
loadPage(html, URL_FIRST);
fail("Should not be authorized");
} catch (final FailingHttpStatusCodeException e) {
// success
}
final boolean urlWithCredentials = !getBrowserVersion().isIE();
try {
// now a url with correct credentials
final URL url = new URL("http://jetty:jetty@localhost:" + PORT + "/");
loadPageWithAlerts(url);
if (!urlWithCredentials) {
fail("Should not be authorized");
}
} catch (final FailingHttpStatusCodeException e) {
if (urlWithCredentials) {
throw e;
}
}
}
Aggregations