Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requests wrongly reusing headers from previous requests? #98

Closed
kuikiker opened this issue Feb 6, 2023 · 14 comments
Closed

Requests wrongly reusing headers from previous requests? #98

kuikiker opened this issue Feb 6, 2023 · 14 comments
Assignees
Labels
bug Something isn't working

Comments

@kuikiker
Copy link

kuikiker commented Feb 6, 2023

I converted a postman collection to K6 but I cannot properly run it. After analysing the HTTP requests with Fiddler I noticed that some requests are wrongly reusing headers from previous requests.
For instance:

  1. Request to /login (user/pass)-> OK (no Content-Type is specified so the default and correct application/x-www-form-urlencoded value is sent).
  2. Request to /endpoint1 using an Authorization bearer header obtained from the previous request. -> OK
  3. Another request to /login (which is a verbatim copy of the first request) -> FAIL, due to wrong headers (Content-Type: application/json & Authorization: Bearer xxxxxxxx) that seems to be coming from the previous request to /endpoint1

Is there something I can do to avoid this behaviour?
I have tried to manually add the Content-Type: application/x-www-form-urlencoded header to the /login requests but the second request to the /login still fails due to the incorrect Authorization: bearer xxxxxxxx header, even though a 'basic' auth is defined for these requests.

Thanks

@thim81
Copy link
Collaborator

thim81 commented Feb 7, 2023

hi @kuikiker

A lot of these things you mentioned often are linked to the Postman collection.
Would it be possible to share the Postman collection (with fake credentials), so we can see what happens in the Postman collection and what K6 scripts are generated.

@kuikiker
Copy link
Author

kuikiker commented Feb 7, 2023

Hi @thim81 ,
I have left the bare minimum of my Postman collection; using fake credentials and only leaving the requests until the second try to /login fails (wrong Content-Type & Authorization headers)

Find attached the Postman collection and the generated K6 script (where I only commented the setTimeout function which is not recognized).

postmanToK6.zip

@thim81
Copy link
Collaborator

thim81 commented Mar 21, 2023

hi @kuikiker
I havent gotten around to look into this, apologies. I hope to find some time in the coming weeks.

@thim81 thim81 self-assigned this Mar 21, 2023
@furiousdog
Copy link

I have the same problem with X-Client-Id header in my scenario. It might only be fixed if I set the value to null.

@thim81 thim81 added the Investigate Needs more investigation, before next steps can be defined. label Jul 11, 2024
@thim81
Copy link
Collaborator

thim81 commented Jul 11, 2024

hi @kuikiker @furiousdog

Is this still happening?

@titanzx
Copy link

titanzx commented Jul 30, 2024

hi @kuikiker @furiousdog

Is this still happening?

Yes it is

@thim81
Copy link
Collaborator

thim81 commented Jul 30, 2024

hi @titanzx

We tried to reproduce it with the sample provided but it looked OK.

Do you have a simple example that you can share, that we can use for reproducing it?
It would be helpful to have a simple Postman collection, the postman-to-k6 settings and the expected, correct output.

@titanzx
Copy link

titanzx commented Jul 30, 2024

hi @titanzx

We tried to reproduce it with the sample provided but it looked OK.

Do you have a simple example that you can share, that we can use for reproducing it? It would be helpful to have a simple Postman collection, the postman-to-k6 settings and the expected, correct output.

Postman Collection
image

