ArnaudBuchholz / ui5-test-runner

A test runner for UI5 applications enabling parallel execution of tests.
https://arnaudbuchholz.github.io/ui5-test-runner/
MIT License
22 stars 9 forks source link

Puppeteer HTTP Authentification #71

Closed rajxsingh closed 10 months ago

rajxsingh commented 10 months ago

Enables Puppeteer HTTP Authentification using environment variables. This is useful in CI Pipeline-Scenarios.

ArnaudBuchholz commented 10 months ago

Hello ! and thank you for submitting a PR to ui5-test-runner. Can you elaborate on the scenario in which you need to add authentication while testing OPA and / or qUnit... The tool was not designed for end-to-end testing but rather integration with mocking... Hence my question.

ArnaudBuchholz commented 10 months ago

Furthermore, I try to limit the dependencies of the project, I suspect the environment variables could be set before starting the runner. Hence we don't really need dotenv

rajxsingh commented 10 months ago

Hello, thank you for considering my PR. I understand that the ui5-test-runner primarily focuses on integration with mocking rather than end-to-end testing. The reason I added authentication support is due to a specific scenario I encountered while testing an application that utilizes custom controls from an internal library. These controls require authentication for the application to initialize properly, even though the authentication itself is not the focus of the testing.

rajxsingh commented 10 months ago

You are right, dotenv is not needed. I will remove it.

ArnaudBuchholz commented 10 months ago

OK, now that I get the scenario, it would be better to offer this evolution as 'normal' options of the puppeteer integration.

You might see at the top of the file that some options are supported, I would propose to add :

['--basic-auth-username', 'Username for basic authentication', ''],
['--basic-auth-password', 'Password for basic authentication', '']

Then I would condition the call to page.authenticate if options.basicAuthUsername || options.basicAuthPassword

From an execution point of view, you can set this parameters using your environment variables.

Any way we could test this to ensure it works ? we could leverage REserve to build a small server that requires http 1.1 authentication..

Does it sound like a plan ?

rajxsingh commented 10 months ago

Thanks for this idea, I've implemented the options as you suggested and also added a test scenario where the application is served by a REserve server. The server requires authentication specifically for the route ^/index.html.

I referenced the configurations from the REserve samples repository for setting up the server.

rajxsingh commented 10 months ago

This should fix the auth-sample test in the CI environment (Ubuntu).

Apparently on Ubuntu, I don't need to pass the browser arguments with -- -- --basic-auth-username. However, on Windows, if I don't do that, the arguments are passed to start-server-and-test which leads to an error.

This way, the test should run successfully in both environments:

"test:auth-sample:remote": "start-server-and-test 'npm run serve:auth-sample' http://localhost:8080 'node . --url http://localhost:8080/test/testsuite.qunit.html --browser $/puppeteer.js --browser-args --basic-auth-username testUsername --browser-args --basic-auth-password testPassword'",
---
SERVE GET /resources/sap/ui/test/OpaCss.css 302 0 ms
SERVE GET /index.html 401 0 ms     // unauthorized, requests username:password
SERVE GET /index.html 200 1 ms     // new request with Authorization header
SERVE GET /@openui5/1.120.0/resources/sap/ui/test/OpaCss.css 200 16 ms
---
ArnaudBuchholz commented 10 months ago

Thanks for your contribution ! I will release a new version of ui5-test-runner soon.

ArnaudBuchholz commented 9 months ago

@rajxsingh your change is published in version 4.0.0

rajxsingh commented 9 months ago

Great 👍🏻