API Key Auth not correctly being assigned to header
millerdrew opened this issue · 5 comments
We have the following logic in lib\auth\apikey.js
const aid = require('../aid');
class ApiKeyAuth {
constructor(settings) {
const params = settings.parameters();
const key = params.get('key');
const value = aid.evalString(params.get('value'));
if (params.get('in') === 'header') {
this.logic = '' + `config.headers['${key}'] = ${value};`;
} else {
this.logic = '' + `config.options['${key}'] = ${value};`;
}
}
}
module.exports = ApiKeyAuth;
I have my Postman collection auth defined like this:
A snippet from the json output from my exported collection:
"auth": {
"type": "apikey",
"apikey": [
{
"key": "value",
"value": "{{Authorization}}",
"type": "string"
},
{
"key": "key",
"value": "Authorization",
"type": "string"
}
]
},
It appears to be incorrectly using config.options instead of config.headers so my auth to fail when using the generated k6s output. If I manually change that part the auth works.
Perhaps something has changed in the output from Postman that's causing the line if (params.get('in') === 'header') {
to not work as expected?
Here is my Postman version:
I notice in the test (test\material\2\apikey.json
) we're expecting this:
{
"info": {
"_postman_id": "3cb6376b-535c-4c2f-a5d6-7bf193bcc6b9",
"name": "Request",
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
},
"item": [
{
"name": "TestRequest",
"request": {
"auth": {
"type": "apikey",
"apikey": {
"key": "Authorization",
"value": "secretApiKey",
"in": "header"
}
},
"method": "GET",
"header": [],
"body": {
"mode": "raw",
"raw": ""
},
"url": "example.com"
},
"response": []
}
]
}
hi @millerdrew
Thanks for providing the details for what seems to be a bug.
Would it be possible to share your Postman collection or a simplified format of the collection?
That way we can try to reproduce the issue.
@thim81 Sure. Here's a simplified export:
API Example.postman_collection.zip
The major difference from what's in the test appears to be this line is missing:
"in": "header"
instead there's only key, value, and type
thanks for the response appreciate your help! let me know if anything else would be useful
hi @millerdrew
Is this issue still happening?
hi @millerdrew
I tried to reproduce your case, but I'm not able to fully understand your issue.
What you would expect?
This is the converted result:
group("Workflow", function() {
postman[Request]({
name: "dosomething",
id: "c36db191-2918-4b63-af77-66300146301e",
method: "POST",
address: "{{BaseUrl}}/SomeAPI/dosomething",
post(response) {
pm.test("Status code is 200", function() {
pm.response.to.have.status(200);
});
},
auth(config, Var) {
config.options["Authorization"] = `${pm[Var]("Authorization")}`;
}
});
});