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
|
|
|
*/
|
2020-06-30 15:09:24 +00:00
|
|
|
class SwiftFileBackendTest extends MediaWikiIntegrationTestCase {
|
2019-09-03 08:04:58 +00:00
|
|
|
/** @var TestingAccessWrapper|SwiftFileBackend */
|
2015-07-30 01:57:23 +00:00
|
|
|
private $backend;
|
|
|
|
|
|
2021-07-22 03:11:47 +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',
|
2021-05-03 14:38:44 +00:00
|
|
|
'lockManager' => $this->getServiceContainer()->getLockManagerGroupFactory()
|
|
|
|
|
->getLockManagerGroup()->get( 'fsLockManager' ),
|
2015-07-30 01:57:23 +00:00
|
|
|
'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
|
|
|
* @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
|
|
|
|
2022-02-08 05:12:43 +00:00
|
|
|
$this->assertEquals( $sanitized, $hdrs, '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 [
|
2020-07-28 13:27:10 +00:00
|
|
|
'empty' => [
|
|
|
|
|
[],
|
|
|
|
|
[]
|
|
|
|
|
],
|
2017-11-20 11:25:20 +00:00
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'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',
|
2019-11-08 16:19:13 +00:00
|
|
|
'content-disposition' => 'inline; filename=xxx',
|
2017-11-20 11:25:20 +00:00
|
|
|
'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'
|
|
|
|
|
]
|
2021-04-20 07:17:41 +00:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'x-delete-at' => 'non numeric',
|
|
|
|
|
'x-delete-after' => 'non numeric',
|
|
|
|
|
'x-content-custom' => 'hello'
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'x-content-custom' => 'hello'
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'x-delete-at' => '12345',
|
|
|
|
|
'x-delete-after' => '12345'
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'x-delete-at' => '12345',
|
|
|
|
|
'x-delete-after' => '12345'
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'x-delete-at' => 12345,
|
|
|
|
|
'x-delete-after' => 12345
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'x-delete-at' => 12345,
|
|
|
|
|
'x-delete-after' => 12345
|
|
|
|
|
]
|
2017-11-20 11:25:20 +00:00
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-30 01:57:23 +00:00
|
|
|
/**
|
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
|
|
|
|
2022-02-08 05:12:43 +00:00
|
|
|
$this->assertEquals( $sanitized, $hdrs, 'getMetadataHeaders() has unexpected result' );
|
2015-07-31 19:41:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @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
|
|
|
|
2022-02-08 05:12:43 +00:00
|
|
|
$this->assertEquals( $sanitized, $hdrs, 'getMetadata() has unexpected result' );
|
2015-07-31 19:41:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|