apideck-libraries/postman-to-k6

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:

image

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:

image

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