bjowes / cypress-ntlm-auth

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

Wildcard support for hosts in cy.ntlm #117

Closed testtek closed 3 years ago

testtek commented 4 years ago

Hi Bjorn,

This is kind of request instead of bug.

Since we upgrade to 2.2.5 we are using suggested workaround of using cy.ntlmSso but to keep script running we have also used the old mechanism of cy.ntlm(with credentials). Is it something possible for you get them together and with cy.ntlmSso(pass crendtials)?

This will help us to get code more cleaner. Thank you in advance.

bjowes commented 4 years ago

Hi @testtek If I understand your request correctly, you would like cy.ntlm and cy.ntlmSso to be merged into one function. This might be feasible since the arguments are quite different, but I think it would make the API a bit unclear. The purpose of cy.ntlm is to be able to explicitly specify the credentials. The purpose of cy.ntlmSso is to use the logged on windows users credentials (hence the Sso ending). I think these are different features for different needs.

If you really want to merge them I think you can do that in your own code. Something like:

function myNtlm(host, username, password) {
  if (typeof host !== 'string') {
    return cy.ntlmSso(host);
  } else {
    return cy.ntlm(host, username, password);
  }
}
testtek commented 4 years ago

Thanks for your reply @bjowes. I understand both methods have different purpose. But for us it is not working. We are running cypress under an agent like team city, we have multiple API's, it would be useful to login SSO for all of them. Right now we are doing something like

Cy.ntlmsso(['*.test.com']) // we need to explicitly to feed credentials to service running under Cy.ntlm('api1.test.com',...credentials) Cy.ntlm('api2.test.com',...credentials) Cy.ntlm('api3.test.com',...credentials) would have been better if you could have a way something like Cy.ntlmsso('*.test.com',...credentials)

Please let me know your thoughts on this.

bjowes commented 4 years ago

Could it be that you are requesting wildcard support for cy.ntlm? So that it would be possible to do: cy.ntlm('*.test.com', username, password)

That would simplify setup when you have many hosts, while preserving the separation between cy.ntlmSso and cy.ntlm

testtek commented 4 years ago

yeah, I believe cy.ntlm('*.test.com', username, password) would work for us. and then we can remove cy.ntlmSso(['*.test.com']); line of code.

OR add support cy.ntlmSso(['*.test.com'], username, password);

Is it something possible for you to get this near future?

bjowes commented 4 years ago

I still don't fully follow what you are after. Do you use SSO for any of your tests? If not, that line can be removed (once the wildcard is implemented).

SSO has the benefits of support for the Negotiate protocol and that you don't need to provide user/password in config files for your tests. This should be used unless you specifically need to access the test site with a different user account than the account executing your tests. Then cy.ntlm is your only option, and the only one you need.

I'm a bit occupied at the moment, will look into wildcard support in a few weeks.

testtek commented 4 years ago

to keep it simple, I am after cy.ntlm('*.test.com', username, password)

look forward to see new changes 🙇‍♂️

bjowes commented 4 years ago

I took a quick look at this yesterday and it seems feasible. In the past, there were technical reasons that made wildcards in hosts difficult to handle, but apparently I had already refactored those parts. My goal is to achieve the same syntax for hosts, so cy.ntlm would also accept an array of hostnames like cy.ntlmSso. Not sure when I will have time to put it together, but hopefully within a few weeks.

sarita555 commented 4 years ago

I took a quick look at this yesterday and it seems feasible. In the past, there were technical reasons that made wildcards in hosts difficult to handle, but apparently I had already refactored those parts. My goal is to achieve the same syntax for hosts, so cy.ntlm would also accept an array of hostnames like cy.ntlmSso. Not sure when I will have time to put it together, but hopefully within a few weeks.

I'm new to cypress and currently big hurdle is i'm unable to access our url due to Windows Security login. I followed steps for ntlm as below but no success i get either 401 or 301:

Screen Shot 2020-06-27 at 2 08 36 AM Screen Shot 2020-06-27 at 2 24 26 AM

npm install --save-dev cypress-ntlm-auth

Added cypress/plugins/index.js 

const ntlmAuth = require("cypress-ntlm-auth/dist/plugin"); module.exports = (on, config) => { config = ntlmAuth.initNtlmAuth(config); return config; };

Added below cypress/support/index.js  import "cypress-ntlm-auth/dist/commands";

package.json "ntlm-proxy": "start /min \"ntlm-proxy\" cmd /c node_modules\.bin\ntlm-proxy", "cypress-ntlm": "npm run ntlm-proxy && (cypress-ntlm open & ntlm-proxy-exit)"

Startup npm run cypress-ntlm

cy.ntlm(ntlmHost, username, password)

When I manually access the url I get Windows Security pop up which is not visible in cypress.

bjowes commented 4 years ago

@sarita555 - you are describing a different issue. For general questions and troubleshooting the best practice is to open a new issue. I have done this, see #120. Lets continue the discussion there.