Basic Digest Authentication request not working

Hi,
Followed examples given in HTTP Authentication and we are getting error: ERRO[0000] GoError: parse “https://test_user@testing.com:testing”: invalid port “:testing” after host
at github.com/loadimpact/k6/js/common.Bind.func1 (native)

We have user id: test_user@testing.com, password: testing123 (sample data) and BASEURL: https://okta.mycompanyconnect.net/IWA/iwa_test.aspx
Mechanism: BASIC_DIGEST

How to implement basic digest authentication?

Hi @huligesh.hanumanthap,
Are you saying that you have @ in the username? In that case you will need to encode it as @ is a special character, you can use encodeURIComponent as in

var username = ...;
var password = ...;
var url = "https://"+encodeURIComponent(username) + ":" + encodeURIComponent(password) + "@hostname.domain/path";

Hope this helps

1 Like

Instead of https://test_user@testing.com:testing, the URL should be https://test_user:testing@testing.com. The URL syntax is scheme://username:password@host:port/path, see URL - Wikipedia

Hi @mstoykov,
Thanks for your time.

I tried below code and it is failing with 401-Unauthorized error:

var username = 'test_user@testing.com';
var password = 'testing123';
var url = "https://"+encodeURIComponent(username) + ":" + encodeURIComponent(password) + "@okta.mycompanyconnect.net/IWA/iwa_test.aspx";
let res = http.get(url);
console.log(res);

Error: HTTP 401 - Unauthorized.

But credential passed are correct and working fine manually.

Thanks

I recommend

  1. printing the url to console
  2. checking with curl that you can make the request from the machine you are running k6 from
  3. using --http-debug to see what is actually being send.

This should provide you with some leads on what to do next.

@huligesh.hanumanthap, since you mention digest authentication in the title, I’m guessing the HTTP call should be like this:

let res = http.get(url, {auth: 'digest'});

See Params

1 Like

Hi @mstoykov and @ned ,
Thanks for you time!

As suggested, We tried using curl and getting expected HTTP 200 OK response.
curl -v https://okta.mycompanyconnect.net/IWA/iwa_test.aspx--ntlm -u test_user@testing.com:testing123

But, when we try in k6 as below, we are getting 401 Un-authorized error. k6 retires 3 times and throws 401 Unauthorized error.

var username = test_user@mycompany.com;
var password = testing123;
var url = "https://"+encodeURIComponent(username) + ":" + encodeURIComponent(password) + “okta.mycompanyconnect.net/IWA/iwa_test.aspx";
let response = http.get(url, {auth: 'ntlm'});

image
It retries 3 times and throws 401 Unauthorized error as below:
image

Any suggestions would be help full here!
Thanks