Merge pull request #4886 from sanish-bruno/fix/bearer-undefined

fix: handle undefined bearer token to send an empty string instead
This commit is contained in:
lohit
2025-06-14 21:50:08 +05:30
committed by GitHub
4 changed files with 32 additions and 5 deletions

View File

@@ -47,7 +47,7 @@ const prepareRequest = (item = {}, collection = {}) => {
}
if (collectionAuth.mode === 'bearer') {
axiosRequest.headers['Authorization'] = `Bearer ${get(collectionAuth, 'bearer.token')}`;
axiosRequest.headers['Authorization'] = `Bearer ${get(collectionAuth, 'bearer.token', '')}`;
}
if (collectionAuth.mode === 'apikey') {
@@ -174,7 +174,7 @@ const prepareRequest = (item = {}, collection = {}) => {
}
if (request.auth.mode === 'bearer') {
axiosRequest.headers['Authorization'] = `Bearer ${get(request, 'auth.bearer.token')}`;
axiosRequest.headers['Authorization'] = `Bearer ${get(request, 'auth.bearer.token', '')}`;
}
if (request.auth.mode === 'wsse') {

View File

@@ -27,7 +27,7 @@ const setAuthHeaders = (axiosRequest, request, collectionRoot) => {
};
break;
case 'bearer':
axiosRequest.headers['Authorization'] = `Bearer ${get(collectionAuth, 'bearer.token')}`;
axiosRequest.headers['Authorization'] = `Bearer ${get(collectionAuth, 'bearer.token', '')}`;
break;
case 'digest':
axiosRequest.digestConfig = {
@@ -152,7 +152,7 @@ const setAuthHeaders = (axiosRequest, request, collectionRoot) => {
};
break;
case 'bearer':
axiosRequest.headers['Authorization'] = `Bearer ${get(request, 'auth.bearer.token')}`;
axiosRequest.headers['Authorization'] = `Bearer ${get(request, 'auth.bearer.token', '')}`;
break;
case 'digest':
axiosRequest.digestConfig = {

View File

@@ -0,0 +1,27 @@
meta {
name: Bearer Auth undefined
type: http
seq: 2
}
get {
url: {{host}}/api/auth/bearer/protected
body: none
auth: bearer
}
headers {
Authorization: Bearer {{bearer_auth_token}}
}
assert {
res.body.message: eq Unauthorized
res.status: eq 401
}
tests {
test("selected auth overrides Authorization header always", function() {
const authHeader = req.getHeader("Authorization")
expect(authHeader).to.eql("Bearer ")
})
}

View File

@@ -11,7 +11,7 @@ get {
}
headers {
Authorization: Bearer your_secret_token
Authorization: Bearer {{bearer_auth_token}}
}
vars:pre-request {