2015-07-30 01:57:23 +00:00
|
|
|
<?php
|
|
|
|
|
|
2017-04-19 19:37:35 +00:00
|
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
|
|
2015-07-30 01:57:23 +00:00
|
|
|
/**
|
|
|
|
|
* @group FileRepo
|
|
|
|
|
* @group FileBackend
|
|
|
|
|
* @group medium
|
2017-02-27 05:08:36 +00:00
|
|
|
*
|
|
|
|
|
* @covers SwiftFileBackend
|
|
|
|
|
* @covers SwiftFileBackendDirList
|
|
|
|
|
* @covers SwiftFileBackendFileList
|
|
|
|
|
* @covers SwiftFileBackendList
|
2015-07-30 01:57:23 +00:00
|
|
|
*/
|
2019-06-13 23:00:08 +00:00
|
|
|
class SwiftFileBackendTest extends MediaWikiTestCase {
|
2019-09-03 08:04:58 +00:00
|
|
|
/** @var TestingAccessWrapper|SwiftFileBackend */
|
2015-07-30 01:57:23 +00:00
|
|
|
private $backend;
|
|
|
|
|
|
2019-10-20 18:11:08 +00:00
|
|
|
protected function setUp() : void {
|
2015-07-30 01:57:23 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
|
|
$this->backend = TestingAccessWrapper::newFromObject(
|
2016-02-17 09:09:32 +00:00
|
|
|
new SwiftFileBackend( [
|
2015-07-30 01:57:23 +00:00
|
|
|
'name' => 'local-swift-testing',
|
2018-01-13 00:02:09 +00:00
|
|
|
'class' => SwiftFileBackend::class,
|
2015-07-30 01:57:23 +00:00
|
|
|
'wikiId' => 'unit-testing',
|
|
|
|
|
'lockManager' => LockManagerGroup::singleton()->get( 'fsLockManager' ),
|
|
|
|
|
'swiftAuthUrl' => 'http://127.0.0.1:8080/auth', // unused
|
|
|
|
|
'swiftUser' => 'test:tester',
|
|
|
|
|
'swiftKey' => 'testing',
|
|
|
|
|
'swiftTempUrlKey' => 'b3968d0207b54ece87cccc06515a89d4' // unused
|
2016-02-17 09:09:32 +00:00
|
|
|
] )
|
2015-07-30 01:57:23 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-20 11:25:20 +00:00
|
|
|
/**
|
2019-09-03 08:04:58 +00:00
|
|
|
* @covers SwiftFileBackend::extractMutableContentHeaders
|
|
|
|
|
* @dataProvider provider_testExtractPostableContentHeaders
|
2017-11-20 11:25:20 +00:00
|
|
|
*/
|
2019-09-03 08:04:58 +00:00
|
|
|
public function testExtractPostableContentHeaders( $raw, $sanitized ) {
|
|
|
|
|
$hdrs = $this->backend->extractMutableContentHeaders( $raw );
|
2017-11-20 11:25:20 +00:00
|
|
|
|
2019-09-03 08:04:58 +00:00
|
|
|
$this->assertEquals( $hdrs, $sanitized, 'Correct extractPostableContentHeaders() result' );
|
2017-11-20 11:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-03 08:04:58 +00:00
|
|
|
public static function provider_testExtractPostableContentHeaders() {
|
2017-11-20 11:25:20 +00:00
|
|
|
return [
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'content-length' => 345,
|
2019-09-03 08:04:58 +00:00
|
|
|
'content-type' => 'image+bitmap/jpeg',
|
2017-11-20 11:25:20 +00:00
|
|
|
'content-disposition' => 'inline',
|
|
|
|
|
'content-duration' => 35.6363,
|
|
|
|
|
'content-Custom' => 'hello',
|
|
|
|
|
'x-content-custom' => 'hello'
|
|
|
|
|
],
|
|
|
|
|
[
|
2019-09-03 08:04:58 +00:00
|
|
|
'content-type' => 'image+bitmap/jpeg',
|
2017-11-20 11:25:20 +00:00
|
|
|
'content-disposition' => 'inline',
|
|
|
|
|
'content-duration' => 35.6363,
|
|
|
|
|
'content-custom' => 'hello',
|
|
|
|
|
'x-content-custom' => 'hello'
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'content-length' => 345,
|
2019-09-03 08:04:58 +00:00
|
|
|
'content-type' => 'image+bitmap/jpeg',
|
2017-11-20 11:25:20 +00:00
|
|
|
'content-Disposition' => 'inline; filename=xxx; ' . str_repeat( 'o', 1024 ),
|
|
|
|
|
'content-duration' => 35.6363,
|
|
|
|
|
'content-custom' => 'hello',
|
|
|
|
|
'x-content-custom' => 'hello'
|
|
|
|
|
],
|
|
|
|
|
[
|
2019-09-03 08:04:58 +00:00
|
|
|
'content-type' => 'image+bitmap/jpeg',
|
2017-11-20 11:25:20 +00:00
|
|
|
'content-disposition' => 'inline;filename=xxx',
|
|
|
|
|
'content-duration' => 35.6363,
|
|
|
|
|
'content-custom' => 'hello',
|
|
|
|
|
'x-content-custom' => 'hello'
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'content-length' => 345,
|
2019-09-03 08:04:58 +00:00
|
|
|
'content-type' => 'image+bitmap/jpeg',
|
2017-11-20 11:25:20 +00:00
|
|
|
'content-disposition' => 'filename=' . str_repeat( 'o', 1024 ) . ';inline',
|
|
|
|
|
'content-duration' => 35.6363,
|
|
|
|
|
'content-custom' => 'hello',
|
|
|
|
|
'x-content-custom' => 'hello'
|
|
|
|
|
],
|
|
|
|
|
[
|
2019-09-03 08:04:58 +00:00
|
|
|
'content-type' => 'image+bitmap/jpeg',
|
2017-11-20 11:25:20 +00:00
|
|
|
'content-disposition' => '',
|
|
|
|
|
'content-duration' => 35.6363,
|
|
|
|
|
'content-custom' => 'hello',
|
|
|
|
|
'x-content-custom' => 'hello'
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-30 01:57:23 +00:00
|
|
|
/**
|
2019-09-03 08:04:58 +00:00
|
|
|
* @covers SwiftFileBackend::extractMetadataHeaders
|
2015-07-31 19:41:03 +00:00
|
|
|
* @dataProvider provider_testGetMetadataHeaders
|
|
|
|
|
*/
|
|
|
|
|
public function testGetMetadataHeaders( $raw, $sanitized ) {
|
2019-09-03 08:04:58 +00:00
|
|
|
$hdrs = $this->backend->extractMetadataHeaders( $raw );
|
2015-07-31 19:41:03 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals( $hdrs, $sanitized, 'getMetadataHeaders() has expected result' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function provider_testGetMetadataHeaders() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[
|
|
|
|
|
[
|
2015-07-31 19:41:03 +00:00
|
|
|
'content-length' => 345,
|
|
|
|
|
'content-custom' => 'hello',
|
|
|
|
|
'x-content-custom' => 'hello',
|
|
|
|
|
'x-object-meta-custom' => 5,
|
|
|
|
|
'x-object-meta-sha1Base36' => 'a3deadfg...',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[
|
2015-07-31 19:41:03 +00:00
|
|
|
'x-object-meta-custom' => 5,
|
|
|
|
|
'x-object-meta-sha1base36' => 'a3deadfg...',
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
];
|
2015-07-31 19:41:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-09-03 08:04:58 +00:00
|
|
|
* @covers SwiftFileBackend::getMetadataFromHeaders
|
2015-07-31 19:41:03 +00:00
|
|
|
* @dataProvider provider_testGetMetadata
|
|
|
|
|
*/
|
|
|
|
|
public function testGetMetadata( $raw, $sanitized ) {
|
2019-09-03 08:04:58 +00:00
|
|
|
$hdrs = $this->backend->getMetadataFromHeaders( $raw );
|
2015-07-31 19:41:03 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals( $hdrs, $sanitized, 'getMetadata() has expected result' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function provider_testGetMetadata() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[
|
|
|
|
|
[
|
2015-07-31 19:41:03 +00:00
|
|
|
'content-length' => 345,
|
|
|
|
|
'content-custom' => 'hello',
|
|
|
|
|
'x-content-custom' => 'hello',
|
|
|
|
|
'x-object-meta-custom' => 5,
|
|
|
|
|
'x-object-meta-sha1Base36' => 'a3deadfg...',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[
|
2015-07-31 19:41:03 +00:00
|
|
|
'custom' => 5,
|
|
|
|
|
'sha1base36' => 'a3deadfg...',
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
];
|
2015-07-31 19:41:03 +00:00
|
|
|
}
|
2015-09-26 14:58:53 +00:00
|
|
|
}
|