diff --git a/src/publisher.spec.ts b/src/publisher.spec.ts index bb6f86c9..099c2c76 100644 --- a/src/publisher.spec.ts +++ b/src/publisher.spec.ts @@ -105,4 +105,32 @@ describe('Publish Spec', () => { expect(p.publish).to.be.a('function'); }); }); + + context('when a bearer token is provided', () => { + context("and specifies a username or password", () => { + it('should fail with an error', () => { + expect(() => + publisherFactory({ + pactBroker: 'http://localhost', + pactFilesOrDirs: [relativePath], + consumerVersion: '1.0.0', + pactBrokerToken: "1234", + pactBrokerUsername: "username", + pactBrokerPassword: "5678", + }) + ).to.throw(Error) + }); + + }); + it('should not fail', () => { + const p = publisherFactory({ + pactBroker: 'http://localhost', + pactFilesOrDirs: [pactFile], + consumerVersion: '1.0.0', + pactBrokerToken: "1234" + }); + expect(p).to.be.ok; + expect(p.publish).to.be.a('function'); + }); + }); }); diff --git a/src/publisher.ts b/src/publisher.ts index 9db2bc92..071a6a56 100644 --- a/src/publisher.ts +++ b/src/publisher.ts @@ -86,6 +86,12 @@ export class Publisher { ); } + if (options.pactBrokerToken && (options.pactBrokerUsername || options.pactBrokerPassword)) { + throw new Error( + 'Must provide pactBrokerToken or pactBrokerUsername/pactBrokerPassword but not both.', + ); + } + this.options = options; } diff --git a/src/verifier.spec.ts b/src/verifier.spec.ts index 573803ee..35722b32 100644 --- a/src/verifier.spec.ts +++ b/src/verifier.spec.ts @@ -318,4 +318,29 @@ describe('Verifier Spec', () => { ).to.not.throw(Error); }); }); + + context('when using a bearer token', () => { + context('and specifies a username or password', () => { + it('should fail with an error', () => { + expect(() => + verifierFactory({ + providerBaseUrl: 'http://localhost', + pactUrls: ['http://idontexist'], + pactBrokerToken: "1234", + pactBrokerUsername: "username", + pactBrokerPassword: "5678", + }), + ).to.throw(Error); + }); + }); + it('should not fail', () => { + const v = verifierFactory({ + providerBaseUrl: 'http://localhost', + pactUrls: ['http://idontexist'], + pactBrokerToken: "1234", + }) + + expect(v.options.pactBrokerToken).to.eq("1234"); + }); + }); }); diff --git a/src/verifier.ts b/src/verifier.ts index 40abd7ec..3c4bf879 100644 --- a/src/verifier.ts +++ b/src/verifier.ts @@ -121,6 +121,12 @@ export class Verifier { checkTypes.assert.string(options.pactBrokerPassword); } + if (options.pactBrokerToken && (options.pactBrokerUsername || options.pactBrokerPassword)) { + throw new Error( + 'Must provide pactBrokerToken or pactBrokerUsername/pactBrokerPassword but not both.', + ); + } + if (options.pactBrokerUrl) { checkTypes.assert.string(options.pactBrokerUrl); }