MediaWiki  REL1_31
FirejailCommandTest.php
Go to the documentation of this file.
1 <?php
2 
24 use Wikimedia\TestingAccessWrapper;
25 
26 class FirejailCommandTest extends PHPUnit\Framework\TestCase {
27 
28  use MediaWikiCoversValidator;
29 
30  public function provideBuildFinalCommand() {
31  global $IP;
32  // phpcs:ignore Generic.Files.LineLength
33  $env = "'MW_INCLUDE_STDERR=;MW_CPU_LIMIT=180; MW_CGROUP='\'''\''; MW_MEM_LIMIT=307200; MW_FILE_SIZE_LIMIT=102400; MW_WALL_CLOCK_LIMIT=180; MW_USE_LOG_PIPE=yes'";
34  $limit = "/bin/bash '$IP/includes/shell/limit.sh'";
35  $profile = "--profile=$IP/includes/shell/firejail.profile";
36  $blacklist = '--blacklist=' . realpath( MW_CONFIG_FILE );
37  $default = "$blacklist --noroot --seccomp --private-dev";
38  return [
39  [
40  'No restrictions',
41  'ls', 0, "$limit ''\''ls'\''' $env"
42  ],
43  [
44  'default restriction',
45  'ls', Shell::RESTRICT_DEFAULT,
46  "$limit 'firejail --quiet $profile $default -- '\''ls'\''' $env"
47  ],
48  [
49  'no network',
50  'ls', Shell::NO_NETWORK,
51  "$limit 'firejail --quiet $profile --net=none -- '\''ls'\''' $env"
52  ],
53  [
54  'default restriction & no network',
55  'ls', Shell::RESTRICT_DEFAULT | Shell::NO_NETWORK,
56  "$limit 'firejail --quiet $profile $default --net=none -- '\''ls'\''' $env"
57  ],
58  [
59  'seccomp',
60  'ls', Shell::SECCOMP,
61  "$limit 'firejail --quiet $profile --seccomp -- '\''ls'\''' $env"
62  ],
63  [
64  'seccomp & no execve',
65  'ls', Shell::SECCOMP | Shell::NO_EXECVE,
66  "$limit 'firejail --quiet $profile --shell=none --seccomp=execve -- '\''ls'\''' $env"
67  ],
68  ];
69  }
70 
75  public function testBuildFinalCommand( $desc, $params, $flags, $expected ) {
76  $command = new FirejailCommand( 'firejail' );
77  $command
78  ->params( $params )
79  ->restrict( $flags );
80  $wrapper = TestingAccessWrapper::newFromObject( $command );
81  $output = $wrapper->buildFinalCommand( $wrapper->command );
82  $this->assertEquals( $expected, $output[0], $desc );
83  }
84 
88  public function testParamsOutput() {
89  $this->expectException( RuntimeException::class );
90  ( new FirejailCommand( 'firejail' ) )->params( 'echo', 'a', '--output=/tmp/fjout', ';id' );
91  }
92 
93 }
MediaWiki\Shell\Shell
Executes shell commands.
Definition: Shell.php:44
use
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Definition: APACHE-LICENSE-2.0.txt:10
FirejailCommandTest\provideBuildFinalCommand
provideBuildFinalCommand()
Definition: FirejailCommandTest.php:30
$output
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place $output
Definition: hooks.txt:2255
FirejailCommandTest
Definition: FirejailCommandTest.php:26
$params
$params
Definition: styleTest.css.php:40
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:37
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:95
MediaWiki\Shell\FirejailCommand
Restricts execution of shell commands using firejail.
Definition: FirejailCommand.php:31
$command
$command
Definition: cdb.php:65
FirejailCommandTest\testParamsOutput
testParamsOutput()
\MediaWiki\Shell\FirejailCommand::params
Definition: FirejailCommandTest.php:88
FirejailCommandTest\testBuildFinalCommand
testBuildFinalCommand( $desc, $params, $flags, $expected)
\MediaWiki\Shell\FirejailCommand::buildFinalCommand() provideBuildFinalCommand
Definition: FirejailCommandTest.php:75
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:56
$IP
$IP
Definition: WebStart.php:52