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

Cypress System Tests fail when writing configuration.php #43465

Closed
muhme opened this issue May 13, 2024 · 1 comment
Closed

Cypress System Tests fail when writing configuration.php #43465

muhme opened this issue May 13, 2024 · 1 comment

Comments

@muhme
Copy link
Contributor

muhme commented May 13, 2024

(edited)

Steps to reproduce the issue

Expected result

  • Cypress.based Joomla installation runs without errors, 'Install Joomla' spec is passing
  • configuration.php parameters like $mailer = 'smtp' are set correct
  • configuration.php file mask is still read-only (444)

Actual result

  1) Install Joomla
       Install Joomla:
     CypressError: `cy.task('writeFile')` failed with the following error:

> EACCES: permission denied, open './configuration.php'

System information (as much as possible)

  • seen with local Joomla installations on macOS 14.4.1, Windows 11 and Linux
  • does not occur on Linux with root user (as typically in Docker container based installation)
    • in Linux root installation there is the file mask 777 from the web-server created configuration.php file, which may be another problem

Additional comments

  • the read-only (444) file mask of configuration.php will likely be the cause
  • workaround for Linux, macOS and Windows WSL 2 is to run the installation step as root user who is able to overwrite a read-only file:
    • sudo npx cypress run --spec 'tests/System/integration/install/Installation.cy.js'
    • this needs Cypress to be installed for root user or you use actual users Cypress installation cache, e.g.
      • sudo CYPRESS_CACHE_FOLDER=$HOME/.cache/Cypress npx cypress run --spec 'tests/System/integration/install/Installation.cy.js'
  • ongoing pull request is Consider file permissions when writing configuration in system tests #43466
muhme added a commit to muhme/joomla-cms that referenced this issue May 13, 2024
Fix for issue joomla#43465 'Cypress System Tests fail when writing configuration.php'
. remember the original file permission
. set 644
. write file
. restore original file permission

additional:
. writing file to ${Cypress.env('cmsPath')}/configuration.php` and no more to 'configuration.php'
. error handle file is not existing
@alikon
Copy link
Contributor

alikon commented May 13, 2024

please test #43466

@alikon alikon closed this as completed May 13, 2024
laoneo added a commit that referenced this issue Jun 7, 2024
…43466)

* Fix for issue #43465 writing configuration.php

Fix for issue #43465 'Cypress System Tests fail when writing configuration.php'
. remember the original file permission
. set 644
. write file
. restore original file permission

additional:
. writing file to ${Cypress.env('cmsPath')}/configuration.php` and no more to 'configuration.php'
. error handle file is not existing

* typo

* updated system tests README

* corrected task names

* Update tests/System/README.md

of course, thank you for checking

Co-authored-by: Richard Fath <richard67@users.noreply.github.com>

* deleted failure handler config_setParameter()

deleted failure handler for readFile as it is not needed, tested with chmod 0, Cypress fails with clear reason:

	CypressError: `cy.readFile("./configuration.php")` failed while trying to read the file at the following path:
	`.../43465/joomla-cms/configuration.php`
	The following error occurred:
	> "EACCES: permission denied, open '/Users/hlu/Desktop/no_backup/43465/joomla-cms/configuration.php'"

* typo

Co-authored-by: Brian Teeman <brian@teeman.net>

* typo

Co-authored-by: Brian Teeman <brian@teeman.net>

* chain the then()-calls

Chaining the then()-calls for a not so deeply nested code source
looks catchy - thank Allon for the recommendation

* adopted code formatting for better readability

* fixing lint:js errors

- deleted console.log statements
- used const for never changing value
- refactored file mask to not use bitwise operation '&'

* fixed lint:testjs errors

* Better fix for configuration.php permission issue

Working with the code when fighting with the drone shows that a `chmod`
was already implemented in `writeFile()`. Following changes with this commit:
- Only using `chmod` method synchronously
- Replaced setting directory mode to setting file mode before writing
- Setting file mode only if the file exists
- Having final file mode as parameter with default 0o444
- Using 0o444 as default file mode and not hard-wired 0o777
- The methods `getFilePermissions()` and `changeFilePermissions()` created for this PR earlier are deleted.

Enhancement of the `tests/System/README.md` for troubleshooting three-user-problem in having
Cypress running user, web server running user and `root` user.

This commitment has been extensively tested in various combinations. Every test contains:
- Checking error before
- Doing the patch
- Running installation twice and running overall test suite

Tests are:
- macOS 14.5 Sonoma, local with apache & Cypress same user, branch 4.4-dev
  - error before `> EACCES: permission denied, open './configuration.php'`
- Docker, one container with joomla and one container with Cypress, using `root` users inside containers
  - no error before, but `configuration.php` is 777
  - after the patch `configuration.php` is 444 inside container and shown 644 on host
  - tested four times, branches 4.4-dev, 5.1-dev, 5.2-dev and 6.0-dev
- Ubuntu 24.04 LTS local installation, one non-root users running Cypress and
  another non-root user running Apache, branch 4.4-dev
  - error before `> EACCES: permission denied, open './configuration.php'`
  - need to use `sudo` and need to set `umask 0`, see troubleshooting
- Windows 11 Pro, Laragon with Cmder, branch 4.4-dev
  - error before `> EPERM: operation not permitted, open 'C:\laragon\www\joomla-cms\configuration.php'`

All tests are successful:
- running `Installation.cy.js` twice, checking `configuration.php` 444 and params are set
- running complete system test suite without errors

* configuration.php CMS path relative && umask 0

- corrected mistake task writeFile was used with cmsPath + 'configuration.php'
- extended writeFile to set process umask 0
  - to prevent the 3-user-problem == no need to set umask 0 in sudo anymore

This commitment has been tested in various combinations. Every test contains:
- Checking error before
- Doing the patch
- Running Installation.cy.js only and running overall test suite

Tests are:
- Docker environment with drone images, root running Cypress and www-data running Apache, branch 4.4-dev
  - no error before, but /tests/www/cmysql/configuration.php has 777
- Ubuntu 24.04 LTS local installation, one non-root user running Cypress and
  another non-root user running Apache, branch 4.4-dev
  - error before `> EACCES: permission denied, open './configuration.php'`
  - need to use `sudo`, see troubleshooting (umask 0 is no more needed)
- Windows 11 Pro, Laragon with Cmder, branch 4.4-dev
  - error before `> EPERM: operation not permitted, open 'C:\laragon\www\joomla-cms\configuration.php'`
  - found out that on the second run cy.exec('rm configuration.php') does not work under Windows
    - deleted file manually and i will create an issue afterwards to avoid enlarging this one
- macOS 14.5 Sonoma, local with apache & Cypress same user, branch 4.4-dev
  - error before `> EACCES: permission denied, open './configuration.php'`

All tests are successful:
- running `Installation.cy.js`, checking `configuration.php` 444 and params are set
- running complete system test suite without errors

---------

Co-authored-by: Richard Fath <richard67@users.noreply.github.com>
Co-authored-by: Brian Teeman <brian@teeman.net>
Co-authored-by: Allon Moritz <allon.moritz@digital-peak.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants