shell: Make ->restrict( RESTRICT_NONE ) actually work

Have ->restrict() overwrite any previous restrictions instead of adding
to the existing list. Multiple examples are provided on how this
function should be called going forward.

According to codesearch, all non-test uses of ->restrict() were already
expecting this behavior, passing values like:
 Shell::RESTRICT_DEFAULT | Shell::NO_NETWORK
when trying to disable network access.

This is a breaking change, but IMO one that is going to fix more things
than it breaks.

Bug: T257278
Change-Id: I1895d1fc73cc793af2f82001e9d5874b7520f802
This commit is contained in:
Kunal Mehta 2020-07-06 17:17:25 -07:00 committed by Tim Starling
parent c2f0417d1c
commit 24ddc62a3c
2 changed files with 18 additions and 3 deletions

View file

@ -241,14 +241,29 @@ class Command {
}
/**
* Set additional restrictions for this request
* Set restrictions for this request, overwriting any previously set restrictions.
*
* Add the "no network" restriction:
* @code
* $command->restrict( Shell::RESTRICT_DEFAULT | Shell::NO_NETWORK );
* @endcode
*
* Allow LocalSettings.php access:
* @code
* $command->restrict( Shell::RESTRICT_DEFAULT & ~Shell::NO_LOCALSETTINGS );
* @endcode
*
* Disable all restrictions:
* @code
* $command->restrict( Shell::RESTRICT_NONE );
* @endcode
*
* @since 1.31
* @param int $restrictions
* @return $this
*/
public function restrict( int $restrictions ): Command {
$this->restrictions |= $restrictions;
$this->restrictions = $restrictions;
return $this;
}

View file

@ -184,8 +184,8 @@ class CommandTest extends PHPUnit\Framework\TestCase {
}
/**
* Ensure that it's possible to disable the default shell restrictions
* @see T257278
* @group Broken
*/
public function testDisablingRestrictions() {
$command = TestingAccessWrapper::newFromObject( new Command() );