Closed rajxsingh closed 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.
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
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.
You are right, dotenv
is not needed. I will remove it.
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 ?
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.
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
---
Thanks for your contribution ! I will release a new version of ui5-test-runner
soon.
@rajxsingh your change is published in version 4.0.0
Great 👍🏻
Enables Puppeteer HTTP Authentification using environment variables. This is useful in CI Pipeline-Scenarios.