2011-06-18 14:56:14 +00:00
|
|
|
<?php
|
2014-03-07 20:22:13 +00:00
|
|
|
|
2011-07-26 23:39:48 +00:00
|
|
|
/**
|
|
|
|
|
* @group Database
|
2013-10-24 20:30:43 +00:00
|
|
|
*
|
|
|
|
|
* @covers UploadStash
|
2011-07-26 23:39:48 +00:00
|
|
|
*/
|
2011-06-18 14:56:14 +00:00
|
|
|
class UploadStashTest extends MediaWikiTestCase {
|
2011-07-12 21:11:43 +00:00
|
|
|
/**
|
2016-05-06 15:11:08 +00:00
|
|
|
* @var TestUser[] Array of UploadStashTestUser
|
2011-07-12 21:11:43 +00:00
|
|
|
*/
|
|
|
|
|
public static $users;
|
|
|
|
|
|
2014-03-07 20:22:13 +00:00
|
|
|
/**
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
private $bug29408File;
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
protected function setUp() {
|
2011-06-18 14:56:14 +00:00
|
|
|
parent::setUp();
|
2012-01-07 09:26:11 +00:00
|
|
|
|
2011-06-18 14:56:14 +00:00
|
|
|
// Setup a file for bug 29408
|
2015-08-31 22:48:27 +00:00
|
|
|
$this->bug29408File = wfTempDir() . '/bug29408';
|
2012-01-07 09:26:11 +00:00
|
|
|
file_put_contents( $this->bug29408File, "\x00" );
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
self::$users = [
|
2012-09-11 00:07:18 +00:00
|
|
|
'sysop' => new TestUser(
|
2011-07-12 21:11:43 +00:00
|
|
|
'Uploadstashtestsysop',
|
|
|
|
|
'Upload Stash Test Sysop',
|
2011-12-21 22:22:01 +00:00
|
|
|
'upload_stash_test_sysop@example.com',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'sysop' ]
|
2011-07-12 21:11:43 +00:00
|
|
|
),
|
2012-09-11 00:07:18 +00:00
|
|
|
'uploader' => new TestUser(
|
2011-07-12 21:11:43 +00:00
|
|
|
'Uploadstashtestuser',
|
|
|
|
|
'Upload Stash Test User',
|
2011-12-21 22:22:01 +00:00
|
|
|
'upload_stash_test_user@example.com',
|
2016-02-17 09:09:32 +00:00
|
|
|
[]
|
2011-07-12 21:11:43 +00:00
|
|
|
)
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2011-06-18 14:56:14 +00:00
|
|
|
}
|
2012-01-07 09:26:11 +00:00
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
protected function tearDown() {
|
|
|
|
|
if ( file_exists( $this->bug29408File . "." ) ) {
|
|
|
|
|
unlink( $this->bug29408File . "." );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( file_exists( $this->bug29408File ) ) {
|
|
|
|
|
unlink( $this->bug29408File );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parent::tearDown();
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-07 20:22:13 +00:00
|
|
|
/**
|
|
|
|
|
* @todo give this test a real name explaining what is being tested here
|
|
|
|
|
*/
|
2011-06-18 14:56:14 +00:00
|
|
|
public function testBug29408() {
|
2016-09-10 15:27:49 +00:00
|
|
|
$this->setMwGlobals( 'wgUser', self::$users['uploader']->getUser() );
|
|
|
|
|
|
2011-06-18 14:56:14 +00:00
|
|
|
$repo = RepoGroup::singleton()->getLocalRepo();
|
2016-09-10 15:27:49 +00:00
|
|
|
$stash = new UploadStash( $repo );
|
2012-01-07 01:33:23 +00:00
|
|
|
|
2011-06-18 14:56:14 +00:00
|
|
|
// Throws exception caught by PHPUnit on failure
|
|
|
|
|
$file = $stash->stashFile( $this->bug29408File );
|
|
|
|
|
// We'll never reach this point if we hit bug 29408
|
|
|
|
|
$this->assertTrue( true, 'Unrecognized file without extension' );
|
2012-01-07 09:26:11 +00:00
|
|
|
|
2011-07-12 21:11:43 +00:00
|
|
|
$stash->removeFile( $file->getFileKey() );
|
2011-06-18 14:56:14 +00:00
|
|
|
}
|
2011-08-15 18:10:10 +00:00
|
|
|
|
2014-09-18 01:28:26 +00:00
|
|
|
public static function provideInvalidRequests() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2014-03-07 20:22:13 +00:00
|
|
|
'Check failure on bad wpFileKey' =>
|
2016-02-17 09:09:32 +00:00
|
|
|
[ new FauxRequest( [ 'wpFileKey' => 'foo' ] ) ],
|
2014-03-07 20:22:13 +00:00
|
|
|
'Check failure on bad wpSessionKey' =>
|
2016-02-17 09:09:32 +00:00
|
|
|
[ new FauxRequest( [ 'wpSessionKey' => 'foo' ] ) ],
|
|
|
|
|
];
|
2014-03-07 20:22:13 +00:00
|
|
|
}
|
2011-08-15 18:10:10 +00:00
|
|
|
|
2014-03-07 20:22:13 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provideInvalidRequests
|
|
|
|
|
*/
|
|
|
|
|
public function testValidRequestWithInvalidRequests( $request ) {
|
|
|
|
|
$this->assertFalse( UploadFromStash::isValidRequest( $request ) );
|
|
|
|
|
}
|
2011-08-15 18:10:10 +00:00
|
|
|
|
2014-09-18 01:28:26 +00:00
|
|
|
public static function provideValidRequests() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2014-03-07 20:22:13 +00:00
|
|
|
'Check good wpFileKey' =>
|
2016-02-17 09:09:32 +00:00
|
|
|
[ new FauxRequest( [ 'wpFileKey' => 'testkey-test.test' ] ) ],
|
2014-03-07 20:22:13 +00:00
|
|
|
'Check good wpSessionKey' =>
|
2016-02-17 09:09:32 +00:00
|
|
|
[ new FauxRequest( [ 'wpFileKey' => 'testkey-test.test' ] ) ],
|
2014-03-07 20:22:13 +00:00
|
|
|
'Check key precedence' =>
|
2016-02-17 09:09:32 +00:00
|
|
|
[ new FauxRequest( [
|
2014-03-07 20:22:13 +00:00
|
|
|
'wpFileKey' => 'testkey-test.test',
|
|
|
|
|
'wpSessionKey' => 'foo'
|
2016-02-17 09:09:32 +00:00
|
|
|
] ) ],
|
|
|
|
|
];
|
2011-08-15 18:10:10 +00:00
|
|
|
}
|
2014-03-07 20:22:13 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provideValidRequests
|
|
|
|
|
*/
|
|
|
|
|
public function testValidRequestWithValidRequests( $request ) {
|
|
|
|
|
$this->assertTrue( UploadFromStash::isValidRequest( $request ) );
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-21 15:06:59 +00:00
|
|
|
}
|