Disable Redirects

Hi,

I have a scenario that is causing me some issues as one of the calls doesn’t accept the basic auth header as the domain changes.

I have a call that has two redirects.

  1. http://domain1.com/step1 - returns as a header the Location needed for step 2.
  2. http://domain1.com/step2 - returns as a header the Location needed for step 3.
  3. http://domain2.com/step3 - fails here with a 401.

Assuming this is not possible due to security concerns I thought I could just make call 1, extract the step2 Location, make call 2, extract the step 3 Location, make call 3. And before each add the Authorization header.

So is it possible to prevent specific calls following redirects so I can attempt this.

SOLVED SOLVED

Fixed the HeaderParams.

headerParams = {
     headers: {
      'Content-Type':'application/x-www-form-urlencoded',
       'Accept':'*/*',
       'Authorization':'Basic XXXXXXXXXXXXXXXXXXX',
     },
  redirects: 0,
  };

I did find an option { redirects: 0} but when set doesn’t seem to work…

Payload = 'Some PayLoad, Some payload, some payload';
  headerParams = {
     headers: {
      'Content-Type':'application/x-www-form-urlencoded',
       'Accept':'*/*',
       'Authorization':'Basic XXXXXXXXXXXXXXXXXXX',
     },
  };

  urlResponse = http.post('domain1.com/login/callback',Payload,headerParams,{ redirects: 0});
  //console.log(urlResponse.body);
    urlResponseCheck = check(urlResponse, {
    'status is 200': (r) => r.status === 200,                     // contains http 200 OK
   // 'response body': (r) => r.body.indexOf('nextToGo') !== -1,   // constains string nextToGo OK
  });

