question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

com.github.tomakehurst.wiremock.security.NotAuthorisedException - when loading stubs - relative and root path

See original GitHub issue

Wiremock Version 2.15.0 you could define file stubs like that

 stubFor(any(urlPathEqualTo(url))
            .withQueryParam(xxxx)
            .withQueryParam(xxxx)
            .willReturn(aResponse()
                    .withStatus(HttpStatus.OK.value())
                    .withBodyFile("/xservice/file.json")));

where /xservice/file.json was under /src/test/resources/__files/xservice/file.json

Upgrading to Version 2.17.0 and checking the implemantion of com.github.tomakehurst.wiremock.common.AbstractSourceFile I can see that the same test will fail with

com.github.tomakehurst.wiremock.security.NotAuthorisedException: Access to file /xservice/

If I strip the / from /xservice so that we define the stub like

 stubFor(any(urlPathEqualTo(url))
            .withQueryParam(xxxx)
            .withQueryParam(xxxx)
            .willReturn(aResponse()
                    .withStatus(HttpStatus.OK.value())
                    .withBodyFile("xservice/file.json")));

It works again.

I am not sure is this intentional or a bug? Mostly I am posting it in case others are affected.

Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8

github_iconTop GitHub Comments

3reactions
WojciechZankowskicommented, Jul 4, 2018

Just wanted to mention that bug still exists in version 2.18.0

It works when I run my build on Windows, but it fails on run in Travis CI. When I strip the path from “/” at the beginning it works on both platforms.

1reaction
tomakehurstcommented, Sep 20, 2018

Closing this since there’s a trivial workaround. Documented in 95a57b0721f5eea463ee3a663f1f502111f89550.

Read more comments on GitHub >

github_iconTop Results From Across the Web

com.github.tomakehurst.wiremock.security ...
com.github.tomakehurst.wiremock.security.NotAuthorisedException - when loading stubs - relative and root path #921.
Read more >
A brand new website interface for an even better experience!
com.github.tomakehurst.wiremock.security.NotAuthorisedException - when loading stubs - relative and root path.
Read more >
com.github.tomakehurst.wiremock.security ... - Tabnine
private void assertFilePathIsUnderRoot(String path) { try { String rootPath = rootDirectory.getCanonicalPath(); File file = new File(path); String filePath ...
Read more >
WireMock Tutorial: Introduction to Stubbing - Petri Kainulainen
This blog post describes how we can stub HTTP requests with WireMock. After we have finished this blog post, we: Know what stubbing...
Read more >
com.github.tomakehurst.wiremock.client.VerificationException
In your code you are stubbing out a response and then verifying that a request has been made for that stub. You are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found