Shruti Sagar Mishra
02/15/2023, 5:25 PMHashMap<ExecutionDataKeys, Object> executionStates = new HashMap<>();
WireMockServer wireMockServer = new WireMockServer(
new WireMockConfiguration().port(8080)
.notifier(new Slf4jNotifier(true))
);
wireMockServer.start();
ArrayList<String> hostNames = new ArrayList<>(
Arrays.asList(
"<https://host1.com>",
"<https://host2.com>",
));
hostNames.forEach(host->{
wireMockServer.stubFor(any(urlMatching(host+".*"))
.atPriority(10)
.willReturn(aResponse().proxiedFrom(host)));
});
I have also set proxy in emulator to localhost:8080. But it seems whitlisting is not working. all of my request are getting blocked.
P.S. I am trying to use appium along with wiremock to test state changes in application
[10:53 PM] I have already waster 3-4 days on this, and feeling kind exausted in this.
[10:53 PM] Please adviceRob Elliot
02/15/2023, 6:05 PMurlMatching(host+".*")
won't work - it only matches on pathList<String> hostNames = Arrays.asList(
"<https://example.com>",
"<https://host2.com>"
);
int i = 0;
for (String host : hostNames) {
WireMockServer wireMockServer = new WireMockServer(
new WireMockConfiguration().port(8080 + i)
.notifier(new Slf4jNotifier(true))
);
wireMockServer.start();
wireMockServer.stubFor(any(urlMatching(".*"))
.atPriority(10)
.willReturn(aResponse().proxiedFrom(host)));
i++;
}
WireMockServer wireMockServer = new WireMockServer(
wireMockConfig()
.enableBrowserProxying(true)
.port(8080)
.notifier(new Slf4jNotifier(true))
);
wireMockServer.start();
When you enableBrowserProxying(true)
you don't need to create the low priority any
stub at all, WireMock will proxy unless told otherwise.<http://localhost:8080>
as your proxy in your emulator.wireMockServer.stubFor(
get(urlPathEqualTo("/foo"))
.withHeader("Host", equalTo("<http://host2.com|host2.com>"))
.willReturn(aResponse().withBody("replacement for <https://host2.com/foo>"))
);
Shruti Sagar Mishra
02/15/2023, 7:03 PMhostNames.forEach(host->{
wireMockServer.stubFor(any(urlMatching(host+".*"))
.atPriority(10)
.willReturn(aResponse().proxiedFrom(host)));
});
Rob Elliot
02/15/2023, 7:03 PMShruti Sagar Mishra
02/15/2023, 7:04 PMRob Elliot
02/15/2023, 7:05 PMShruti Sagar Mishra
02/15/2023, 7:07 PMRob Elliot
02/15/2023, 7:08 PMShruti Sagar Mishra
02/15/2023, 7:09 PMRob Elliot
02/15/2023, 7:09 PMany
stub for /.*
to proxy to the real service.
• A single WireMock and set up multiple any
stubs, one for each remote API, matching on the Host
header - but this will require you to override the Host
header when making the request, which your HTTP client may make quite difficult.
I wouldn't recommend the second one.Shruti Sagar Mishra
02/15/2023, 7:41 PMRob Elliot
02/16/2023, 2:50 PMjava -jar wiremock-jre8-standalone-2.35.0.jar --enable-browser-proxying --port 8080 --verbose
. Then WireMock will be running before the emulator starts.
3. Start the emulator and configure the proxy
4. Try opening a browser inside the emulator and see if you can access https://example.com from it, with WireMock seeing the traffic. At least the browser should give you more feedback about what is wrong - whether it is a certificate problem or something else.Shruti Sagar Mishra
02/19/2023, 7:28 PMRob Elliot
02/19/2023, 7:34 PMShruti Sagar Mishra
02/19/2023, 8:01 PMPS C:\Users\Apollo247\IdeaProjects\Mobile_Tests> java -jar wiremock-jre8-standalone-2.35.0.jar --enable-browser-proxying --port 8080 --verbose
2023-02-20 01:28:14.807 Verbose logging enabled
2023-02-20 01:28:21.967 Verbose logging enabled
2023-02-20 01:28:22.076 Verbose logging enabled
/$$ /$$ /$$ /$$ /$$ /$$
| $$ /$ | $$|__/ | $$$ /$$$ | $$
| $$ /$$$| $$ /$$ /$$$$$$ /$$$$$$ | $$$$ /$$$$ /$$$$$$ /$$$$$$$| $$ /$$
| $$/$$ $$ $$| $$ /$$__ $$ /$$__ $$| $$ $$/$$ $$ /$$__ $$ /$$_____/| $$ /$$/
| $$$$_ $$$$| $$| $$ \__/| $$$$$$$$| $$ $$$| $$| $$ \ $$| $$ | $$$$$$/
| $$$/ \ $$$| $$| $$ | $$_____/| $$\ $ | $$| $$ | $$| $$ | $$_ $$
| $$/ \ $$| $$| $$ | $$$$$$$| $$ \/ | $$| $$$$$$/| $$$$$$$| $$ \ $$
|__/ \__/|__/|__/ \_______/|__/ |__/ \______/ \_______/|__/ \__/
port: 8080
enable-browser-proxying: true
trust-all-proxy-targets: false
ca-keystore: C:\Users\Apollo247\.wiremock\ca-keystore.jks
ca-keystore-type: jks
disable-banner: false
no-request-journal: false
verbose: true
2023-02-20 01:29:00.148 Request received:
127.0.0.1 - GET /openapi/v2
Host: [localhost:8080]
Connection: [close]
Matched response definition:
(no response definition configured)
Response:
HTTP/1.1 404
(no headers)
2023-02-20 01:29:00.266 Admin request received:
127.0.0.1 - GET /not-matched
Host: [localhost:8080]
Connection: [close]
2023-02-20 01:29:00.361
Request was not matched
=======================
-----------------------------------------------------------------------------------------------------------------------
| Closest stub | Request |
-----------------------------------------------------------------------------------------------------------------------
|
gen_204 |
|
GET | GET
/gen_204 | /openapi/v2 <<<<< URL does not match
|
|
-----------------------------------------------------------------------------------------------------------------------
2023-02-20 01:29:21.089 Proxying: GET http://clientservices.googleapis.com/chrome-variations/seed?osname=android&channel=stable&milestone=83
2023-02-20 01:29:22.113 Request received:
127.0.0.1 - GET /chrome-variations/seed?osname=android&channel=stable&milestone=83 (via browser proxy request)
Host: [clientservices.googleapis.com]
Connection: [keep-alive]
If-None-Match: [Cl/fVXpCtfFgoatvvVRS9Fi/y9JOWXENT7GoqNoBTzAsehGfZazB8zNUu1L1EYgfVqWzjtOuuuCuCwAtvGng/ah3dFEY2wDmyNeZDKdLojRDxU4/WSEsa6i1pkjuCgsg1hABGiAv46mVYQKm1JQwjkhe3OJivOCguSiLjxHlV0t+4nhRJiAB]
A-IM: [x-bm,gzip]
User-Agent: [Mozilla/5.0 (Linux; Android 11; sdk_gphone_x86_64_arm64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Mobile Safari/537.36]
Accept-Encoding: [gzip, deflate]
Matched response definition:
{
"status" : 200
}
Response:
HTTP/1.1 200
Im: [gzip]
X-Content-Type-Options: [nosniff]
X-Country: [in]
X-Frame-Options: [SAMEORIGIN]
X-Seed-Signature: [MEUCIEPwddanATRBn3BeNXgMIfOALtgpzCfVRbaGNfEgMRQoAiEA6nz6uEmotvpddo0YtSPX76AA+zkOE0FkkQLrHZNGy1g=]
X-Xss-Protection: [0]
Date: [Sun, 19 Feb 2023 19:59:22 GMT]
Content-Type: [application/x-gzip]
2023-02-20 01:30:02.636 Request received:
127.0.0.1 - GET /generate_204 (via browser proxy request)
Connection: [close]
User-Agent: [Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.32 Safari/537.36]
Host: [connectivitycheck.gstatic.com]
Accept-Encoding: [gzip]
Matched response definition:
{
"status" : 500,
"base64Body" : "TmV0d29yayBmYWlsdXJlIHRyeWluZyB0byBtYWtlIGEgcHJveGllZCByZXF1ZXN0IGZyb20gV2lyZU1vY2sgdG8gMTkyLjE2OC4xLjM4L2dlbmVyYXRlXzIwNA0KVGFyZ2V0IGhvc3QgaXMgbm90IHNwZWNpZmllZA=="
}
Response:
HTTP/1.1 500
Matched-Stub-Id: [193032b0-72d9-4bf6-a4c4-388e3542104f]
Matched-Stub-Name: [generate_204]
2023-02-20 01:30:02.703 Request received:
127.0.0.1 - GET /generate_204 (via browser proxy request)
Connection: [close]
User-Agent: [Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.32 Safari/537.36]
Host: [play.googleapis.com]
Accept-Encoding: [gzip]
Matched response definition:
{
"status" : 500,
"base64Body" : "TmV0d29yayBmYWlsdXJlIHRyeWluZyB0byBtYWtlIGEgcHJveGllZCByZXF1ZXN0IGZyb20gV2lyZU1vY2sgdG8gMTkyLjE2OC4xLjM4L2dlbmVyYXRlXzIwNA0KVGFyZ2V0IGhvc3QgaXMgbm90IHNwZWNpZmllZA=="
}
Response:
HTTP/1.1 500
Matched-Stub-Id: [193032b0-72d9-4bf6-a4c4-388e3542104f]
Matched-Stub-Name: [generate_204]
2023-02-20 01:30:15.588 Request received:
127.0.0.1 - GET / (via browser proxy request)
Host: [mitm.it]
Connection: [keep-alive]
Upgrade-Insecure-Requests: [1]
User-Agent: [Mozilla/5.0 (Linux; Android 11; sdk_gphone_x86_64_arm64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Mobile Safari/537.36]
Accept: [text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9]
Purpose: [prefetch]
Accept-Encoding: [gzip, deflate]
Accept-Language: [en-US,en;q=0.9]
Matched response definition:
{
"status" : 500,
"base64Body" : "TmV0d29yayBmYWlsdXJlIHRyeWluZyB0byBtYWtlIGEgcHJveGllZCByZXF1ZXN0IGZyb20gV2lyZU1vY2sgdG8gMTkyLjE2OC4xLjM4Lw0KVGFyZ2V0IGhvc3QgaXMgbm90IHNwZWNpZmllZA=="
}
Response:
HTTP/1.1 500
Matched-Stub-Id: [a57fdb68-b507-4a58-8a2d-982a675b42bc]
Matched-Stub-Name: []
2023-02-20 01:30:18.880 Proxying: GET http://mitm.it/favicon.ico
2023-02-20 01:30:19.430 Request received:
127.0.0.1 - GET /favicon.ico (via browser proxy request)
Host: [mitm.it]
Connection: [keep-alive]
User-Agent: [Mozilla/5.0 (Linux; Android 11; sdk_gphone_x86_64_arm64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Mobile Safari/537.36]
Accept: [image/webp,image/apng,image/*,*/*;q=0.8]
Referer: [http://mitm.it/]
Accept-Encoding: [gzip, deflate]
Accept-Language: [en-US,en;q=0.9]
Matched response definition:
{
"status" : 200
}
Response:
HTTP/1.1 403
Content-Type: [application/xml]
Date: [Sun, 19 Feb 2023 20:00:20 GMT]
Server: [AmazonS3]
X-Cache: [Error from cloudfront]
Via: [1.1 118076cb0590da05a105adf088b49476.cloudfront.net (CloudFront)]
X-Amz-Cf-Pop: [DEL54-C1]
X-Amz-Cf-Id: [ppwoANi4jVLdso8EkB60v7s2-CwZckhepQpC11MYJyqjycHF8ExYBg==]
2023-02-20 01:30:34.353 Request received:
127.0.0.1 - GET / (via browser proxy request)
Host: [example.com]
Connection: [keep-alive]
Upgrade-Insecure-Requests: [1]
User-Agent: [Mozilla/5.0 (Linux; Android 11; sdk_gphone_x86_64_arm64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Mobile Safari/537.36]
Accept: [text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9]
Accept-Encoding: [gzip, deflate]
Accept-Language: [en-US,en;q=0.9]
Matched response definition:
{
"status" : 500,
"base64Body" : "TmV0d29yayBmYWlsdXJlIHRyeWluZyB0byBtYWtlIGEgcHJveGllZCByZXF1ZXN0IGZyb20gV2lyZU1vY2sgdG8gMTkyLjE2OC4xLjM4Lw0KVGFyZ2V0IGhvc3QgaXMgbm90IHNwZWNpZmllZA=="
}
Response:
HTTP/1.1 500
Matched-Stub-Id: [1f44f953-f075-45ad-acdf-c9a0362e72c8]
Matched-Stub-Name: []
2023-02-20 01:30:34.700 Proxying: GET http://example.com/favicon.ico
2023-02-20 01:30:35.138 Request received:
127.0.0.1 - GET /favicon.ico (via browser proxy request)
Host: [example.com]
Connection: [keep-alive]
User-Agent: [Mozilla/5.0 (Linux; Android 11; sdk_gphone_x86_64_arm64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Mobile Safari/537.36]
Accept: [image/webp,image/apng,image/*,*/*;q=0.8]
Referer: [http://example.com/]
Accept-Encoding: [gzip, deflate]
Accept-Language: [en-US,en;q=0.9]
Matched response definition:
{
"status" : 200
}
Response:
HTTP/1.1 404
Content-Encoding: [gzip]
Accept-Ranges: [bytes]
Age: [586122]
Cache-Control: [max-age=604800]
Content-Type: [text/html; charset=UTF-8]
Date: [Sun, 19 Feb 2023 20:00:35 GMT]
Expires: [Sun, 26 Feb 2023 20:00:35 GMT]
Last-Modified: [Mon, 13 Feb 2023 01:11:53 GMT]
Server: [ECS (nyb/1D25)]
Vary: [Accept-Encoding]
X-Cache: [404-HIT]
Content-Length: [648]Rob Elliot
02/19/2023, 8:07 PMShruti Sagar Mishra
02/19/2023, 8:10 PMRob Elliot
02/19/2023, 8:10 PMShruti Sagar Mishra
02/19/2023, 8:10 PMRob Elliot
02/19/2023, 8:13 PMShruti Sagar Mishra
02/19/2023, 8:27 PMRob Elliot
02/19/2023, 8:28 PMShruti Sagar Mishra
02/19/2023, 8:29 PMRob Elliot
02/19/2023, 8:30 PMShruti Sagar Mishra
02/19/2023, 8:31 PMRob Elliot
02/19/2023, 8:32 PM