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: *6acd424e0dSessionManager: Notify AuthPlugin before calling hooks *4d1ad32d8aClose a loophole in CookieSessionProvider *fcdd643a46SessionManager: Don't save non-persisted sessions to backend storage *058aec4c76MessageCache: Don't get a ParserOptions for $wgUser before the end of Setup.php *b5c0c03bb7SessionManager: Save user name to metadata even if the user doesn't exist locally *13f2f09a19SECURITY: Fix User::setToken() call on User::newSystemUser *305bc75b27SessionManager: Don't generate user tokens when checking the tokens *7c4bd85d21RequestContext::exportSession() should only export persisted session IDs *296ccfd4a9SessionManager: Save 'persisted' flag in session metadata *94ba53f677Move CSRF token handling into MediaWiki\Session\Session *46a565d6b0Avoid false "added in both Session and $_SESSION" when value is null *c00d0b5d94Log backtrace for "User::loadFromSession called before the end of Setup.php" *4eeff5b559Use $wgSecureCookie to decide whether to actually mark secure cookies as 'secure' *7491b52f70Call session_cache_limiter() before starting a session *2c34aeea72SessionManager: Abstract forceHTTPS cookie setting *9aa53627a5Ignore auth cookies with value 'deleted' *43f904b51aSessionManager: Kill getPersistedSessionId() *50c5256352SessionManager: Add SessionBackend::setProviderMetadata() *f640d40315SessionManager: Notify AuthPlugin when auto-creating accounts *70b05d1ac1Add checks of $wgEnableBotPasswords in more places *bfed32eb78Do not raise a PHP warning when session write fails *722a7331adOnly check LoggedOut timestamp on the user loaded from session *4f5057b84bSessionManager: Change behavior of getSessionById() *66e82e614eFix typo in [[MediaWiki:Botpasswords-editexisting/en]] *f9fd9516d9Add "bot passwords" *d7716f1df0Add missing argument for wfDebugLog *a73c5b7395Add SessionManager Change-Id: I2389a8133e25ab929e9f27f41fa9a05df8147a50
155 lines
3.8 KiB
PHP
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" );
|
|
}
|
|
}
|