POST /login/callback HTTP/1.1
Host: domain1.com
User-Agent: k6/0.35.0 (https://k6.io/)
Content-Length: 2185
Accept: /
Authorization: Basic XXXXXXXXXXXXXXXXXXX
Content-Type: application/x-www-form-urlencoded
Cookie: did=s%3Av0%3A6dd4da60-74ed-11ec-8a23-cf877737bcde.WCkkp9MO%2FFBStm3c6QZctqz0Mail3g%2F5jlnxLZlywtA; did_compat=s%3Av0%3A6dd4da60-74ed-11ec-8a23-cf877737bcde.WCkkp9MO%2FFBStm3c6QZctqz0Mail3g%2F5jlnxLZlywtA; vendor=s%3AToXho0ba0m4AcwucF6rLCJFQ6JKH1vcO.maaY%2Ftv8oat%2FtmnAjQqqcnMznKm%2FwLR4DbvCuXzrt2M; vendor_compat=s%3AToXho0ba0m4AcwucF6rLCJFQ6JKH1vcO.maaY%2Ftv8oat%2FtmnAjQqqcnMznKm%2FwLR4DbvCuXzrt2M
Accept-Encoding: gzip

group= iter=0 request_id=14c4efe6-9c44-43be-51dc-018506fee301 scenario=default source=http-debug vu=1
INFO[0005] Response:
HTTP/2.0 302 Found
Content-Length: 78
Cache-Control: private, no-store, no-cache, must-revalidate, post-check=0, pre-check=0, no-transform
Content-Type: text/plain; charset=utf-8
Date: Fri, 14 Jan 2022 03:52:46 GMT
Location: /authorize/resume?state=C3f2r5GXfg4SW50gYENlwwk6njdM5hk5
Server: nginx
Set-Cookie: vendor=s%3AToXho0ba0m4AcwucF6rLCJFQ6JKH1vcO.maaY%2Ftv8oat%2FtmnAjQqqcnMznKm%2FwLR4DbvCuXzrt2M; Path=/; Expires=Fri, 14 Jan 2022 05:52:46 GMT; HttpOnly; Secure; SameSite=None
Set-Cookie: vendor_compat=s%3AToXho0ba0m4AcwucF6rLCJFQ6JKH1vcO.maaY%2Ftv8oat%2FtmnAjQqqcnMznKm%2FwLR4DbvCuXzrt2M; Path=/; Expires=Fri, 14 Jan 2022 05:52:46 GMT; HttpOnly; Secure
Strict-Transport-Security: max-age=31536000
X-vendor-Requestid: ada7a360cf977a00a211
X-Robots-Tag: noindex, nofollow, nosnippet, noarchive

group= iter=0 request_id=14c4efe6-9c44-43be-51dc-018506fee301 scenario=default source=http-debug vu=1
INFO[0006] Request:
GET /authorize/resume?state=C3f2r5GXfg4SW50gYENlwwk6njdM5hk5 HTTP/1.1
Host: domain1.com
User-Agent: k6/0.35.0 (https://k6.io/)
Accept: /
Authorization: Basic XXXXXXXXXXXXXXXXXXX
Content-Type: application/x-www-form-urlencoded
Cookie: did=s%3Av0%3A6dd4da60-74ed-11ec-8a23-cf877737bcde.WCkkp9MO%2FFBStm3c6QZctqz0Mail3g%2F5jlnxLZlywtA; did_compat=s%3Av0%3A6dd4da60-74ed-11ec-8a23-cf877737bcde.WCkkp9MO%2FFBStm3c6QZctqz0Mail3g%2F5jlnxLZlywtA; vendor=s%3AToXho0ba0m4AcwucF6rLCJFQ6JKH1vcO.maaY%2Ftv8oat%2FtmnAjQqqcnMznKm%2FwLR4DbvCuXzrt2M; vendor_compat=s%3AToXho0ba0m4AcwucF6rLCJFQ6JKH1vcO.maaY%2Ftv8oat%2FtmnAjQqqcnMznKm%2FwLR4DbvCuXzrt2M
Referer: https://domain1.com/login/callback
Accept-Encoding: gzip

group= iter=0 request_id=1fc91997-82a9-4288-7beb-49788b0618ba scenario=default source=http-debug vu=1
INFO[0006] Response:
HTTP/2.0 302 Found
Content-Length: 75
Cache-Control: no-store, max-age=0, no-transform
Content-Type: text/plain; charset=utf-8
Date: Fri, 14 Jan 2022 03:52:47 GMT
Location: https://domain2.com/redirect?code=AjSr_K6WepftJg3F
Pragma: no-cache
Server: nginx
Set-Cookie: vendor=s%3AwTuzgedk0Tc7b2kBoWMrymCBBBpMliy-.WarwGPF0deCf3FXxRRO%2Bp35iUWSVr%2BHOyExy2XYdUS8; Path=/; Expires=Fri, 14 Jan 2022 05:52:47 GMT; HttpOnly; Secure; SameSite=None
Set-Cookie: vendor_compat=s%3AwTuzgedk0Tc7b2kBoWMrymCBBBpMliy-.WarwGPF0deCf3FXxRRO%2Bp35iUWSVr%2BHOyExy2XYdUS8; Path=/; Expires=Fri, 14 Jan 2022 05:52:47 GMT; HttpOnly; Secure
Strict-Transport-Security: max-age=31536000
X-vendor-Requestid: 447136f63c6f1c9e63ed
X-Robots-Tag: noindex, nofollow, nosnippet, noarchive

group= iter=0 request_id=1fc91997-82a9-4288-7beb-49788b0618ba scenario=default source=http-debug vu=1
INFO[0006] Request:
GET /redirect?code=AjSr_K6WepftJg3F HTTP/1.1
Host: domain2.com
User-Agent: k6/0.35.0 (https://k6.io/)
Accept: /
Content-Type: application/x-www-form-urlencoded
Referer: https://domain1.com/authorize/resume?state=C3f2r5GXfg4SW50gYENlwwk6njdM5hk5
Accept-Encoding: gzip

group= iter=0 request_id=481a1b21-753c-498e-7283-210b7a7977c3 scenario=default source=http-debug vu=1
INFO[0006] Response:
HTTP/2.0 401 Unauthorized
Content-Length: 172
Content-Type: text/html; charset=utf-8
Date: Fri, 14 Jan 2022 03:52:47 GMT
Server: nginx
Www-Authenticate: Basic realm=“Basic Auth”

I see that you solved the issue yourself, but just in case anyone stumbles on this in the future, the redirects option has to be on the same level as the headers in the request parameters: Params