support basic auth with just pass token (#4063)

* feat: support basic auth with token

* refactor: change param name
This commit is contained in:
Caleb Cartwright
2019-09-22 11:14:01 -05:00
committed by GitHub
parent 7e0ae39a20
commit d18d4218fc
3 changed files with 25 additions and 3 deletions

View File

@@ -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
}

View File

@@ -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',
})
})
})
})

View File

@@ -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 }) {