-
Bug
-
Resolution: Fixed
-
Minor
-
4.1.18, 4.4.8, 4.5.3, 5.0
When test code uses \core\encryption, this will create a key file which, for security and reliability reasons, is set to 0400 (u=r) permission.
(In a real system, it would be bad if the key file gets written because then all your encrypted admin settings would irrevocably stop working.)
However, this is annoying when writing PHPunit tests (for unrelated code that happens to use encryption) because the reset after the test completes is unable to delete the data directory. To make this work, you have to add code like this in each test case that uses encryption:
#[\Override]
|
protected function tearDown(): void {
|
// A key file may be generated, change permissions so it can be deleted.
|
$keyfile = \core\encryption::get_key_file(\core\encryption::METHOD_SODIUM);
|
if (file_exists($keyfile)) {
|
chmod($keyfile, 0700);
|
}
|
parent::tearDown();
|
}
|
This is pretty rubbish.
There is already code to prevent it breaking Behat tests by disabling the file permissions in Behat runs. I think we should do the same thing for unit tests.
https://github.com/moodle/moodle/blob/main/lib/classes/encryption.php#L64
- has been marked as being related by
-
MDL-65818 Provide admin setting type for secure data (passwords/tokens)
-
- Closed
-