-
Notifications
You must be signed in to change notification settings - Fork 67
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
Pact mock server not returning proper CORS headers #72
Comments
Your Http-Origin header appears to be empty: pact-mock_service/lib/pact/consumer/mock_service/cors_origin_header_middleware.rb Line 26 in 7d4fd1f
|
Here's some documentation on using CORS with the mock service. https://github.com/pact-foundation/pact-mock_service/wiki/Using-the-mock-service-with-CORS |
Why is http-origin header empty when pact mock service is created with cors enabled ( Please note pact mock service creation config above with cors: true). cors_origin_header_middleware adds the 'Access-Control-Allow-Origin with value of '*' when i create pact mock service with cors enabled. but thats not seems to work for me as i have cors enabled and Access-Control-Allow-Origin is still null. |
def add_cors_header env, response
[response[0], response[1].merge('Access-Control-Allow-Origin' => env.fetch('HTTP_ORIGIN','*')), response[2]]
end env.fetch will return the second argument if the given key is not found. As |
Thanks for clarifying it. i am using mocha to fire my tests and for a react-action in testing, it logs the following request in pact.log: I, [2017-07-17T11:34:55.421448 #15431] INFO -- : Received request GET /mydata?address=75001 Here "Origin": "null" is populated automatically and even though request matches with the interaction and generates the pact file but the response is not returned from mock server. How do i resolve the issue now? |
My local nodejs was automatically populating the request header with origin null. Pact started working fine when i fixed it. Thanks for your time. @bethesque |
No worries, glad you've fixed it. |
My Pact mock server is listening in different port from my tests and my pact mock server is running with following configuration:
const provider = pact({
consumer: 'myconsumer',
provider: 'myprovider',
port: 8989,
cors: true,
log: path.resolve(process.cwd(), 'logs', 'pact.log'),
dir: path.resolve(process.cwd(), 'pacts'),
logLevel: 'DEBUG',
spec: 1
});
I request the above mock server using 'axios' and the request is matched with one of the interaction i have configured on the provider (as per pact.log). But response always throws error with CORS.
My pact log has following information:
Received OPTIONS request for mock service administration endpoint POST /interactions. Returning CORS headers: {"Access-Control-Allow-Origin":"null","Access-Control-Allow-Headers":"x-pact-mock-service","Access-Control-Allow-Methods":"DELETE, POST, GET, HEAD, PUT, TRACE, CONNECT, PATCH"}.
why is Access-Control-Allow-Origin is null instead of '*'. ?
How can i disable CORS security completely with tests as the final resorts when i use webpack, npm and mocha based tests.?
The text was updated successfully, but these errors were encountered: