fix(#3269636): use stream wrapper URL resolution for private:// redirect paths#6
fix(#3269636): use stream wrapper URL resolution for private:// redirect paths#6Decipher wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughUpdates the ChangesRedirect path resolution and test behavior updates
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
646d619 to
5838b8a
Compare
Demonstrates that Redirect::getPath() resolves private:// destinations to the raw filesystem path instead of the web-accessible route, per https://www.drupal.org/project/filefield_paths/issues/3269636. Expected to fail until the underlying bug is fixed.
5838b8a to
348bd10
Compare
…ect paths Redirect::getPath() called LocalStream::getDirectoryPath() for every scheme, which for private:// returns the raw filesystem base path instead of a web-accessible route. Only public:// keeps the directory path behaviour; other schemes now resolve through the stream wrapper's getExternalUrl(), which builds the correct Drupal-managed route (e.g. system.private_file_download for private://).
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 8.x-1.x #6 +/- ##
===========================================
+ Coverage 79.72% 79.79% +0.06%
===========================================
Files 17 17
Lines 666 668 +2
===========================================
+ Hits 531 533 +2
Misses 135 135 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
Adds Kernel test coverage for
src/Redirect.php, which currently has 0%coverage. Includes a test that intentionally fails, reproducing the bug
reported in #3269636
("Incorrect redirect from public to private folder"). This is deliberately
a test-only, red MR — the fix will follow as a separate MR once this is
reviewed.
Closes #
Background
Drupal.org issue #3269636 reports that moving a file from
public://toprivate://creates a redirect pointing at the raw private filesystem path(e.g.
/sites/default/PRIVATE/folder/file) instead of the web-accessibledownload route (
/system/files/folder/file). The issue had been Postponed[NMI] since 2022 pending re-confirmation against rc1.
Root cause, confirmed while writing this test:
Redirect::getPath()calls$wrapper->getDirectoryPath()for anyLocalStream-based wrapper. Forpublic://this happens to be web-accessible, butPrivateStream::getDirectoryPath()returnsSettings::get('file_private_path')— the raw filesystem base path — rather than going through
PrivateStream::getExternalUrl(), which builds thesystem.private_file_downloadroute.While building this test, also found and documented (but did not fix) a
second, previously unreported bug: the dedup pre-check in
createRedirect()hashes the destination path, but theredirectentity's own
preSave()always recomputes its stored hash from thesource path. The two never match, so calling
createRedirect()twicewith identical arguments throws an uncaught
EntityStorageExceptioninstead of being silently skipped. Tracked as a
@todo-style note in thetest for now; no Drupal.org issue filed yet.
Changes
tests/src/Kernel/RedirectTest.phpRedirect::createRedirect()/getPath(): public:// happy path (passing), duplicate-call behaviour (passing, documents the dedup bug), private:// destination path (failing — reproduces #3269636)Test plan
DRUPAL_VERSION=10 make test-unitpasses (11/11)DRUPAL_VERSION=10 make test-kernel— 2 pass, 1 intentionally fails (testCreateRedirectForPrivateSchemeUsesWebAccessiblePath), confirming the reproductionDRUPAL_VERSION=10 make lint— PHPCS clean (PHPStan hits a pre-existing environment memory-limit issue unrelated to this change, reproduced on8.x-1.xHEAD as well)Redirect::getPath()to resolve a web-accessible URL for non-directly-servable schemes; this test should then turn greenSummary by CodeRabbit
public://andprivate://file paths, including handling duplicate redirect creation without errors.public://vs non-publicschemes, ensuring the resulting redirect URL uses the appropriate, user-facing path format.