Day 27 Authorisation test failing

When I submit my answer the “Authorisation added correctly” test is failing with “AssertionError: expected ‘header’ to equal ‘{{token}}’” and I can’t work out why.

Here is what I have for the authorisation of the folder and all the requests in the folder inherit from the parent. Please can anyone help?

When I look at the auth details in the response of the submit request I see.

                            "type": "apikey",
                            "apikey": [
                                {
                                    "key": "in",
                                    "value": "header",
                                    "type": "string"
                                },
                                {
                                    "key": "value",
                                    "value": "{{token}}",
                                    "type": "string"
                                },
                                {
                                    "key": "key",
                                    "value": "x-api-key",
                                    "type": "string"
                                }

And if I change the index from 0 to 1 in the test it passes pm.expect(newFlowFolder.auth.apikey[0].value).equals("{{token}}") - so have I done something wrong or has the auth information been formatted differently in the response?

1 Like

I think you just need to “get” the token first as what you have here is literally putting “{{token}}” as a string…

Try something like this (change depending on where your token variable is stored);

pm.collectionVariables.get("token")
pm.globals.get("token");
pm.environment.get("token");

So the full check would be something like this…

pm.test("Check token", () => {
pm.expect(newFlowFolder.auth.apikey[0].value).equals(pm.collectionVariables.get("token"));
});

For the second part,
Arrays start at 0, so if you set ‘expect’ to equal “{{token}}” for [0] then it would fail as [0] doesn’t have this set… But [1] does have {{token}} set… I’ve added comments here so you can see the structure;

"type":"apikey",
"apikey":[ //<--- array starts here

//This is 0
	{
		"key":"in",
		"value":"header",
		"type":"string"
	},
//This is 1
	{
		"key":"value",
		"value":"{{token}}",
		"type":"string"
	},
//This is 2
	{
		"key":"key",
		"value":"x-api-key",
		"type":"string"
	}
2 Likes

Thank you for your reply.

The {{token}} is a collection variable and when I hover over it in the authorization for the folder it is displayed ok so it should be getting the value of the variable OK, I believe.

The test that fails uses the array above that you have commented. Index 0 fails however if I change the test to index 1 it passes - that is why I am asking if something has changed in the array since the test was written as it looks like the test should be on index 1 item.

It is possible that the apikey array was changed to include the items that now live in index [0] (pushing your token check to index [1])… But you’d have to check with the API developer(s) to confirm… Or go through test run logs / check history etc.

In postman on the left you might be able to use the “history” tab to go back and look at what the response used to be…

2 Likes

Thank you. I’ll investigate.

Hello! I would like to ask you: did you find a solution?I have the same mistake, since newFlowFolder.auth.apikey[0].value = ‘x-api-key’

@elizavetaaantipina Can you share a link to your collection? You can either make your workspace public (as you will need to do it eventually when submitting) or follow the steps outlined here:

@arlemi Postman

@arlem

Isn’t this the same issue that the Galaxy 101 course had (which recently got fixed)?

Caused by the change from the old method of submitting through a public collection vs the new method of using “x-api-key” in the header.

The new method goes through a different API and is returning slightly different JSON to the old API.

The following should only have one entry but instead its returning two.

"id": "7164d605-4eb0-4e51-bf9b-redacted",
"auth": {
    "type": "apikey",
    "apikey": [
        {
            "key": "key",
            "value": "x-api-key",
            "type": "string"
        },
        {
            "key": "value",
            "value": "{{token}}",
            "type": "string"
        }
    ]
},

I can see that the Galaxy 101 test got changed quite significantly, so it just checks that the property exists instead of the full path to the item and value (which got broke because of the same array issue).

pm.expect(authObj).to.have.property('apikey');

Looks like the test need to be updated.

Indeed that’s what it was @michaelderekjones! :sweat_smile:

@elizavetaaantipina I’ve updated the tests on our end so when you’re finished with your 30 days feel free to submit here and the day 27 shouldn’t have any issues.

We’ll get the tests in the collection updated later today.

1 Like

@arlem @michaelderekjones thank you! I’ve got a badge :slight_smile:

1 Like