Skip to content

Commit

Permalink
Merge pull request #322 from tmueller/1.1.0-fix-auth
Browse files Browse the repository at this point in the history
fix for HTTP Authentication
  • Loading branch information
detro committed Mar 11, 2014
2 parents c38a796 + c25cdd4 commit d1bf0eb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/session.js
Expand Up @@ -107,6 +107,7 @@ ghostdriver.Session = function(desiredCapabilities) {
_capsPageSettingsPref = "phantomjs.page.settings.",
_capsPageCustomHeadersPref = "phantomjs.page.customHeaders.",
_pageSettings = {},
_additionalAllowedPageSettings = { userName: 1, password: 1 },
_pageCustomHeaders = {},
_log = ghostdriver.logger.create("Session [" + _id + "]"),
k, settingKey, headerKey;
Expand Down Expand Up @@ -334,7 +335,7 @@ ghostdriver.Session = function(desiredCapabilities) {
// 6. Applying Page settings received via capabilities
for (k in _pageSettings) {
// Apply setting only if really supported by PhantomJS
if (page.settings.hasOwnProperty(k)) {
if (page.settings.hasOwnProperty(k) || _additionalAllowedPageSettings.hasOwnProperty(k)) {
page.settings[k] = _pageSettings[k];
}
}
Expand Down
37 changes: 37 additions & 0 deletions test/java/src/test/java/ghostdriver/AuthBasicTest.java
@@ -0,0 +1,37 @@
package ghostdriver;

import static org.junit.Assert.assertTrue;

import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;

public class AuthBasicTest extends BaseTest {

// credentials for testing, no one would ever use these
private final static String userName = "admin";
private final static String password = "admin";

@Override
public void prepareDriver() throws Exception {
sCaps.setCapability(PhantomJSDriverService.PHANTOMJS_PAGE_SETTINGS_PREFIX + "userName", userName);
sCaps.setCapability(PhantomJSDriverService.PHANTOMJS_PAGE_SETTINGS_PREFIX + "password", password);

super.prepareDriver();
}

@Test
public void simpleBasicAuthShouldWork() {
// Get Driver Instance
WebDriver driver = getDriver();

// wrong password
driver.get(String.format("http://httpbin.org/basic-auth/%s/Wrong%s", userName, password));
assertTrue(!driver.getPageSource().contains("authenticated"));

// we should be authorized
driver.get(String.format("http://httpbin.org/basic-auth/%s/%s", userName, password));
assertTrue(driver.getPageSource().contains("authenticated"));
}

}

0 comments on commit d1bf0eb

Please sign in to comment.