Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
Should still return header if either user or password is set for basic
Browse files Browse the repository at this point in the history
  • Loading branch information
Dom Harrington committed Sep 8, 2017
1 parent 02debab commit 1483691
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions packages/api-explorer-ui/__tests__/lib/configure-security.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@ describe('configure-security', () => {
components: { securitySchemes: { test: { type: 'basic' } } },
}, values, { test: {} })).toEqual(false);
});

test('should return with a header if user or password are not blank', () => {
const user = 'user';
const values = {
auth: { test: { user, password: '' } },
};

expect(configureSecurity({
components: { securitySchemes: { test: { type: 'basic' } } },
}, values, { test: {} })).toEqual({
type: 'headers',
value: {
name: 'Authorization',
value: `Basic ${new Buffer(`${user}:`).toString('base64')}`,
},
});
});
});

describe('type=oauth2', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/api-explorer-ui/src/lib/configure-security.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = function configureSecurity(oas, values, scheme) {

if (security.type === 'basic') {
// Return with no header if user and password are blank
if (!(values.auth[key].user && values.auth[key].password)) return false;
if (!values.auth[key].user && !values.auth[key].password) return false;

return harValue('headers', {
name: 'Authorization',
Expand Down

0 comments on commit 1483691

Please sign in to comment.