From 0c1af06f664f73e9014b23dc6d58e97efebdfb7d Mon Sep 17 00:00:00 2001 From: mefellows Date: Thu, 14 Nov 2024 16:20:35 +1100 Subject: [PATCH] fix: replace basic auth pact broker with bearer token --- .github/workflows/build-and-test.yml | 2 ++ .github/workflows/publish.yml | 2 ++ examples/e2e/README.md | 11 +---------- examples/e2e/package.json | 6 +++--- examples/e2e/test/provider.spec.js | 13 ++++++------- examples/graphql/package.json | 2 +- examples/graphql/src/provider.spec.ts | 13 ++++++++----- examples/jest/package.json | 2 +- examples/messages/package.json | 2 +- examples/messages/provider/message-provider.spec.ts | 13 ++++++++----- examples/serverless/README.md | 8 ++++---- examples/serverless/package.json | 6 +++--- .../serverless/provider/message-provider.spec.js | 13 ++++++++----- examples/v3/e2e/README.md | 10 +--------- examples/v3/e2e/package.json | 6 +++--- examples/v3/e2e/test/provider.spec.js | 11 +++++++---- 16 files changed, 59 insertions(+), 61 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index f8ba81e13..1792cead0 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -11,6 +11,8 @@ env: GIT_REF: ${{ github.ref }} GIT_BRANCH: ${{ github.head_ref || github.ref_name }} LOG_LEVEL: info + PACT_BROKER_BASE_URL: ${{ secrets.PACT_BROKER_BASE_URL }} + PACT_BROKER_TOKEN: ${{ secrets.PACT_BROKER_TOKEN }} jobs: build-and-test: diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 669cd1bc5..2e5ffcfb9 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -10,6 +10,8 @@ env: GIT_COMMIT: ${{ github.sha }} GIT_REF: ${{ github.ref }} LOG_LEVEL: info + PACT_BROKER_BASE_URL: ${{ secrets.PACT_BROKER_BASE_URL }} + PACT_BROKER_TOKEN: ${{ secrets.PACT_BROKER_TOKEN }} jobs: release: diff --git a/examples/e2e/README.md b/examples/e2e/README.md index 06522171d..bb29cf74a 100644 --- a/examples/e2e/README.md +++ b/examples/e2e/README.md @@ -109,13 +109,4 @@ curl -X GET http://localhost:8080/suggestions/1 ## Viewing contracts with the Pact Broker -A test [Pact Boker](https://github.com/pact-foundation/pact_broker) is running at https://test.pactflow.io - very kindly provided by PactFlow: - -- Username: `dXfltyFMgNOFZAxr8io9wJ37iUpY42M` -- Password: `O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1` - -Or use the API: - -``` -curl -v -u 'dXfltyFMgNOFZAxr8io9wJ37iUpY42M:O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1' https://test.pactflow.io -``` +A test [Pact Boker](https://github.com/pact-foundation/pact_broker) is running at https://testdemo.pactflow.io/login?code=88f7810e-c7dc-493b-9c3d-7849952f1d9a diff --git a/examples/e2e/package.json b/examples/e2e/package.json index f4b383c97..49e4d2b58 100644 --- a/examples/e2e/package.json +++ b/examples/e2e/package.json @@ -6,11 +6,11 @@ "test": "npm run test:consumer && npm run test:publish && npm run test:provider", "test:no:publish": "npm run test:consumer && npm run test:provider", "test:consumer": "mocha test/consumer.spec.js", - "test:publish": "pact-broker publish ./pacts --consumer-app-version=\"$(npx absolute-version)\" --auto-detect-version-properties --broker-base-url=https://test.pactflow.io --broker-username dXfltyFMgNOFZAxr8io9wJ37iUpY42M --broker-password O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1", + "test:publish": "pact-broker publish ./pacts --consumer-app-version=\"$(npx absolute-version)\" --auto-detect-version-properties --broker-base-url=https://testdemo.pactflow.io", "test:provider": "mocha test/provider.spec.js", "can-i-deploy": "npm run can-i-deploy:consumer && npm run can-i-deploy:provider", - "can-i-deploy:consumer": "pact-broker can-i-deploy --pacticipant 'Matching Service' --latest --broker-base-url https://test.pactflow.io --broker-username dXfltyFMgNOFZAxr8io9wJ37iUpY42M --broker-password O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1", - "can-i-deploy:provider": "pact-broker can-i-deploy --pacticipant 'Animal Profile Service' --latest --broker-base-url https://test.pactflow.io --broker-username dXfltyFMgNOFZAxr8io9wJ37iUpY42M --broker-password O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1", + "can-i-deploy:consumer": "pact-broker can-i-deploy --pacticipant 'Matching Service' --latest --broker-base-url https://testdemo.pactflow.io", + "can-i-deploy:provider": "pact-broker can-i-deploy --pacticipant 'Animal Profile Service' --latest --broker-base-url https://testdemo.pactflow.io", "api": "concurrently 'npm run provider' 'npm run consumer'", "consumer": "node ./consumerService.js", "provider": "node ./providerService.js" diff --git a/examples/e2e/test/provider.spec.js b/examples/e2e/test/provider.spec.js index 4bb04bdf4..892b040cc 100644 --- a/examples/e2e/test/provider.spec.js +++ b/examples/e2e/test/provider.spec.js @@ -60,7 +60,7 @@ describe('Pact Verification', () => { }, // Fetch pacts from broker - pactBrokerUrl: 'https://test.pactflow.io/', + pactBrokerUrl: process.env.PACT_BROKER_BASE_URL, // Fetch from broker with given tags // consumerVersionTags: ['master', 'test', 'prod', 'feat/v3.0.0'], @@ -96,14 +96,13 @@ describe('Pact Verification', () => { // ], // If you're using the open source Pact Broker, use the username/password option as per below - pactBrokerUsername: - process.env.PACT_BROKER_USERNAME || 'dXfltyFMgNOFZAxr8io9wJ37iUpY42M', - pactBrokerPassword: - process.env.PACT_BROKER_PASSWORD || 'O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1', - + // pactBrokerUsername: process.env.PACT_BROKER_USERNAME + // pactBrokerPassword: process.env.PACT_BROKER_PASSWORD + // // if you're using a PactFlow broker, you must authenticate using the bearer token option // You can obtain the token from https://.pactflow.io/settings/api-tokens - // pactBrokerToken: " { const opts = { // Local pacts // pactUrls: [path.resolve(process.cwd(), "./pacts/graphqlconsumer-graphqlprovider.json")], - pactBrokerUrl: 'https://test.pactflow.io/', - pactBrokerUsername: - process.env.PACT_BROKER_USERNAME || 'dXfltyFMgNOFZAxr8io9wJ37iUpY42M', - pactBrokerPassword: - process.env.PACT_BROKER_PASSWORD || 'O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1', + pactBrokerUrl: process.env.PACT_BROKER_BASE_URL, + // If you're using the open source Pact Broker, use the username/password option as per below + // pactBrokerUsername: process.env.PACT_BROKER_USERNAME + // pactBrokerPassword: process.env.PACT_BROKER_PASSWORD + // + // if you're using a PactFlow broker, you must authenticate using the bearer token option + // You can obtain the token from https://.pactflow.io/settings/api-tokens + pactBrokerToken: process.env.PACT_BROKER_TOKEN, provider: 'GraphQLProvider', providerBaseUrl: 'http://localhost:4000/graphql', // Your version numbers need to be unique for every different version of your provider diff --git a/examples/jest/package.json b/examples/jest/package.json index 2b5703406..7691f4159 100644 --- a/examples/jest/package.json +++ b/examples/jest/package.json @@ -5,7 +5,7 @@ "main": "index.js", "scripts": { "test": "rimraf pact && jest __tests__/ --runInBand", - "test:publish": "pact-broker publish pact/pacts --consumer-app-version=\"$(npx absolute-version)\" --auto-detect-version-properties --broker-base-url=https://test.pactflow.io --broker-username dXfltyFMgNOFZAxr8io9wJ37iUpY42M --broker-password O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1" + "test:publish": "pact-broker publish pact/pacts --consumer-app-version=\"$(npx absolute-version)\" --auto-detect-version-properties --broker-base-url=https://testdemo.pactflow.io" }, "license": "MIT", "jest": { diff --git a/examples/messages/package.json b/examples/messages/package.json index adbb0282d..4c0096792 100644 --- a/examples/messages/package.json +++ b/examples/messages/package.json @@ -10,7 +10,7 @@ "test:no:publish": "npm run test:consumer && npm run test:provider", "test:consumer": "mocha consumer/*.spec.ts", "test:provider": "mocha -t 20000 provider/*.spec.ts", - "test:publish": "pact-broker publish ./pacts --consumer-app-version=\"$(npx absolute-version)\" --auto-detect-version-properties --broker-base-url=https://test.pactflow.io --broker-username dXfltyFMgNOFZAxr8io9wJ37iUpY42M --broker-password O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1" + "test:publish": "pact-broker publish ./pacts --consumer-app-version=\"$(npx absolute-version)\" --auto-detect-version-properties --broker-base-url=https://testdemo.pactflow.io" }, "author": "", "license": "MIT", diff --git a/examples/messages/provider/message-provider.spec.ts b/examples/messages/provider/message-provider.spec.ts index 525b05a82..501602958 100644 --- a/examples/messages/provider/message-provider.spec.ts +++ b/examples/messages/provider/message-provider.spec.ts @@ -31,11 +31,14 @@ describe('Message provider tests', () => { // For local validation // pactUrls: [path.resolve(process.cwd(), "pacts", "myjsmessageconsumer-myjsmessageprovider.json")], // Broker validation - pactBrokerUrl: 'https://test.pactflow.io/', - pactBrokerUsername: - process.env.PACT_BROKER_USERNAME || 'dXfltyFMgNOFZAxr8io9wJ37iUpY42M', - pactBrokerPassword: - process.env.PACT_BROKER_PASSWORD || 'O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1', + pactBrokerUrl: process.env.PACT_BROKER_BASE_URL, + // If you're using the open source Pact Broker, use the username/password option as per below + // pactBrokerUsername: process.env.PACT_BROKER_USERNAME + // pactBrokerPassword: process.env.PACT_BROKER_PASSWORD + // + // if you're using a PactFlow broker, you must authenticate using the bearer token option + // You can obtain the token from https://.pactflow.io/settings/api-tokens + pactBrokerToken: process.env.PACT_BROKER_TOKEN, providerVersionBranch: process.env.GIT_BRANCH || 'master', // Find _all_ pacts that match the current provider branch diff --git a/examples/serverless/README.md b/examples/serverless/README.md index 2dee45d9e..aa74a811c 100644 --- a/examples/serverless/README.md +++ b/examples/serverless/README.md @@ -61,7 +61,7 @@ To use any of the commands below, ensure you have valid [AWS credentials](https: ### Pact Broker integration -[PactFlow](https://pactflow.io) have kindly provided a test broker for the Pact Foundation to use. Using the test broker, https://test.pactflow.io (user/pass: `dXfltyFMgNOFZAxr8io9wJ37iUpY42M` / `O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1`), we make use of the [`can-i-deploy` tool](https://github.com/pact-foundation/pact_broker/wiki/Provider-verification-results#querying) (available from the [Pact CLI suite](https://github.com/pact-foundation/pact-ruby-standalone/releases) but also bundled as part of `pact`), that ensures it is safe to deploy the consumer or provider before a releasing a change. +[PactFlow](https://pactflow.io) have kindly provided a test broker for the Pact Foundation to use. Using the test broker, https://test.pactflow.io (login: https://testdemo.pactflow.io/login?code=88f7810e-c7dc-493b-9c3d-7849952f1d9a), we make use of the [`can-i-deploy` tool](https://github.com/pact-foundation/pact_broker/wiki/Provider-verification-results#querying) (available from the [Pact CLI suite](https://github.com/pact-foundation/pact-ruby-standalone/releases) but also bundled as part of `pact`), that ensures it is safe to deploy the consumer or provider before a releasing a change. Whenever we create, change or verify a contract with Pact, the results are shared with the broker, which is then able to determine compatibility between components at any point in time. @@ -78,9 +78,9 @@ You will see something like: ```sh Computer says yes \o/ -CONSUMER | C.VERSION | PROVIDER | P.VERSION | SUCCESS? ----------------------|-----------|----------------------|-----------|--------- -SNSPactEventConsumer | 1.0.1 | SNSPactEventProvider | 1.0.0 | true +| CONSUMER | C.VERSION | PROVIDER | P.VERSION | SUCCESS? | +| -------------------- | --------- | -------------------- | --------- | -------- | +| SNSPactEventConsumer | 1.0.1 | SNSPactEventProvider | 1.0.0 | true | All verification results are published and successful ``` diff --git a/examples/serverless/package.json b/examples/serverless/package.json index 4d61d9931..347c96afa 100644 --- a/examples/serverless/package.json +++ b/examples/serverless/package.json @@ -9,10 +9,10 @@ "test:no:publish": "npm run test:consumer && npm run test:provider", "test:consumer": "mocha consumer/*.spec.js", "test:provider": "mocha -t 30000 provider/*.spec.js", - "test:publish": "pact-broker publish ./pacts --consumer-app-version=\"$(npx absolute-version)\" --auto-detect-version-properties --broker-base-url=https://test.pactflow.io --broker-username dXfltyFMgNOFZAxr8io9wJ37iUpY42M --broker-password O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1", + "test:publish": "pact-broker publish ./pacts --consumer-app-version=\"$(npx absolute-version)\" --auto-detect-version-properties --broker-base-url=https://testdemo.pactflow.io", "can-i-deploy": "npm run can-i-deploy:consumer && npm run can-i-deploy:provider", - "can-i-deploy:consumer": "$(find ../../ -name pact-broker | grep -e 'bin/pact-broker$' | head -n 1) can-i-deploy --pacticipant SNSPactEventConsumer --latest --broker-base-url https://test.pactflow.io --broker-username dXfltyFMgNOFZAxr8io9wJ37iUpY42M --broker-password O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1", - "can-i-deploy:provider": "$(find ../../ -name pact-broker | grep -e 'bin/pact-broker$' | head -n 1) can-i-deploy --pacticipant SNSPactEventProvider --latest --broker-base-url https://test.pactflow.io --broker-username dXfltyFMgNOFZAxr8io9wJ37iUpY42M --broker-password O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1", + "can-i-deploy:consumer": "$(find ../../ -name pact-broker | grep -e 'bin/pact-broker$' | head -n 1) can-i-deploy --pacticipant SNSPactEventConsumer --latest --broker-base-url https://testdemo.pactflow.io", + "can-i-deploy:provider": "$(find ../../ -name pact-broker | grep -e 'bin/pact-broker$' | head -n 1) can-i-deploy --pacticipant SNSPactEventProvider --latest --broker-base-url https://testdemo.pactflow.io", "create-stack": "serverless deploy --verbose", "deploy": "npm run deploy:consumer && npm run deploy:provider", "deploy:consumer": "npm run can-i-deploy && serverless deploy -f consumer", diff --git a/examples/serverless/provider/message-provider.spec.js b/examples/serverless/provider/message-provider.spec.js index bfcd35c0a..f38a5b80b 100644 --- a/examples/serverless/provider/message-provider.spec.js +++ b/examples/serverless/provider/message-provider.spec.js @@ -26,11 +26,14 @@ describe('Message provider tests', () => { // pactUrls: [path.resolve(process.cwd(), "pacts", "snspacteventconsumer-snspacteventprovider.json")], // Uncomment to use the broker - pactBrokerUrl: 'https://test.pactflow.io/', - pactBrokerUsername: - process.env.PACT_BROKER_USERNAME || 'dXfltyFMgNOFZAxr8io9wJ37iUpY42M', - pactBrokerPassword: - process.env.PACT_BROKER_PASSWORD || 'O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1', + pactBrokerUrl: process.env.PACT_BROKER_BASE_URL, + // If you're using the open source Pact Broker, use the username/password option as per below + // pactBrokerUsername: process.env.PACT_BROKER_USERNAME + // pactBrokerPassword: process.env.PACT_BROKER_PASSWORD + // + // if you're using a PactFlow broker, you must authenticate using the bearer token option + // You can obtain the token from https://.pactflow.io/settings/api-tokens + pactBrokerToken: process.env.PACT_BROKER_TOKEN, publishVerificationResult: true, providerVersionBranch: process.env.GIT_BRANCH || 'master', diff --git a/examples/v3/e2e/README.md b/examples/v3/e2e/README.md index 7f06985bb..161e61060 100644 --- a/examples/v3/e2e/README.md +++ b/examples/v3/e2e/README.md @@ -110,16 +110,8 @@ curl -X GET http://localhost:8080/suggestions/1 ## Viewing contracts with the Pact Broker -A test [Pact Broker](https://github.com/bethesque/pact_broker) is running at https://test.pactflow.io: +A test [Pact Broker](https://github.com/bethesque/pact_broker) is running at https://testdemo.pactflow.io/login?code=88f7810e-c7dc-493b-9c3d-7849952f1d9a -- Username: `dXfltyFMgNOFZAxr8io9wJ37iUpY42M` -- Password: `O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1` - -Or use the API: - -``` -curl -v -u 'dXfltyFMgNOFZAxr8io9wJ37iUpY42M:O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1' https://test.pactflow.io -``` ## Running with Vagrant diff --git a/examples/v3/e2e/package.json b/examples/v3/e2e/package.json index cfa1053c6..fcb0d65c3 100644 --- a/examples/v3/e2e/package.json +++ b/examples/v3/e2e/package.json @@ -6,11 +6,11 @@ "test": "npm run test:consumer && npm run test:publish && npm run test:provider", "test:no:publish": "npm run test:consumer && npm run test:provider", "test:consumer": "mocha --config=test/.mocharc.json test/consumer.spec.js", - "test:publish": "pact-broker publish ./pacts --consumer-app-version=\"$(npx absolute-version)\" --auto-detect-version-properties --broker-base-url=https://test.pactflow.io --broker-username dXfltyFMgNOFZAxr8io9wJ37iUpY42M --broker-password O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1", + "test:publish": "pact-broker publish ./pacts --consumer-app-version=\"$(npx absolute-version)\" --auto-detect-version-properties --broker-base-url=https://testdemo.pactflow.io", "test:provider": "mocha --config=test/.mocharc.json test/provider.spec.js", "can-i-deploy": "npm run can-i-deploy:consumer && npm run can-i-deploy:provider", - "can-i-deploy:consumer": "pact-broker can-i-deploy --pacticipant 'Matching Service' --latest --broker-base-url https://test.pactflow.io --broker-username dXfltyFMgNOFZAxr8io9wJ37iUpY42M --broker-password O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1", - "can-i-deploy:provider": "pact-broker can-i-deploy --pacticipant 'Animal Profile Service' --latest --broker-base-url https://test.pactflow.io --broker-username dXfltyFMgNOFZAxr8io9wJ37iUpY42M --broker-password O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1", + "can-i-deploy:consumer": "pact-broker can-i-deploy --pacticipant 'Matching Service' --latest --broker-base-url https://testdemo.pactflow.io", + "can-i-deploy:provider": "pact-broker can-i-deploy --pacticipant 'Animal Profile Service' --latest --broker-base-url https://testdemo.pactflow.io", "api": "concurrently 'npm run provider' 'npm run consumer'", "consumer": "node ./consumerService.js", "provider": "node ./providerService.js" diff --git a/examples/v3/e2e/test/provider.spec.js b/examples/v3/e2e/test/provider.spec.js index abc384096..6f785d893 100644 --- a/examples/v3/e2e/test/provider.spec.js +++ b/examples/v3/e2e/test/provider.spec.js @@ -97,10 +97,13 @@ describe('Pact Verification', () => { // ), // ], - pactBrokerUsername: - process.env.PACT_BROKER_USERNAME || 'dXfltyFMgNOFZAxr8io9wJ37iUpY42M', - pactBrokerPassword: - process.env.PACT_BROKER_PASSWORD || 'O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1', + // If you're using the open source Pact Broker, use the username/password option as per below + // pactBrokerUsername: process.env.PACT_BROKER_USERNAME + // pactBrokerPassword: process.env.PACT_BROKER_PASSWORD + // + // if you're using a PactFlow broker, you must authenticate using the bearer token option + // You can obtain the token from https://.pactflow.io/settings/api-tokens + pactBrokerToken: process.env.PACT_BROKER_TOKEN, publishVerificationResult: true, providerVersion: '1.0.0', })