Jayesh Guru
02/08/2022, 3:47 PMAuthorization: Bearer <hardcode token>
in verification step in Buildkite pipeline before publishing pact to the pact-broker, below are the steps in our BK pipeline
1. Run consumer Contract Test and upload pact.json file to the artifacts
2. Download pact.json file
3. Verify pact with Provider
4. Publish pacts to the pact-broker
Getting below error for invalid authorization as hardcoded token was passed
Verifying a pact between cmedia-distribute-api and vmedia-mats-app
Given get schema tag enums
return schema tags
with GET /metadata/schema-tag-enums
returns a response which
has status code 200 (FAILED - 1)
has a matching body (FAILED - 2)
Failure/Error: expect(response_status).to eql expected_response_status
expected: 200
got: 401
(compared using eql?)
# /pact/bin/pact:15:in `<top (required)>'
Failure/Error: expect(response_body).to match_term expected_response_body, diff_options, example
Actual: {"title":"Unauthorized","message":"401 Unauthorized: Invalid token: Cannot extract header,payload and signature","mats_error_code":1001}
Diff
--------------------------------------
Key: - is expected
+ is actual
Antonio Gámiz Delgado
02/14/2022, 9:26 AM{
"consumer": "Consumer",
"state": "User exists and has resources",
"states": [
"User exists and has resources"
],
"params": {}
}
Matt (pactflow.io / pact-js / pact-go)
settings.PACT_CONSUMER_NAME
(and the provider one) is defined?Jayesh Guru
02/16/2022, 1:40 PMlocalhost:1234
while starting the pact service pact.start_service()
in conftest.py. FYI, it is working fine in my local but failing in Buildkite PipelineBeth (pactflow.io/Pact Broker/pact-ruby)
Caíque Coelho
02/20/2022, 6:49 PMcustom_provider_headers
to my verifier.verify_with_broker
but I still getting failures verifications. Someone can help me? I was wandering if there is any way to see the current response from the verification, because I only received a generic return like has status code 200 (FAILED - 1)
there is any wait to see the actual status code return and the body response. I think if I can see the actual return will be more easy to understand what I’m doing wrong. I’m putting all my code in this thread, thank you all!Yumi
03/01/2022, 8:20 AMI, [2022-03-01T16:05:12.110368 #6736] INFO -- : Sending PUT request to path: "/api/cartItems" with headers: {"CONTENT_TYPE"=>"application/json", "HTTP_X_PACT_ORIGINAL_HEADER_NAMES"=>"Content-Type"}, see debug logs for body
D, [2022-03-01T16:05:12.113360 #6736] DEBUG -- : body :[{"duration":0,"id":"c3c46c8ccd254b32bfa52ba84aafa371","number":1}]
I, [2022-03-01T16:05:15.427349 #6736] INFO -- : Received response with status: 200, headers: {"P3p"=>"CP=CAO PSA OUR", "Bluewareguid"=>"7b0774ea1ea787f7", "X-Blueware-App-Data"=>"Olx7QXtkY0UQancBBFEGGAsAJhgCCisNIA51JUI0PDgGcD0EHhw6FQ0bMD5hMyofbmkjZz0cMQsYGhwNBBMxPmFyciZnEnx0TRFiRFpMeVtRUHZVfGVqRwd+d3oPRj4GRkxiG1FJdVYrM2sTU3FtYQcEcDc=", "Content-Type"=>"application/json", "Date"=>"Tue, 01 Mar 2022 08:05:12 GMT", "Cache-Control"=>"no-cache, no-store, max-age=0, must-revalidate", "Pragma"=>"no-cache", "Expires"=>"0", "X-Xss-Protection"=>"1 ; mode=block", "Referrer-Policy"=>"no-referrer", "Vary"=>"Origin\nAccess-Control-Request-Method\nAccess-Control-Request-Headers", "Strict-Transport-Security"=>"max-age=16000000; includeSubDomains; preload;", "Content-Length"=>"79"}, see debug logs for body
D, [2022-03-01T16:05:15.430341 #6736] DEBUG -- : body: {"state":"OK","body":null,"requestId":"reqId-171d3c0265906198b4f02-b83abbaa-1"}
What I use to verify is like:
pact-verifier --log-dir=F:\code\pact-python-master-1227\consumer\mop\pact_logs --provider-base-url=<https://baseurl.cn> --pact-ur
l=F:\code\pact-python-master-1227\consumer\mop\contract_files\ECS\ECS-OP_EditCaterProduct.json --custom-provider-header=Cookie:CMECLOUDTOKEN=3a8c6ccb407e48bb8857535bc23cba37
I'm wondering if there is a log that I can check when the request is replayed, it does request with what I provide in the custom-provider-header?Agustina BOSSO
03/01/2022, 3:03 PMagustina.bosso@Agustinas-MBP in ~/Repos/pact-python/examples/consumer (master) > pytest --run-broker True --publish-pact 1
ImportError while loading conftest '/Users/agustina.bosso/Repos/pact-python/examples/consumer/conftest.py'.
conftest.py:2: in <module>
from testcontainers.compose import DockerCompose
E ImportError: No module named testcontainers.compose
Mike Geeves
03/02/2022, 1:55 PMSandeep
03/03/2022, 11:21 AMverifier = Verifier(provider='UserService', provider_base_url=PACT_URL)
output, logs = verifier.verify_pacts('./userserviceclient-userservice.json', log_dir='/tmp/logs/, log_level='DEBUG')
For example: if the status code comparison fails, I would like to append it result to my test reportElliott Murray
03/06/2022, 3:01 PMjson
03/07/2022, 3:26 PMjson
03/07/2022, 9:38 PMJoachim David
03/14/2022, 12:31 PMUzumaki
03/19/2022, 3:01 PMAbhi Nandan
03/28/2022, 5:26 AM403
error. We are using the following command on the provider side
pipenv run pact-verifier --provider-base-url=<http://localhost:8000> \
--pact-url="<server_base_url>/pacts/provider/<provider>/consumer/<consumer>/latest" \
--provider-app-version $VERSION \
--pact-broker-username <pact_broker_user_name> \
--pact-broker-password <pact_broker_pwd> \
--publish-verification-results
Provider application is running in docker container on port 8000
. The above command is working fine from the local dev system, however it fails from our CI (GitLab), with the following error -
HTTP request failed: status=403 /usr/local/lib/python3.9/site-packages/pact/bin/pact/lib/vendor/ruby/2.2.0/gems/pact-support-1.17.0/lib/pact/consumer_contract/pact_file.rb:73:in `block in get_remote_with_retry'
on Pact Broker log found this -
WARN -- : attack prevented by Rack::protection::IPSpoofing
nginx log shows the following -
"GET /pacts/provider/<provider_name>/consumer/<consumer_name>/latest HTTP/1.1" 403 9 "-" "Ruby" "<http://xx.xxx.xx.xxx|xx.xxx.xx.xxx>"
can anyone please help us with what is wrong here?Uzumaki
03/30/2022, 2:12 PMYumi
04/01/2022, 8:21 AMdef test_get_metadata(self):
expected = {
"body": [
{
"name": "可用区1",
"status": "ONLINE",
"visible": True
}
],
"requestId": Like("abc"),
"state": "OK"
}
# 定义响应头
headers = {
"Content-Type": "application/json"
}
query = {"name":"可用区1","signature":"asdf"}
(self.pact
.upon_receiving('查询有效可用区信息')
.with_request(
method='GET',
path=self.PATH,
query=query,
headers=headers
).will_respond_with(200, headers, expected))
with self.pact:
resp = requests.get("<http://localhost>:{}{}".format(MOCK_SERVER_PORT,self.PATH),
params=query,headers = headers)
print('*******************************')
print(resp.json())
self.assertEqual(resp.json(), get_generated_values(expected))
when using pact-verifier command to verify the json file. It shows that the value of "name" in query parameters is urlencoded as "%E5%8F%AF%E7%94%A8%E5%8C%BA1". however when I change the query from list to string like this :
query = "name=可用区1&signature=asdf"
when using pact-varifier command,it shows:
URI::InvalidURIError:
URI must be ascii only "/api/change?name=\u{53ef}\u{7528}\u{533a}1&signature=asdf"
# D:/python/Lib/site-packages/pact/bin/pact/lib/ruby/lib/ruby/2.2.0/uri/rfc3986_parser.rb:20:in `split'
# D:/python/Lib/site-packages/pact/bin/pact/lib/ruby/lib/ruby/2.2.0/uri/rfc3986_parser.rb:72:in `parse'
# D:/python/Lib/site-packages/pact/bin/pact/lib/ruby/lib/ruby/2.2.0/uri/common.rb:226:in `parse'
Is there a way to deal with this kind of situation?I've found a issue https://github.com/pact-foundation/pact-provider-proxy/issues/6 but it seems different from @Beth (pactflow.io/Pact Broker/pact-ruby) said.I thought hash form will not be encoded🥲Matt (pactflow.io / pact-js / pact-go)
Ashish
04/07/2022, 6:48 PMElliott Murray
04/11/2022, 1:28 PMCaíque Coelho
04/14/2022, 5:37 PMLike({array: [1, 2, 3]})
, but when I’m running this contract in my provider verification the provider return an array with 6 elements and the validation fail. Is there any way to ignore the array length and just verify if the response in my provider contains an array with length greater than 0 in the body?James Fraser
04/18/2022, 9:22 AMHimanshu Pandey
04/25/2022, 5:35 AMAshish
04/26/2022, 9:07 PMCreating /Users/ashishgoyal/gitrepos/pact-python/venv_pact/lib/python3.9/site-packages/pact-python.egg-link (link to .)
Adding pact-python 1.5.2 to easy-install.pth file
Installing pact-verifier script to /Users/ashishgoyal/gitrepos/pact-python/venv_pact/bin
Installed /Users/ashishgoyal/gitrepos/pact-python
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "/Users/ashishgoyal/gitrepos/pact-python/setup.py", line 212, in <module>
setup(
File "/Users/ashishgoyal/gitrepos/pact-python/venv_pact/lib/python3.9/site-packages/setuptools/__init__.py", line 87, in setup
return distutils.core.setup(**attrs)
File "/Users/ashishgoyal/gitrepos/pact-python/venv_pact/lib/python3.9/site-packages/setuptools/_distutils/core.py", line 148, in setup
return run_commands(dist)
File "/Users/ashishgoyal/gitrepos/pact-python/venv_pact/lib/python3.9/site-packages/setuptools/_distutils/core.py", line 163, in run_commands
dist.run_commands()
File "/Users/ashishgoyal/gitrepos/pact-python/venv_pact/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 967, in run_commands
self.run_command(cmd)
File "/Users/ashishgoyal/gitrepos/pact-python/venv_pact/lib/python3.9/site-packages/setuptools/dist.py", line 1214, in run_command
super().run_command(command)
File "/Users/ashishgoyal/gitrepos/pact-python/venv_pact/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 986, in run_command
cmd_obj.run()
File "/Users/ashishgoyal/gitrepos/pact-python/setup.py", line 64, in run
install_ruby_app(package_bin_path, download_bin_path=None)
File "/Users/ashishgoyal/gitrepos/pact-python/setup.py", line 118, in install_ruby_app
raise RuntimeError('Could not find {} binary.'.format(path))
RuntimeError: Could not find /Users/ashishgoyal/gitrepos/pact-python/pact/bin/pact-1.88.83-osx.tar.gz binary.
Yousaf Nabi (pactflow.io)
json
05/19/2022, 8:49 PMjson
05/19/2022, 9:02 PMPooja Kunder
06/01/2022, 2:53 AMjson
06/16/2022, 3:01 PM./tests
directory I added a pact_provider
directory to projects which are pact providers and a pact_consumer
directory to projects that are pact consumers, with the idea being that the pytest tests which generate the contract live inside the pact_consumer
directory and the start-up logic for running the server in pact-verification mode lives in pact_provider
. (As best as I can tell, FastAPI needs a separate starting point to run the provider server in "pact-mode" because it has to add an extra router to define the "/_pact/provider_states"
endpoint, via this example).
We use poetry to manage dependencies and run the code, so in our pyproject.toml
alongside the start = "<app_name>.run:start"
script, I'm defining start_pact_verifier = "tests.pact_provider.setup:run"
. So in order to implement this solution, a developer has to add:
• the start_pact_verifier
script line to their pyproject.toml
• the ./tests/pact_provider/setup.py
file with a run method which imports the main application's FastAPI
instance and adds the pact states router to it
• the new pact states router itself, including the mapping of state strings to setup functions
• plus the setup functions themselves
It just seems like a lot to ask a developer to understand, and I was wondering if anyone had any tips to simplify it. Is there a way I could maybe utilize an internal poetry library to hide a lot of this boiler-plate away from the developer trying to implement this? Or maybe just a better design pattern I could be taking advantage of? My architect recommended moving the run
function to the <app_name>/run.py
module, but that seems like a pretty small step.