postmanlabs / newman

Newman is a command-line collection runner for Postman
https://www.postman.com
Apache License 2.0
6.84k stars 1.16k forks source link

URI malformed error coming while executing from Newman works fine in postman #2328

Closed mr097065 closed 4 years ago

mr097065 commented 4 years ago
  1. Newman Version (can be found via newman -v):
  2. OS details (type, version, and architecture):
  3. Are you using Newman as a library, or via the CLI?
  4. Did you encounter this recently, or has this bug always been there:
  5. Expected behaviour:
  6. Command / script used to run Newman:
  7. Sample collection, and auxiliary files (minus the sensitive details):
  8. Screenshots (if applicable):
codenirvana commented 4 years ago

@mr097065 Can you share a scaled-down collection (or API endpoint) which we can use to reproduce this issue?

mr097065 commented 4 years ago

URL: You can create a mock server in postman to utilize this as I have utilized my limit.

/addresses?country=AUS&id=AUG|5f246f9b-7c97-4233-8de7-2d57f74cd86b|7.7305OAUGGwvjBwAAAAAIAgEAAAAAB7zTAAAAAAAAADEAAP..ZAAAAAD.....AAAAAAAAAAAAAAAAAAAAMTc3IHBhY2lmaWMgaHd5AAAAAAA-$15&dataset=GNAF

Response: 200 ok

{   "addressLine1": "Level 2 111 Pacific Highway",   "suburb": "SYDNEY",   "postcode": "2000",   "country": "Australia",   "unitNumber": "Level",   "level": “2”,   "streetNumber": “111”,   "streetName": "Pacific",   "streetType": "Highway",   "state": "NSW",   "countryCode": "AUS" }

My local Newman Version = 4.5.3 ( JSONError comes on local too)

Below error comes while executing via Jenkins. Error I am getting: Unexpected token 'H' at 1:1 HTTP request parsing failed with error: "Malformed URI: /v1/addresses?country=A ^

This error comes in Newman only while in postman it works fine. Jenkins console logs:

codenirvana commented 4 years ago

@mr097065 Created a mock server as you suggested but still can't reproduces the issue locally.

Screenshot 2020-04-26 at 4 54 01 PM
mr097065 commented 4 years ago

I suspect it's something that MuleSoft might've patched in CloudHub (for security reasons) and now forcing consumers to encode the URI. Is it possible to encode URI in newman?

codenirvana commented 4 years ago

@mr097065 you can either manually encode the additional/unsafe characters which are not encoded automatically or add the following script as part of your Pre-request Script:

pm.request.url.query.each((q) => {
     q.update(encodeURI(q.toString()))
});

This script mutates (encodes the additional characters) the request URL before sending it.

Also, can you verify that your request works fine in Postman after enabling the "Use next generation URL processing" setting?

76343092-99977080-6325-11ea-9b37-0e824726847f
mr097065 commented 4 years ago

Thanks. Let me try that and also after enabling setting in postman to "Use next generation URL processing" it doesn't work in postman too. image

codenirvana commented 4 years ago

@mr097065 Thanks for the verification.

With this new setting Postman encodes the URL based on the WHATWG URL standard (know more about this change) which is similar to most of the web browsers.

Are you facing a similar issue when you send this request from Chrome or any other browser?

codenirvana commented 4 years ago

@mr097065 The only character which is causing (because it's not encoded) this issue is | which needs to be encoded as %7C according to your request middleware.

mr097065 commented 4 years ago

Yes, I get same error in chrome when I hit the URL there.

Below is the error in chrome. HTTP request parsing failed with error: "Malformed URI: /v1/addresses?country=AUS&id=AUG|5f246f9b-7c97-4233-8de7-2d57f74cd86b|7.7305OAUGGwvjBwAAAAAIAgEAAAAAB7zTAAAAAAAAADEAAP..ZAAAAAD.....AAAAAAAAAAAAAAAAAAAAMTc3IHBhY2lmaWMgaHd5AAAAAAA-$15&dataset=GNAF"

I just added the provided code in Pre-request Script and it started working fine in postman even after enabling the in "Use next generation URL processing" setting, but as soon as I executed the same request in my local Newman it again failed.

image

mr097065 commented 4 years ago

Yes you are correct only the pipe sign is not getting decoded properly. I will try to decode manually and then run in Newman

codenirvana commented 4 years ago

@mr097065 This is probably because of parsing invalid/non-JSON string (maybe the response is different).

Also, This change in the URL processor is enabled by default since Newman v5. I think you are using an older version of Newman locally and v5 on Jenkins.

mr097065 commented 4 years ago

Yes I am using old version just updated Newman to V 5 and voilà it worked. Closing this issue. Thanks alot for your help.