Skip to content
This repository has been archived by the owner on Jul 19, 2019. It is now read-only.

Commit

Permalink
SimonStewart: Starting to ensure that it's possible to access sites w…
Browse files Browse the repository at this point in the history
…ith an invalid SSL certificate
  • Loading branch information
simon.m.stewart committed Oct 6, 2008
1 parent 0033e94 commit d81b048
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 37 deletions.
Binary file added common/test/java/keystore
Binary file not shown.
36 changes: 16 additions & 20 deletions common/test/java/org/openqa/selenium/AbstractDriverTestCase.java
Expand Up @@ -7,15 +7,12 @@

import org.openqa.selenium.environment.GlobalTestEnvironment;
import org.openqa.selenium.environment.TestEnvironment;
import org.openqa.selenium.environment.webserver.AppServer;

import junit.framework.TestCase;

public class AbstractDriverTestCase extends TestCase implements NeedsDriver {
protected WebDriver driver;
protected String hostName;
protected String alternateHostName;
protected String baseUrl;
protected String alternateBaseUrl;
protected String simpleTestPage;
protected String xhtmlTestPage;
protected String formPage;
Expand All @@ -39,23 +36,22 @@ protected void setUp() throws Exception {
driver.setVisible(true);

TestEnvironment environment = GlobalTestEnvironment.get();

AppServer appServer = environment.getAppServer();
simpleTestPage = appServer.whereIs("simpleTest.html");
xhtmlTestPage = appServer.whereIs("xhtmlTest.html");
formPage = appServer.whereIs("formPage.html");
metaRedirectPage = appServer.whereIs("meta-redirect.html");
redirectPage = appServer.whereIs("redirect");
javascriptPage = appServer.whereIs("javascriptPage.html");
framesetPage = appServer.whereIs("frameset.html");
iframePage = appServer.whereIs("iframes.html");
dragAndDropPage = appServer.whereIs("dragAndDropTest.html");
chinesePage = appServer.whereIs("cn-test.html");
nestedPage = appServer.whereIs("nestedElements.html");

baseUrl = environment.getAppServer().getBaseUrl();
simpleTestPage = baseUrl + "simpleTest.html";
xhtmlTestPage = baseUrl + "xhtmlTest.html";
formPage = baseUrl + "formPage.html";
metaRedirectPage = baseUrl + "meta-redirect.html";
redirectPage = baseUrl + "redirect";
javascriptPage = baseUrl + "javascriptPage.html";
framesetPage = baseUrl + "frameset.html";
iframePage = baseUrl + "iframes.html";
dragAndDropPage = baseUrl + "dragAndDropTest.html";
chinesePage = baseUrl + "cn-test.html";
nestedPage = baseUrl + "nestedElements.html";

hostName = environment.getAppServer().getHostName();
alternateHostName = environment.getAppServer().getAlternateHostName();
alternateBaseUrl = environment.getAppServer().getAlternateBaseUrl();
String hostName = environment.getAppServer().getHostName();
String alternateHostName = environment.getAppServer().getAlternateHostName();

assertThat(hostName, is(not(equalTo(alternateHostName))));
}
Expand Down
2 changes: 1 addition & 1 deletion common/test/java/org/openqa/selenium/AlertsTest.java
Expand Up @@ -11,7 +11,7 @@ protected void setUp() throws Exception {
super.setUp();

TestEnvironment environment = GlobalTestEnvironment.get();
alertPage = environment.getAppServer().getBaseUrl() + "alerts.html";
alertPage = environment.getAppServer().whereIs("alerts.html");
}

@JavascriptEnabled
Expand Down
14 changes: 10 additions & 4 deletions common/test/java/org/openqa/selenium/CookieImplementationTest.java
Expand Up @@ -6,6 +6,8 @@
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.core.IsNot.not;
import org.openqa.selenium.environment.GlobalTestEnvironment;
import org.openqa.selenium.environment.webserver.AppServer;

import java.util.Calendar;
import java.util.Iterator;
Expand All @@ -22,13 +24,14 @@ public void testAddCookiesWithDifferentPaths() {
options.addCookie(cookie1);
options.addCookie(cookie2);

driver.get(baseUrl + "animals");
AppServer appServer = GlobalTestEnvironment.get().getAppServer();
driver.get(appServer.whereIs("animals"));
Set<Cookie> cookies = options.getCookies();

assertThat(cookies.contains(cookie1), is(true));
assertThat(cookies.contains(cookie2), is(false));

driver.get(baseUrl + "galaxy");
driver.get(appServer.whereIs("galaxy"));
cookies = options.getCookies();
assertThat(cookies.contains(cookie1), is(false));
assertThat(cookies.contains(cookie2), is(true));
Expand All @@ -54,7 +57,9 @@ public void testGetAllCookies() {

@Ignore("ie")
public void testCookieIntegrity() {
driver.get(alternateBaseUrl + "animals");
String url = GlobalTestEnvironment.get().getAppServer().whereElseIs("animals");

driver.get(url);
driver.manage().deleteAllCookies();

Calendar c = Calendar.getInstance();
Expand Down Expand Up @@ -170,7 +175,8 @@ public void testGetCookieDoesNotRetriveBeyondCurrentDomain() {
WebDriver.Options options = driver.manage();
options.addCookie(cookie1);

driver.get(alternateBaseUrl);
String url = GlobalTestEnvironment.get().getAppServer().whereElseIs("");
driver.get(url);
Set<Cookie> cookies = options.getCookies();
assertThat(cookies, not(hasItem(cookie1)));
}
Expand Down
10 changes: 10 additions & 0 deletions common/test/java/org/openqa/selenium/PageLoadingTest.java
Expand Up @@ -2,6 +2,7 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import org.openqa.selenium.environment.GlobalTestEnvironment;

public class PageLoadingTest extends AbstractDriverTestCase {
public void testShouldWaitForDocumentToBeLoaded() {
Expand Down Expand Up @@ -82,4 +83,13 @@ public void testShouldBeAbleToNavigateForwardsInTheBrowserHistory() {
driver.navigate().forward();
assertThat(driver.getTitle(), equalTo("We Arrive Here"));
}

@Ignore("safari, ie, firefox")
public void testShouldBeAbleToAccessPagesWithAnInsecureSslCertificate() {
String url = GlobalTestEnvironment.get().getAppServer().whereIsSecure("simpleTest.html");
driver.get(url);

// This should work
assertThat(driver.getTitle(), equalTo("Hello WebDriver"));
}
}
2 changes: 1 addition & 1 deletion common/test/java/org/openqa/selenium/TextHandlingTest.java
Expand Up @@ -172,7 +172,7 @@ public void testShouldHandleWhitespaceInInlineElements() {

@Ignore("ie, safari")
public void testReadALargeAmountOfData() {
driver.get(GlobalTestEnvironment.get().getAppServer().getBaseUrl() + "macbeth.html");
driver.get(GlobalTestEnvironment.get().getAppServer().whereIs("macbeth.html"));
String source = driver.getPageSource().trim();

assertThat(source.endsWith("</html>"), is(true));
Expand Down
4 changes: 3 additions & 1 deletion common/test/java/org/openqa/selenium/TextPagesTest.java
Expand Up @@ -2,14 +2,16 @@

package org.openqa.selenium;

import org.openqa.selenium.environment.GlobalTestEnvironment;

public class TextPagesTest extends AbstractDriverTestCase {
private String textPage;

@Override
protected void setUp() throws Exception {
super.setUp();

textPage = baseUrl + "plain.txt";
textPage = GlobalTestEnvironment.get().getAppServer().whereIs("plain.txt");
}

@Ignore("firefox, ie, safari")
Expand Down
Expand Up @@ -37,7 +37,6 @@ public void stop() {
}

public static void main(String[] args) {
InProcessTestEnvironment environment = new InProcessTestEnvironment();
System.out.println("Application server started. " + environment.getAppServer().getBaseUrl());
new InProcessTestEnvironment();
}
}
Expand Up @@ -23,8 +23,9 @@ public interface AppServer {
String getHostName();
String getAlternateHostName();

String getBaseUrl();
String getAlternateBaseUrl();
String whereIs(String relativeUrl);
String whereElseIs(String relativeUrl);
String whereIsSecure(String relativeUrl);

void start();
void stop();
Expand Down
Expand Up @@ -21,6 +21,7 @@

import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.security.SslSocketConnector;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.webapp.WebAppContext;

Expand All @@ -32,12 +33,12 @@

public class Jetty6AppServer implements AppServer {
private int port;
private int securePort;
private File path;
private final Server server = new Server();
private WebAppContext context;


public Jetty6AppServer() {
public Jetty6AppServer() {
path = findRootOfWebApp();

context = addWebApplication("", path.getAbsolutePath());
Expand All @@ -46,6 +47,7 @@ public Jetty6AppServer() {
addServlet("InfinitePagerServer", "/page/*", PageServlet.class);

listenOn(3000);
listenSecurelyOn(3443);
}


Expand Down Expand Up @@ -80,19 +82,36 @@ public String getAlternateHostName() {
}
}

public String getBaseUrl() {
return "http://" + getHostName() + ":" + port + "/";
public String whereIs(String relativeUrl) {
return "http://" + getHostName() + ":" + port + "/" + relativeUrl;
}

public String whereElseIs(String relativeUrl) {
return "http://" + getAlternateHostName() + ":" + port + "/" + relativeUrl;
}

public String getAlternateBaseUrl() {
return "http://" + getAlternateHostName() + ":" + port + "/";
public String whereIsSecure(String relativeUrl) {
return "https://" + getHostName() + ":" + securePort + "/" + relativeUrl;
}

public void start() {
SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(port);
server.addConnector(connector);

File keyStore = new File(findRootOfWebApp(), "../../test/java/keystore");
if (!keyStore.exists())
throw new RuntimeException("Cannot find keystore for SSL cert");

SslSocketConnector secureSocket = new SslSocketConnector();
secureSocket.setPort(securePort);
secureSocket.setKeystore(keyStore.getAbsolutePath());
secureSocket.setPassword("password");
secureSocket.setKeyPassword("password");
secureSocket.setTruststore(keyStore.getAbsolutePath());
secureSocket.setTrustPassword("password");
server.addConnector(secureSocket);

try {
server.start();
} catch (Exception e) {
Expand All @@ -104,6 +123,10 @@ public void listenOn(int port) {
this.port = port;
}

public void listenSecurelyOn(int port) {
this.securePort = port;
}


protected void addListener(Connector listener) {
server.addConnector(listener);
Expand Down

0 comments on commit d81b048

Please sign in to comment.