https://linen.dev logo
#help
Title
# help
ž

Žiga sternad

03/04/2024, 6:39 PM
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

Tom

03/04/2024, 6:48 PM
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
ž

Žiga sternad

03/04/2024, 6:51 PM
Yeah, I did that, but that does not seem to help.
t

Tom

03/04/2024, 6:52 PM
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
ž

Žiga sternad

03/04/2024, 6:54 PM
This is the first one in the list
second one is the one I created
t

Tom

03/04/2024, 6:55 PM
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…
ž

Žiga sternad

03/04/2024, 6:56 PM
ok, let me try that
t

Tom

03/04/2024, 6:56 PM
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
ž

Žiga sternad

03/04/2024, 6:59 PM
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

Tom

03/04/2024, 7:01 PM
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
ž

Žiga sternad

03/04/2024, 7:09 PM
ok, but then I would need to enable https, right?
t

Tom

03/04/2024, 7:09 PM
No, counterintuitively
Almost no clients will proxy through HTTPS
Only HTTP
It’s still possible to proxy to an HTTPS destination
ž

Žiga sternad

03/04/2024, 7:10 PM
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

Tom

03/04/2024, 7:10 PM
Looks like your proxy settings are still pointing at 2424
ž

Žiga sternad

03/04/2024, 7:11 PM
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

Tom

03/04/2024, 7:13 PM
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
ž

Žiga sternad

03/04/2024, 7:16 PM
Omg… 🫠 so my problem the whole time was because I was using HTTPS setting!
t

Tom

03/04/2024, 7:17 PM
You’re not alone with that. Trips everyone up!
Forward proxying is surprisingly confusing, especially when you’re trying to do MITM
ž

Žiga sternad

03/04/2024, 7:19 PM
Ahh, I can’t believe it 😄 Thank you very much for your time, Tom! 🙇 This is a life saving 🍻
t

Tom

03/04/2024, 7:19 PM
No worries 👍
ž

Žiga sternad

03/04/2024, 7:31 PM
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

Tom

03/04/2024, 7:34 PM
--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
        }
    }
}'
ž

Žiga sternad

03/04/2024, 7:39 PM
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

Tom

03/04/2024, 7:40 PM
That’s very weird. Might be worth resetting WireMock, generating some traffic, then hitting
/__admin/requests
to see what’s there
ž

Žiga sternad

03/04/2024, 7:41 PM
Yeah, now I can confirm that the App network is not being forwarded. I also restarted the server and removed
--record-mappings
.
t

Tom

03/04/2024, 7:42 PM
So there’s nothing in the request log?
ž

Žiga sternad

03/04/2024, 7:44 PM
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

Tom

03/04/2024, 7:46 PM
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?
ž

Žiga sternad

03/04/2024, 7:47 PM
no, not this time. It works normally
t

Tom

03/04/2024, 7:48 PM
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
ž

Žiga sternad

03/04/2024, 7:49 PM
Exactly, though Safari on the device works
t

Tom

03/04/2024, 7:49 PM
That’s because you’re going directly with Safari
ž

Žiga sternad

03/04/2024, 7:49 PM
Is there anything else i need to setup?
t

Tom

03/04/2024, 7:49 PM
Not from what you’ve told me
It might be worth testing the setup with Postman the way I suggested
If you use it
ž

Žiga sternad

03/04/2024, 7:50 PM
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

Tom

03/04/2024, 7:51 PM
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)
ž

Žiga sternad

03/04/2024, 7:53 PM
Copy code
Network failure trying to make a proxied request from WireMock to <https://domain/gw-api/v2/{path}>
domain
t

Tom

03/04/2024, 7:53 PM
Have you deleted all your proxy stubs?
ž

Žiga sternad

03/04/2024, 7:55 PM
only this one:
Copy code
{
  "request": {
    "method": "GET",
    "urlPattern": "/api/v2/.*"
  },
  "response": {
    "proxyBaseUrl": "<https://myendpoint.net>"
  }
}
t

Tom

03/04/2024, 7:55 PM
If you have any others, delete them too
ž

Žiga sternad

03/04/2024, 7:56 PM
Now i get:
Copy code
No response could be served as there are no stub mappings in this WireMock instance.
t

Tom

03/04/2024, 7:56 PM
Did you set up Postman to proxy like in my screenshot?
ž

Žiga sternad

03/04/2024, 7:56 PM
yes
t

Tom

03/04/2024, 7:57 PM
Try doing
GET
<https://api.github.com/users>
in Postman
ž

Žiga sternad

03/04/2024, 7:57 PM
image.png
t

Tom

03/04/2024, 7:58 PM
OK, that’s progress
Did you see the data from it in WireMock’s log?
ž

Žiga sternad

03/04/2024, 7:58 PM
yeah, now it works in Postman
sending the endpoints to actual hostname
t

Tom

03/04/2024, 7:59 PM
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
ž

Žiga sternad

03/04/2024, 8:01 PM
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

Tom

03/04/2024, 8:02 PM
Ah, that’ll be it
ž

Žiga sternad

03/04/2024, 8:03 PM
Super awesome! It finally works 🙇 thank you soo much!!!
t

Tom

03/04/2024, 8:04 PM
No probs
ž

Žiga sternad

03/05/2024, 9:00 AM
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

Tom

03/05/2024, 3:19 PM
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?
ž

Žiga sternad

03/06/2024, 12:19 PM
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.
40 Views