Hi Team, 1. Is it possible to fetch dynamic value...
# help
s
Hi Team, 1. Is it possible to fetch dynamic value in request header (not in response) in line no 75 of this image. 2. To have the value of that key, inorder to validate the content inside it. (For reference in line 79). Thanks.
b
@Shruti Mishra: a request filter will help here. Extract the request header value, perform the verification you need and based on that, either continue processing the request or seen back a response (probably a 401 in case of failed verification)
s
@Bas Dijkstra Probably 2 things: What can be passed as a value of "Auth" : "" Is method call is allowed under the stubFor block? If yes then will include "Auth" : filter("value")
b
That’s not how a request filter works. A request filter is a WireMock extension that you build by extending the built in StubRequestFilter class. See https://wiremock.org/docs/extending-wiremock/ under ‘Intercepting and modifying requests’. It’s a separate class that you can then use in WireMock by loading it when you start the WireMock instance. Again, have a look at this example, but I pointed you to this a couple of days ago: https://github.com/basdijkstra/wiremock-workshop/blob/main/src/test/java/answers/extensions/BasicAuthRequestFilter.java
All incoming requests will pass through the filter before WireMock tries to find a response definition for them, so you don’t need to change your stubFor() method, although you can remove the request matching on the Authorization header, because the request filter takes care of that.
s
Okay @Bas Dijkstra that means just registering the request filter class in the implementation class will work. Thanks!
b
Yes. Again, please have a look at the examples and let me know if you worked it out, or if you’re stuck. Happy to help once I get back to work (Thursday) if needed.
s
Sure, thanks!