Skip to content

Commit

Permalink
Fix tests, linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Carlino committed May 2, 2019
1 parent 06f84d2 commit 8f5fa41
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
16 changes: 11 additions & 5 deletions src/Dev/Tasks/SecureAssetsMigrationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use League\Flysystem\Filesystem;
use SilverStripe\Assets\File;
use SilverStripe\Assets\Flysystem\FlysystemAssetStore;
use SilverStripe\Assets\Folder;
use SilverStripe\Core\Config\Configurable;
use SilverStripe\Core\Injector\Injectable;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\Queries\SQLSelect;

/**
Expand Down Expand Up @@ -36,10 +38,12 @@ class SecureAssetsMigrationHelper
protected $htaccessRegexes = [];

private static $dependencies = [
'logger' => '%$' . LoggerInterface::class,
'logger' => '%$' . LoggerInterface::class . '.quiet',
];

/** @var LoggerInterface */
/**
* @var LoggerInterface
*/
private $logger;

public function __construct()
Expand Down Expand Up @@ -73,14 +77,15 @@ public function run(FlysystemAssetStore $store)
// or from an already used 4.x database with built-in asset protections.
// Because the module itself has been removed in 4.x installs,
// we can no longer tell the difference between those cases.
$fileTable = DataObject::getSchema()->baseDataTable(File::class);
$securedFolders = SQLSelect::create()
->setFrom('File')
->setFrom("\"$fileTable\"")
->setSelect([
'"ID"',
'"FileFilename"',
])
->addWhere([
'"ClassName" = ?' => 'SilverStripe\Assets\Folder',
'"ClassName" = ?' => Folder::class,
// We don't need to check 'Inherited' permissions,
// since Apache applies parent .htaccess and the module doesn't create them in this case.
// See SecureFileExtension->needsAccessFile()
Expand All @@ -106,6 +111,7 @@ public function run(FlysystemAssetStore $store)

/**
* @param LoggerInterface $logger
* @return $this
*/
public function setLogger(LoggerInterface $logger)
{
Expand Down Expand Up @@ -133,7 +139,7 @@ public function htaccessMatch($content)
return false;
}

foreach($lines as $i => $line) {
foreach ($lines as $i => $line) {
if (!preg_match($regexes[$i], $line)) {
return false;
}
Expand Down
1 change: 0 additions & 1 deletion tests/php/Dev/Tasks/SecureAssetsMigrationHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,4 @@ public function testHtaccessDoesNotMatchWithAdditionsInBetween()
$helper = new SecureAssetsMigrationHelper();
$this->assertFalse($helper->htaccessMatch($htaccess));
}

}

0 comments on commit 8f5fa41

Please sign in to comment.