Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
automatic_updates-3449631
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
automatic_updates-3449631
Commits
3ee6fad7
Commit
3ee6fad7
authored
3 years ago
by
Adam G-H
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3258611
by phenaproxima: ExcludedPathsSubscriber should ignore unreadable directories
parent
35ba7688
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
package_manager/src/EventSubscriber/ExcludedPathsSubscriber.php
+2
-1
2 additions, 1 deletion
...e_manager/src/EventSubscriber/ExcludedPathsSubscriber.php
package_manager/tests/src/Kernel/ExcludedPathsTest.php
+68
-43
68 additions, 43 deletions
package_manager/tests/src/Kernel/ExcludedPathsTest.php
with
70 additions
and
44 deletions
package_manager/src/EventSubscriber/ExcludedPathsSubscriber.php
+
2
−
1
View file @
3ee6fad7
...
...
@@ -189,7 +189,8 @@ class ExcludedPathsSubscriber implements EventSubscriberInterface {
->
directories
()
->
name
(
'.git'
)
->
ignoreVCS
(
FALSE
)
->
ignoreDotFiles
(
FALSE
);
->
ignoreDotFiles
(
FALSE
)
->
ignoreUnreadableDirs
();
foreach
(
$finder
as
$git_directory
)
{
$project
[]
=
$git_directory
->
getPathname
();
...
...
This diff is collapsed.
Click to expand it.
package_manager/tests/src/Kernel/ExcludedPathsTest.php
+
68
−
43
View file @
3ee6fad7
...
...
@@ -3,6 +3,7 @@
namespace
Drupal\Tests\package_manager\Kernel
;
use
Drupal\Core\Database\Connection
;
use
Drupal\Core\DependencyInjection\ContainerBuilder
;
use
Drupal\package_manager
\Event\PreCreateEvent
;
use
Drupal\package_manager
\EventSubscriber\ExcludedPathsSubscriber
;
...
...
@@ -14,18 +15,19 @@ use Drupal\package_manager\EventSubscriber\ExcludedPathsSubscriber;
class
ExcludedPathsTest
extends
PackageManagerKernelTestBase
{
/**
* The mocked SQLite database connection.
*
* @var \Drupal\Core\Database\Connection|\Prophecy\Prophecy\ObjectProphecy
* {@inheritdoc}
*/
private
$mockDatabase
;
public
function
register
(
ContainerBuilder
$container
)
{
parent
::
register
(
$container
);
$container
->
getDefinition
(
'package_manager.excluded_paths_subscriber'
)
->
setClass
(
TestExcludedPathsSubscriber
::
class
);
}
/**
*
{@inheritdoc}
*
Tests that certain paths are excluded from staging operations.
*/
protected
function
setUp
():
void
{
parent
::
setUp
();
public
function
testExcludedPaths
():
void
{
// The private stream wrapper is only registered if this setting is set.
// @see \Drupal\Core\CoreServiceProvider::register()
$this
->
setSetting
(
'file_private_path'
,
'private'
);
...
...
@@ -38,16 +40,6 @@ class ExcludedPathsTest extends PackageManagerKernelTestBase {
// Ensure we have an up-to-date container.
$this
->
container
=
$this
->
container
->
get
(
'kernel'
)
->
getContainer
();
// Mock a SQLite database connection so we can test that the subscriber will
// exclude the database files.
$this
->
mockDatabase
=
$this
->
prophesize
(
Connection
::
class
);
$this
->
mockDatabase
->
driver
()
->
willReturn
(
'sqlite'
);
}
/**
* Tests that certain paths are excluded from staging operations.
*/
public
function
testExcludedPaths
():
void
{
$this
->
createTestProject
();
$active_dir
=
$this
->
container
->
get
(
'package_manager.path_locator'
)
->
getActiveDirectory
();
...
...
@@ -59,10 +51,17 @@ class ExcludedPathsTest extends PackageManagerKernelTestBase {
// Mock a SQLite database connection to a file in the active directory. The
// file should not be staged.
$this
->
mockDatabase
->
getConnectionOptions
()
->
willReturn
([
$database
=
$this
->
prophesize
(
Connection
::
class
);
$database
->
driver
()
->
willReturn
(
'sqlite'
);
$database
->
getConnectionOptions
()
->
willReturn
([
'database'
=>
$site_path
.
'/db.sqlite'
,
]);
$this
->
setUpSubscriber
(
$site_path
);
// Update the event subscriber's dependencies.
/** @var \Drupal\Tests\package_manager\Kernel\TestExcludedPathsSubscriber $subscriber */
$subscriber
=
$this
->
container
->
get
(
'package_manager.excluded_paths_subscriber'
);
$subscriber
->
sitePath
=
$site_path
;
$subscriber
->
database
=
$database
->
reveal
();
$stage
=
$this
->
createStage
();
$stage
->
create
();
...
...
@@ -162,13 +161,11 @@ class ExcludedPathsTest extends PackageManagerKernelTestBase {
/**
* Tests that SQLite database paths are excluded from the staging area.
*
* The exclusion of SQLite databases from the staging area is functionally
* tested by \Drupal\Tests\package_manager\Functional\ExcludedPathsTest. The
* purpose of this test is to ensure that SQLite database paths are processed
* properly (e.g., converting an absolute path to a relative path) before
* being flagged for exclusion.
* This test ensures that SQLite database paths are processed properly (e.g.,
* converting an absolute path to a relative path) before being flagged for
* exclusion.
*
* @param string $database
* @param string $database
_path
* The path of the SQLite database, as set in the database connection
* options.
* @param string[] $expected_exclusions
...
...
@@ -176,32 +173,60 @@ class ExcludedPathsTest extends PackageManagerKernelTestBase {
*
* @dataProvider providerSqliteDatabaseExcluded
*/
public
function
testSqliteDatabaseExcluded
(
string
$database
,
array
$expected_exclusions
):
void
{
$this
->
mockDatabase
->
getConnectionOptions
()
->
willReturn
([
'database'
=>
$database
,
public
function
testSqliteDatabaseExcluded
(
string
$database_path
,
array
$expected_exclusions
):
void
{
$database
=
$this
->
prophesize
(
Connection
::
class
);
$database
->
driver
()
->
willReturn
(
'sqlite'
);
$database
->
getConnectionOptions
()
->
willReturn
([
'database'
=>
$database_path
,
]);
// Update the event subscriber to use the mocked database.
/** @var \Drupal\Tests\package_manager\Kernel\TestExcludedPathsSubscriber $subscriber */
$subscriber
=
$this
->
container
->
get
(
'package_manager.excluded_paths_subscriber'
);
$subscriber
->
database
=
$database
->
reveal
();
$event
=
new
PreCreateEvent
(
$this
->
createStage
());
$this
->
setUpSubscriber
();
$this
->
container
->
get
(
'package_manager.excluded_paths_subscriber'
)
->
ignoreCommonPaths
(
$event
);
// Invoke the event subscriber directly, so we can check that the database
// was correctly excluded.
$subscriber
->
ignoreCommonPaths
(
$event
);
// All of the expected exclusions should be flagged.
$this
->
assertEmpty
(
array_diff
(
$expected_exclusions
,
$event
->
getExcludedPaths
()));
}
/**
* Sets up the event subscriber with a mocked database and site path.
*
* @param string $site_path
* (optional) The site path. Defaults to 'sites/default'.
* Tests that unreadable directories are ignored by the event subscriber.
*/
private
function
setUpSubscriber
(
string
$site_path
=
'sites/default'
):
void
{
$this
->
container
->
set
(
'package_manager.excluded_paths_subscriber'
,
new
ExcludedPathsSubscriber
(
$site_path
,
$this
->
container
->
get
(
'package_manager.symfony_file_system'
),
$this
->
container
->
get
(
'stream_wrapper_manager'
),
$this
->
mockDatabase
->
reveal
(),
$this
->
container
->
get
(
'package_manager.path_locator'
)
));
public
function
testUnreadableDirectoriesAreIgnored
():
void
{
$this
->
createTestProject
();
$active_dir
=
$this
->
container
->
get
(
'package_manager.path_locator'
)
->
getActiveDirectory
();
// Create an unreadable directory within the active directory, which will
// raise an exception as the event subscriber tries to scan for .git
// directories...unless unreadable directories are being ignored, as they
// should be.
$unreadable_dir
=
$active_dir
.
'/unreadable'
;
mkdir
(
$unreadable_dir
,
0000
);
$this
->
assertDirectoryIsNotReadable
(
$unreadable_dir
);
$this
->
createStage
()
->
create
();
}
}
/**
* A test-only version of the excluded paths event subscriber.
*/
class
TestExcludedPathsSubscriber
extends
ExcludedPathsSubscriber
{
/**
* {@inheritdoc}
*/
public
$sitePath
;
/**
* {@inheritdoc}
*/
public
$database
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment