hoverfly icon indicating copy to clipboard operation
hoverfly copied to clipboard

Hoverfly tries to connect to stubbed server in simulation mode and fails

Open martin-tarjanyi opened this issue 11 months ago • 1 comments

Description of the bug

In our integration tests we are seeing a strange error which only happens in our pipeline and not locally. We set Hoverfly to simulation mode and import a simulation using the Java client. However, it looks like Hoverfly tries to connect to the actual service and fails with SSL error. Is it expected that Hoverfly tries to connect to the actual service in simulation mode?

Also, it looks like after getting this error Hoverfly just proxies the request to the actual service instead of using the simulation.

Steps to reproduce the issue

Couldn't reproduce it unfortunately. It only happens in our pipeline.

Observed result

Hoverfly error messages seen (If none, say none) Last line is the important error coming from Hoverfly. In the actual log it is not example.com, I didn't want to share the actual host.

     2024-03-11 17:10:44.796  INFO [,,,] 1018 --- [r @coroutine#33] i.s.hoverfly.junit.core.TempFileManager  : Selecting the following binary based on the current operating system: hoverfly_linux_amd64
     2024-03-11 17:10:44.796  INFO [,,,] 1018 --- [r @coroutine#33] i.s.hoverfly.junit.core.TempFileManager  : Storing binary in temporary directory /tmp/hoverfly.16751592908307880508/hoverfly_linux_amd64
     2024-03-11 17:10:44.885  INFO [,,,] 1018 --- [r @coroutine#33] io.specto.hoverfly.junit.core.Hoverfly   : Executing binary at /tmp/hoverfly.16751592908307880508/hoverfly_linux_amd64
     2024-03-11 17:10:44.904  INFO [,,,] 1018 --- [     Thread-109] hoverfly                                 : Default proxy port has been overwritten port=41033
     2024-03-11 17:10:44.905  INFO [,,,] 1018 --- [     Thread-109] hoverfly                                 : Default admin port has been overwritten port=42491
     2024-03-11 17:10:44.905  INFO [,,,] 1018 --- [     Thread-109] hoverfly                                 : Using memory backend 
     2024-03-11 17:10:44.905  INFO [,,,] 1018 --- [     Thread-109] hoverfly                                 : Proxy prepared... Destination=. Mode=simulate ProxyPort=41033
     2024-03-11 17:10:44.905  INFO [,,,] 1018 --- [     Thread-109] hoverfly                                 : current proxy configuration destination=. mode=simulate port=41033
     2024-03-11 17:10:44.905  INFO [,,,] 1018 --- [     Thread-109] hoverfly                                 : Admin interface is starting... AdminPort=42491
     2024-03-11 17:10:44.905  INFO [,,,] 1018 --- [     Thread-109] hoverfly                                 : serving proxy 
     2024-03-11 17:10:44.945  INFO [,,,] 1018 --- [r @coroutine#33] io.specto.hoverfly.junit.core.Hoverfly   : A local Hoverfly with version v1.6.3 is ready
     2024-03-11 17:10:44.948  INFO [,,,] 1018 --- [     Thread-109] hoverfly                                 : Mode has been changed mode=simulate
     2024-03-11 17:10:44.954  INFO [,,,] 1018 --- [r @coroutine#33] i.s.hoverfly.junit.core.ProxyConfigurer  : Setting proxy host to localhost
     2024-03-11 17:10:44.954  INFO [,,,] 1018 --- [r @coroutine#33] i.s.hoverfly.junit.core.ProxyConfigurer  : Setting proxy proxyPort to 41033
 
 com.example.SomeTest > Test case STANDARD_OUT
     2024-03-11 17:10:44.972  INFO [,,,] 1018 --- [@coroutine#7652] io.specto.hoverfly.junit.core.Hoverfly   : Importing simulation data to Hoverfly
     2024-03-11 17:10:44.991  INFO [,,,] 1018 --- [     Thread-109] hoverfly                                 : payloads imported failed=0 successful=10 total=10
     2024-03-11 17:10:45.122  INFO [,,,] 1018 --- [     Thread-109] hoverfly                                 : 2024/03/11 17:10:45 [001] WARN: Cannot handshake client example.com:443 remote error: tls: unknown certificate

If possible, add screenshots to help explain your problem

Expected result

No outgoing call to the actual service, no failure, simulation is used to return response.

Additional relevant information

  1. Hoverfly version: 1.6.3
  2. Anything that might help us to diagnose the problem We also stub another external service which doesn't produce this issue. Also, if we run a test with the service first which doesn't produce this issue, then the test using the service which otherwise produces the issue also works fine.

martin-tarjanyi avatar Mar 11 '24 17:03 martin-tarjanyi

In simulate mode, hoverfly will not make any request to the real service.

Looking at this error Cannot handshake client example.com:443 remote error: tls: unknown certificate, it seems that your CI build environment hasn't trusted the hoverfly self-cert yet. Can you try this please? https://docs.hoverfly.io/en/latest/pages/tutorials/basic/https/https.html#simulating-https-apis

It has instructions on downloading the cert, and then you just need to import it into your trusted ca list in your build environment.

Let me know how it goes, we probably need to update the docs, it seems to be common issue.

tommysitu avatar Mar 12 '24 21:03 tommysitu