support basic auth with just pass token (#4063)
* feat: support basic auth with token * refactor: change param name
This commit is contained in:
@@ -1,14 +1,26 @@
|
||||
'use strict'
|
||||
|
||||
class AuthHelper {
|
||||
constructor({ userKey, passKey, isRequired = false }, privateConfig) {
|
||||
constructor(
|
||||
{
|
||||
userKey,
|
||||
passKey,
|
||||
isRequired = false,
|
||||
defaultToEmptyStringForUser = false,
|
||||
},
|
||||
privateConfig
|
||||
) {
|
||||
if (!userKey && !passKey) {
|
||||
throw Error('Expected userKey or passKey to be set')
|
||||
}
|
||||
|
||||
this._userKey = userKey
|
||||
this._passKey = passKey
|
||||
this.user = userKey ? privateConfig[userKey] : undefined
|
||||
if (userKey) {
|
||||
this.user = privateConfig[userKey]
|
||||
} else {
|
||||
this.user = defaultToEmptyStringForUser ? '' : undefined
|
||||
}
|
||||
this.pass = passKey ? privateConfig[passKey] : undefined
|
||||
this.isRequired = isRequired
|
||||
}
|
||||
|
||||
@@ -91,6 +91,13 @@ describe('AuthHelper', function() {
|
||||
given({ userKey: 'myci_user', passKey: 'myci_pass' }, {}).expect(
|
||||
undefined
|
||||
)
|
||||
given(
|
||||
{ passKey: 'myci_pass', defaultToEmptyStringForUser: true },
|
||||
{ myci_pass: 'abc123' }
|
||||
).expect({
|
||||
user: '',
|
||||
pass: 'abc123',
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -16,7 +16,10 @@ const latestBuildSchema = Joi.object({
|
||||
|
||||
module.exports = class AzureDevOpsBase extends BaseJsonService {
|
||||
static get auth() {
|
||||
return { passKey: 'azure_devops_token' }
|
||||
return {
|
||||
passKey: 'azure_devops_token',
|
||||
defaultToEmptyStringForUser: true,
|
||||
}
|
||||
}
|
||||
|
||||
async fetch({ url, options, schema, errorMessages }) {
|
||||
|
||||
Reference in New Issue
Block a user