For a project I am working on I need to fake an IP address to appear that I am coming from another country.
Basically if the IP detected is from the UK, show popup A, if the IP detected is from outside the UK then show popup B.
I would like to be able to automate this. Currently all our browser automation tests are written in cucumber/watir and I would like to get a solution that uses the same framework.
Does anyone know of a possible way to do this?
Thanks!
Through an IP address alone, a company can determine not only in which country a user is located, but also the state, city, and postal code-globally. Using this information, businesses can serve up localized content and targeted ads, as well as help to prevent online fraud, amongst many other beneficial applications.
To test geolocation, you can use the Appium framework to automate geolocation testing and test app behavior from different countries with Appium's IP geolocation feature.
Generally speaking, if you care about the result of your HTTP request getting back to you, IP spoofing is not possible.
http://en.wikipedia.org/wiki/IP_address_spoofing
If this is for testing, you can run a Virtual Machine on your local network for each use case "in UK" and "not in UK". Assign a local IP address to each VM that will not change.
Run a HTTP proxy server in each VM and have your unit test connect through different proxy servers depending on the test case.
Add override logic to your geolocation code to consider these well-known, local IP addresses to be part of their respective test locations. Note that a well-behaved proxy server will include both the proxy server's IP address and the original IP address in the request. Be sure you use the proxy server's IP address for geolocation for this unit test (generally, you would want to use the original IP address where available for production geolocation).
Note that it is very easy for anyone who cares to circumvent this type of control. It is possible to gain access to an HTTP proxy server in the UK that intentionally does not forward the original IP address for a very small fee.
The easiest solution would be to add some magic request parameter which would allow you to switch between UK and others. For example, let's say something like this would enable "UK mode":
browser.goto "localhost/?country=UK"
Then, in server-side there should be some if-statement for checking that parameter. In pseudo-code:
if get_parameters["country"] == "UK"
enable_uk_mode
end
That would allow you to just specify that GET parameter
to switch ON "UK mode" or some other mode. I'm usually going this route, since installing and managing all VM-s and proxy servers and managing all their configuration is just taking much more time than the effort of adding some control logic to development mode of your application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With