Hi, I need help connecting an iPhone simulator wit...
# help
ž
Hi, I need help connecting an iPhone simulator with the WireMock server. I’m running a
standalone version 3.4.1
I have set up my Mac machine network to use HTTP and HTTPS to my local address with specified ports: • port = 9999 • https-port = 2424 IP: • Tried both 127.0.0.1 and actual local IP address. I have also set up my own certificate using OpenSSL and keytool and I’m adding these when starting the server: • --https-keystore cert/keystore.jks • --keystore-password xxx • --key-manager-password xxx • --keystore-type JKS Additional flags I set for running a server: • --proxy-all “https://censored.net” • --https-port 2424 • --verbose • --bind-address 0.0.0.0 • --preserve-host-header • --enable-browser-proxying • --trust-all-proxy-targets I have installed the
server.cert
that was generated via. OpenSSL to the Simulator device and gave permissions/enabled it. When I start the Application on my device, I’m just not getting any response. There is no traffic visible in the terminal. Opening
localhost:9999/__admin/
in Safari of the device works fine and I can see traffic printer to terminal. I would really appreciate anyones help 🙏 I’ve spend the whole day trying to figure this out 😐
t
Are you trying to get the iPhone simulator to use forward proxying as a way of integrating with your mock API?
If so, drop the
--proxy-all
1
If the URL your app is trying to connect to is HTTPS, then you’ll probably also have to make the simulator trust the WireMock CA cert, otherwise it’ll refuse the connection on account the certificate not being valid
ž
Yeah, I did that, but that does not seem to help.
t
You may have trusted WireMock’s HTTPS certificate rather than the CA cert is uses to sign generated certs when proxying.
🤔 1
Per these instructions you need to download wiremock-ca.crt and trust that
ž
This is the first one in the list
second one is the one I created
t
Might be worth dropping the one you created, at least from the WireMock startup parameters. I don’t think you need it, and although it shouldn’t interfere with proxying, you never know…
ž
ok, let me try that
t
In terms of WireMock startup, I suggest only these parameters:
Copy code
--port 9999 --verbose --enable-browser-proxying --trust-all-proxy-targets
And ensure your simulator is using HTTP port 9999 as its proxy
ž
Done, I downloaded the certificate again and approved it:
I was able to access:
localhost:9999/__admin/
and mock a single response via. Safari with my defined stub.
t
That doesn’t prove much unfortunately. If you have Postman installed you could try setting up forward proxying and testing from this.
The reason being that Postman is by default quite relaxed about certificates so you confirm that the problem is cert related and not something else
ž
ok, but then I would need to enable https, right?
t
No, counterintuitively
Almost no clients will proxy through HTTPS
Only HTTP
It’s still possible to proxy to an HTTPS destination
ž
I received this error:
Copy code
Network failure trying to make a proxied request from WireMock to {some-url}
Connect to <http://127.0.0.1:2424> [/127.0.0.1] failed: Connection refused
t
Looks like your proxy settings are still pointing at 2424
ž
Ahh yes, I fixed it 🙂
🎉 1
now, using the
localhost:9999/{somepath}
, redirects to the actual Service I’m trying to hit.
But my question is - how do I achieve this now using my real App… Does my app need to hit localhost?
t
No, if you’ve got forward proxying set up correctly
Your app should remain as-is without configuration changes, and the proxy setup will route calls through WireMock
Your proxy settings in your simulator should be for HTTP and port 9999
1
ž
Omg… 🫠 so my problem the whole time was because I was using HTTPS setting!
t
You’re not alone with that. Trips everyone up!
Forward proxying is surprisingly confusing, especially when you’re trying to do MITM
ž
Ahh, I can’t believe it 😄 Thank you very much for your time, Tom! 🙇 This is a life saving 🍻
t
No worries 👍
ž
I added
--record-mappings
to my command hoping that I could record a session with an app. I actually noticed that while using the app, the endpoints are not being forwarded, because they are not recorded 🤔 I’m getting records only when using Safari and hitting the endpoints directly to
localhost:9999/{somepath}
.
t
--record-mappings
is the old way and doesn’t really work with forward proxying. Instead I suggest you use the newer snapshot recording approach - let some traffic flow through first, then snapshot afterwards like this:
Copy code
curl -v <http://localhost:9999/__admin/recordings/snapshot> -d '{
    "captureHeaders": {
        "Host" : {
          "caseInsensitive" : true
        }
    }
}'
ž
Hmm… something’s not right. I used the app for some time and when I executed the
curl
, there are only few records created with url as
SectigoRSADomainValidationSecureServerCA.crt
🤔
t
That’s very weird. Might be worth resetting WireMock, generating some traffic, then hitting
/__admin/requests
to see what’s there
ž
Yeah, now I can confirm that the App network is not being forwarded. I also restarted the server and removed
--record-mappings
.
t
So there’s nothing in the request log?
ž
no, not until I run the endpoint
localhost:9999/{path}
via. Safari
my redirect stub is set up like this:
Copy code
{
  "request": {
    "method": "GET",
    "urlPattern": "/api/v2/.*"
  },
  "response": {
    "proxyBaseUrl": "<https://myendpoint.net>"
  }
}
t
This isn’t required. You only need a proxy config like this for reverse proxying (where you’ve changed the endpoint config in your app). When forward proxying the destination is embedded in the request.
Although if it was otherwise working I’d still expect some traffic in the log
Is your iOS app throwing errors when you try to run it?
ž
no, not this time. It works normally
t
If there are no requests in WireMock’s log and the app works OK that suggests that it’s not proxying through WireMock at all
ž
Exactly, though Safari on the device works
t
That’s because you’re going directly with Safari
ž
Is there anything else i need to setup?
t
Not from what you’ve told me
It might be worth testing the setup with Postman the way I suggested
If you use it
ž
I did set it up in the meantime
I’m hitting the
localhost:0000/{path}
-> and is redirected correctly
now that i have removed the redirect stub, it does not work anymore
t
Set up Postman Proxy like this:
Then make a Postman request to https://yourtargetserver.com
(replacing the domain with the one you want to proxy to)
ž
Copy code
Network failure trying to make a proxied request from WireMock to <https://domain/gw-api/v2/{path}>
domain
t
Have you deleted all your proxy stubs?
ž
only this one:
Copy code
{
  "request": {
    "method": "GET",
    "urlPattern": "/api/v2/.*"
  },
  "response": {
    "proxyBaseUrl": "<https://myendpoint.net>"
  }
}
t
If you have any others, delete them too
ž
Now i get:
Copy code
No response could be served as there are no stub mappings in this WireMock instance.
t
Did you set up Postman to proxy like in my screenshot?
ž
yes
t
Try doing
GET
<https://api.github.com/users>
in Postman
ž
t
OK, that’s progress
Did you see the data from it in WireMock’s log?
ž
yeah, now it works in Postman
sending the endpoints to actual hostname
t
OK, so you’ve got WireMock set up correctly. Now you just have to get your iOS emulator to proxy in the same way as Postman
ž
I think I finally solved it
i had to enable both HTTP and HTTPS in the network configuration:
i only had HTTP set up
t
Ah, that’ll be it
ž
Super awesome! It finally works 🙇 thank you soo much!!!
t
No probs
ž
Hi again, Tom 👋 I’m trying to connect the proxy on Browserstack’s device to my local machine via. the local tunnel. I see it with 2 options: • Force Browserstack’s network to run over my local network via. the tunnel, while my network is set to run via. proxy on my local machine. If I set this up, I’m unable to start the execution because because it can not connect to Browserstack. • Force Browserstack to run via Proxy, where I determine my local IP + PORT. _In this case I’m getting this error: “[CONN_FAIL:4004] Looks like you have SSL inspection enabled. You can either bypass *.browserstack.com or disable SSL inspection entirely for BrowserStack local to connect.”_ Which option would be preferable in your opinion? Is there a way to exclude the SSL inspection for browserstack endpoints?
t
It’s a long while since I’ve worked with Browserstack and I don’t think I ever tried it with MITM proxying so I’m probably not the best person to ask. I’m guessing the bypass suggestion didn’t help?
ž
Thanks for your feedback. I managed to make the connection to the proxy from the device on Browserstack, but now I’m struggling because the proxy changes the header when forwarding to our server, especially user-agent. What is the most efficient way to avoid this? 🤔 … my goal is to keep the user-agent in the header and pass the same value to our server.
I read that Wiremock should send exactly the same headers as sent from the client. But our BE devs have confirmed, that the user-agent is different.
The user agent that is forwarded is
apache-httpClient/5.3.1 (Java/17.0.9)
instead of the custom one, that the client is sending to the proxy.
145 Views