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.

Are header names modified by the mock service?

See original GitHub issue

I’m attempting to mock a vendor’s service for unit test purposes, and it requires an access_token header (specifically “access_token”) and would like to assert that the request at least contains a header with that name. Problem is, when I include something like this in my ProviderServiceRequest object:

                    Headers = new Dictionary<string, Object>()
                    {
                        ["Content-Type"] = "application/json; charset=utf-8",
                        ["access_token"] = Match.Type(Token.WriteToken())
                    }

…I get something like the following in my pact log:

Description of differences
--------------------------------------
* Could not find key "access_token" (keys present are: Content-Length, Content-Type, Accept, Access-Token, Host, Expect, Version) at $.headers

Notice that Access-Token is an options, but access_token is not. I’ve verified both that, when I debug an application processing this request, the header name is reflected as access_token in the current HttpContext, and that the code under test works with the vendor’s service (whereas manually sending Access-Token does not.)

Is Pact changing the header names it receives prior to checking for valid interactions?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
bethesquecommented, May 7, 2018

Yes, it is. It’s actually Rack, the http library that does the http calls in the test cases. It assumes that all headers are in the standard format (underscores really aren’t standard, I have to say). Nonetheless, there is a workaround for this scenario. I’ll ferret it out and get back to you.

0reactions
neilcampbellcommented, May 13, 2018

@bethesque Oh cool! Yep updated to 1.43.1

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to mock HttpServletRequest with Headers?
@473183469 Yes. You are right. Enumeration<String> headerNames = Collections.enumeration(headers.keySet()) would have been shorter and smarter.
Read more >
API Mocking Service Release Notes
When an OAS API specification is tested, the mocking service now handles the header correctly by accepting the value of the header name...
Read more >
Modifying Headers In HTTP(s) Requests In UI Automation ...
Duplicate header names are permitted in an HTTP request, so before setting the replacement header you must first delete the existing header ...
Read more >
Working with MockServices | SOAP Mocking
The SOAP Service Mocking functionality in SoapUI lets you create a standards ... responses (including scripts, attachments and custom http headers).
Read more >
Service Mocking Overview | REST Mocking
Configure custom headers. Specify the content type in the Content | Media Type drop-down list. Create and modify the body content in the...
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