From 8a8cbe8355c00f9cbef69ffb91c28a8e11c391ff Mon Sep 17 00:00:00 2001
From: Adam G-H <32250-phenaproxima@users.noreply.drupalcode.org>
Date: Mon, 5 Jun 2023 21:00:24 +0000
Subject: [PATCH] Issue #3364748 by phenaproxima: Add test coverage for the
 permissions handling that SiteConfigurationExcluder does for `sites/default`

---
 .../SiteConfigurationExcluderTest.php         | 28 +++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/package_manager/tests/src/Kernel/PathExcluder/SiteConfigurationExcluderTest.php b/package_manager/tests/src/Kernel/PathExcluder/SiteConfigurationExcluderTest.php
index 0d72207fdf..7f5fd7e5d8 100644
--- a/package_manager/tests/src/Kernel/PathExcluder/SiteConfigurationExcluderTest.php
+++ b/package_manager/tests/src/Kernel/PathExcluder/SiteConfigurationExcluderTest.php
@@ -80,6 +80,34 @@ class SiteConfigurationExcluderTest extends PackageManagerKernelTestBase {
     }
   }
 
+  /**
+   * Tests that `sites/default` is made writable in the stage directory.
+   */
+  public function testDefaultSiteDirectoryPermissions(): void {
+    $project_root = $this->container->get(PathLocator::class)
+      ->getProjectRoot();
+    $live_dir = $project_root . '/sites/default';
+    chmod($live_dir, 0555);
+    $this->assertDirectoryIsNotWritable($live_dir);
+    // Record the permissions of the directory now, so we can be sure those
+    // permissions are restored after apply.
+    $original_permissions = fileperms($live_dir);
+    $this->assertIsInt($original_permissions);
+
+    $stage = $this->createStage();
+    $stage->create();
+    // The staged `sites/default` will be made world-writable, because we want
+    // to ensure the scaffold plugin can copy certain files into there.
+    $staged_dir = str_replace($project_root, $stage->getStageDirectory(), $live_dir);
+    $this->assertDirectoryIsWritable($staged_dir);
+
+    $stage->require(['ext-json:*']);
+    $stage->apply();
+    // After applying, the live directory should NOT inherit the staged
+    // directory's world-writable permissions.
+    $this->assertSame($original_permissions, fileperms($live_dir));
+  }
+
 }
 
 /**
-- 
GitLab