handstandsam / wiremock-android

WireMock running in an Android Application.
Apache License 2.0
3 stars 2 forks source link

Can you run the tests with https protocol #1

Open abhagupta opened 8 years ago

abhagupta commented 8 years ago

Hi @handstandsam , sorry this is not an issue, but more of a question. I have been using your examples and tests to prove that the same tests can be executed when we use HTTPS instead of HTTP. I have created self-signed certificate and a private key and created a BKS Keystore for Android emulator to read but I cannot get rid of SSLHandshake error I have posted below. I reached to a point when I can say that Wiremock , (Jetty rather), is not going to work Android because of some settings in Jetty server which are not supported in an Android emulator becasue of difference in JVM and Java Security. It works on desktop but not on Android. Now , I am not an android developer and I have started on Wiremock only 2 weeks ago, but I have investigated enough on SSL/TLS, HTTPS and Certificates, Handshake process between client and server to come to that conclusion. Error stack :

javax.net.ssl.SSLHandshakeException: Connection closed by peer
at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:324)
at com.android.okhttp.internal.http.SocketConnector.connectTls(SocketConnector.java:103)
at com.android.okhttp.Connection.connect(Connection.java:143)

Basically, server stops as soon as you communicate https.

Have you tried running the tests on https? Any help would be appreciated.

Thanks Abha

handstandsam commented 8 years ago

Hey @abhagupta. I have not tried using HTTPS in tests yet, but I have written out the steps I would take to debug this and get it working.

Assuming that all that works, it would be your programatic usage of WireMock in the Unit Test. Look at docs here: http://wiremock.org/https.html That should get you working... If none of that works, it could be something to do with the fact that we're using the Android Apache HTTP implementation instead of the full blown one? (Required to work on Android). Please report back to share how you got this to work. If you are unable to get it to work, please provide the code you are using to help debug the issue.

handstandsam commented 8 years ago

Also note, this GitHub project was a quick hack together and is not maintained. I'll be trying to keep the following repository up to date as time permits: https://github.com/handstandsam/AndroidHttpMockingExamples

handstandsam commented 8 years ago

And lastly, if none of this helps, maybe @tomakehurst could provide some helpful input as he's authored WireMock.

tomakehurst commented 8 years ago

Not sure I can be of much help I'm afraid.

Does the server actually stop when you hit the HTTPS port, or does it just drop the connection (which is fairly standard when TLS connection setup fails)?

abhagupta commented 8 years ago

Thanks @handstandsam and @tomakehurst . My keystore was the issue. The way I was generating, it didnt work on Android, but when I used the certificate posted by Marius from here, SSLHandshakeException went away. I still have not been able to create my own certificate successfully the way this has been created, but thats a seperate issue and could be my machine. But I am close.

Thanks for all your suggestions and help.

tomakehurst commented 8 years ago

Would you be willing to blog about this when you've cracked it? I'm sure this would be hugely useful to a lot of people.

I'd be happy to link to your post from (the soon to be re-designed) wiremock.org.

abhagupta commented 8 years ago

Yes, I am planning to write something up, and will also send you a PR to make wiremock work on Android.

Thanks again.

handstandsam commented 8 years ago

Awesome! I look forward to reading your blog post and linking to it! Thanks @abhagupta and @tomakehurst!