browsermob-proxy icon indicating copy to clipboard operation
browsermob-proxy copied to clipboard

Can't play video due IP region doesn't matched up with the country code using BrowserMob Proxy Selenium

Open janetesantos opened this issue 5 years ago • 0 comments

Hi,

i'm trying to create automation tests for the following scenario:

Given i am in "<country>"
Given I navigate to the 'Home' page as a logged in user
When I click on the play button of a video under 'Home' page
Then the video starts playing

Examples:
  | country     |
  | Brazil      |
  | New Zealand |
  | Italy       |

To connect to another country i'm creating a proxy and then i change the X-CountryCode to the country code that i want. The problem is when i try to play the video, the video never plays because i receive 403 forbidden for the request. It seems the server have some kind of protection to detect whether your IP region matched up with the country code i provide or something. My local network ip is from Portugal but i'm passing the X-country code to Brazil.

Could someone help me how to figured out how can i manipulate the ip address to the same country of X-country header?

Below it's the code that i use to create the proxy and change the header:

public class ProxyVPN extends BrowserMobProxyServer {
 
    private static ProxyVPN proxyVPN;

    private String countryCode;
    private ArrayList<String> codes = new ArrayList<>();


    private ProxyVPN() {
        this.addRequestFilter((request, contents, messageInfo) -> {

            getLogger().info("SETUP REQUEST [Country: " + countryCode + "]");

            if (countryCode != null) {
                request.headers().set("X-CountryCode", countryCode);
            } else {
                request.headers().remove("X-CountryCode");
            }

            getLogger().info("[REQUEST][" + request.getMethod() +
                    "][" + request.getUri() +
                    "][" + request.headers().entries() +
                    "]" + addResponseFilter(););
            return null;
        });
    }

    public static ProxyVPN getInstance() {
        if (proxyVPN == null) {
            proxyVPN = new ProxyVPN();
        }
        return proxyVPN;
    }

    BrowserMobProxy getProxyServer() {
        getLogger().info("START PROXY");
        this.setTrustAllServers(true);
        getInstance().start(8080);
        return proxyVPN;
    }

    Proxy getSeleniumProxy() {
        return ClientUtil.createSeleniumProxy(proxyVPN);

    }


    public void stopProxy() {
        this.stop();
    }


    public void overwriteCountryCodeHeader(String country) {
        switch (country.toLowerCase()) {
            case "brazil":
                countryCode = "BR";
                break;
       }
    }
}
private void useChrome(boolean isProxy) throws MalformedURLException {
  
            WebDriverManager.chromedriver().setup();
                ChromeOptions options = new ChromeOptions();
                getLogger().info("BrowserMob Proxy running on port: " + ProxyVPN.getInstance().getProxyServer().getPort());
                options.setAcceptInsecureCerts(true);
                options.setCapability(CapabilityType.PROXY, ProxyVPN.getInstance().getSeleniumProxy());
                driver = new ChromeDriver(options);
            

janetesantos avatar Feb 11 '20 11:02 janetesantos