Skip to content

Commit

Permalink
fix: replace basic auth pact broker with bearer token
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Nov 14, 2024
1 parent b238fd0 commit 0c1af06
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 61 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 1 addition & 10 deletions examples/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions examples/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 6 additions & 7 deletions examples/e2e/test/provider.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -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://<your broker>.pactflow.io/settings/api-tokens
// pactBrokerToken: "<insert your token here"
pactBrokerToken: process.env.PACT_BROKER_TOKEN,

publishVerificationResult: true,
// Your version numbers need to be unique for every different version of your provider
// see https://docs.pact.io/getting_started/versioning_in_the_pact_broker/ for details.
Expand Down
2 changes: 1 addition & 1 deletion examples/graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"test": "npm run clean && 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": "nyc --reporter=text-summary mocha src/consumer.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",
"test:provider": "nyc --reporter=text-summary mocha -t 30000 src/provider.spec.ts"
},
"keywords": [
Expand Down
13 changes: 8 additions & 5 deletions examples/graphql/src/provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ describe('Pact Verification', () => {
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://<your broker>.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
Expand Down
2 changes: 1 addition & 1 deletion examples/jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion examples/messages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 8 additions & 5 deletions examples/messages/provider/message-provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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://<your broker>.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
Expand Down
8 changes: 4 additions & 4 deletions examples/serverless/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
```
Expand Down
6 changes: 3 additions & 3 deletions examples/serverless/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 8 additions & 5 deletions examples/serverless/provider/message-provider.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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://<your broker>.pactflow.io/settings/api-tokens
pactBrokerToken: process.env.PACT_BROKER_TOKEN,
publishVerificationResult: true,

providerVersionBranch: process.env.GIT_BRANCH || 'master',
Expand Down
10 changes: 1 addition & 9 deletions examples/v3/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions examples/v3/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 7 additions & 4 deletions examples/v3/e2e/test/provider.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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://<your broker>.pactflow.io/settings/api-tokens
pactBrokerToken: process.env.PACT_BROKER_TOKEN,
publishVerificationResult: true,
providerVersion: '1.0.0',
})
Expand Down

0 comments on commit 0c1af06

Please sign in to comment.