Issue #3135390 by munish.kumar, jungle, mondrake, xjm, daffie: Replace assertions involving calls to is_readable() and is_writeable() on files and directories with PHPUnit assertions

merge-requests/2419/head
xjm 2020-05-19 12:48:39 -05:00
parent a7ff8b3092
commit 24fad1ccb8
4 changed files with 13 additions and 9 deletions

View File

@ -65,8 +65,10 @@ class SitesDirectoryHardeningTest extends BrowserTestBase {
$this->assertStringContainsString('settings.php is not protected from modifications and poses a security risk.', $description);
$this->assertStringContainsString('services.yml is not protected from modifications and poses a security risk.', $description);
$this->assertTrue(is_writable($site_path), 'Site directory remains writable when automatically fixing permissions is disabled.');
$this->assertTrue(is_writable($settings_file), 'settings.php remains writable when automatically fixing permissions is disabled.');
// Verify that site directory and the settings.php remain writable when
// automatically enforcing file permissions is disabled.
$this->assertDirectoryIsWritable($site_path);
$this->assertFileIsWritable($settings_file);
// Re-enable permissions enforcement.
$settings = Settings::getAll();
@ -77,8 +79,10 @@ class SitesDirectoryHardeningTest extends BrowserTestBase {
$requirements = $this->checkSystemRequirements();
$this->assertEquals('Protected', (string) $requirements['configuration_files']['value']);
$this->assertFalse(is_writable($site_path), 'Site directory is protected when automatically fixing permissions is enabled.');
$this->assertFalse(is_writable($settings_file), 'settings.php is protected when automatically fixing permissions is enabled.');
// Verify that site directory and the settings.php remain protected when
// automatically enforcing file permissions is enabled.
$this->assertDirectoryNotIsWritable($site_path);
$this->assertFileNotIsWritable($settings_file);
}
/**

View File

@ -27,8 +27,8 @@ class InstallerSkipPermissionHardeningTest extends InstallerTestBase {
*/
protected function setUpSite() {
$site_directory = $this->container->getParameter('app.root') . '/' . $this->siteDirectory;
$this->assertTrue(is_writable($site_directory));
$this->assertTrue(is_writable($site_directory . '/settings.php'));
$this->assertDirectoryIsWritable($site_directory);
$this->assertFileIsWritable($site_directory . '/settings.php');
$this->assertSession()->responseContains('All necessary changes to <em class="placeholder">' . $this->siteDirectory . '</em> and <em class="placeholder">' . $this->siteDirectory . '/settings.php</em> have been made, so you should remove write permissions to them now in order to avoid security risks. If you are unsure how to do so, consult the <a href="https://www.drupal.org/server-permissions">online handbook</a>.');

View File

@ -95,8 +95,8 @@ class InstallerTest extends InstallerTestBase {
// Test that SiteConfigureForm::buildForm() has made the site directory and
// the settings file non-writable.
$site_directory = $this->container->getParameter('app.root') . '/' . $this->siteDirectory;
$this->assertFalse(is_writable($site_directory));
$this->assertFalse(is_writable($site_directory . '/settings.php'));
$this->assertDirectoryNotIsWritable($site_directory);
$this->assertFileNotIsWritable($site_directory . '/settings.php');
parent::setUpSite();
}

View File

@ -188,7 +188,7 @@ class ImageTest extends UnitTestCase {
public function testIsValid() {
$this->getTestImage(FALSE);
$this->assertTrue($this->image->isValid());
$this->assertTrue(is_readable($this->image->getSource()));
$this->assertFileIsReadable($this->image->getSource());
}
/**