* 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
21 lines
589 B
JavaScript
21 lines
589 B
JavaScript
import sinon from 'sinon'
|
|
import { expect } from 'chai'
|
|
import { fetch } from './docker-hub-common-fetch.js'
|
|
|
|
describe('fetch', function () {
|
|
it('invokes withJwtAuth', async function () {
|
|
const serviceInstance = {
|
|
_requestJson: sinon.stub().resolves('fake-response'),
|
|
authHelper: {
|
|
withJwtAuth: sinon.stub(),
|
|
},
|
|
}
|
|
|
|
const resp = await fetch(serviceInstance, {})
|
|
|
|
expect(serviceInstance.authHelper.withJwtAuth.calledOnce).to.be.true
|
|
expect(serviceInstance._requestJson.calledOnce).to.be.true
|
|
expect(resp).to.equal('fake-response')
|
|
})
|
|
})
|