Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: get auth token correct when login with sso #50

Merged
merged 1 commit into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const getAuth = (uri, opts = {}) => {
if (forceAuth && !regKey) {
return new Auth({
scopeAuthKey: null,
token: forceAuth._authToken,
token: forceAuth._authToken || forceAuth.token,
username: forceAuth.username,
password: forceAuth._password || forceAuth.password,
auth: forceAuth._auth || forceAuth.auth,
Expand Down
30 changes: 30 additions & 0 deletions test/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,36 @@ t.test('forceAuth', t => {
.then(res => t.equal(res, 'success', 'used forced auth details'))
})

t.test('forceAuth token', t => {
const config = {
registry: 'https://my.custom.registry/here/',
token: 'deadbeef',
'always-auth': false,
'//my.custom.registry/here/:_authToken': 'c0ffee',
'//my.custom.registry/here/:token': 'nope',
forceAuth: {
token: 'cafebad',
},
}
t.same(getAuth(config.registry, config), {
scopeAuthKey: null,
isBasicAuth: false,
token: 'cafebad',
auth: null,
}, 'correct forceAuth token picked out')

const opts = Object.assign({}, OPTS, config)
tnock(t, opts.registry)
.matchHeader('authorization', auth => {
t.equal(auth[0], 'Bearer cafebad', 'got correct bearer token')
return auth[0] === 'Bearer cafebad'
})
.get('/hello')
.reply(200, '"success"')
return fetch.json('/hello', opts)
.then(res => t.equal(res, 'success', 'token forceAuth succeeded'))
})

t.test('_auth auth', t => {
const config = {
registry: 'https://my.custom.registry/here/',
Expand Down