bjowes / cypress-ntlm-auth

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

Cannot perform handshake. Error: NTLM authentication failed #241

Closed totomare closed 9 months ago

totomare commented 10 months ago

1. Context

2. Settings

3. The login test

Given ("Test login", ()=> {

 cy.ntlm(["site-autentification.dev.com"], "username","password!");
 cy.visit('https://site-application.dev. com');

})

4. Launch Cypress in DEBUG mode

The /.http-mitm-proxy directory is created ~/qa-tests/.http-mitm-proxy/

5. Message

The authentication step prevents me from adopting Cypress as a testing framework Please help.

bjowes commented 10 months ago

Hi @totomare

First, thanks for the complete description of the issue from the start. This saves me a lot of effort!

The issue itself is quite weird. Since the plugin is starting a handshake, it has received a 401 response from the https://site-autentification.dev.comsite which indicates in the response headers that NTLM is supported. But then it fails the handshake directly. I have not seen this behaviour before. Usually the whole handshake is performed (type 1 msg from plugin -> server, type 2 msg from server -> plugin, type 3 msg from plugin -> server), and then the response indicates if the login succeeded or not. I also looked at the content of the type 1 msg and it looks fine. To me it seems that the server is not following the NTLM protocol properly.

You state that both sites are run on linux. What is the platform of the software - is it NET 6 or something else?

When you run the test with plain cypress, what is the error? Should be a 401, please confirm it is for site-autentification.dev.com. Just asking since sometimes you need to include additional servers in the cy.ntlm list.

Some other hints (that won't solve the issue):

totomare commented 10 months ago

Hello @bjowes

Thanks for responding quickly.

Our company uses Computer Associates (CA) SiteMinder for authentication management. SiteMinder uses cookies to perform validation. If you need some details about Siteminder you can check this link : About CA SiteMinder (Sun OpenSSO Enterprise 8.0 Integration Guide) (oracle.com)

So it is necessary to assign the cookie content to the request header. The plugin currently does not do this. To test our theory, we modified the file ntlm.manager.js directly in node_modules directory.

 requestOptions.headers["authorization"] = type1header;
 requestOptions.headers["cookie"] = ctx.proxyToServerRequestOptions.headers.cookie;
 requestOptions.headers["connection"] = "keep-alive";

It corresponds to line 81 in github repository. https://github.com/bjowes/cypress-ntlm-auth/blob/master/src/proxy/ntlm.manager.ts#L81C5-L81C5

With this change the test passed successfully.

Can you please add an additional parameter to plugin configuration so plugin include cookies in authentication request once its set to true. To minimize impact on users that does not need to pass cookies when performing NTLM authentication.

Since SiteMinder is widely used in the market it will be profitable to make this addition to the plugin. We want to use the official version of the plugin to benefit from subsequent improvements.

Thanks for the feedback Credits for solution: development team.

PM: if you need additional information’s or clarifications feel free to contact me back.

bjowes commented 9 months ago

Thanks for investigating and suggesting a fix! I think passing along cookies is a sensible thing to do for all users. Implemented in v4.1.3