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

Fix CORS parameter not doing anything #341

Merged
merged 1 commit into from
Apr 29, 2023

Conversation

Lukas-dev-threads
Copy link
Contributor

@Lukas-dev-threads Lukas-dev-threads commented Apr 14, 2023

We found that pact ignores the CORS parameter of the Consumer.has_pact_with() function.
If the CORS parameter is set to True --cors=* is appended to the list of commands for the external mock service.

The mock service itself already supports this parameter.

@Lukas-dev-threads Lukas-dev-threads marked this pull request as ready for review April 14, 2023 14:12
pact/pact.py Outdated
@@ -214,6 +214,8 @@ def start_service(self):
command.extend(['--sslcert', self.sslcert])
if self.sslkey:
command.extend(['--sslkey', self.sslkey])
if self.cors:
command.extend(['--cors=*'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the =*? I think just passing this without arguments (i.e. treat it as a flag) is all that is needed.

Or is this something specific to the way the python CLI lib interacts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it without passing =* and it works fine.

The documentation of the mock server tells me that an argument must be provided

pact\bin\pact\bin\pact-mock-service.bat help start

 -o, [--cors=CORS]  # Support browser security in tests by responding to OPTIONS requests and adding CORS headers to mocked responses

But because self.cors is a boolean there is no way to pass different options for the cors parameter and it is
therefore better to append --cors without any value.

For now I pushed an update that removes =* from the command.

If the cors parameter is set to True '--cors=*' is appended to
the list of commands for the external mock service.
Previously the parameter was ignored.
@YOU54F YOU54F merged commit 6944330 into pact-foundation:master Apr 29, 2023
7 checks passed
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

Successfully merging this pull request may close these issues.

None yet

3 participants