You are here

public function SecurityFileUploadEventSubscriberTest::provideFilenames in Drupal 10

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Unit/Event/SecurityFileUploadEventSubscriberTest.php \Drupal\Tests\system\Unit\Event\SecurityFileUploadEventSubscriberTest::provideFilenames()

Provides data for testSanitizeName().

Return value

array Arrays with original name, allowed extensions, expected name and (optional) expected name 'allow_insecure_uploads' is set to TRUE.

File

core/modules/system/tests/src/Unit/Event/SecurityFileUploadEventSubscriberTest.php, line 73

Class

SecurityFileUploadEventSubscriberTest
SecurityFileUploadEventSubscriber tests.

Namespace

Drupal\Tests\system\Unit\Event

Code

public function provideFilenames() {
  return [
    'All extensions allowed filename not munged' => [
      'foo.txt',
      '',
      'foo.txt',
    ],
    'All extensions allowed with .php file' => [
      'foo.php',
      '',
      'foo.php_.txt',
      'foo.php',
    ],
    'All extensions allowed with .pHp file' => [
      'foo.pHp',
      '',
      'foo.pHp_.txt',
      'foo.pHp',
    ],
    'All extensions allowed with .PHP file' => [
      'foo.PHP',
      '',
      'foo.PHP_.txt',
      'foo.PHP',
    ],
    '.php extension allowed with .php file' => [
      'foo.php',
      'php',
      'foo.php',
      'foo.php',
    ],
    '.PhP extension allowed with .php file' => [
      'foo.php',
      'PhP',
      'foo.php',
      'foo.php',
    ],
    '.php, .txt extension allowed with .php file' => [
      'foo.php',
      'php txt',
      'foo.php_.txt',
      'foo.php',
    ],
    '.PhP, .tXt extension allowed with .php file' => [
      'foo.php',
      'PhP tXt',
      'foo.php_.txt',
      'foo.php',
    ],
    'no extension produces no errors' => [
      'foo',
      '',
      'foo',
    ],
    'filename is munged' => [
      'foo.phar.png.php.jpg',
      'jpg png',
      'foo.phar_.png_.php_.jpg',
    ],
    'filename is munged regardless of case' => [
      'FOO.pHAR.PNG.PhP.jpg',
      'jpg png',
      'FOO.pHAR_.PNG_.PhP_.jpg',
    ],
    'null bytes are removed' => [
      'foo' . chr(0) . '.txt' . chr(0),
      '',
      'foo.txt',
    ],
    'dot files are renamed' => [
      '.git',
      '',
      'git',
    ],
    'htaccess files are renamed even if allowed' => [
      '.htaccess',
      'htaccess txt',
      '.htaccess_.txt',
      '.htaccess',
    ],
  ];
}