fix/generate code auth header validation (#2490)

* geenrate code for request to include collection auth headers only if request auth is of type inherit

* validations
This commit is contained in:
lohit 2024-06-21 10:44:24 +05:30 committed by GitHub
parent 1e2b07dead
commit 929d2b5299
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 5 deletions

View File

@ -1,12 +1,12 @@
import get from 'lodash/get';
export const getAuthHeaders = (collectionRootAuth, requestAuth) => {
const auth = collectionRootAuth && ['inherit', 'none'].includes(requestAuth.mode) ? collectionRootAuth : requestAuth;
const auth = collectionRootAuth && ['inherit'].includes(requestAuth?.mode) ? collectionRootAuth : requestAuth;
switch (auth.mode) {
case 'basic':
const username = get(auth, 'basic.username');
const password = get(auth, 'basic.password');
const username = get(auth, 'basic.username', '');
const password = get(auth, 'basic.password', '');
const basicToken = Buffer.from(`${username}:${password}`).toString('base64');
return [
@ -21,7 +21,7 @@ export const getAuthHeaders = (collectionRootAuth, requestAuth) => {
{
enabled: true,
name: 'Authorization',
value: `Bearer ${get(auth, 'bearer.token')}`
value: `Bearer ${get(auth, 'bearer.token', '')}`
}
];
default:

View File

@ -162,7 +162,7 @@ const prepareRequest = (request, collectionRoot, collectionPath) => {
method: request.method,
url,
headers,
pathParams: request.params.filter((param) => param.type === 'path'),
pathParams: request?.params?.filter((param) => param.type === 'path'),
responseType: 'arraybuffer'
};