Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: webui: Address several issues #6690

Closed
wants to merge 4 commits into from

Conversation

stanislavlevin
Copy link
Contributor

@stanislavlevin stanislavlevin commented Feb 15, 2023

  • allow file access from files in tests
  • load qunit only once
  • updated vendored qunit

Related: https://pagure.io/freeipa/issue/9329

https://peter.sh/experiments/chromium-command-line-switches/#allow-file-access-from-files
> By default, file:// URIs cannot read other file:// URIs. This is an
  override for developers who need the old behavior for testing.

Fixes webui tests on CI:
```
Testing test/all_tests.html
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
Access to XMLHttpRequest at 'file:///__w/freeipa/freeipa/install/ui/test/qunit.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-untrusted, https.
Failed to load resource: net::ERR_FAILED
Access to XMLHttpRequest at 'file:///__w/freeipa/freeipa/install/ui/test/data/i18n_messages.json' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-untrusted, https.
Failed to load resource: net::ERR_FAILED
>> Error: Error: Couldn't receive translations
```

Related: https://pagure.io/freeipa/issue/9329
Signed-off-by: Stanislav Levin <[email protected]>
@stanislavlevin stanislavlevin changed the title webui: Disable web security in tests tests: webui: Address several issues Feb 16, 2023
@stanislavlevin
Copy link
Contributor Author

qunit tests manually checked against FF and Chromium.

@stanislavlevin
Copy link
Contributor Author

The tests are broken with recent grunt-contrib-qunit 7, but it's worth to notice that the previous version
6.2.1 literally checks nothing. For example,
https://dev.azure.com/freeipa/freeipa/_build/results?buildId=12471&view=logs&j=95a7e090-ce4f-5217-53f4-3d03c3589378&t=0fca0f6f-4451-532e-f43d-ff5cce934480:

Running "qunit:all" (qunit) task
Verifying property qunit.all exists in config...OK
Files: test/all_tests.html -> all
Options: timeout=5000, inject="/__w/1/s/install/ui/node_modules/grunt-contrib-qunit/chrome/bridge.js", urls=[], force=false, console, httpBase=false, summaryOnly=false
Finishing: WebUI Unit Tests

and there was no produced tests report.

webui unit tests fail with grunt-contrib-qunit:
```
Testing test/all_tests.html

>> Error: Error: QUnit has already been defined.
>>     at exportQUnit (file:///home/test/freeipa/install/ui/js/qunit.js:2475:12)
>>     at file:///home/test/freeipa/install/ui/js/qunit.js:2946:3
>>     at file:///home/test/freeipa/install/ui/js/qunit.js:5061:2

>> Error: TypeError: Cannot set properties of undefined (setting 'reorder')
>>     at <anonymous>:175:24
>>     at runFactory (file:///home/test/freeipa/install/ui/js/dojo/dojo.js:1:17157)
>>     at execModule (file:///home/test/freeipa/install/ui/js/dojo/dojo.js:1:19541)
>>     at file:///home/test/freeipa/install/ui/js/dojo/dojo.js:1:20002
>>     at guardCheckComplete (file:///home/test/freeipa/install/ui/js/dojo/dojo.js:1:19707)
>>     at checkComplete (file:///home/test/freeipa/install/ui/js/dojo/dojo.js:1:19854)
>>     at onLoadCallback (file:///home/test/freeipa/install/ui/js/dojo/dojo.js:1:22296)
>>     at HTMLScriptElement.onLoad (file:///home/test/freeipa/install/ui/js/dojo/dojo.js:1:26209)
```

Load `qunit` with `dojo.require` that among other useful things helps
> Preventing loading Dojo packages twice.
  dojo.require will simply return if the package is already loaded.

See also https://github.com/gruntjs/grunt-contrib-qunit#loading-qunit-with-amd

Related: https://pagure.io/freeipa/issue/9329
Signed-off-by: Stanislav Levin <[email protected]>
It's helpful for debugging regressions.

Related: https://pagure.io/freeipa/issue/9329
Signed-off-by: Stanislav Levin <[email protected]>
Updated qunit to latest supported version from
https://code.jquery.com/qunit.

See https://qunitjs.com/intro/#release-channels for details.

Related: https://pagure.io/freeipa/issue/9329
Signed-off-by: Stanislav Levin <[email protected]>
@stanislavlevin
Copy link
Contributor Author

There are several unrelated to this PR warnings/errors in FF/Chromium, but I think it's ok as it is.

@flo-renaud
Copy link
Contributor

@stanislavlevin
thanks for the patch, it will unblock many PRs in review ⭐
Also tested manually: follow the instructions from https://www.freeipa.org/page/FreeIPAv2:UI_Unit_Tests#Necessary_steps_for_running_tests

  • with firefox, one needs to change the setting security.fileuri.strict_origin_policy to false (in about:config), then launch cd install/ui/test && firefox index.html
  • with google-chrome: cd install/ui/test && google-chrome --allow-file-access-from-files index.html

@flo-renaud flo-renaud self-assigned this Feb 17, 2023
@flo-renaud flo-renaud added ack Pull Request approved, can be merged ipa-4-9 Mark for backport to ipa 4.9 ipa-4-10 Mark for backport to ipa 4.10 pushed Pull Request has already been pushed labels Feb 17, 2023
@flo-renaud
Copy link
Contributor

master:

  • 5c35405 tests: webui: Allow file access from files in tests
  • a7e13f9 tests: webui: Load qunit only once
  • 8d634d8 AP: webui: List installed nodejs packages
  • 64fa6b7 tests: webui: Update vendored qunit

@stanislavlevin
Copy link
Contributor Author

@flo-renaud, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ack Pull Request approved, can be merged ipa-4-9 Mark for backport to ipa 4.9 ipa-4-10 Mark for backport to ipa 4.10 pushed Pull Request has already been pushed
Projects
None yet
2 participants