aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin/tests
diff options
context:
space:
mode:
authorChristopher Ng <chrng8@gmail.com>2023-05-31 19:06:42 -0700
committerChristopher Ng <chrng8@gmail.com>2023-05-31 19:06:42 -0700
commit7c430a8afcf4645190fa66bea326103f45d26e0d (patch)
treef5a33f382efb2f9ea23c43a1609ff6e65adb3694 /apps/files_trashbin/tests
parentaaa226df1ced518d412e87d5e2aa438f5bae167d (diff)
downloadnextcloud-server-7c430a8afcf4645190fa66bea326103f45d26e0d.tar.gz
nextcloud-server-7c430a8afcf4645190fa66bea326103f45d26e0d.zip
fix(trashbin): Truncate long filenames
Signed-off-by: Christopher Ng <chrng8@gmail.com>
Diffstat (limited to 'apps/files_trashbin/tests')
-rw-r--r--apps/files_trashbin/tests/StorageTest.php45
1 files changed, 45 insertions, 0 deletions
diff --git a/apps/files_trashbin/tests/StorageTest.php b/apps/files_trashbin/tests/StorageTest.php
index b4892d2deb0..15b47385d45 100644
--- a/apps/files_trashbin/tests/StorageTest.php
+++ b/apps/files_trashbin/tests/StorageTest.php
@@ -88,6 +88,11 @@ class StorageTest extends \Test\TestCase {
*/
private $userView;
+ // 239 chars so appended timestamp of 12 chars will exceed max length of 250 chars
+ private const LONG_FILENAME = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt';
+ // 250 chars
+ private const MAX_FILENAME = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt';
+
protected function setUp(): void {
parent::setUp();
@@ -109,6 +114,8 @@ class StorageTest extends \Test\TestCase {
$this->rootView = new \OC\Files\View('/');
$this->userView = new \OC\Files\View('/' . $this->user . '/files/');
$this->userView->file_put_contents('test.txt', 'foo');
+ $this->userView->file_put_contents(static::LONG_FILENAME, 'foo');
+ $this->userView->file_put_contents(static::MAX_FILENAME, 'foo');
$this->userView->mkdir('folder');
$this->userView->file_put_contents('folder/inside.txt', 'bar');
@@ -165,6 +172,44 @@ class StorageTest extends \Test\TestCase {
}
/**
+ * Test that deleting a file with a long filename puts it into the trashbin.
+ */
+ public function testSingleStorageDeleteLongFilename() {
+ $truncatedFilename = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt';
+
+ $this->assertTrue($this->userView->file_exists(static::LONG_FILENAME));
+ $this->userView->unlink(static::LONG_FILENAME);
+ [$storage,] = $this->userView->resolvePath(static::LONG_FILENAME);
+ $storage->getScanner()->scan(''); // make sure we check the storage
+ $this->assertFalse($this->userView->getFileInfo(static::LONG_FILENAME));
+
+ // check if file is in trashbin
+ $results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/files/');
+ $this->assertEquals(1, count($results));
+ $name = $results[0]->getName();
+ $this->assertEquals($truncatedFilename, substr($name, 0, strrpos($name, '.')));
+ }
+
+ /**
+ * Test that deleting a file with the max filename length puts it into the trashbin.
+ */
+ public function testSingleStorageDeleteMaxLengthFilename() {
+ $truncatedFilename = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt';
+
+ $this->assertTrue($this->userView->file_exists(static::MAX_FILENAME));
+ $this->userView->unlink(static::MAX_FILENAME);
+ [$storage,] = $this->userView->resolvePath(static::MAX_FILENAME);
+ $storage->getScanner()->scan(''); // make sure we check the storage
+ $this->assertFalse($this->userView->getFileInfo(static::MAX_FILENAME));
+
+ // check if file is in trashbin
+ $results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/files/');
+ $this->assertEquals(1, count($results));
+ $name = $results[0]->getName();
+ $this->assertEquals($truncatedFilename, substr($name, 0, strrpos($name, '.')));
+ }
+
+ /**
* Test that deleting a file from another mounted storage properly
* lands in the trashbin. This is a cross-storage situation because
* the trashbin folder is in the root storage while the mounted one