K6 Script

  group("Block3", function() {
    group("KYC_PDPA", function() {
      postman[Request]({
        name: "KYC",
        id: "b7bbf1c8-650a-42e3-a400-01a50c8a7fc7",
        method: "GET",
        address: "{{https}}{{host}}{{url_kyc}}",
        headers: {
          "X-Correlation-Id": "{{$randomUUID}}",
          TimeStamp: "{{timestamp}}",
          "Content-Signature": "{{signature_key}}"
        },
        pre() {
        },
        post(response) {
          var json = pm.response.json();

          pm.test("Message should be success", function() {
            pm.expect(json.status.message).to.eql("success");
          });

          pm.test("Status code is 200", function() {
            pm.expect(pm.response.code).to.eql(200);
          });
        },
        auth(config, Var) {
          config.headers.Authorization = `Bearer ${pm[Var]("access_token")}`;
        }
      });

      postman[Request]({
        name: "PDPA",
        id: "6b1a5943-3e7a-4b28-9296-438f62f2e9ec",
        method: "GET",
        address: "{{https}}{{host}}{{url_pdpa}}",
        headers: {
          "X-Correlation-Id": "{{$randomUUID}}",
          TimeStamp: "{{timestamp}}",
          "Content-Signature": "{{signature_key}}"
        },
        pre() {
        },
        post(response) {
          var json = pm.response.json();

          pm.test("Message should be success", function() {
            pm.expect(json.status.message).to.eql("success");
          });

          pm.test("Status code is 200", function() {
            pm.expect(pm.response.code).to.eql(200);
          });
        },
        auth(config, Var) {
          config.headers.Authorization = `Bearer ${pm[Var]("access_token")}`;
        }
      });
    });
  });

  group("Block3.5", function() {
    group("My_Widget", function() {
      postman[Request]({
        name: "My_Tax",
        id: "071d6899-2800-4ee7-b56b-97379a035eb6",
        method: "POST",
        address: "{{https}}{{host}}{{url_my_widget}}",
        data:
          '{\n    "isLogin": true,\n    "widget_id": "0",\n    "callFrom": "my-tax"\n}',
        headers: {
          "X-Correlation-Id": "{{$randomUUID}}",
          deviceId: "{{deviceIdEncrypt}}",
          Timestamp: "{{timestamp}}"
        },
        pre() {
        },
        post(response) {
          var json = pm.response.json();

          pm.test("Message should be success", function() {
            pm.expect(json.status.message).to.eql("success");
          });

          pm.test("Status code is 200", function() {
            pm.expect(pm.response.code).to.eql(200);
          });
        }
      });
    })
  })

K6 Log
Screenshot 2024-07-30 at 17 59 48

@thim81
Copy link
Collaborator

thim81 commented Jul 30, 2024

hi @titanzx

I rebuild your postman collection but it seems to properly render the headers.

In attachment, you can find the result.
k6-result.zip.zip

Can you point out what is incorrect?

@titanzx
Copy link

titanzx commented Jul 31, 2024

hi @titanzx

I rebuild your postman collection but it seems to properly render the headers.

In attachment, you can find the result. k6-result.zip.zip

Can you point out what is incorrect?

The request does not include an authorization header, but when the request is executed, the authorization is automatically added from previous request authorization header

@thim81
Copy link
Collaborator

thim81 commented Jul 31, 2024

I was focussed on the K6 script, but not on the K6 execution.
I spotted just now what you mean:
image

Thanks for helping to understand this unexpected behaviour.

I'll further investigate, to try to find the source.

@thim81
Copy link
Collaborator

thim81 commented Jul 31, 2024

@titanzx and @kuikiker Found the cause and just released a new version 1.12.0 that should solve your issue.
Before the fix, the headers were passed along as options, which made that they were passed along between requests.

Can you update your project to use postman-to-k6 1.12.0 and verify if your issue is resolved?

@thim81 thim81 added bug Something isn't working and removed Investigate Needs more investigation, before next steps can be defined. labels Jul 31, 2024
@daniel-gonzaleza
Copy link

Hey @thim81, found this thread while investigating an issue in our executions where headers used on some requests were being incorrectly reused by later requests. Updating to version 1.12.0 fixed the issue for us.

@thim81
Copy link
Collaborator

thim81 commented Aug 13, 2024

@daniel-gonzaleza thanks for the validation and confirmation.

I ll close the issue, based on your feedback.

If you experiencing other issues, please do report them so we can investigate and improve postman-to-k6

@thim81 thim81 closed this as completed Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants