Skip to content

Commit a93b8a7

Browse files
icewind1991backportbot[bot]
authored andcommitted
test: add tests for trashbin filename truncate
Signed-off-by: Robin Appelman <robin@icewind.nl> Signed-off-by: Louis Chmn <louis@chmn.me>
1 parent 562d95c commit a93b8a7

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

apps/files_trashbin/tests/StorageTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public function testSingleStorageDeleteFolder(): void {
227227
* Test that deleting a file with a long filename puts it into the trashbin.
228228
*/
229229
public function testSingleStorageDeleteLongFilename(): void {
230-
$truncatedFilename = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt';
230+
$truncatedFilename = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt';
231231

232232
$this->assertTrue($this->userView->file_exists(static::LONG_FILENAME));
233233
$this->userView->unlink(static::LONG_FILENAME);
@@ -246,7 +246,7 @@ public function testSingleStorageDeleteLongFilename(): void {
246246
* Test that deleting a file with the max filename length puts it into the trashbin.
247247
*/
248248
public function testSingleStorageDeleteMaxLengthFilename(): void {
249-
$truncatedFilename = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt';
249+
$truncatedFilename = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt';
250250

251251
$this->assertTrue($this->userView->file_exists(static::MAX_FILENAME));
252252
$this->userView->unlink(static::MAX_FILENAME);

apps/files_trashbin/tests/TrashbinTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use OCP\IUserManager;
3131
use OCP\Server;
3232
use OCP\Share\IShare;
33+
use PHPUnit\Framework\Attributes\DataProvider;
3334

3435
/**
3536
* Class Test_Encryption
@@ -697,6 +698,32 @@ public static function loginHelper($user, $create = false) {
697698
\OC_Util::setupFS($user);
698699
Server::get(IRootFolder::class)->getUserFolder($user);
699700
}
701+
702+
public static function trashFilenameProvider(): array {
703+
return [
704+
['foo.txt', 'foo.txt.d1234'],
705+
[
706+
'a_very_long_filename_with_a_lot_a_characters_such_that_it_reaches_the_file_length_limit_and_would_cause_issues_if_we_just_appended_the_'
707+
. 'timestamp_because_then_the_combined_length_would_overflow_the_column_limit_of_the_filecache_and_truncate_in_db.txt',
708+
'a_very_long_filename_with_a_lot_a_characters_such_that_it_reaches_the_file_length_limit_and_would_cause_issues_if_we_just_ded_the_'
709+
. 'timestamp_because_then_the_combined_length_would_overflow_the_column_limit_of_the_filecache_and_truncate_in_db.txt.d1234'
710+
],
711+
[
712+
'a_very_long_filename_with_a_lot_a_characters_such_that_it_reaches_the_file_length_limit_and_would_cause_issues_if_we_just_äøšá_the_'
713+
. 'timestamp_because_then_the_combined_length_would_overflow_the_column_limit_of_the_filecache_and_truncate_in_db.txt',
714+
'a_very_long_filename_with_a_lot_a_characters_such_that_it_reaches_the_file_length_limit_and_would_cause_issues_if_we_ju_á_the_'
715+
. 'timestamp_because_then_the_combined_length_would_overflow_the_column_limit_of_the_filecache_and_truncate_in_db.txt.d1234'
716+
],
717+
];
718+
}
719+
720+
#[DataProvider(methodName: 'trashFilenameProvider')]
721+
public function testGetTrashFilename(string $filename, string $expected): void {
722+
$result = Trashbin::getTrashFilename($filename, 1234);
723+
$this->assertTrue(mb_check_encoding($result, 'UTF-8'));
724+
$this->assertEquals($expected, $result);
725+
$this->assertTrue(strlen($result) <= 250);
726+
}
700727
}
701728

702729

0 commit comments

Comments
 (0)