wiki.techinc.nl/tests/phpunit/includes/upload/UploadFromUrlTest.php
Brad Jorsch 5083e810eb Remove SessionManager, temporarily
The plan here is to take it out of 1.27.0-wmf.12 and put it back in
1.27.0-wmf.13.

Since BotPasswords depends on SessionManager, that's getting temporarily
removed too.

This reverts the following commits:
* 6acd424e0d SessionManager: Notify AuthPlugin before calling hooks
* 4d1ad32d8a Close a loophole in CookieSessionProvider
* fcdd643a46 SessionManager: Don't save non-persisted sessions to backend storage
* 058aec4c76 MessageCache: Don't get a ParserOptions for $wgUser before the end of Setup.php
* b5c0c03bb7 SessionManager: Save user name to metadata even if the user doesn't exist locally
* 13f2f09a19 SECURITY: Fix User::setToken() call on User::newSystemUser
* 305bc75b27 SessionManager: Don't generate user tokens when checking the tokens
* 7c4bd85d21 RequestContext::exportSession() should only export persisted session IDs
* 296ccfd4a9 SessionManager: Save 'persisted' flag in session metadata
* 94ba53f677 Move CSRF token handling into MediaWiki\Session\Session
* 46a565d6b0 Avoid false "added in both Session and $_SESSION" when value is null
* c00d0b5d94 Log backtrace for "User::loadFromSession called before the end of Setup.php"
* 4eeff5b559 Use $wgSecureCookie to decide whether to actually mark secure cookies as 'secure'
* 7491b52f70 Call session_cache_limiter() before starting a session
* 2c34aeea72 SessionManager: Abstract forceHTTPS cookie setting
* 9aa53627a5 Ignore auth cookies with value 'deleted'
* 43f904b51a SessionManager: Kill getPersistedSessionId()
* 50c5256352 SessionManager: Add SessionBackend::setProviderMetadata()
* f640d40315 SessionManager: Notify AuthPlugin when auto-creating accounts
* 70b05d1ac1 Add checks of $wgEnableBotPasswords in more places
* bfed32eb78 Do not raise a PHP warning when session write fails
* 722a7331ad Only check LoggedOut timestamp on the user loaded from session
* 4f5057b84b SessionManager: Change behavior of getSessionById()
* 66e82e614e Fix typo in [[MediaWiki:Botpasswords-editexisting/en]]
* f9fd9516d9 Add "bot passwords"
* d7716f1df0 Add missing argument for wfDebugLog
* a73c5b7395 Add SessionManager

Change-Id: I2389a8133e25ab929e9f27f41fa9a05df8147a50
2016-02-01 22:06:49 +00:00

155 lines
3.8 KiB
PHP

<?php
/**
* @group Broken
* @group Upload
* @group Database
*
* @covers UploadFromUrl
*/
class UploadFromUrlTest extends ApiTestCase {
protected function setUp() {
parent::setUp();
$this->setMwGlobals( array(
'wgEnableUploads' => true,
'wgAllowCopyUploads' => true,
) );
wfSetupSession();
if ( wfLocalFile( 'UploadFromUrlTest.png' )->exists() ) {
$this->deleteFile( 'UploadFromUrlTest.png' );
}
}
protected function doApiRequest( array $params, array $unused = null,
$appendModule = false, User $user = null
) {
$sessionId = session_id();
session_write_close();
$req = new FauxRequest( $params, true, $_SESSION );
$module = new ApiMain( $req, true );
$module->execute();
wfSetupSession( $sessionId );
return array(
$module->getResult()->getResultData( null, array( 'Strip' => 'all' ) ),
$req
);
}
/**
* Ensure that the job queue is empty before continuing
*/
public function testClearQueue() {
$job = JobQueueGroup::singleton()->pop();
while ( $job ) {
$job = JobQueueGroup::singleton()->pop();
}
$this->assertFalse( $job );
}
/**
* @depends testClearQueue
*/
public function testSetupUrlDownload( $data ) {
$token = $this->user->getEditToken();
$exception = false;
try {
$this->doApiRequest( array(
'action' => 'upload',
) );
} catch ( UsageException $e ) {
$exception = true;
$this->assertEquals( "The token parameter must be set", $e->getMessage() );
}
$this->assertTrue( $exception, "Got exception" );
$exception = false;
try {
$this->doApiRequest( array(
'action' => 'upload',
'token' => $token,
), $data );
} catch ( UsageException $e ) {
$exception = true;
$this->assertEquals( "One of the parameters sessionkey, file, url is required",
$e->getMessage() );
}
$this->assertTrue( $exception, "Got exception" );
$exception = false;
try {
$this->doApiRequest( array(
'action' => 'upload',
'url' => 'http://www.example.com/test.png',
'token' => $token,
), $data );
} catch ( UsageException $e ) {
$exception = true;
$this->assertEquals( "The filename parameter must be set", $e->getMessage() );
}
$this->assertTrue( $exception, "Got exception" );
$this->user->removeGroup( 'sysop' );
$exception = false;
try {
$this->doApiRequest( array(
'action' => 'upload',
'url' => 'http://www.example.com/test.png',
'filename' => 'UploadFromUrlTest.png',
'token' => $token,
), $data );
} catch ( UsageException $e ) {
$exception = true;
$this->assertEquals( "Permission denied", $e->getMessage() );
}
$this->assertTrue( $exception, "Got exception" );
}
/**
* @depends testClearQueue
*/
public function testSyncDownload( $data ) {
$token = $this->user->getEditToken();
$job = JobQueueGroup::singleton()->pop();
$this->assertFalse( $job, 'Starting with an empty jobqueue' );
$this->user->addGroup( 'users' );
$data = $this->doApiRequest( array(
'action' => 'upload',
'filename' => 'UploadFromUrlTest.png',
'url' => 'http://upload.wikimedia.org/wikipedia/mediawiki/b/bc/Wiki.png',
'ignorewarnings' => true,
'token' => $token,
), $data );
$job = JobQueueGroup::singleton()->pop();
$this->assertFalse( $job );
$this->assertEquals( 'Success', $data[0]['upload']['result'] );
$this->deleteFile( 'UploadFromUrlTest.png' );
return $data;
}
protected function deleteFile( $name ) {
$t = Title::newFromText( $name, NS_FILE );
$this->assertTrue( $t->exists(), "File '$name' exists" );
if ( $t->exists() ) {
$file = wfFindFile( $name, array( 'ignoreRedirect' => true ) );
$empty = "";
FileDeleteForm::doDelete( $t, $file, $empty, "none", true );
$page = WikiPage::factory( $t );
$page->doDeleteArticle( "testing" );
}
$t = Title::newFromText( $name, NS_FILE );
$this->assertFalse( $t->exists(), "File '$name' was deleted" );
}
}