Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DSL unusable on Windows due to incorrect relative response body file path handling #311

Closed
codebrewer opened this issue Jan 26, 2025 · 3 comments

Comments

@codebrewer
Copy link
Contributor

Description of the bug

Relative response body file paths are converted to absolute paths prior to launching the native Hoverfly process. On Windows, the conversion results in a string that doesn't represent a valid Windows path (e.g. C:\\C:\\Users\\...) and the Hoverfly process returns an error.

Steps to reproduce the issue

Run the ResponseBodyFileTest test class on Windows.

Observed result

Tests shouldResolveResponseBodyFilesInDefaultHoverflyFolder, shouldResolveResponseBodyFilesInTestResourcesFolder and shouldWorksWithDsl all fail. For instance,shouldResolveResponseBodyFilesInDefaultHoverflyFolder logs the following when run on Windows 10:

2025-01-26 15:13:34,200 [INFO ] i.s.h.j.c.TempFileManager Selecting the following binary based on the current operating system: hoverfly_windows_amd64.exe
2025-01-26 15:13:34,232 [INFO ] i.s.h.j.c.TempFileManager Storing binary in temporary directory C:\Users\mark\AppData\Local\Temp\hoverfly.6856899247979433770\hoverfly_windows_amd64.exe
2025-01-26 15:13:34,278 [INFO ] i.s.h.j.c.Hoverfly Executing binary at C:\Users\mark\AppData\Local\Temp\hoverfly.6856899247979433770\hoverfly_windows_amd64.exe
2025-01-26 15:13:35,500 [INFO ] hoverfly Default proxy port has been overwritten port=65183
2025-01-26 15:13:35,509 [INFO ] hoverfly Default admin port has been overwritten port=65184
2025-01-26 15:13:35,509 [INFO ] hoverfly Using memory backend 
2025-01-26 15:13:35,509 [INFO ] hoverfly Proxy prepared... Destination=. Mode=simulate ProxyPort=65183
2025-01-26 15:13:35,509 [INFO ] hoverfly current proxy configuration destination=. mode=simulate port=65183
2025-01-26 15:13:35,509 [INFO ] hoverfly serving proxy 
2025-01-26 15:13:35,509 [INFO ] hoverfly Admin interface is starting... AdminPort=65184
2025-01-26 15:13:35,681 [INFO ] i.s.h.j.c.Hoverfly A local Hoverfly with version v1.10.7 is ready
2025-01-26 15:13:35,710 [INFO ] hoverfly Mode has been changed mode=simulate
2025-01-26 15:13:35,713 [INFO ] i.s.h.j.c.ProxyConfigurer Setting proxy host to localhost
2025-01-26 15:13:35,713 [INFO ] i.s.h.j.c.ProxyConfigurer Setting proxy proxyPort to 65183
2025-01-26 15:13:35,713 [INFO ] i.s.h.j.c.Hoverfly Importing simulation data to Hoverfly
2025-01-26 15:13:35,736 [WARN ] i.s.h.j.a.HoverflyClient Failed to set simulation: Unexpected response (code=500, message={"error":"An error occurred: data.pairs[0].response open C:\\C:\\Users\\mark\\Development\\GitHub\\codebrewer-forks\\hoverfly-java\\build\\resources\\test\\hoverfly\\responses\\booking-200.json: The filename, directory name, or volume label syntax is incorrect."})
2025-01-26 15:13:35,736 [INFO ] i.s.h.j.c.Hoverfly Destroying hoverfly process

Failed to set simulation: Unexpected response (code=500, message={"error":"An error occurred: data.pairs[0].response open C:\\C:\\Users\\mark\\Development\\GitHub\\codebrewer-forks\\hoverfly-java\\build\\resources\\test\\hoverfly\\responses\\booking-200.json: The filename, directory name, or volume label syntax is incorrect."})
io.specto.hoverfly.junit.api.HoverflyClientException: Failed to set simulation: Unexpected response (code=500, message={"error":"An error occurred: data.pairs[0].response open C:\\C:\\Users\\mark\\Development\\GitHub\\codebrewer-forks\\hoverfly-java\\build\\resources\\test\\hoverfly\\responses\\booking-200.json: The filename, directory name, or volume label syntax is incorrect."})
	at io.specto.hoverfly.junit.api.OkHttpHoverflyClient.setSimulation(OkHttpHoverflyClient.java:104)
	at io.specto.hoverfly.junit.core.Hoverfly.simulate(Hoverfly.java:302)
	at io.specto.hoverfly.junit.core.ResponseBodyFileTest.shouldResolveResponseBodyFilesInDefaultHoverflyFolder(ResponseBodyFileTest.java:30)
...

Note the filename present in the error message: C:\\C:\\Users\\...

As a consequence (and my actual use case...) attempting to use a relative response body file path via the DSL fails.

Expected result

The unit test should pass and, as a consequence, the DSL should function correctly with relative response body file paths - but see item 3 below.

Additional relevant information

If not indicated above:

  1. Hoverfly Java version: 0.19.1;
  2. It's a straightforward fix and I'll raise a PR;
  3. Fixing this bug isn't sufficient to allow the failing ResponseBodyFileTest tests to pass (or the DSL to be used successfully with a relative response body file path) due to a Windows-specific bug in Hoverfly itself - I'll raise an issue and PR against SpectoLabs/hoverfly for that and link them here.
@codebrewer
Copy link
Contributor Author

Raised #312 to address this

@codebrewer
Copy link
Contributor Author

Raised issue 1173 and PR 1174 against SpectoLabs/hoverfly to address item 3 in the additional info section above.

@tommysitu
Copy link
Member

Your fix has been released: https://github.com/SpectoLabs/hoverfly-java/releases/tag/0.20.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants