ui5-community / wdi5

official UI5 end-to-end test framework for UI5 web-apps. wdi5 = Webdriver.IO + UI5 Test API
https://ui5-community.github.io/wdi5/
Apache License 2.0
102 stars 43 forks source link

BasicAuthentication is not working when Username or Password contains URL special characters #615

Closed danielang-ortec closed 6 months ago

danielang-ortec commented 6 months ago

Describe the bug When using the Basic Authentication method of wdi5 with usernames or passwords that contain special URL characters like # or @ the program stops with the exception: TypeError: Invalid URL (Stacktrace attached).

To Reproduce Steps to reproduce the behavior:

  1. Provide credentials with URL special characters in the .envfile
  2. Start wdi5
  3. 🧨

Expected behavior Currently the content of the .env file simply put inside the URL. But instead it should be encoded before used in an URL. The following snippet in BasicAuthenticator.ts:23 resolves the issue:

const username = encodeURIComponent(this.getUsername());
const password = encodeURIComponent(this.getPassword());
const basicAuthUrls = matches[1] + username + ":" + password + "@" + matches[2];

Logs/Console Output

[0-0] RUNNING in chrome - file:///C:/development/repositories/.../webapp/test/e2e/ResourceTypeListJourney.test.ts
[0-0] 2024-05-17T11:48:43.193Z ERROR @wdio/utils:shim: TypeError: Invalid URL
[0-0]     at new URL (node:internal/url:775:36)
[0-0]     at Browser.url (file:///C:/development/repositories/.../node_modules/webdriverio/build/commands/browser/url.js:43:17)
[0-0]     at Browser.wrapCommandFn (file:///C:/development/repositories/.../node_modules/@wdio/utils/build/shim.js:90:38)
[0-0]     at processTicksAndRejections (node:internal/process/task_queues:95:5)
[0-0]     at async BasicAuthenticator.basicAuthLogin (file:///C:/development/repositories/.../node_modules/wdio-ui5-service/src/lib/authentication/BasicAuthenticator.ts:32:6)
[0-0]     at async BasicAuthenticator.login (file:///C:/development/repositories/.../node_modules/wdio-ui5-service/src/lib/authentication/BasicAuthenticator.ts:15:9)
[0-0]     at async authenticate (file:///C:/development/repositories/.../node_modules/wdio-ui5-service/src/lib/wdi5-bridge.ts:183:13)       
[0-0]     at async Service.before (file:///C:/development/repositories/.../node_modules/wdio-ui5-service/src/service.ts:47:17)
[0-0]     at async Promise.all (index 0)
[0-0]     at async executeHooksWithArgs (file:///C:/development/repositories/.../node_modules/@wdio/utils/build/shim.js:68:20)
[0-0]     at async Runner.run (file:///C:/development/repositories/.../node_modules/@wdio/runner/build/index.js:99:9)

Runtime Env (please complete the following information):