2011-06-18 14:56:14 +00:00
|
|
|
<?php
|
2011-07-26 23:39:48 +00:00
|
|
|
/**
|
|
|
|
|
* @group Database
|
|
|
|
|
*/
|
2011-06-18 14:56:14 +00:00
|
|
|
class UploadStashTest extends MediaWikiTestCase {
|
2011-07-12 21:11:43 +00:00
|
|
|
/**
|
|
|
|
|
* @var Array of UploadStashTestUser
|
|
|
|
|
*/
|
|
|
|
|
public static $users;
|
|
|
|
|
|
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
|
2012-08-27 19:03:15 +00:00
|
|
|
$this->bug29408File = __DIR__ . '/bug29408';
|
2012-01-07 09:26:11 +00:00
|
|
|
file_put_contents( $this->bug29408File, "\x00" );
|
|
|
|
|
|
2011-07-12 21:11:43 +00:00
|
|
|
self::$users = array(
|
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',
|
2011-07-12 21:11:43 +00:00
|
|
|
array( 'sysop' )
|
|
|
|
|
),
|
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',
|
2011-07-12 21:11:43 +00:00
|
|
|
array()
|
|
|
|
|
)
|
|
|
|
|
);
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-18 14:56:14 +00:00
|
|
|
public function testBug29408() {
|
2013-03-21 19:35:44 +00:00
|
|
|
$this->setMwGlobals( 'wgUser', self::$users['uploader']->user );
|
2012-01-07 09:26:11 +00:00
|
|
|
|
2011-06-18 14:56:14 +00:00
|
|
|
$repo = RepoGroup::singleton()->getLocalRepo();
|
|
|
|
|
$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
|
|
|
|
|
|
|
|
public function testValidRequest() {
|
2013-02-15 10:35:55 +00:00
|
|
|
$request = new FauxRequest( array( 'wpFileKey' => 'foo' ) );
|
|
|
|
|
$this->assertFalse( UploadFromStash::isValidRequest( $request ), 'Check failure on bad wpFileKey' );
|
2011-08-15 18:10:10 +00:00
|
|
|
|
2013-02-15 10:35:55 +00:00
|
|
|
$request = new FauxRequest( array( 'wpSessionKey' => 'foo' ) );
|
|
|
|
|
$this->assertFalse( UploadFromStash::isValidRequest( $request ), 'Check failure on bad wpSessionKey' );
|
2011-08-15 18:10:10 +00:00
|
|
|
|
2013-02-15 10:35:55 +00:00
|
|
|
$request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test' ) );
|
|
|
|
|
$this->assertTrue( UploadFromStash::isValidRequest( $request ), 'Check good wpFileKey' );
|
2011-08-15 18:10:10 +00:00
|
|
|
|
2013-02-15 10:35:55 +00:00
|
|
|
$request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test' ) );
|
|
|
|
|
$this->assertTrue( UploadFromStash::isValidRequest( $request ), 'Check good wpSessionKey' );
|
2011-08-15 18:10:10 +00:00
|
|
|
|
2013-02-15 10:35:55 +00:00
|
|
|
$request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test', 'wpSessionKey' => 'foo' ) );
|
|
|
|
|
$this->assertTrue( UploadFromStash::isValidRequest( $request ), 'Check key precedence' );
|
2011-08-15 18:10:10 +00:00
|
|
|
}
|
2011-06-21 15:06:59 +00:00
|
|
|
}
|