bjowes / cypress-ntlm-auth

Windows authentication plugin for Cypress
MIT License
55 stars 9 forks source link

Passing parameter ntlmhosts #179

Open mohamdmahdi opened 3 years ago

mohamdmahdi commented 3 years ago

Thanks for developing this plug in

I have a case and I hope you can help me with it I have to get a token through ntlm authentication on cypress. Moreover this token needed to get through not only a domain but a full URL so my domain is for exmapl [example.eu.domoan.com] but also i need to go to specific link to get this token which is https://example.eu.domoan.com/endpoing/api/v1/token

so i need to call this endpoint through ntlm, providing username and password and also domain, then i can take this token and go to the https://example.eu.domoan.com/ to access the system

So when i only provide the domain in the ntlm as you specify, i do not get the token so i can not access the website

I hope that i got it clear

bjowes commented 3 years ago

Hi @mohamdmahdi - configuring a NTLM target for a domain applies those settings to that domain, including all URLs that start with that domain. Hence your use case should work fine as I understand your description.

mohamdmahdi commented 3 years ago

Hi @bjowes I did the following configuration cy.ntlm("https://example.eu.domoan.com/endpoing/api/v1/token",'uesername','password')

and i got this error

` Invalid ntlmHost, must not contain any path or query (https://www.google.com is ok, https://www.google.com/search is not ok) node_modules/cypress-ntlm-auth/dist/commands/index.js:41:1 39 | const validationResult = ConfigValidator.validateLegacy(ntlmHosts); 40 | if (!validationResult.ok) {

41 | throw new Error(validationResult.message); | ^ 42 | } 43 | ntlmHosts = ConfigValidator.convertLegacy(ntlmHosts); 44 | } `

and if i remove the end point /endpoing/api/v1/token

it does not work can you please advice

bjowes commented 3 years ago

You are using a legacy variant of the cy.ntlm method. The recommended current method has an array as first parameter. Try using it like this: cy.ntlm(["example.eu.domoan.com"],'username','password')

mohamdmahdi commented 3 years ago

@bjowes Thank you again for your support and quick response let me explain what is my ideal situation as steps 1- i to use NTLM to go the the endpoint "https://example.eu.domoan.com/endpoing/api/v1/token 2- i provide the NTLM the user name and password as well 3- The end point will return a token 4- I visit the site https://example.eu.domoan.com/ and providing the token to access the system

i did as you mentioned cy.ntlm(["example.eu.domoan.com"],'username','password')

when it try to fitch the response i got ok status only without any token returned

This token is very important i only get the through going to the end point endpoing/api/v1/token and then i got a token and then i use this token to pass it to the server to be able to access the application

if i use this way cy.ntlm(["example.eu.domoan.com/ endpoing/api/v1/token"],'username','password')

I got back this message

invalid host [example.eu.domoan.com/endpoing/api/v1/token] in ntlmHosts, must be one of: 1) a hostname or FQDN, wildcards accepted. 2) hostname or FQDN with port, wildcards not accepted (localhost:8080 or www.google.com or *.acme.com are ok, https://www.google.com:443/search is not ok).