Skip to content

Commit

Permalink
allow all resources in whitelist (#514)
Browse files Browse the repository at this point in the history
  • Loading branch information
jesg authored Mar 22, 2017
1 parent 7cf96db commit be7ffd9
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,12 @@ ghostdriver.Session = function(desiredCapabilities) {
}
if (k.indexOf(_capsPageBlacklistPref) === 0) {
const pageBlacklist = [];
const len = desiredCapabilities[k].length;
for(var i = 0; i < len; i++) {
const pageBlacklistLength = desiredCapabilities[k].length;
for(var i = 0; i < pageBlacklistLength; i++) {
pageBlacklist.push(new RegExp(desiredCapabilities[k][i]));
}
_pageBlacklistFilter = function(url, net) {
for(var i = 0; i < len; i++) {
for(var i = 0; i < pageBlacklistLength; i++) {
if(url.search(pageBlacklist[i]) !== -1) {
net.abort();
_log.debug("blacklist abort " + url);
Expand All @@ -201,17 +201,18 @@ ghostdriver.Session = function(desiredCapabilities) {
}
if (k.indexOf(_capsPageWhitelistPref) === 0) {
const pageWhitelist = [];
const len2 = desiredCapabilities[k].length;
for(var i = 0; i < len; i++) {
const pageWhitelistLength = desiredCapabilities[k].length;
for(var i = 0; i < pageWhitelistLength; i++) {
pageWhitelist.push(new RegExp(desiredCapabilities[k][i]));
}
_pageWhitelistFilter = function(url, net) {
for(var i = 0; i < len2; i++) {
if(url.search(pageWhitelist[i]) === -1) {
net.abort();
_log.debug("whitelist abort " + url);
for(var i = 0; i < pageWhitelistLength; i++) {
if(url.search(pageWhitelist[i]) !== -1) {
return;
}
}
net.abort();
_log.debug("whitelist abort " + url);
}
}
if (k.indexOf(_capsPageSettingsProxyPref) === 0) {
Expand Down
57 changes: 57 additions & 0 deletions test/java/src/test/java/BlacklistWhitelistTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
This file is part of the GhostDriver by Ivan De Marino <http://ivandemarino.me>.
Copyright (c) 2017, Jason Gowan
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package ghostdriver;

import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.WebDriver;

import java.util.Arrays;

public class BlacklistWhitelistTest extends BaseTest {
@BeforeClass
public static void setBlacklistWhitelistCapabilities() {
sCaps.setCapability(
"phantomjs.page.blacklist",
Arrays.asList("png$")
);
sCaps.setCapability(
"phantomjs.page.whitelist",
Arrays.asList("^https:..github.com", "^https:..assets-cdn.github.com")
);
}

@Test
public void testBlacklistWhitelistCapabilities() {
WebDriver d = getDriver();

d.get("https://github.com");
// need some way to verify
}

}

0 comments on commit be7ffd9

Please sign in to comment.