* allow user to set dockerhub credentials * add withJwtAuth function to AuthHelper * use withJwtAuth in DockerHub badges * add unit tests for JWT auth * use auth when calling docker cloud * refactor and assert fetch helpers call withJwtAuth * store token for a max duration (defaults to 1 hour) * tangent: update test example
24 lines
651 B
JavaScript
24 lines
651 B
JavaScript
import sinon from 'sinon'
|
|
import { expect } from 'chai'
|
|
import { fetchBuild } from './docker-cloud-common-fetch.js'
|
|
|
|
describe('fetchBuild', function () {
|
|
it('invokes withJwtAuth', async function () {
|
|
const serviceInstance = {
|
|
_requestJson: sinon.stub().resolves('fake-response'),
|
|
authHelper: {
|
|
withJwtAuth: sinon.stub(),
|
|
},
|
|
}
|
|
|
|
const resp = await fetchBuild(serviceInstance, {
|
|
user: 'user',
|
|
repo: 'repo',
|
|
})
|
|
|
|
expect(serviceInstance.authHelper.withJwtAuth.calledOnce).to.be.true
|
|
expect(serviceInstance._requestJson.calledOnce).to.be.true
|
|
expect(resp).to.equal('fake-response')
|
|
})
|
|
})
|