diff --git a/dev/tests/integration/testsuite/Magento/Framework/Lock/Backend/FileLockTest.php b/dev/tests/integration/testsuite/Magento/Framework/Lock/Backend/FileLockTest.php index b587696ae2bdb..d465e230e0f29 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Lock/Backend/FileLockTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Lock/Backend/FileLockTest.php @@ -35,10 +35,11 @@ protected function setUp(): void ); } - public function testLockAndUnlock() + /** + * @dataProvider lockNameProvider + */ + public function testLockAndUnlock(string $name) { - $name = 'test_lock'; - $this->assertFalse($this->model->isLocked($name)); $this->assertTrue($this->model->lock($name)); @@ -49,35 +50,53 @@ public function testLockAndUnlock() $this->assertFalse($this->model->isLocked($name)); } - public function testUnlockWithoutExistingLock() + /** + * @dataProvider lockNameProvider + */ + public function testUnlockWithoutExistingLock(string $name) { - $name = 'test_lock'; - $this->assertFalse($this->model->isLocked($name)); $this->assertFalse($this->model->unlock($name)); } - public function testCleanupOldFile() + /** + * @dataProvider lockNameProvider + */ + public function testCleanupOldFile(string $name) { - $name = 'test_lock'; - $this->assertTrue($this->model->lock($name)); $this->assertTrue($this->model->unlock($name)); - touch(sprintf('%s/%s', $this->lockPath, $name), strtotime('30 hours ago')); + touch($this->getFilePath($name), strtotime('30 hours ago')); $this->assertEquals(1, $this->model->cleanupOldLocks()); } - public function testDontCleanupNewFile() + /** + * @dataProvider lockNameProvider + */ + public function testDontCleanupNewFile(string $name) { - $name = 'test_lock'; - $this->assertTrue($this->model->lock($name)); $this->assertTrue($this->model->unlock($name)); - touch(sprintf('%s/%s', $this->lockPath, $name), strtotime('1 hour ago')); + touch($this->getFilePath($name), strtotime('1 hour ago')); $this->assertEquals(0, $this->model->cleanupOldLocks()); } + + private function getFilePath(string $name): string + { + return $this->lockPath . '/' . rawurlencode($name); + } + + public static function lockNameProvider(): array + { + return [ + 'standard_alphanumeric' => ['test_lock_name'], + 'with_unix_forbidden_chars' => ['test/lock/name'], + 'with_windows_forbidden_chars' => ['*ts:t"l/o\\c|k?_name'], + 'with_spaces' => ['test lock name'] + ]; + } } diff --git a/lib/internal/Magento/Framework/Lock/Backend/FileLock.php b/lib/internal/Magento/Framework/Lock/Backend/FileLock.php index 69ffa04be8e70..86c977b093bb2 100644 --- a/lib/internal/Magento/Framework/Lock/Backend/FileLock.php +++ b/lib/internal/Magento/Framework/Lock/Backend/FileLock.php @@ -133,7 +133,8 @@ public function cleanupOldLocks(): int continue; } - if ($this->isLocked(basename($lockFile))) { + $filename = basename($lockFile); + if ($this->isLocked(rawurldecode($filename))) { continue; } @@ -204,7 +205,7 @@ public function unlock(string $name): bool */ private function getLockPath(string $name): string { - return $this->path . $name; + return $this->path . rawurlencode($name); } /**