diff options
author | Carl Schwan <carl@carlschwan.eu> | 2022-08-15 15:28:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-15 15:28:30 +0200 |
commit | 51b9847fad73a1ca67dbf504358d90bd8f9e71d8 (patch) | |
tree | b104cf1c540dd1dd195ca5fd30c42b888012cbab /tests/lib | |
parent | 6d6662ec68c8e15c4c6bfdf1c694794badd412d7 (diff) | |
parent | cb97e8f15c75cc46e345ebfc79dcad1b9c48bd01 (diff) | |
download | nextcloud-server-51b9847fad73a1ca67dbf504358d90bd8f9e71d8.tar.gz nextcloud-server-51b9847fad73a1ca67dbf504358d90bd8f9e71d8.zip |
Merge branch 'master' into display-name-cache-public
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'tests/lib')
55 files changed, 2044 insertions, 1461 deletions
diff --git a/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php b/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php index 4746c296ab4..a2d56838b07 100644 --- a/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php +++ b/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php @@ -1890,12 +1890,12 @@ EJL3BaQAQaASSsvFrcozYxrQG4VzEg== $file = $this->createMock(ISimpleFile::class); $folder = $this->createMock(ISimpleFolder::class); $folder - ->expects($this->at(0)) + ->expects($this->once()) ->method('getFile') ->with('apps.json') ->willThrowException(new NotFoundException()); $folder - ->expects($this->at(1)) + ->expects($this->once()) ->method('newFile') ->with('apps.json') ->willReturn($file); @@ -1946,7 +1946,7 @@ EJL3BaQAQaASSsvFrcozYxrQG4VzEg== } $file - ->expects($this->at(0)) + ->expects($this->once()) ->method('putContent'); $file ->method('getContent') @@ -2017,12 +2017,12 @@ EJL3BaQAQaASSsvFrcozYxrQG4VzEg== $file = $this->createMock(ISimpleFile::class); $folder = $this->createMock(ISimpleFolder::class); $folder - ->expects($this->at(0)) + ->expects($this->once()) ->method('getFile') ->with('future-apps.json') ->willThrowException(new NotFoundException()); $folder - ->expects($this->at(1)) + ->expects($this->once()) ->method('newFile') ->with('future-apps.json') ->willReturn($file); @@ -2073,7 +2073,7 @@ EJL3BaQAQaASSsvFrcozYxrQG4VzEg== } $file - ->expects($this->at(0)) + ->expects($this->once()) ->method('putContent'); $file ->method('getContent') @@ -2104,12 +2104,12 @@ EJL3BaQAQaASSsvFrcozYxrQG4VzEg== $file = $this->createMock(ISimpleFile::class); $folder = $this->createMock(ISimpleFolder::class); $folder - ->expects($this->at(0)) + ->expects($this->once()) ->method('getFile') ->with('apps.json') ->willThrowException(new NotFoundException()); $folder - ->expects($this->at(1)) + ->expects($this->once()) ->method('newFile') ->with('apps.json') ->willReturn($file); diff --git a/tests/lib/App/AppStore/Fetcher/FetcherBase.php b/tests/lib/App/AppStore/Fetcher/FetcherBase.php index 87a09cb617d..42ad02ce6d8 100644 --- a/tests/lib/App/AppStore/Fetcher/FetcherBase.php +++ b/tests/lib/App/AppStore/Fetcher/FetcherBase.php @@ -76,22 +76,20 @@ abstract class FetcherBase extends TestCase { public function testGetWithAlreadyExistingFileAndUpToDateTimestampAndVersion() { $this->config - ->expects($this->at(0)) + ->expects($this->once()) ->method('getSystemValueBool') ->with('appstoreenabled', true) ->willReturn(true); $this->config - ->expects($this->at(1)) - ->method('getSystemValue') - ->with('has_internet_connection', true) - ->willReturn(true); - $this->config - ->expects($this->at(2)) + ->expects($this->exactly(2)) ->method('getSystemValue') - ->with( - $this->equalTo('version'), - $this->anything() - )->willReturn('11.0.0.2'); + ->withConsecutive( + ['has_internet_connection', true], + [$this->equalTo('version'), $this->anything()], + )->willReturnOnConsecutiveCalls( + true, + '11.0.0.2', + ); $folder = $this->createMock(ISimpleFolder::class); $file = $this->createMock(ISimpleFile::class); @@ -148,12 +146,12 @@ abstract class FetcherBase extends TestCase { ->with('/') ->willReturn($folder); $folder - ->expects($this->at(0)) + ->expects($this->once()) ->method('getFile') ->with($this->fileName) ->willThrowException(new NotFoundException()); $folder - ->expects($this->at(1)) + ->expects($this->once()) ->method('newFile') ->with($this->fileName) ->willReturn($file); @@ -177,15 +175,15 @@ abstract class FetcherBase extends TestCase { ->willReturn('"myETag"'); $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1502,"ncversion":"11.0.0.2","ETag":"\"myETag\""}'; $file - ->expects($this->at(0)) + ->expects($this->once()) ->method('putContent') ->with($fileData); $file - ->expects($this->at(1)) + ->expects($this->once()) ->method('getContent') ->willReturn($fileData); $this->timeFactory - ->expects($this->at(0)) + ->expects($this->once()) ->method('getTime') ->willReturn(1502); @@ -227,14 +225,25 @@ abstract class FetcherBase extends TestCase { ->method('getFile') ->with($this->fileName) ->willReturn($file); + $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1502,"ncversion":"11.0.0.2","ETag":"\"myETag\""}'; $file - ->expects($this->at(0)) + ->expects($this->once()) + ->method('putContent') + ->with($fileData); + $file + ->expects($this->exactly(2)) ->method('getContent') - ->willReturn('{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}},"ncversion":"11.0.0.2"}'); + ->willReturnOnConsecutiveCalls( + '{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}},"ncversion":"11.0.0.2"}', + $fileData + ); $this->timeFactory - ->expects($this->at(0)) + ->expects($this->exactly(2)) ->method('getTime') - ->willReturn(4801); + ->willReturnOnConsecutiveCalls( + 4801, + 1502 + ); $client = $this->createMock(IClient::class); $this->clientService ->expects($this->once()) @@ -253,19 +262,6 @@ abstract class FetcherBase extends TestCase { $response->method('getHeader') ->with($this->equalTo('ETag')) ->willReturn('"myETag"'); - $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1502,"ncversion":"11.0.0.2","ETag":"\"myETag\""}'; - $file - ->expects($this->at(1)) - ->method('putContent') - ->with($fileData); - $file - ->expects($this->at(2)) - ->method('getContent') - ->willReturn($fileData); - $this->timeFactory - ->expects($this->at(1)) - ->method('getTime') - ->willReturn(1502); $expected = [ [ @@ -309,12 +305,20 @@ abstract class FetcherBase extends TestCase { ->method('getFile') ->with($this->fileName) ->willReturn($file); + $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1201,"ncversion":"11.0.0.2","ETag":"\"myETag\""}'; + $file + ->expects($this->once()) + ->method('putContent') + ->with($fileData); $file - ->expects($this->at(0)) + ->expects($this->exactly(2)) ->method('getContent') - ->willReturn('{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}}'); + ->willReturnOnConsecutiveCalls( + '{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}}', + $fileData + ); $this->timeFactory - ->expects($this->at(0)) + ->expects($this->once()) ->method('getTime') ->willReturn(1201); $client = $this->createMock(IClient::class); @@ -335,15 +339,6 @@ abstract class FetcherBase extends TestCase { $response->method('getHeader') ->with($this->equalTo('ETag')) ->willReturn('"myETag"'); - $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1201,"ncversion":"11.0.0.2","ETag":"\"myETag\""}'; - $file - ->expects($this->at(1)) - ->method('putContent') - ->with($fileData); - $file - ->expects($this->at(2)) - ->method('getContent') - ->willReturn($fileData); $expected = [ [ @@ -387,10 +382,18 @@ abstract class FetcherBase extends TestCase { ->method('getFile') ->with($this->fileName) ->willReturn($file); + $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1201,"ncversion":"11.0.0.2","ETag":"\"myETag\""}'; + $file + ->expects($this->once()) + ->method('putContent') + ->with($fileData); $file - ->expects($this->at(0)) + ->expects($this->exactly(2)) ->method('getContent') - ->willReturn('{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}},"ncversion":"11.0.0.1"'); + ->willReturnOnConsecutiveCalls( + '{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}},"ncversion":"11.0.0.1"', + $fileData + ); $this->timeFactory ->method('getTime') ->willReturn(1201); @@ -412,15 +415,6 @@ abstract class FetcherBase extends TestCase { $response->method('getHeader') ->with($this->equalTo('ETag')) ->willReturn('"myETag"'); - $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1201,"ncversion":"11.0.0.2","ETag":"\"myETag\""}'; - $file - ->expects($this->at(1)) - ->method('putContent') - ->with($fileData); - $file - ->expects($this->at(2)) - ->method('getContent') - ->willReturn($fileData); $expected = [ [ @@ -457,7 +451,7 @@ abstract class FetcherBase extends TestCase { ->with($this->fileName) ->willReturn($file); $file - ->expects($this->at(0)) + ->expects($this->once()) ->method('getContent') ->willReturn('{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}}}'); $client = $this->createMock(IClient::class); @@ -501,18 +495,26 @@ abstract class FetcherBase extends TestCase { ->with($this->fileName) ->willReturn($file); $origData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1200,"ncversion":"11.0.0.2","ETag":"\"myETag\""}'; + + $newData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":4802,"ncversion":"11.0.0.2","ETag":"\"myETag\""}'; $file - ->expects($this->at(0)) + ->expects($this->once()) + ->method('putContent') + ->with($newData); + $file + ->expects($this->exactly(2)) ->method('getContent') - ->willReturn($origData); - $this->timeFactory - ->expects($this->at(0)) - ->method('getTime') - ->willReturn(4801); + ->willReturnOnConsecutiveCalls( + $origData, + $newData, + ); $this->timeFactory - ->expects($this->at(1)) + ->expects($this->exactly(2)) ->method('getTime') - ->willReturn(4802); + ->willReturnOnConsecutiveCalls( + 4801, + 4802 + ); $client = $this->createMock(IClient::class); $this->clientService ->expects($this->once()) @@ -534,16 +536,6 @@ abstract class FetcherBase extends TestCase { $response->method('getStatusCode') ->willReturn(304); - $newData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":4802,"ncversion":"11.0.0.2","ETag":"\"myETag\""}'; - $file - ->expects($this->at(1)) - ->method('putContent') - ->with($newData); - $file - ->expects($this->at(2)) - ->method('getContent') - ->willReturn($newData); - $expected = [ [ 'id' => 'MyNewApp', @@ -579,14 +571,29 @@ abstract class FetcherBase extends TestCase { ->with('/') ->willReturn($folder); $folder - ->expects($this->at(0)) + ->expects($this->once()) ->method('getFile') ->with($this->fileName) ->willReturn($file); + $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":4802,"ncversion":"11.0.0.2","ETag":"\"newETag\""}'; $file - ->expects($this->at(0)) + ->expects($this->once()) + ->method('putContent') + ->with($fileData); + $file + ->expects($this->exactly(2)) ->method('getContent') - ->willReturn('{"data":[{"id":"MyOldApp","abc":"def"}],"timestamp":1200,"ncversion":"11.0.0.2","ETag":"\"myETag\""}'); + ->willReturnOnConsecutiveCalls( + '{"data":[{"id":"MyOldApp","abc":"def"}],"timestamp":1200,"ncversion":"11.0.0.2","ETag":"\"myETag\""}', + $fileData, + ); + $this->timeFactory + ->expects($this->exactly(2)) + ->method('getTime') + ->willReturnOnConsecutiveCalls( + 4801, + 4802, + ); $client = $this->createMock(IClient::class); $this->clientService ->expects($this->once()) @@ -615,23 +622,6 @@ abstract class FetcherBase extends TestCase { $response->method('getHeader') ->with($this->equalTo('ETag')) ->willReturn('"newETag"'); - $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":4802,"ncversion":"11.0.0.2","ETag":"\"newETag\""}'; - $file - ->expects($this->at(1)) - ->method('putContent') - ->with($fileData); - $file - ->expects($this->at(2)) - ->method('getContent') - ->willReturn($fileData); - $this->timeFactory - ->expects($this->at(0)) - ->method('getTime') - ->willReturn(4801); - $this->timeFactory - ->expects($this->at(1)) - ->method('getTime') - ->willReturn(4802); $expected = [ [ @@ -668,14 +658,22 @@ abstract class FetcherBase extends TestCase { ->with('/') ->willReturn($folder); $folder - ->expects($this->at(0)) + ->expects($this->once()) ->method('getFile') ->with($this->fileName) ->willReturn($file); + $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1501,"ncversion":"11.0.0.3","ETag":"\"newETag\""}'; + $file + ->expects($this->once()) + ->method('putContent') + ->with($fileData); $file - ->expects($this->at(0)) + ->expects($this->exactly(2)) ->method('getContent') - ->willReturn('{"data":[{"id":"MyOldApp","abc":"def"}],"timestamp":1200,"ncversion":"11.0.0.2","ETag":"\"myETag\""}'); + ->willReturnOnConsecutiveCalls( + '{"data":[{"id":"MyOldApp","abc":"def"}],"timestamp":1200,"ncversion":"11.0.0.2","ETag":"\"myETag\""}', + $fileData + ); $client = $this->createMock(IClient::class); $this->clientService ->expects($this->once()) @@ -701,15 +699,6 @@ abstract class FetcherBase extends TestCase { $response->method('getHeader') ->with($this->equalTo('ETag')) ->willReturn('"newETag"'); - $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1501,"ncversion":"11.0.0.3","ETag":"\"newETag\""}'; - $file - ->expects($this->at(1)) - ->method('putContent') - ->with($fileData); - $file - ->expects($this->at(2)) - ->method('getContent') - ->willReturn($fileData); $this->timeFactory ->expects($this->once()) ->method('getTime') diff --git a/tests/lib/App/InfoParserTest.php b/tests/lib/App/InfoParserTest.php index 8de0f4cfd4f..bc561611501 100644 --- a/tests/lib/App/InfoParserTest.php +++ b/tests/lib/App/InfoParserTest.php @@ -11,16 +11,16 @@ namespace Test\App; use OC; use OC\App\InfoParser; use Test\TestCase; +use OCP\Cache\CappedMemoryCache; class InfoParserTest extends TestCase { - /** @var OC\Cache\CappedMemoryCache */ + /** @var OCP\Cache\CappedMemoryCache */ private static $cache; public static function setUpBeforeClass(): void { - self::$cache = new OC\Cache\CappedMemoryCache(); + self::$cache = new CappedMemoryCache(); } - public function parserTest($expectedJson, $xmlFile, $cache = null) { $parser = new InfoParser($cache); diff --git a/tests/lib/AppFramework/Db/EntityTest.php b/tests/lib/AppFramework/Db/EntityTest.php index 17234849a2d..d76a8ccfe06 100644 --- a/tests/lib/AppFramework/Db/EntityTest.php +++ b/tests/lib/AppFramework/Db/EntityTest.php @@ -43,6 +43,8 @@ use PHPUnit\Framework\Constraint\IsType; * @method bool getAnotherBool() * @method bool isAnotherBool() * @method void setAnotherBool(bool $anotherBool) + * @method string getLongText() + * @method void setLongText(string $longText) */ class TestEntity extends Entity { protected $name; @@ -51,11 +53,13 @@ class TestEntity extends Entity { protected $preName; protected $trueOrFalse; protected $anotherBool; + protected $longText; public function __construct($name = null) { $this->addType('testId', 'integer'); $this->addType('trueOrFalse', 'bool'); $this->addType('anotherBool', 'boolean'); + $this->addType('longText', 'blob'); $this->name = $name; } } @@ -210,6 +214,18 @@ class EntityTest extends \Test\TestCase { $this->assertSame(null, $entity->getId()); } + public function testSetterConvertsResourcesToStringProperly() { + $string = 'Definitely a string'; + $stream = fopen('php://memory', 'r+'); + fwrite($stream, $string); + rewind($stream); + + $entity = new TestEntity(); + $entity->setLongText($stream); + fclose($stream); + $this->assertSame($string, $entity->getLongText()); + } + public function testGetFieldTypes() { $entity = new TestEntity(); @@ -218,6 +234,7 @@ class EntityTest extends \Test\TestCase { 'testId' => 'integer', 'trueOrFalse' => 'bool', 'anotherBool' => 'boolean', + 'longText' => 'blob', ], $entity->getFieldTypes()); } diff --git a/tests/lib/AppFramework/Http/DispatcherTest.php b/tests/lib/AppFramework/Http/DispatcherTest.php index e1d78082a2d..8f591f26e58 100644 --- a/tests/lib/AppFramework/Http/DispatcherTest.php +++ b/tests/lib/AppFramework/Http/DispatcherTest.php @@ -89,6 +89,8 @@ class DispatcherTest extends \Test\TestCase { /** @var Dispatcher */ private $dispatcher; private $controllerMethod; + /** @var Controller|MockObject */ + private $controller; private $response; /** @var IRequest|MockObject */ private $request; diff --git a/tests/lib/AppFramework/Http/JSONResponseTest.php b/tests/lib/AppFramework/Http/JSONResponseTest.php index 504876b2d88..8c8318eb602 100644 --- a/tests/lib/AppFramework/Http/JSONResponseTest.php +++ b/tests/lib/AppFramework/Http/JSONResponseTest.php @@ -88,10 +88,10 @@ class JSONResponseTest extends \Test\TestCase { $this->assertEquals($expected, $this->json->render()); } - + public function testRenderWithNonUtf8Encoding() { - $this->expectException(\Exception::class); - $this->expectExceptionMessage('Could not json_encode due to invalid non UTF-8 characters in the array: array ('); + $this->expectException(\JsonException::class); + $this->expectExceptionMessage('Malformed UTF-8 characters, possibly incorrectly encoded'); $params = ['test' => hex2bin('e9')]; $this->json->setData($params); diff --git a/tests/lib/AppFramework/Http/RequestTest.php b/tests/lib/AppFramework/Http/RequestTest.php index e15f3fe656c..cf5ebdca2f0 100644 --- a/tests/lib/AppFramework/Http/RequestTest.php +++ b/tests/lib/AppFramework/Http/RequestTest.php @@ -381,15 +381,15 @@ class RequestTest extends \Test\TestCase { public function testGetRemoteAddressWithNoTrustedHeader() { $this->config - ->expects($this->at(0)) + ->expects($this->exactly(2)) ->method('getSystemValue') - ->with('trusted_proxies') - ->willReturn(['10.0.0.2']); - $this->config - ->expects($this->at(1)) - ->method('getSystemValue') - ->with('forwarded_for_headers') - ->willReturn([]); + ->withConsecutive( + ['trusted_proxies'], + ['forwarded_for_headers'], + )->willReturnOnConsecutiveCalls( + ['10.0.0.2'], + [] + ); $request = new Request( [ @@ -410,15 +410,15 @@ class RequestTest extends \Test\TestCase { public function testGetRemoteAddressWithSingleTrustedRemote() { $this->config - ->expects($this->at(0)) - ->method('getSystemValue') - ->with('trusted_proxies') - ->willReturn(['10.0.0.2']); - $this->config - ->expects($this->at(1)) + ->expects($this->exactly(2)) ->method('getSystemValue') - ->with('forwarded_for_headers') - ->willReturn(['HTTP_X_FORWARDED']); + ->withConsecutive( + ['trusted_proxies'], + ['forwarded_for_headers'], + )-> willReturnOnConsecutiveCalls( + ['10.0.0.2'], + ['HTTP_X_FORWARDED'], + ); $request = new Request( [ @@ -439,15 +439,15 @@ class RequestTest extends \Test\TestCase { public function testGetRemoteAddressIPv6WithSingleTrustedRemote() { $this->config - ->expects($this->at(0)) + ->expects($this->exactly(2)) ->method('getSystemValue') - ->with('trusted_proxies') - ->willReturn(['2001:db8:85a3:8d3:1319:8a2e:370:7348']); - $this->config - ->expects($this->at(1)) - ->method('getSystemValue') - ->with('forwarded_for_headers') - ->willReturn(['HTTP_X_FORWARDED']); + ->withConsecutive( + ['trusted_proxies'], + ['forwarded_for_headers'], + )-> willReturnOnConsecutiveCalls( + ['2001:db8:85a3:8d3:1319:8a2e:370:7348'], + ['HTTP_X_FORWARDED'], + ); $request = new Request( [ @@ -468,19 +468,19 @@ class RequestTest extends \Test\TestCase { public function testGetRemoteAddressVerifyPriorityHeader() { $this->config - ->expects($this->at(0)) + ->expects($this->exactly(2)) ->method('getSystemValue') - ->with('trusted_proxies') - ->willReturn(['10.0.0.2']); - $this->config - ->expects($this->at(1)) - ->method('getSystemValue') - ->with('forwarded_for_headers') - ->willReturn([ - 'HTTP_CLIENT_IP', - 'HTTP_X_FORWARDED_FOR', - 'HTTP_X_FORWARDED' - ]); + ->withConsecutive( + ['trusted_proxies'], + ['forwarded_for_headers'], + )-> willReturnOnConsecutiveCalls( + ['10.0.0.2'], + [ + 'HTTP_CLIENT_IP', + 'HTTP_X_FORWARDED_FOR', + 'HTTP_X_FORWARDED', + ], + ); $request = new Request( [ @@ -501,19 +501,19 @@ class RequestTest extends \Test\TestCase { public function testGetRemoteAddressIPv6VerifyPriorityHeader() { $this->config - ->expects($this->at(0)) + ->expects($this->exactly(2)) ->method('getSystemValue') - ->with('trusted_proxies') - ->willReturn(['2001:db8:85a3:8d3:1319:8a2e:370:7348']); - $this->config - ->expects($this->at(1)) - ->method('getSystemValue') - ->with('forwarded_for_headers') - ->willReturn([ - 'HTTP_CLIENT_IP', - 'HTTP_X_FORWARDED_FOR', - 'HTTP_X_FORWARDED' - ]); + ->withConsecutive( + ['trusted_proxies'], + ['forwarded_for_headers'], + )-> willReturnOnConsecutiveCalls( + ['2001:db8:85a3:8d3:1319:8a2e:370:7348'], + [ + 'HTTP_CLIENT_IP', + 'HTTP_X_FORWARDED_FOR', + 'HTTP_X_FORWARDED' + ], + ); $request = new Request( [ @@ -534,15 +534,15 @@ class RequestTest extends \Test\TestCase { public function testGetRemoteAddressWithMatchingCidrTrustedRemote() { $this->config - ->expects($this->at(0)) - ->method('getSystemValue') - ->with('trusted_proxies') - ->willReturn(['192.168.2.0/24']); - $this->config - ->expects($this->at(1)) + ->expects($this->exactly(2)) ->method('getSystemValue') - ->with('forwarded_for_headers') - ->willReturn(['HTTP_X_FORWARDED_FOR']); + ->withConsecutive( + ['trusted_proxies'], + ['forwarded_for_headers'], + )-> willReturnOnConsecutiveCalls( + ['192.168.2.0/24'], + ['HTTP_X_FORWARDED_FOR'], + ); $request = new Request( [ @@ -585,17 +585,94 @@ class RequestTest extends \Test\TestCase { $this->assertSame('192.168.3.99', $request->getRemoteAddress()); } - public function testGetRemoteAddressWithXForwardedForIPv6() { + public function testGetRemoteIpv6AddressWithMatchingIpv6CidrTrustedRemote() { $this->config - ->expects($this->at(0)) + ->expects($this->exactly(2)) + ->method('getSystemValue') + ->withConsecutive( + ['trusted_proxies'], + ['forwarded_for_headers'] + )->willReturnOnConsecutiveCalls( + ['2001:db8:85a3:8d3:1319:8a20::/95'], + ['HTTP_X_FORWARDED_FOR'] + ); + + $request = new Request( + [ + 'server' => [ + 'REMOTE_ADDR' => '2001:db8:85a3:8d3:1319:8a21:370:7348', + 'HTTP_X_FORWARDED' => '10.4.0.5, 10.4.0.4', + 'HTTP_X_FORWARDED_FOR' => '192.168.0.233' + ], + ], + $this->requestId, + $this->config, + $this->csrfTokenManager, + $this->stream + ); + + $this->assertSame('192.168.0.233', $request->getRemoteAddress()); + } + + public function testGetRemoteAddressIpv6WithNotMatchingCidrTrustedRemote() { + $this->config + ->expects($this->once()) ->method('getSystemValue') ->with('trusted_proxies') - ->willReturn(['192.168.2.0/24']); + ->willReturn(['fd::/8']); + + $request = new Request( + [ + 'server' => [ + 'REMOTE_ADDR' => '2001:db8:85a3:8d3:1319:8a2e:370:7348', + 'HTTP_X_FORWARDED' => '10.4.0.5, 10.4.0.4', + 'HTTP_X_FORWARDED_FOR' => '192.168.0.233' + ], + ], + $this->requestId, + $this->config, + $this->csrfTokenManager, + $this->stream + ); + + $this->assertSame('2001:db8:85a3:8d3:1319:8a2e:370:7348', $request->getRemoteAddress()); + } + + public function testGetRemoteAddressIpv6WithInvalidTrustedProxy() { + $this->config + ->expects($this->once()) + ->method('getSystemValue') + ->with('trusted_proxies') + ->willReturn(['fx::/8']); + + $request = new Request( + [ + 'server' => [ + 'REMOTE_ADDR' => '2001:db8:85a3:8d3:1319:8a2e:370:7348', + 'HTTP_X_FORWARDED' => '10.4.0.5, 10.4.0.4', + 'HTTP_X_FORWARDED_FOR' => '192.168.0.233' + ], + ], + $this->requestId, + $this->config, + $this->csrfTokenManager, + $this->stream + ); + + $this->assertSame('2001:db8:85a3:8d3:1319:8a2e:370:7348', $request->getRemoteAddress()); + } + + public function testGetRemoteAddressWithXForwardedForIPv6() { $this->config - ->expects($this->at(1)) + ->expects($this->exactly(2)) ->method('getSystemValue') - ->with('forwarded_for_headers') - ->willReturn(['HTTP_X_FORWARDED_FOR']); + ->withConsecutive( + ['trusted_proxies'], + ['forwarded_for_headers'], + )-> willReturnOnConsecutiveCalls( + ['192.168.2.0/24'], + ['HTTP_X_FORWARDED_FOR'], + ); $request = new Request( [ @@ -666,20 +743,12 @@ class RequestTest extends \Test\TestCase { public function testGetServerProtocolWithOverride() { $this->config - ->expects($this->at(0)) - ->method('getSystemValue') - ->with('overwriteprotocol') - ->willReturn('customProtocol'); - $this->config - ->expects($this->at(1)) - ->method('getSystemValue') - ->with('overwritecondaddr') - ->willReturn(''); - $this->config - ->expects($this->at(2)) + ->expects($this->exactly(3)) ->method('getSystemValue') - ->with('overwriteprotocol') - ->willReturn('customProtocol'); + ->willReturnMap([ + ['overwriteprotocol', '', 'customProtocol'], + ['overwritecondaddr', '', ''], + ]); $request = new Request( [], @@ -1266,20 +1335,12 @@ class RequestTest extends \Test\TestCase { public function testGetOverwriteHostWithOverwrite() { $this->config - ->expects($this->at(0)) - ->method('getSystemValue') - ->with('overwritehost') - ->willReturn('www.owncloud.org'); - $this->config - ->expects($this->at(1)) - ->method('getSystemValue') - ->with('overwritecondaddr') - ->willReturn(''); - $this->config - ->expects($this->at(2)) + ->expects($this->exactly(3)) ->method('getSystemValue') - ->with('overwritehost') - ->willReturn('www.owncloud.org'); + ->willReturnMap([ + ['overwritehost', '', 'www.owncloud.org'], + ['overwritecondaddr', '', ''], + ]); $request = new Request( [], @@ -1493,15 +1554,12 @@ class RequestTest extends \Test\TestCase { */ public function testGetRequestUriWithOverwrite($expectedUri, $overwriteWebRoot, $overwriteCondAddr) { $this->config - ->expects($this->at(0)) - ->method('getSystemValue') - ->with('overwritewebroot') - ->willReturn($overwriteWebRoot); - $this->config - ->expects($this->at(1)) + ->expects($this->exactly(2)) ->method('getSystemValue') - ->with('overwritecondaddr') - ->willReturn($overwriteCondAddr); + ->willReturnMap([ + ['overwritewebroot', '', $overwriteWebRoot], + ['overwritecondaddr', '', $overwriteCondAddr], + ]); $request = $this->getMockBuilder('\OC\AppFramework\Http\Request') ->setMethods(['getScriptName']) diff --git a/tests/lib/AppFramework/Middleware/Security/BruteForceMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/BruteForceMiddlewareTest.php index cc04992ae18..7dfcfe22261 100644 --- a/tests/lib/AppFramework/Middleware/Security/BruteForceMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/Security/BruteForceMiddlewareTest.php @@ -36,8 +36,7 @@ class BruteForceMiddlewareTest extends TestCase { private $throttler; /** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */ private $request; - /** @var BruteForceMiddleware */ - private $bruteForceMiddleware; + private BruteForceMiddleware $bruteForceMiddleware; protected function setUp(): void { parent::setUp(); diff --git a/tests/lib/AppFramework/Middleware/Security/RateLimitingMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/RateLimitingMiddlewareTest.php index aa713b99156..38d01950f6a 100644 --- a/tests/lib/AppFramework/Middleware/Security/RateLimitingMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/Security/RateLimitingMiddlewareTest.php @@ -66,25 +66,20 @@ class RateLimitingMiddlewareTest extends TestCase { public function testBeforeControllerWithoutAnnotation() { $this->reflector - ->expects($this->at(0)) + ->expects($this->exactly(4)) ->method('getAnnotationParameter') - ->with('AnonRateThrottle', 'limit') - ->willReturn(''); - $this->reflector - ->expects($this->at(1)) - ->method('getAnnotationParameter') - ->with('AnonRateThrottle', 'period') - ->willReturn(''); - $this->reflector - ->expects($this->at(2)) - ->method('getAnnotationParameter') - ->with('UserRateThrottle', 'limit') - ->willReturn(''); - $this->reflector - ->expects($this->at(3)) - ->method('getAnnotationParameter') - ->with('UserRateThrottle', 'period') - ->willReturn(''); + ->withConsecutive( + ['AnonRateThrottle', 'limit'], + ['AnonRateThrottle', 'period'], + ['UserRateThrottle', 'limit'], + ['UserRateThrottle', 'period'] + ) + ->willReturnMap([ + ['AnonRateThrottle', 'limit', ''], + ['AnonRateThrottle', 'period', ''], + ['UserRateThrottle', 'limit', ''], + ['UserRateThrottle', 'period', ''], + ]); $this->limiter ->expects($this->never()) @@ -107,25 +102,20 @@ class RateLimitingMiddlewareTest extends TestCase { ->willReturn('127.0.0.1'); $this->reflector - ->expects($this->at(0)) - ->method('getAnnotationParameter') - ->with('AnonRateThrottle', 'limit') - ->willReturn('100'); - $this->reflector - ->expects($this->at(1)) - ->method('getAnnotationParameter') - ->with('AnonRateThrottle', 'period') - ->willReturn('10'); - $this->reflector - ->expects($this->at(2)) - ->method('getAnnotationParameter') - ->with('UserRateThrottle', 'limit') - ->willReturn(''); - $this->reflector - ->expects($this->at(3)) + ->expects($this->exactly(4)) ->method('getAnnotationParameter') - ->with('UserRateThrottle', 'period') - ->willReturn(''); + ->withConsecutive( + ['AnonRateThrottle', 'limit'], + ['AnonRateThrottle', 'period'], + ['UserRateThrottle', 'limit'], + ['UserRateThrottle', 'period'] + ) + ->willReturnMap([ + ['AnonRateThrottle', 'limit', '100'], + ['AnonRateThrottle', 'period', '10'], + ['UserRateThrottle', 'limit', ''], + ['UserRateThrottle', 'period', ''], + ]); $this->limiter ->expects($this->never()) @@ -155,25 +145,20 @@ class RateLimitingMiddlewareTest extends TestCase { ->willReturn($user); $this->reflector - ->expects($this->at(0)) + ->expects($this->exactly(4)) ->method('getAnnotationParameter') - ->with('AnonRateThrottle', 'limit') - ->willReturn(''); - $this->reflector - ->expects($this->at(1)) - ->method('getAnnotationParameter') - ->with('AnonRateThrottle', 'period') - ->willReturn(''); - $this->reflector - ->expects($this->at(2)) - ->method('getAnnotationParameter') - ->with('UserRateThrottle', 'limit') - ->willReturn('100'); - $this->reflector - ->expects($this->at(3)) - ->method('getAnnotationParameter') - ->with('UserRateThrottle', 'period') - ->willReturn('10'); + ->withConsecutive( + ['AnonRateThrottle', 'limit'], + ['AnonRateThrottle', 'period'], + ['UserRateThrottle', 'limit'], + ['UserRateThrottle', 'period'] + ) + ->willReturnMap([ + ['AnonRateThrottle', 'limit', ''], + ['AnonRateThrottle', 'period', ''], + ['UserRateThrottle', 'limit', '100'], + ['UserRateThrottle', 'period', '10'], + ]); $this->limiter ->expects($this->never()) @@ -201,25 +186,20 @@ class RateLimitingMiddlewareTest extends TestCase { ->willReturn(false); $this->reflector - ->expects($this->at(0)) - ->method('getAnnotationParameter') - ->with('AnonRateThrottle', 'limit') - ->willReturn('200'); - $this->reflector - ->expects($this->at(1)) - ->method('getAnnotationParameter') - ->with('AnonRateThrottle', 'period') - ->willReturn('20'); - $this->reflector - ->expects($this->at(2)) - ->method('getAnnotationParameter') - ->with('UserRateThrottle', 'limit') - ->willReturn('100'); - $this->reflector - ->expects($this->at(3)) + ->expects($this->exactly(4)) ->method('getAnnotationParameter') - ->with('UserRateThrottle', 'period') - ->willReturn('10'); + ->withConsecutive( + ['AnonRateThrottle', 'limit'], + ['AnonRateThrottle', 'period'], + ['UserRateThrottle', 'limit'], + ['UserRateThrottle', 'period'] + ) + ->willReturnMap([ + ['AnonRateThrottle', 'limit', '200'], + ['AnonRateThrottle', 'period', '20'], + ['UserRateThrottle', 'limit', '100'], + ['UserRateThrottle', 'period', '10'], + ]); $this->limiter ->expects($this->never()) diff --git a/tests/lib/AppFramework/Routing/RoutingTest.php b/tests/lib/AppFramework/Routing/RoutingTest.php index b4965d61d4f..22037c31d0d 100644 --- a/tests/lib/AppFramework/Routing/RoutingTest.php +++ b/tests/lib/AppFramework/Routing/RoutingTest.php @@ -304,36 +304,23 @@ class RoutingTest extends \Test\TestCase { $urlWithParam = $url . '/{' . $paramName . '}'; - // we expect create to be called once: - $router - ->expects($this->at(0)) - ->method('create') - ->with($this->equalTo('ocs.app1.' . $resourceName . '.index'), $this->equalTo($url)) - ->willReturn($indexRoute); - - $router - ->expects($this->at(1)) - ->method('create') - ->with($this->equalTo('ocs.app1.' . $resourceName . '.show'), $this->equalTo($urlWithParam)) - ->willReturn($showRoute); - - $router - ->expects($this->at(2)) - ->method('create') - ->with($this->equalTo('ocs.app1.' . $resourceName . '.create'), $this->equalTo($url)) - ->willReturn($createRoute); - - $router - ->expects($this->at(3)) - ->method('create') - ->with($this->equalTo('ocs.app1.' . $resourceName . '.update'), $this->equalTo($urlWithParam)) - ->willReturn($updateRoute); - + // we expect create to be called five times: $router - ->expects($this->at(4)) + ->expects($this->exactly(5)) ->method('create') - ->with($this->equalTo('ocs.app1.' . $resourceName . '.destroy'), $this->equalTo($urlWithParam)) - ->willReturn($destroyRoute); + ->withConsecutive( + [$this->equalTo('ocs.app1.' . $resourceName . '.index'), $this->equalTo($url)], + [$this->equalTo('ocs.app1.' . $resourceName . '.show'), $this->equalTo($urlWithParam)], + [$this->equalTo('ocs.app1.' . $resourceName . '.create'), $this->equalTo($url)], + [$this->equalTo('ocs.app1.' . $resourceName . '.update'), $this->equalTo($urlWithParam)], + [$this->equalTo('ocs.app1.' . $resourceName . '.destroy'), $this->equalTo($urlWithParam)], + )->willReturnOnConsecutiveCalls( + $indexRoute, + $showRoute, + $createRoute, + $updateRoute, + $destroyRoute, + ); // load route configuration $config = new RouteConfig($container, $router, $yaml); @@ -364,36 +351,23 @@ class RoutingTest extends \Test\TestCase { $urlWithParam = $url . '/{' . $paramName . '}'; - // we expect create to be called once: - $router - ->expects($this->at(0)) - ->method('create') - ->with($this->equalTo('app1.' . $resourceName . '.index'), $this->equalTo($url)) - ->willReturn($indexRoute); - - $router - ->expects($this->at(1)) - ->method('create') - ->with($this->equalTo('app1.' . $resourceName . '.show'), $this->equalTo($urlWithParam)) - ->willReturn($showRoute); - - $router - ->expects($this->at(2)) - ->method('create') - ->with($this->equalTo('app1.' . $resourceName . '.create'), $this->equalTo($url)) - ->willReturn($createRoute); - - $router - ->expects($this->at(3)) - ->method('create') - ->with($this->equalTo('app1.' . $resourceName . '.update'), $this->equalTo($urlWithParam)) - ->willReturn($updateRoute); - + // we expect create to be called five times: $router - ->expects($this->at(4)) + ->expects($this->exactly(5)) ->method('create') - ->with($this->equalTo('app1.' . $resourceName . '.destroy'), $this->equalTo($urlWithParam)) - ->willReturn($destroyRoute); + ->withConsecutive( + [$this->equalTo('app1.' . $resourceName . '.index'), $this->equalTo($url)], + [$this->equalTo('app1.' . $resourceName . '.show'), $this->equalTo($urlWithParam)], + [$this->equalTo('app1.' . $resourceName . '.create'), $this->equalTo($url)], + [$this->equalTo('app1.' . $resourceName . '.update'), $this->equalTo($urlWithParam)], + [$this->equalTo('app1.' . $resourceName . '.destroy'), $this->equalTo($urlWithParam)], + )->willReturnOnConsecutiveCalls( + $indexRoute, + $showRoute, + $createRoute, + $updateRoute, + $destroyRoute, + ); // load route configuration $config = new RouteConfig($container, $router, $yaml); diff --git a/tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php b/tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php index 6ad57515c16..1ef0aa80817 100644 --- a/tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php +++ b/tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php @@ -25,6 +25,7 @@ namespace Test\Authentication\Token; use OC\Authentication\Exceptions\ExpiredTokenException; use OC\Authentication\Exceptions\InvalidTokenException; +use OC\Authentication\Exceptions\PasswordlessTokenException; use OC\Authentication\Token\IToken; use OC\Authentication\Token\PublicKeyToken; use OC\Authentication\Token\PublicKeyTokenMapper; @@ -83,6 +84,10 @@ class PublicKeyTokenProviderTest extends TestCase { $name = 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12'; $type = IToken::PERMANENT_TOKEN; + $this->config->method('getSystemValueBool') + ->willReturnMap([ + ['auth.storeCryptedPassword', true, true], + ]); $actual = $this->tokenProvider->generateToken($token, $uid, $user, $password, $name, $type, IToken::DO_NOT_REMEMBER); $this->assertInstanceOf(PublicKeyToken::class, $actual); @@ -93,6 +98,48 @@ class PublicKeyTokenProviderTest extends TestCase { $this->assertSame($password, $this->tokenProvider->getPassword($actual, $token)); } + public function testGenerateTokenNoPassword(): void { + $token = 'token'; + $uid = 'user'; + $user = 'User'; + $password = 'passme'; + $name = 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12'; + $type = IToken::PERMANENT_TOKEN; + $this->config->method('getSystemValueBool') + ->willReturnMap([ + ['auth.storeCryptedPassword', true, false], + ]); + $this->expectException(PasswordlessTokenException::class); + + $actual = $this->tokenProvider->generateToken($token, $uid, $user, $password, $name, $type, IToken::DO_NOT_REMEMBER); + + $this->assertInstanceOf(PublicKeyToken::class, $actual); + $this->assertSame($uid, $actual->getUID()); + $this->assertSame($user, $actual->getLoginName()); + $this->assertSame($name, $actual->getName()); + $this->assertSame(IToken::DO_NOT_REMEMBER, $actual->getRemember()); + $this->tokenProvider->getPassword($actual, $token); + } + + public function testGenerateTokenLongPassword() { + $token = 'token'; + $uid = 'user'; + $user = 'User'; + $password = ''; + for ($i = 0; $i < 500; $i++) { + $password .= 'e'; + } + $name = 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12'; + $type = IToken::PERMANENT_TOKEN; + $this->config->method('getSystemValueBool') + ->willReturnMap([ + ['auth.storeCryptedPassword', true, true], + ]); + $this->expectException(\RuntimeException::class); + + $actual = $this->tokenProvider->generateToken($token, $uid, $user, $password, $name, $type, IToken::DO_NOT_REMEMBER); + } + public function testGenerateTokenInvalidName() { $token = 'token'; $uid = 'user'; @@ -103,6 +150,10 @@ class PublicKeyTokenProviderTest extends TestCase { . 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12' . 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12'; $type = IToken::PERMANENT_TOKEN; + $this->config->method('getSystemValueBool') + ->willReturnMap([ + ['auth.storeCryptedPassword', true, true], + ]); $actual = $this->tokenProvider->generateToken($token, $uid, $user, $password, $name, $type, IToken::DO_NOT_REMEMBER); @@ -120,6 +171,10 @@ class PublicKeyTokenProviderTest extends TestCase { ->method('updateActivity') ->with($tk, $this->time); $tk->setLastActivity($this->time - 200); + $this->config->method('getSystemValueBool') + ->willReturnMap([ + ['auth.storeCryptedPassword', true, true], + ]); $this->tokenProvider->updateTokenActivity($tk); @@ -157,6 +212,10 @@ class PublicKeyTokenProviderTest extends TestCase { $password = 'passme'; $name = 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12'; $type = IToken::PERMANENT_TOKEN; + $this->config->method('getSystemValueBool') + ->willReturnMap([ + ['auth.storeCryptedPassword', true, true], + ]); $actual = $this->tokenProvider->generateToken($token, $uid, $user, $password, $name, $type, IToken::DO_NOT_REMEMBER); @@ -185,6 +244,10 @@ class PublicKeyTokenProviderTest extends TestCase { $name = 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12'; $type = IToken::PERMANENT_TOKEN; + $this->config->method('getSystemValueBool') + ->willReturnMap([ + ['auth.storeCryptedPassword', true, true], + ]); $actual = $this->tokenProvider->generateToken($token, $uid, $user, $password, $name, $type, IToken::DO_NOT_REMEMBER); $this->tokenProvider->getPassword($actual, 'wrongtoken'); @@ -197,6 +260,10 @@ class PublicKeyTokenProviderTest extends TestCase { $password = 'passme'; $name = 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12'; $type = IToken::PERMANENT_TOKEN; + $this->config->method('getSystemValueBool') + ->willReturnMap([ + ['auth.storeCryptedPassword', true, true], + ]); $actual = $this->tokenProvider->generateToken($token, $uid, $user, $password, $name, $type, IToken::DO_NOT_REMEMBER); @@ -301,7 +368,7 @@ class PublicKeyTokenProviderTest extends TestCase { $this->tokenProvider->renewSessionToken('oldId', 'newId'); } - public function testRenewSessionTokenWithPassword() { + public function testRenewSessionTokenWithPassword(): void { $token = 'oldId'; $uid = 'user'; $user = 'User'; @@ -309,6 +376,10 @@ class PublicKeyTokenProviderTest extends TestCase { $name = 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12'; $type = IToken::PERMANENT_TOKEN; + $this->config->method('getSystemValueBool') + ->willReturnMap([ + ['auth.storeCryptedPassword', true, true], + ]); $oldToken = $this->tokenProvider->generateToken($token, $uid, $user, $password, $name, $type, IToken::DO_NOT_REMEMBER); $this->mapper @@ -319,7 +390,7 @@ class PublicKeyTokenProviderTest extends TestCase { $this->mapper ->expects($this->once()) ->method('insert') - ->with($this->callback(function (PublicKeyToken $token) use ($user, $uid, $name) { + ->with($this->callback(function (PublicKeyToken $token) use ($user, $uid, $name): bool { return $token->getUID() === $uid && $token->getLoginName() === $user && $token->getName() === $name && @@ -331,14 +402,14 @@ class PublicKeyTokenProviderTest extends TestCase { $this->mapper ->expects($this->once()) ->method('delete') - ->with($this->callback(function ($token) use ($oldToken) { + ->with($this->callback(function ($token) use ($oldToken): bool { return $token === $oldToken; })); $this->tokenProvider->renewSessionToken('oldId', 'newId'); } - public function testGetToken() { + public function testGetToken(): void { $token = new PublicKeyToken(); $this->config->method('getSystemValue') @@ -441,6 +512,10 @@ class PublicKeyTokenProviderTest extends TestCase { $name = 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12'; $type = IToken::PERMANENT_TOKEN; + $this->config->method('getSystemValueBool') + ->willReturnMap([ + ['auth.storeCryptedPassword', true, true], + ]); $actual = $this->tokenProvider->generateToken($token, $uid, $user, $password, $name, $type, IToken::DO_NOT_REMEMBER); $new = $this->tokenProvider->rotate($actual, 'oldtoken', 'newtoken'); @@ -507,6 +582,10 @@ class PublicKeyTokenProviderTest extends TestCase { 'random2', IToken::PERMANENT_TOKEN, IToken::REMEMBER); + $this->config->method('getSystemValueBool') + ->willReturnMap([ + ['auth.storeCryptedPassword', true, true], + ]); $this->mapper->method('hasExpiredTokens') ->with($uid) diff --git a/tests/lib/Avatar/AvatarManagerTest.php b/tests/lib/Avatar/AvatarManagerTest.php index ce6981a2a21..06ff4086f72 100644 --- a/tests/lib/Avatar/AvatarManagerTest.php +++ b/tests/lib/Avatar/AvatarManagerTest.php @@ -37,6 +37,7 @@ use OCP\Files\SimpleFS\ISimpleFolder; use OCP\IConfig; use OCP\IL10N; use OCP\IUser; +use OC\User\User; use OCP\IUserSession; use Psr\Log\LoggerInterface; @@ -101,7 +102,7 @@ class AvatarManagerTest extends \Test\TestCase { } public function testGetAvatarForSelf() { - $user = $this->createMock(IUser::class); + $user = $this->createMock(User::class); $user ->expects($this->any()) ->method('getUID') @@ -151,7 +152,7 @@ class AvatarManagerTest extends \Test\TestCase { } public function testGetAvatarValidUserDifferentCasing() { - $user = $this->createMock(IUser::class); + $user = $this->createMock(User::class); $this->userManager->expects($this->once()) ->method('get') ->with('vaLid-USER') @@ -161,6 +162,10 @@ class AvatarManagerTest extends \Test\TestCase { ->method('getUID') ->willReturn('valid-user'); + $this->userSession->expects($this->once()) + ->method('getUser') + ->willReturn($user); + $folder = $this->createMock(ISimpleFolder::class); $this->appData ->expects($this->once()) @@ -168,26 +173,45 @@ class AvatarManagerTest extends \Test\TestCase { ->with('valid-user') ->willReturn($folder); + $account = $this->createMock(IAccount::class); + $this->accountManager->expects($this->once()) + ->method('getAccount') + ->with($user) + ->willReturn($account); + + $property = $this->createMock(IAccountProperty::class); + $account->expects($this->once()) + ->method('getProperty') + ->with(IAccountManager::PROPERTY_AVATAR) + ->willReturn($property); + + $property->expects($this->once()) + ->method('getScope') + ->willReturn(IAccountManager::SCOPE_FEDERATED); + $expected = new UserAvatar($folder, $this->l10n, $user, $this->logger, $this->config); $this->assertEquals($expected, $this->avatarManager->getAvatar('vaLid-USER')); } - public function knownUnknownProvider() { + public function dataGetAvatarScopes() { return [ - [IAccountManager::SCOPE_LOCAL, false, false, false], - [IAccountManager::SCOPE_LOCAL, true, false, false], - // public access cannot see real avatar [IAccountManager::SCOPE_PRIVATE, true, false, true], // unknown users cannot see real avatar [IAccountManager::SCOPE_PRIVATE, false, false, true], // known users can see real avatar [IAccountManager::SCOPE_PRIVATE, false, true, false], + [IAccountManager::SCOPE_LOCAL, false, false, false], + [IAccountManager::SCOPE_LOCAL, true, false, false], + [IAccountManager::SCOPE_FEDERATED, false, false, false], + [IAccountManager::SCOPE_FEDERATED, true, false, false], + [IAccountManager::SCOPE_PUBLISHED, false, false, false], + [IAccountManager::SCOPE_PUBLISHED, true, false, false], ]; } /** - * @dataProvider knownUnknownProvider + * @dataProvider dataGetAvatarScopes */ public function testGetAvatarScopes($avatarScope, $isPublicCall, $isKnownUser, $expectedPlaceholder) { if ($isPublicCall) { @@ -202,7 +226,7 @@ class AvatarManagerTest extends \Test\TestCase { ->method('getUser') ->willReturn($requestingUser); - $user = $this->createMock(IUser::class); + $user = $this->createMock(User::class); $user ->expects($this->once()) ->method('getUID') diff --git a/tests/lib/Avatar/UserAvatarTest.php b/tests/lib/Avatar/UserAvatarTest.php index dd5f25163f2..9a81f0bcd35 100644 --- a/tests/lib/Avatar/UserAvatarTest.php +++ b/tests/lib/Avatar/UserAvatarTest.php @@ -11,7 +11,6 @@ namespace Test\Avatar; use OC\Files\SimpleFS\SimpleFolder; use OC\User\User; use OCP\Files\File; -use OCP\Files\Folder; use OCP\Files\NotFoundException; use OCP\Files\SimpleFS\ISimpleFile; use OCP\IConfig; @@ -19,7 +18,7 @@ use OCP\IL10N; use Psr\Log\LoggerInterface; class UserAvatarTest extends \Test\TestCase { - /** @var Folder | \PHPUnit\Framework\MockObject\MockObject */ + /** @var SimpleFolder | \PHPUnit\Framework\MockObject\MockObject */ private $folder; /** @var \OC\Avatar\UserAvatar */ @@ -57,7 +56,7 @@ class UserAvatarTest extends \Test\TestCase { ->willReturn($file); $this->folder->method('getFile') - ->willReturnCallback(function ($path) { + ->willReturnCallback(function (string $path) { if ($path === 'avatar.64.png') { throw new NotFoundException(); } @@ -91,12 +90,13 @@ class UserAvatarTest extends \Test\TestCase { ->willReturnMap([ ['avatar.jpg', true], ['avatar.128.jpg', true], + ['generated', false], ]); $expected = new \OC_Image(); $expected->loadFromFile(\OC::$SERVERROOT . '/tests/data/testavatar.png'); - $file = $this->createMock(File::class); + $file = $this->createMock(ISimpleFile::class); $file->method('getContent')->willReturn($expected->data()); $this->folder->method('getFile')->with('avatar.128.jpg')->willReturn($file); @@ -107,12 +107,13 @@ class UserAvatarTest extends \Test\TestCase { $this->folder->method('fileExists') ->willReturnMap([ ['avatar.jpg', true], + ['generated', false], ]); $expected = new \OC_Image(); $expected->loadFromFile(\OC::$SERVERROOT . '/tests/data/testavatar.png'); - $file = $this->createMock(File::class); + $file = $this->createMock(ISimpleFile::class); $file->method('getContent')->willReturn($expected->data()); $this->folder->method('getFile')->with('avatar.jpg')->willReturn($file); @@ -122,8 +123,10 @@ class UserAvatarTest extends \Test\TestCase { public function testGetAvatarNoSizeMatch() { $this->folder->method('fileExists') ->willReturnMap([ + ['avatar.jpg', false], ['avatar.png', true], ['avatar.32.png', false], + ['generated', false], ]); $expected = new \OC_Image(); @@ -132,7 +135,7 @@ class UserAvatarTest extends \Test\TestCase { $expected2->loadFromFile(\OC::$SERVERROOT . '/tests/data/testavatar.png'); $expected2->resize(32); - $file = $this->createMock(File::class); + $file = $this->createMock(ISimpleFile::class); $file->method('getContent')->willReturn($expected->data()); $this->folder->method('getFile') @@ -146,7 +149,7 @@ class UserAvatarTest extends \Test\TestCase { } ); - $newFile = $this->createMock(File::class); + $newFile = $this->createMock(ISimpleFile::class); $newFile->expects($this->once()) ->method('putContent') ->with($expected2->data()); @@ -202,12 +205,12 @@ class UserAvatarTest extends \Test\TestCase { $this->folder->method('getDirectoryListing') ->willReturn([$avatarFileJPG, $avatarFilePNG, $resizedAvatarFile]); - $generated = $this->createMock(File::class); + $generated = $this->createMock(ISimpleFile::class); $this->folder->method('getFile') ->with('generated') ->willReturn($generated); - $newFile = $this->createMock(File::class); + $newFile = $this->createMock(ISimpleFile::class); $this->folder->expects($this->once()) ->method('newFile') ->with('avatar.png') @@ -258,17 +261,17 @@ class UserAvatarTest extends \Test\TestCase { } public function testMixPalette() { - $colorFrom = new \OC\Color(0, 0, 0); - $colorTo = new \OC\Color(6, 12, 18); + $colorFrom = new \OCP\Color(0, 0, 0); + $colorTo = new \OCP\Color(6, 12, 18); $steps = 6; - $palette = $this->invokePrivate($this->avatar, 'mixPalette', [$steps, $colorFrom, $colorTo]); + $palette = \OCP\Color::mixPalette($steps, $colorFrom, $colorTo); foreach ($palette as $j => $color) { // calc increment - $incR = $colorTo->r / $steps * $j; - $incG = $colorTo->g / $steps * $j; - $incB = $colorTo->b / $steps * $j; + $incR = $colorTo->red() / $steps * $j; + $incG = $colorTo->green() / $steps * $j; + $incB = $colorTo->blue() / $steps * $j; // ensure everything is equal - $this->assertEquals($color, new \OC\Color($incR, $incG, $incB)); + $this->assertEquals($color, new \OCP\Color($incR, $incG, $incB)); } $hashToInt = $this->invokePrivate($this->avatar, 'hashToInt', ['abcdef', 18]); $this->assertTrue(gettype($hashToInt) === 'integer'); diff --git a/tests/lib/BackgroundJob/DummyJobList.php b/tests/lib/BackgroundJob/DummyJobList.php index 0751409f62c..be9c06257b7 100644 --- a/tests/lib/BackgroundJob/DummyJobList.php +++ b/tests/lib/BackgroundJob/DummyJobList.php @@ -19,20 +19,20 @@ class DummyJobList extends \OC\BackgroundJob\JobList { /** * @var IJob[] */ - private $jobs = []; + private array $jobs = []; - private $last = 0; + private int $last = 0; public function __construct() { } /** - * @param IJob|string $job + * @param IJob|class-string<IJob> $job * @param mixed $argument */ - public function add($job, $argument = null) { + public function add($job, $argument = null): void { if (is_string($job)) { - /** @var \OC\BackgroundJob\Job $job */ + /** @var IJob $job */ $job = new $job; } $job->setArgument($argument); @@ -45,7 +45,7 @@ class DummyJobList extends \OC\BackgroundJob\JobList { * @param IJob|string $job * @param mixed $argument */ - public function remove($job, $argument = null) { + public function remove($job, $argument = null): void { $index = array_search($job, $this->jobs); if ($index !== false) { unset($this->jobs[$index]); @@ -59,7 +59,7 @@ class DummyJobList extends \OC\BackgroundJob\JobList { * @param mixed $argument * @return bool */ - public function has($job, $argument) { + public function has($job, $argument): bool { return array_search($job, $this->jobs) !== false; } @@ -68,15 +68,28 @@ class DummyJobList extends \OC\BackgroundJob\JobList { * * @return IJob[] */ - public function getAll() { + public function getAll(): array { return $this->jobs; } + public function getJobs($job, ?int $limit, int $offset): array { + if ($job instanceof IJob) { + $jobClass = get_class($job); + } else { + $jobClass = $job; + } + return array_slice( + array_filter( + $this->jobs, + fn ($job) => ($jobClass === null) || (get_class($job) == $jobClass) + ), + $offset, + $limit + ); + } + /** * get the next job in the list - * - * @param bool $onlyTimeSensitive - * @return IJob|null */ public function getNext(bool $onlyTimeSensitive = false): ?IJob { if (count($this->jobs) > 0) { @@ -96,7 +109,7 @@ class DummyJobList extends \OC\BackgroundJob\JobList { * * @param \OC\BackgroundJob\Job $job */ - public function setLastJob(IJob $job) { + public function setLastJob(IJob $job): void { $i = array_search($job, $this->jobs); if ($i !== false) { $this->last = $i; @@ -105,11 +118,7 @@ class DummyJobList extends \OC\BackgroundJob\JobList { } } - /** - * @param int $id - * @return IJob - */ - public function getById($id) { + public function getById(int $id): IJob { foreach ($this->jobs as $job) { if ($job->getId() === $id) { return $job; @@ -122,16 +131,11 @@ class DummyJobList extends \OC\BackgroundJob\JobList { return null; } - /** - * set the lastRun of $job to now - * - * @param IJob $job - */ - public function setLastRun(IJob $job) { + public function setLastRun(IJob $job): void { $job->setLastRun(time()); } - public function setExecutionTime(IJob $job, $timeTaken) { + public function setExecutionTime(IJob $job, $timeTaken): void { } public function resetBackgroundJob(IJob $job): void { diff --git a/tests/lib/Cache/CappedMemoryCacheTest.php b/tests/lib/Cache/CappedMemoryCacheTest.php index db0d2bd1193..b9d10b66100 100644 --- a/tests/lib/Cache/CappedMemoryCacheTest.php +++ b/tests/lib/Cache/CappedMemoryCacheTest.php @@ -30,11 +30,11 @@ namespace Test\Cache; class CappedMemoryCacheTest extends TestCache { protected function setUp(): void { parent::setUp(); - $this->instance = new \OC\Cache\CappedMemoryCache(); + $this->instance = new \OCP\Cache\CappedMemoryCache(); } public function testSetOverCap() { - $instance = new \OC\Cache\CappedMemoryCache(3); + $instance = new \OCP\Cache\CappedMemoryCache(3); $instance->set('1', 'a'); $instance->set('2', 'b'); diff --git a/tests/lib/Collaboration/Collaborators/LookupPluginTest.php b/tests/lib/Collaboration/Collaborators/LookupPluginTest.php index 1d856252745..b52e1d2745e 100644 --- a/tests/lib/Collaboration/Collaborators/LookupPluginTest.php +++ b/tests/lib/Collaboration/Collaborators/LookupPluginTest.php @@ -92,19 +92,20 @@ class LookupPluginTest extends TestCase { ->method('getAppValue') ->with('files_sharing', 'lookupServerEnabled', 'yes') ->willReturn('yes'); - $this->config->expects($this->at(0)) + $this->config->expects($this->exactly(2)) ->method('getSystemValue') - ->with('gs.enabled', false) - ->willReturn(false); + ->withConsecutive( + ['gs.enabled', false], + ['lookup_server', 'https://lookup.nextcloud.com'], + )->willReturnOnConsecutiveCalls( + false, + '', + ); - $this->config->expects($this->at(2)) + $this->config->expects($this->once()) ->method('getSystemValueBool') ->with('has_internet_connection', true) ->willReturn(true); - $this->config->expects($this->at(3)) - ->method('getSystemValue') - ->with('lookup_server', 'https://lookup.nextcloud.com') - ->willReturn(''); $this->clientService->expects($this->never()) ->method('newClient'); @@ -120,12 +121,12 @@ class LookupPluginTest extends TestCase { ->method('getAppValue') ->with('files_sharing', 'lookupServerEnabled', 'yes') ->willReturn('yes'); - $this->config->expects($this->at(0)) + $this->config->expects($this->once()) ->method('getSystemValue') ->with('gs.enabled', false) ->willReturn(false); - $this->config->expects($this->at(2)) + $this->config->expects($this->once()) ->method('getSystemValueBool') ->with('has_internet_connection', true) ->willReturn(false); @@ -156,19 +157,20 @@ class LookupPluginTest extends TestCase { ->method('getAppValue') ->with('files_sharing', 'lookupServerEnabled', 'yes') ->willReturn('yes'); - $this->config->expects($this->at(0)) + $this->config->expects($this->exactly(2)) ->method('getSystemValue') - ->with('gs.enabled', false) - ->willReturn(false); + ->withConsecutive( + ['gs.enabled', false], + ['lookup_server', 'https://lookup.nextcloud.com'], + )->willReturnOnConsecutiveCalls( + false, + $searchParams['server'], + ); - $this->config->expects($this->at(2)) + $this->config->expects($this->once()) ->method('getSystemValueBool') ->with('has_internet_connection', true) ->willReturn(true); - $this->config->expects($this->at(3)) - ->method('getSystemValue') - ->with('lookup_server', 'https://lookup.nextcloud.com') - ->willReturn($searchParams['server']); $response = $this->createMock(IResponse::class); $response->expects($this->once()) @@ -215,23 +217,24 @@ class LookupPluginTest extends TestCase { ->method('getAppValue') ->with('files_sharing', 'lookupServerEnabled', 'yes') ->willReturn($LookupEnabled ? 'yes' : 'no'); - $this->config->expects($this->at(0)) - ->method('getSystemValue') - ->with('gs.enabled', false) - ->willReturn($GSEnabled); if ($GSEnabled || $LookupEnabled) { $searchResult->expects($this->once()) ->method('addResultSet') ->with($type, $searchParams['expectedResult'], []); - $this->config->expects($this->at(2)) + $this->config->expects($this->once()) ->method('getSystemValueBool') ->with('has_internet_connection', true) ->willReturn(true); - $this->config->expects($this->at(3)) + $this->config->expects($this->exactly(2)) ->method('getSystemValue') - ->with('lookup_server', 'https://lookup.nextcloud.com') - ->willReturn($searchParams['server']); + ->withConsecutive( + ['gs.enabled', false], + ['lookup_server', 'https://lookup.nextcloud.com'], + )->willReturnOnConsecutiveCalls( + $GSEnabled, + $searchParams['server'], + ); $response = $this->createMock(IResponse::class); $response->expects($this->once()) @@ -252,6 +255,10 @@ class LookupPluginTest extends TestCase { ->willReturn($client); } else { $searchResult->expects($this->never())->method('addResultSet'); + $this->config->expects($this->once()) + ->method('getSystemValue') + ->with('gs.enabled', false) + ->willReturn($GSEnabled); } $moreResults = $this->plugin->search( $searchParams['search'], diff --git a/tests/lib/Collaboration/Collaborators/UserPluginTest.php b/tests/lib/Collaboration/Collaborators/UserPluginTest.php index 20e1ed898ad..0d9d89c7f8b 100644 --- a/tests/lib/Collaboration/Collaborators/UserPluginTest.php +++ b/tests/lib/Collaboration/Collaborators/UserPluginTest.php @@ -23,9 +23,6 @@ namespace Test\Collaboration\Collaborators; -use OC\Collaboration\Collaborators\SearchResult; -use OC\Collaboration\Collaborators\UserPlugin; -use OC\KnownUser\KnownUserService; use OCP\Collaboration\Collaborators\ISearchResult; use OCP\IConfig; use OCP\IGroup; @@ -35,25 +32,29 @@ use OCP\IUserManager; use OCP\IUserSession; use OCP\Share\IShare; use OCP\UserStatus\IManager as IUserStatusManager; +use OC\Collaboration\Collaborators\SearchResult; +use OC\Collaboration\Collaborators\UserPlugin; +use OC\KnownUser\KnownUserService; +use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class UserPluginTest extends TestCase { - /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IConfig|MockObject */ protected $config; - /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IUserManager|MockObject */ protected $userManager; - /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IGroupManager|MockObject */ protected $groupManager; - /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IUserSession|MockObject */ protected $session; - /** @var KnownUserService|\PHPUnit\Framework\MockObject\MockObject */ + /** @var KnownUserService|MockObject */ protected $knownUserService; - /** @var IUserStatusManager|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IUserStatusManager|MockObject */ protected $userStatusManager; /** @var UserPlugin */ @@ -62,13 +63,11 @@ class UserPluginTest extends TestCase { /** @var ISearchResult */ protected $searchResult; - /** @var int */ - protected $limit = 2; + protected int $limit = 2; - /** @var int */ - protected $offset = 0; + protected int $offset = 0; - /** @var IUser|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IUser|MockObject */ protected $user; protected function setUp(): void { @@ -657,7 +656,7 @@ class UserPluginTest extends TestCase { [ 'core' => [ 'shareapi_allow_share_dialog_user_enumeration' => 'no', - 'shareapi_restrict_user_enumeration_full_match_ignore_second_display_name' => 'yes', + 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn' => 'yes', ], ] ], @@ -798,13 +797,15 @@ class UserPluginTest extends TestCase { $this->session->expects($this->any()) ->method('getUser') ->willReturn($this->getUserMock('test', 'foo')); - // current user - $this->groupManager->expects($this->at(0)) - ->method('getUserGroupIds') - ->willReturn($userGroups); $this->groupManager->expects($this->any()) ->method('getUserGroupIds') - ->willReturnCallback(function ($user) use ($matchingUsers) { + ->willReturnCallback(function ($user) use ($matchingUsers, $userGroups) { + static $firstCall = true; + if ($firstCall) { + $firstCall = false; + // current user + return $userGroups; + } $neededObject = array_filter( $matchingUsers, function ($e) use ($user) { diff --git a/tests/lib/Collaboration/Resources/ProviderManagerTest.php b/tests/lib/Collaboration/Resources/ProviderManagerTest.php index 01e45de9fdf..8f408418409 100644 --- a/tests/lib/Collaboration/Resources/ProviderManagerTest.php +++ b/tests/lib/Collaboration/Resources/ProviderManagerTest.php @@ -91,14 +91,15 @@ class ProviderManagerTest extends TestCase { } public function testGetResourceProvidersValidAndInvalidProvider(): void { - $this->serverContainer->expects($this->at(0)) + $this->serverContainer->expects($this->exactly(2)) ->method('query') - ->with($this->equalTo('InvalidResourceProvider')) - ->willThrowException(new QueryException('A meaningful error message')); - $this->serverContainer->expects($this->at(1)) - ->method('query') - ->with($this->equalTo(ResourceProvider::class)) - ->willReturn($this->createMock(ResourceProvider::class)); + ->withConsecutive( + [$this->equalTo('InvalidResourceProvider')], + [$this->equalTo(ResourceProvider::class)], + )->willReturnOnConsecutiveCalls( + $this->throwException(new QueryException('A meaningful error message')), + $this->createMock(ResourceProvider::class), + ); $this->logger->expects($this->once()) ->method('error'); diff --git a/tests/lib/Command/CronBusTest.php b/tests/lib/Command/CronBusTest.php index ea610a135d8..100de0a861c 100644 --- a/tests/lib/Command/CronBusTest.php +++ b/tests/lib/Command/CronBusTest.php @@ -47,4 +47,11 @@ class CronBusTest extends AsyncBusTest { $job->execute($this->jobList); } } + + public function testClosureFromPreviousVersion() { + $serializedClosure = 'C:32:"Opis\\Closure\\SerializableClosure":217:{a:5:{s:3:"use";a:0:{}s:8:"function";s:64:"function () {\\Test\\Command\\AsyncBusTest::$lastCommand = \'opis\';}";s:5:"scope";s:24:"Test\\Command\\CronBusTest";s:4:"this";N;s:4:"self";s:32:"0000000027dcfe2f00000000407fa805";}}'; + $this->jobList->add('OC\Command\ClosureJob', $serializedClosure); + $this->runJobs(); + $this->assertEquals('opis', AsyncBusTest::$lastCommand); + } } diff --git a/tests/lib/Command/Integrity/SignAppTest.php b/tests/lib/Command/Integrity/SignAppTest.php index fefed296a0c..66005ca06f5 100644 --- a/tests/lib/Command/Integrity/SignAppTest.php +++ b/tests/lib/Command/Integrity/SignAppTest.php @@ -56,25 +56,24 @@ class SignAppTest extends TestCase { $outputInterface = $this->createMock(OutputInterface::class); $inputInterface - ->expects($this->at(0)) + ->expects($this->exactly(3)) ->method('getOption') - ->with('path') - ->willReturn(null); - $inputInterface - ->expects($this->at(1)) - ->method('getOption') - ->with('privateKey') - ->willReturn('PrivateKey'); - $inputInterface - ->expects($this->at(2)) - ->method('getOption') - ->with('certificate') - ->willReturn('Certificate'); + ->withConsecutive( + ['path'], + ['privateKey'], + ['certificate'], + )->willReturnOnConsecutiveCalls( + null, + 'PrivateKey', + 'Certificate', + ); $outputInterface - ->expects($this->at(0)) + ->expects($this->any()) ->method('writeln') - ->with('This command requires the --path, --privateKey and --certificate.'); + ->withConsecutive( + ['This command requires the --path, --privateKey and --certificate.'] + ); $this->assertSame(1, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface])); } @@ -84,25 +83,24 @@ class SignAppTest extends TestCase { $outputInterface = $this->createMock(OutputInterface::class); $inputInterface - ->expects($this->at(0)) + ->expects($this->exactly(3)) ->method('getOption') - ->with('path') - ->willReturn('AppId'); - $inputInterface - ->expects($this->at(1)) - ->method('getOption') - ->with('privateKey') - ->willReturn(null); - $inputInterface - ->expects($this->at(2)) - ->method('getOption') - ->with('certificate') - ->willReturn('Certificate'); + ->withConsecutive( + ['path'], + ['privateKey'], + ['certificate'], + )->willReturnOnConsecutiveCalls( + 'AppId', + null, + 'Certificate', + ); $outputInterface - ->expects($this->at(0)) - ->method('writeln') - ->with('This command requires the --path, --privateKey and --certificate.'); + ->expects($this->any()) + ->method('writeln') + ->withConsecutive( + ['This command requires the --path, --privateKey and --certificate.'] + ); $this->assertSame(1, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface])); } @@ -112,25 +110,24 @@ class SignAppTest extends TestCase { $outputInterface = $this->createMock(OutputInterface::class); $inputInterface - ->expects($this->at(0)) + ->expects($this->exactly(3)) ->method('getOption') - ->with('path') - ->willReturn('AppId'); - $inputInterface - ->expects($this->at(1)) - ->method('getOption') - ->with('privateKey') - ->willReturn('privateKey'); - $inputInterface - ->expects($this->at(2)) - ->method('getOption') - ->with('certificate') - ->willReturn(null); + ->withConsecutive( + ['path'], + ['privateKey'], + ['certificate'], + )->willReturnOnConsecutiveCalls( + 'AppId', + 'privateKey', + null, + ); $outputInterface - ->expects($this->at(0)) + ->expects($this->any()) ->method('writeln') - ->with('This command requires the --path, --privateKey and --certificate.'); + ->withConsecutive( + ['This command requires the --path, --privateKey and --certificate.'] + ); $this->assertSame(1, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface])); } @@ -140,31 +137,31 @@ class SignAppTest extends TestCase { $outputInterface = $this->createMock(OutputInterface::class); $inputInterface - ->expects($this->at(0)) + ->expects($this->exactly(3)) ->method('getOption') - ->with('path') - ->willReturn('AppId'); - $inputInterface - ->expects($this->at(1)) - ->method('getOption') - ->with('privateKey') - ->willReturn('privateKey'); - $inputInterface - ->expects($this->at(2)) - ->method('getOption') - ->with('certificate') - ->willReturn('certificate'); + ->withConsecutive( + ['path'], + ['privateKey'], + ['certificate'], + )->willReturnOnConsecutiveCalls( + 'AppId', + 'privateKey', + 'certificate', + ); $this->fileAccessHelper - ->expects($this->at(0)) + ->expects($this->any()) ->method('file_get_contents') - ->with('privateKey') - ->willReturn(false); + ->withConsecutive(['privateKey']) + ->willReturnOnConsecutiveCalls(false); + $outputInterface - ->expects($this->at(0)) + ->expects($this->any()) ->method('writeln') - ->with('Private key "privateKey" does not exists.'); + ->withConsecutive( + ['Private key "privateKey" does not exists.'] + ); $this->assertSame(1, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface])); } @@ -174,36 +171,36 @@ class SignAppTest extends TestCase { $outputInterface = $this->createMock(OutputInterface::class); $inputInterface - ->expects($this->at(0)) + ->expects($this->exactly(3)) ->method('getOption') - ->with('path') - ->willReturn('AppId'); - $inputInterface - ->expects($this->at(1)) - ->method('getOption') - ->with('privateKey') - ->willReturn('privateKey'); - $inputInterface - ->expects($this->at(2)) - ->method('getOption') - ->with('certificate') - ->willReturn('certificate'); + ->withConsecutive( + ['path'], + ['privateKey'], + ['certificate'], + )->willReturnOnConsecutiveCalls( + 'AppId', + 'privateKey', + 'certificate', + ); $this->fileAccessHelper - ->expects($this->at(0)) + ->expects($this->any()) ->method('file_get_contents') - ->with('privateKey') - ->willReturn(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key'); - $this->fileAccessHelper - ->expects($this->at(1)) - ->method('file_get_contents') - ->with('certificate') - ->willReturn(false); + ->withConsecutive( + ['privateKey'], + ['certificate'], + ) + ->willReturnOnConsecutiveCalls( + \OC::$SERVERROOT . '/tests/data/integritycheck/core.key', + false + ); $outputInterface - ->expects($this->at(0)) + ->expects($this->any()) ->method('writeln') - ->with('Certificate "certificate" does not exists.'); + ->withConsecutive( + ['Certificate "certificate" does not exists.'] + ); $this->assertSame(1, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface])); } @@ -213,31 +210,29 @@ class SignAppTest extends TestCase { $outputInterface = $this->createMock(OutputInterface::class); $inputInterface - ->expects($this->at(0)) - ->method('getOption') - ->with('path') - ->willReturn('AppId'); - $inputInterface - ->expects($this->at(1)) - ->method('getOption') - ->with('privateKey') - ->willReturn('privateKey'); - $inputInterface - ->expects($this->at(2)) + ->expects($this->exactly(3)) ->method('getOption') - ->with('certificate') - ->willReturn('certificate'); + ->withConsecutive( + ['path'], + ['privateKey'], + ['certificate'], + )->willReturnOnConsecutiveCalls( + 'AppId', + 'privateKey', + 'certificate', + ); $this->fileAccessHelper - ->expects($this->at(0)) - ->method('file_get_contents') - ->with('privateKey') - ->willReturn(file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key')); - $this->fileAccessHelper - ->expects($this->at(1)) + ->expects($this->any()) ->method('file_get_contents') - ->with('certificate') - ->willReturn(file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt')); + ->withConsecutive( + ['privateKey'], + ['certificate'], + ) + ->willReturnOnConsecutiveCalls( + file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key'), + file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt'), + ); $this->checker ->expects($this->once()) @@ -245,9 +240,11 @@ class SignAppTest extends TestCase { ->willThrowException(new \Exception('My error message')); $outputInterface - ->expects($this->at(0)) + ->expects($this->any()) ->method('writeln') - ->with('Error: My error message'); + ->withConsecutive( + ['Error: My error message'] + ); $this->assertSame(1, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface])); } @@ -257,40 +254,40 @@ class SignAppTest extends TestCase { $outputInterface = $this->createMock(OutputInterface::class); $inputInterface - ->expects($this->at(0)) - ->method('getOption') - ->with('path') - ->willReturn('AppId'); - $inputInterface - ->expects($this->at(1)) + ->expects($this->exactly(3)) ->method('getOption') - ->with('privateKey') - ->willReturn('privateKey'); - $inputInterface - ->expects($this->at(2)) - ->method('getOption') - ->with('certificate') - ->willReturn('certificate'); + ->withConsecutive( + ['path'], + ['privateKey'], + ['certificate'], + )->willReturnOnConsecutiveCalls( + 'AppId', + 'privateKey', + 'certificate', + ); $this->fileAccessHelper - ->expects($this->at(0)) - ->method('file_get_contents') - ->with('privateKey') - ->willReturn(file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key')); - $this->fileAccessHelper - ->expects($this->at(1)) + ->expects($this->any()) ->method('file_get_contents') - ->with('certificate') - ->willReturn(file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt')); + ->withConsecutive( + ['privateKey'], + ['certificate'], + ) + ->willReturnOnConsecutiveCalls( + file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key'), + file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt'), + ); $this->checker ->expects($this->once()) ->method('writeAppSignature'); $outputInterface - ->expects($this->at(0)) + ->expects($this->any()) ->method('writeln') - ->with('Successfully signed "AppId"'); + ->withConsecutive( + ['Successfully signed "AppId"'] + ); $this->assertSame(0, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface])); } diff --git a/tests/lib/Command/Integrity/SignCoreTest.php b/tests/lib/Command/Integrity/SignCoreTest.php index 3b7fe7f3a8b..d67e2a9e2b4 100644 --- a/tests/lib/Command/Integrity/SignCoreTest.php +++ b/tests/lib/Command/Integrity/SignCoreTest.php @@ -51,20 +51,24 @@ class SignCoreTest extends TestCase { $outputInterface = $this->createMock(OutputInterface::class); $inputInterface - ->expects($this->at(0)) + ->expects($this->exactly(3)) ->method('getOption') - ->with('privateKey') - ->willReturn(null); - $inputInterface - ->expects($this->at(1)) - ->method('getOption') - ->with('certificate') - ->willReturn('Certificate'); + ->withConsecutive( + ['privateKey'], + ['certificate'], + ['path'], + )->willReturnOnConsecutiveCalls( + null, + 'certificate', + 'certificate', + ); $outputInterface - ->expects($this->at(0)) + ->expects($this->any()) ->method('writeln') - ->with('--privateKey, --certificate and --path are required.'); + ->withConsecutive( + ['--privateKey, --certificate and --path are required.'] + ); $this->assertSame(1, self::invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface])); } @@ -74,20 +78,24 @@ class SignCoreTest extends TestCase { $outputInterface = $this->createMock(OutputInterface::class); $inputInterface - ->expects($this->at(0)) - ->method('getOption') - ->with('privateKey') - ->willReturn('privateKey'); - $inputInterface - ->expects($this->at(1)) + ->expects($this->exactly(3)) ->method('getOption') - ->with('certificate') - ->willReturn(null); + ->withConsecutive( + ['privateKey'], + ['certificate'], + ['path'], + )->willReturnOnConsecutiveCalls( + 'privateKey', + null, + 'certificate', + ); $outputInterface - ->expects($this->at(0)) + ->expects($this->any()) ->method('writeln') - ->with('--privateKey, --certificate and --path are required.'); + ->withConsecutive( + ['--privateKey, --certificate and --path are required.'] + ); $this->assertSame(1, self::invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface])); } @@ -97,31 +105,34 @@ class SignCoreTest extends TestCase { $outputInterface = $this->createMock(OutputInterface::class); $inputInterface - ->expects($this->at(0)) - ->method('getOption') - ->with('privateKey') - ->willReturn('privateKey'); - $inputInterface - ->expects($this->at(1)) + ->expects($this->exactly(3)) ->method('getOption') - ->with('certificate') - ->willReturn('certificate'); - $inputInterface - ->expects($this->at(2)) - ->method('getOption') - ->with('path') - ->willReturn('certificate'); + ->withConsecutive( + ['privateKey'], + ['certificate'], + ['path'], + )->willReturnOnConsecutiveCalls( + 'privateKey', + 'certificate', + 'certificate', + ); $this->fileAccessHelper - ->expects($this->at(0)) + ->expects($this->any()) ->method('file_get_contents') - ->with('privateKey') - ->willReturn(false); + ->withConsecutive( + ['privateKey'], + ) + ->willReturnOnConsecutiveCalls( + false, + ); $outputInterface - ->expects($this->at(0)) + ->expects($this->any()) ->method('writeln') - ->with('Private key "privateKey" does not exists.'); + ->withConsecutive( + ['Private key "privateKey" does not exists.'] + ); $this->assertSame(1, self::invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface])); } @@ -131,36 +142,36 @@ class SignCoreTest extends TestCase { $outputInterface = $this->createMock(OutputInterface::class); $inputInterface - ->expects($this->at(0)) - ->method('getOption') - ->with('privateKey') - ->willReturn('privateKey'); - $inputInterface - ->expects($this->at(1)) + ->expects($this->exactly(3)) ->method('getOption') - ->with('certificate') - ->willReturn('certificate'); - $inputInterface - ->expects($this->at(2)) - ->method('getOption') - ->with('path') - ->willReturn('certificate'); + ->withConsecutive( + ['privateKey'], + ['certificate'], + ['path'], + )->willReturnOnConsecutiveCalls( + 'privateKey', + 'certificate', + 'certificate', + ); $this->fileAccessHelper - ->expects($this->at(0)) - ->method('file_get_contents') - ->with('privateKey') - ->willReturn(file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key')); - $this->fileAccessHelper - ->expects($this->at(1)) + ->expects($this->any()) ->method('file_get_contents') - ->with('certificate') - ->willReturn(false); + ->withConsecutive( + ['privateKey'], + ['certificate'], + ) + ->willReturnOnConsecutiveCalls( + file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key'), + false, + ); $outputInterface - ->expects($this->at(0)) + ->expects($this->any()) ->method('writeln') - ->with('Certificate "certificate" does not exists.'); + ->withConsecutive( + ['Certificate "certificate" does not exists.'] + ); $this->assertSame(1, self::invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface])); } @@ -170,31 +181,29 @@ class SignCoreTest extends TestCase { $outputInterface = $this->createMock(OutputInterface::class); $inputInterface - ->expects($this->at(0)) + ->expects($this->exactly(3)) ->method('getOption') - ->with('privateKey') - ->willReturn('privateKey'); - $inputInterface - ->expects($this->at(1)) - ->method('getOption') - ->with('certificate') - ->willReturn('certificate'); - $inputInterface - ->expects($this->at(2)) - ->method('getOption') - ->with('path') - ->willReturn('certificate'); + ->withConsecutive( + ['privateKey'], + ['certificate'], + ['path'], + )->willReturnOnConsecutiveCalls( + 'privateKey', + 'certificate', + 'certificate', + ); $this->fileAccessHelper - ->expects($this->at(0)) - ->method('file_get_contents') - ->with('privateKey') - ->willReturn(file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key')); - $this->fileAccessHelper - ->expects($this->at(1)) + ->expects($this->any()) ->method('file_get_contents') - ->with('certificate') - ->willReturn(file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt')); + ->withConsecutive( + ['privateKey'], + ['certificate'], + ) + ->willReturnOnConsecutiveCalls( + file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key'), + file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt'), + ); $this->checker ->expects($this->once()) @@ -202,9 +211,11 @@ class SignCoreTest extends TestCase { ->willThrowException(new \Exception('My exception message')); $outputInterface - ->expects($this->at(0)) + ->expects($this->any()) ->method('writeln') - ->with('Error: My exception message'); + ->withConsecutive( + ['Error: My exception message'] + ); $this->assertEquals(1, self::invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface])); } @@ -214,40 +225,40 @@ class SignCoreTest extends TestCase { $outputInterface = $this->createMock(OutputInterface::class); $inputInterface - ->expects($this->at(0)) + ->expects($this->exactly(3)) ->method('getOption') - ->with('privateKey') - ->willReturn('privateKey'); - $inputInterface - ->expects($this->at(1)) - ->method('getOption') - ->with('certificate') - ->willReturn('certificate'); - $inputInterface - ->expects($this->at(2)) - ->method('getOption') - ->with('path') - ->willReturn('certificate'); + ->withConsecutive( + ['privateKey'], + ['certificate'], + ['path'], + )->willReturnOnConsecutiveCalls( + 'privateKey', + 'certificate', + 'certificate', + ); $this->fileAccessHelper - ->expects($this->at(0)) - ->method('file_get_contents') - ->with('privateKey') - ->willReturn(file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key')); - $this->fileAccessHelper - ->expects($this->at(1)) + ->expects($this->any()) ->method('file_get_contents') - ->with('certificate') - ->willReturn(file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt')); + ->withConsecutive( + ['privateKey'], + ['certificate'], + ) + ->willReturnOnConsecutiveCalls( + file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key'), + file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt'), + ); $this->checker ->expects($this->once()) ->method('writeCoreSignature'); $outputInterface - ->expects($this->at(0)) + ->expects($this->any()) ->method('writeln') - ->with('Successfully signed "core"'); + ->withConsecutive( + ['Successfully signed "core"'] + ); $this->assertEquals(0, self::invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface])); } diff --git a/tests/lib/Comments/FakeManager.php b/tests/lib/Comments/FakeManager.php index 5406df96a96..b524f5a5000 100644 --- a/tests/lib/Comments/FakeManager.php +++ b/tests/lib/Comments/FakeManager.php @@ -141,4 +141,8 @@ class FakeManager implements ICommentsManager { public function getLastCommentDateByActor(string $objectType, string $objectId, string $verb, string $actorType, array $actors): array { return []; } + + public function deleteCommentsExpiredAtObject(string $objectType, string $objectId = ''): bool { + return true; + } } diff --git a/tests/lib/Comments/ManagerTest.php b/tests/lib/Comments/ManagerTest.php index 6bcd0dec8ed..1af460e6f1b 100644 --- a/tests/lib/Comments/ManagerTest.php +++ b/tests/lib/Comments/ManagerTest.php @@ -14,6 +14,7 @@ use OCP\IConfig; use OCP\IDBConnection; use OCP\IInitialStateService; use OCP\IUser; +use OCP\Server; use Psr\Log\LoggerInterface; use Test\TestCase; @@ -37,7 +38,7 @@ class ManagerTest extends TestCase { $this->connection->prepare($sql)->execute(); } - protected function addDatabaseEntry($parentId, $topmostParentId, $creationDT = null, $latestChildDT = null, $objectId = null) { + protected function addDatabaseEntry($parentId, $topmostParentId, $creationDT = null, $latestChildDT = null, $objectId = null, $expireDate = null) { if (is_null($creationDT)) { $creationDT = new \DateTime(); } @@ -63,6 +64,7 @@ class ManagerTest extends TestCase { 'latest_child_timestamp' => $qb->createNamedParameter($latestChildDT, 'datetime'), 'object_type' => $qb->createNamedParameter('files'), 'object_id' => $qb->createNamedParameter($objectId), + 'expire_date' => $qb->createNamedParameter($expireDate, 'datetime'), ]) ->execute(); @@ -701,6 +703,91 @@ class ManagerTest extends TestCase { $this->assertTrue($wasSuccessful); } + public function testDeleteCommentsExpiredAtObjectTypeAndId(): void { + $ids = []; + $ids[] = $this->addDatabaseEntry(0, 0, null, null, null, new \DateTime('+2 hours')); + $ids[] = $this->addDatabaseEntry(0, 0, null, null, null, new \DateTime('+2 hours')); + $ids[] = $this->addDatabaseEntry(0, 0, null, null, null, new \DateTime('+2 hours')); + $ids[] = $this->addDatabaseEntry(0, 0, null, null, null, new \DateTime('-2 hours')); + $ids[] = $this->addDatabaseEntry(0, 0, null, null, null, new \DateTime('-2 hours')); + $ids[] = $this->addDatabaseEntry(0, 0, null, null, null, new \DateTime('-2 hours')); + + $manager = new Manager( + $this->connection, + $this->createMock(LoggerInterface::class), + $this->createMock(IConfig::class), + Server::get(ITimeFactory::class), + new EmojiHelper($this->connection), + $this->createMock(IInitialStateService::class) + ); + + // just to make sure they are really set, with correct actor data + $comment = $manager->get((string) $ids[1]); + $this->assertSame($comment->getObjectType(), 'files'); + $this->assertSame($comment->getObjectId(), 'file64'); + + $deleted = $manager->deleteCommentsExpiredAtObject('files', 'file64'); + $this->assertTrue($deleted); + + $deleted = 0; + $exists = 0; + foreach ($ids as $id) { + try { + $manager->get((string) $id); + $exists++; + } catch (NotFoundException $e) { + $deleted++; + } + } + $this->assertSame($exists, 3); + $this->assertSame($deleted, 3); + + // actor info is gone from DB, but when database interaction is alright, + // we still expect to get true back + $deleted = $manager->deleteCommentsExpiredAtObject('files', 'file64'); + $this->assertFalse($deleted); + } + + public function testDeleteCommentsExpiredAtObjectType(): void { + $ids = []; + $ids[] = $this->addDatabaseEntry(0, 0, null, null, 'file1', new \DateTime('-2 hours')); + $ids[] = $this->addDatabaseEntry(0, 0, null, null, 'file2', new \DateTime('-2 hours')); + $ids[] = $this->addDatabaseEntry(0, 0, null, null, 'file3', new \DateTime('-2 hours')); + $ids[] = $this->addDatabaseEntry(0, 0, null, null, 'file3', new \DateTime()); + $ids[] = $this->addDatabaseEntry(0, 0, null, null, 'file3', new \DateTime()); + $ids[] = $this->addDatabaseEntry(0, 0, null, null, 'file3', new \DateTime()); + + $manager = new Manager( + $this->connection, + $this->createMock(LoggerInterface::class), + $this->createMock(IConfig::class), + Server::get(ITimeFactory::class), + new EmojiHelper($this->connection), + $this->createMock(IInitialStateService::class) + ); + + $deleted = $manager->deleteCommentsExpiredAtObject('files'); + $this->assertTrue($deleted); + + $deleted = 0; + $exists = 0; + foreach ($ids as $id) { + try { + $manager->get((string) $id); + $exists++; + } catch (NotFoundException $e) { + $deleted++; + } + } + $this->assertSame($exists, 0); + $this->assertSame($deleted, 6); + + // actor info is gone from DB, but when database interaction is alright, + // we still expect to get true back + $deleted = $manager->deleteCommentsExpiredAtObject('files'); + $this->assertFalse($deleted); + } + public function testSetMarkRead() { /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */ $user = $this->createMock(IUser::class); diff --git a/tests/lib/DB/MigrationsTest.php b/tests/lib/DB/MigrationsTest.php index 206fe1a3798..3d115f25adf 100644 --- a/tests/lib/DB/MigrationsTest.php +++ b/tests/lib/DB/MigrationsTest.php @@ -115,12 +115,12 @@ class MigrationsTest extends \Test\TestCase { ->willReturn($wrappedSchema); $step = $this->createMock(IMigrationStep::class); - $step->expects($this->at(0)) + $step->expects($this->once()) ->method('preSchemaChange'); - $step->expects($this->at(1)) + $step->expects($this->once()) ->method('changeSchema') ->willReturn($schemaResult); - $step->expects($this->at(2)) + $step->expects($this->once()) ->method('postSchemaChange'); $this->migrationService = $this->getMockBuilder(MigrationService::class) @@ -145,12 +145,12 @@ class MigrationsTest extends \Test\TestCase { ->method('migrateToSchema'); $step = $this->createMock(IMigrationStep::class); - $step->expects($this->at(0)) + $step->expects($this->once()) ->method('preSchemaChange'); - $step->expects($this->at(1)) + $step->expects($this->once()) ->method('changeSchema') ->willReturn(null); - $step->expects($this->at(2)) + $step->expects($this->once()) ->method('postSchemaChange'); $this->migrationService = $this->getMockBuilder(MigrationService::class) diff --git a/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php b/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php index 08392b09d8d..0ea6e69c956 100644 --- a/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php +++ b/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php @@ -501,4 +501,21 @@ class FunctionBuilderTest extends TestCase { $result->closeCursor(); $this->assertEquals(1, $row); } + + public function testCase() { + $query = $this->connection->getQueryBuilder(); + + $query->select($query->func()->case([ + ['when' => $query->expr()->gt($query->expr()->literal(1, IQueryBuilder::PARAM_INT), $query->expr()->literal(2, IQueryBuilder::PARAM_INT)), 'then' => $query->expr()->literal('first')], + ['when' => $query->expr()->lt($query->expr()->literal(1, IQueryBuilder::PARAM_INT), $query->expr()->literal(2, IQueryBuilder::PARAM_INT)), 'then' => $query->expr()->literal('second')], + ['when' => $query->expr()->eq($query->expr()->literal(1, IQueryBuilder::PARAM_INT), $query->expr()->literal(2, IQueryBuilder::PARAM_INT)), 'then' => $query->expr()->literal('third')], + ], $query->createNamedParameter('else'))); + $query->from('appconfig') + ->setMaxResults(1); + + $result = $query->execute(); + $row = $result->fetchOne(); + $result->closeCursor(); + $this->assertEquals('second', $row); + } } diff --git a/tests/lib/DirectEditing/ManagerTest.php b/tests/lib/DirectEditing/ManagerTest.php index b00de02bcf5..e19c44b1a06 100644 --- a/tests/lib/DirectEditing/ManagerTest.php +++ b/tests/lib/DirectEditing/ManagerTest.php @@ -106,6 +106,10 @@ class ManagerTest extends TestCase { */ private $userFolder; /** + * @var MockObject|IL10N + */ + private $l10n; + /** * @var MockObject|IManager */ private $encryptionManager; diff --git a/tests/lib/Encryption/DecryptAllTest.php b/tests/lib/Encryption/DecryptAllTest.php index 90ff045a9b9..92ed2dcd701 100644 --- a/tests/lib/Encryption/DecryptAllTest.php +++ b/tests/lib/Encryption/DecryptAllTest.php @@ -224,12 +224,12 @@ class DecryptAllTest extends TestCase { $this->userInterface->expects($this->any()) ->method('getUsers') ->willReturn(['user1', 'user2']); - $instance->expects($this->at(0)) + $instance->expects($this->exactly(2)) ->method('decryptUsersFiles') - ->with('user1'); - $instance->expects($this->at(1)) - ->method('decryptUsersFiles') - ->with('user2'); + ->withConsecutive( + ['user1'], + ['user2'], + ); } else { $instance->expects($this->once()) ->method('decryptUsersFiles') @@ -269,17 +269,18 @@ class DecryptAllTest extends TestCase { $sharedStorage->expects($this->once())->method('instanceOfStorage') ->with('OCA\Files_Sharing\SharedStorage')->willReturn(true); - $this->view->expects($this->at(0))->method('getDirectoryContent') - ->with('/user1/files')->willReturn( + $this->view->expects($this->exactly(2)) + ->method('getDirectoryContent') + ->withConsecutive( + ['/user1/files'], + ['/user1/files/foo'] + ) + ->willReturnOnConsecutiveCalls( [ new FileInfo('path', $storage, 'intPath', ['name' => 'foo', 'type' => 'dir'], null), new FileInfo('path', $storage, 'intPath', ['name' => 'bar', 'type' => 'file', 'encrypted' => true], null), new FileInfo('path', $sharedStorage, 'intPath', ['name' => 'shared', 'type' => 'file', 'encrypted' => true], null), - ] - ); - - $this->view->expects($this->at(3))->method('getDirectoryContent') - ->with('/user1/files/foo')->willReturn( + ], [ new FileInfo('path', $storage, 'intPath', ['name' => 'subfile', 'type' => 'file', 'encrypted' => true], null) ] @@ -295,12 +296,12 @@ class DecryptAllTest extends TestCase { } ); - $instance->expects($this->at(0)) - ->method('decryptFile') - ->with('/user1/files/bar'); - $instance->expects($this->at(1)) + $instance->expects($this->exactly(2)) ->method('decryptFile') - ->with('/user1/files/foo/subfile'); + ->withConsecutive( + ['/user1/files/bar'], + ['/user1/files/foo/subfile'], + ); /* We need format method to return a string */ diff --git a/tests/lib/Encryption/Keys/StorageTest.php b/tests/lib/Encryption/Keys/StorageTest.php index 30680646f73..bb7bbbcd7c1 100644 --- a/tests/lib/Encryption/Keys/StorageTest.php +++ b/tests/lib/Encryption/Keys/StorageTest.php @@ -162,21 +162,21 @@ class StorageTest extends TestCase { ->method('isSystemWideMountPoint') ->willReturn(false); - $this->view->expects($this->at(0)) - ->method('file_exists') - ->with($this->equalTo('/user1/files_encryption/keys' . $strippedPartialName . '/encModule/fileKey')) - ->willReturn($originalKeyExists); - $this->crypto->method('decrypt') ->willReturnCallback(function ($data, $pass) { return $data; }); if (!$originalKeyExists) { - $this->view->expects($this->at(1)) + $this->view->expects($this->exactly(2)) ->method('file_exists') - ->with($this->equalTo('/user1/files_encryption/keys' . $path . '/encModule/fileKey')) - ->willReturn(true); + ->withConsecutive( + [$this->equalTo('/user1/files_encryption/keys' . $strippedPartialName . '/encModule/fileKey')], + [$this->equalTo('/user1/files_encryption/keys' . $path . '/encModule/fileKey')], + )->willReturnOnConsecutiveCalls( + $originalKeyExists, + true, + ); $this->view->expects($this->once()) ->method('file_get_contents') @@ -184,6 +184,11 @@ class StorageTest extends TestCase { ->willReturn(json_encode(['key' => base64_encode('key2')])); } else { $this->view->expects($this->once()) + ->method('file_exists') + ->with($this->equalTo('/user1/files_encryption/keys' . $strippedPartialName . '/encModule/fileKey')) + ->willReturn($originalKeyExists); + + $this->view->expects($this->once()) ->method('file_get_contents') ->with($this->equalTo('/user1/files_encryption/keys' . $strippedPartialName . '/encModule/fileKey')) ->willReturn(json_encode(['key' => base64_encode('key')])); @@ -627,10 +632,11 @@ class StorageTest extends TestCase { ->with('user1/files_encryption/backup')->willReturn(!$createBackupDir); if ($createBackupDir) { - $this->view->expects($this->at(1))->method('mkdir') - ->with('user1/files_encryption/backup'); - $this->view->expects($this->at(2))->method('mkdir') - ->with('user1/files_encryption/backup/test.encryptionModule.1234567'); + $this->view->expects($this->exactly(2))->method('mkdir') + ->withConsecutive( + ['user1/files_encryption/backup'], + ['user1/files_encryption/backup/test.encryptionModule.1234567'], + ); } else { $this->view->expects($this->once())->method('mkdir') ->with('user1/files_encryption/backup/test.encryptionModule.1234567'); diff --git a/tests/lib/Encryption/UtilTest.php b/tests/lib/Encryption/UtilTest.php index 84d81dd1cbb..248377fc698 100644 --- a/tests/lib/Encryption/UtilTest.php +++ b/tests/lib/Encryption/UtilTest.php @@ -4,8 +4,12 @@ namespace Test\Encryption; use OC\Encryption\Util; use OC\Files\View; +use OCA\Files_External\Lib\StorageConfig; +use OCA\Files_External\Service\GlobalStoragesService; use OCP\Encryption\IEncryptionModule; use OCP\IConfig; +use OCP\IGroupManager; +use OCP\IUserManager; use Test\TestCase; class UtilTest extends TestCase { @@ -13,24 +17,21 @@ class UtilTest extends TestCase { /** * block size will always be 8192 for a PHP stream * @see https://bugs.php.net/bug.php?id=21641 - * @var integer */ - protected $headerSize = 8192; + protected int $headerSize = 8192; /** @var \PHPUnit\Framework\MockObject\MockObject */ protected $view; - /** @var \PHPUnit\Framework\MockObject\MockObject */ + /** @var \PHPUnit\Framework\MockObject\MockObject|IUserManager */ protected $userManager; - /** @var \PHPUnit\Framework\MockObject\MockObject */ + /** @var \PHPUnit\Framework\MockObject\MockObject|IGroupManager */ protected $groupManager; - /** @var \PHPUnit\Framework\MockObject\MockObject */ + /** @var \PHPUnit\Framework\MockObject\MockObject|IConfig */ private $config; - - /** @var \OC\Encryption\Util */ - private $util; + private Util $util; protected function setUp(): void { parent::setUp(); @@ -38,17 +39,9 @@ class UtilTest extends TestCase { ->disableOriginalConstructor() ->getMock(); - $this->userManager = $this->getMockBuilder('OC\User\Manager') - ->disableOriginalConstructor() - ->getMock(); - - $this->groupManager = $this->getMockBuilder('OC\Group\Manager') - ->disableOriginalConstructor() - ->getMock(); - - $this->config = $this->getMockBuilder(IConfig::class) - ->disableOriginalConstructor() - ->getMock(); + $this->userManager = $this->createMock(IUserManager::class); + $this->groupManager = $this->createMock(IGroupManager::class); + $this->config = $this->createMock(IConfig::class); $this->util = new Util( $this->view, @@ -188,4 +181,43 @@ class UtilTest extends TestCase { ['/foo/test.txt.ocTransferId7567.part', '/foo/test.txt'], ]; } + + public function dataTestIsSystemWideMountPoint() { + return [ + [false, 'non-matching mount point name', [], [], '/mp_another'], + [true, 'applicable to all', [], []], + [true, 'applicable to user directly', ['user1'], []], + [true, 'applicable to group directly', [], ['group1']], + [false, 'non-applicable to current user', ['user2'], []], + [false, 'non-applicable to current user\'s group', [], ['group2']], + [true, 'mount point without leading slash', [], [], 'mp'], + ]; + } + + /** + * @dataProvider dataTestIsSystemWideMountPoint + */ + public function testIsSystemWideMountPoint($expectedResult, $expectationText, $applicableUsers, $applicableGroups, $mountPointName = '/mp') { + $this->groupManager->method('isInGroup') + ->will($this->returnValueMap([ + ['user1', 'group1', true], // user is only in group1 + ['user1', 'group2', false], + ])); + + $storages = []; + + $storageConfig = $this->createMock(StorageConfig::class); + $storageConfig->method('getMountPoint')->willReturn($mountPointName); + $storageConfig->method('getApplicableUsers')->willReturn($applicableUsers); + $storageConfig->method('getApplicableGroups')->willReturn($applicableGroups); + $storages[] = $storageConfig; + + $storagesServiceMock = $this->createMock(GlobalStoragesService::class); + $storagesServiceMock->expects($this->atLeastOnce())->method('getAllStorages') + ->willReturn($storages); + + $this->overwriteService(GlobalStoragesService::class, $storagesServiceMock); + + $this->assertEquals($expectedResult, $this->util->isSystemWideMountPoint('/files/mp', 'user1'), 'Test case: ' . $expectationText); + } } diff --git a/tests/lib/Files/Cache/SearchBuilderTest.php b/tests/lib/Files/Cache/SearchBuilderTest.php index 82c4dbaa27f..5eb1a0252f0 100644 --- a/tests/lib/Files/Cache/SearchBuilderTest.php +++ b/tests/lib/Files/Cache/SearchBuilderTest.php @@ -79,7 +79,7 @@ class SearchBuilderTest extends TestCase { $this->numericStorageId = 10000; $this->builder->select(['fileid']) - ->from('filecache') + ->from('filecache', 'file') // alias needed for QuerySearchHelper#getOperatorFieldAndValue ->where($this->builder->expr()->eq('storage', new Literal($this->numericStorageId))); } diff --git a/tests/lib/Files/Config/UserMountCacheTest.php b/tests/lib/Files/Config/UserMountCacheTest.php index 221159bc983..8b26b309daa 100644 --- a/tests/lib/Files/Config/UserMountCacheTest.php +++ b/tests/lib/Files/Config/UserMountCacheTest.php @@ -11,7 +11,7 @@ namespace Test\Files\Config; use OC\DB\QueryBuilder\Literal; use OC\Files\Mount\MountPoint; use OC\Files\Storage\Storage; -use OC\Cache\CappedMemoryCache; +use OCP\Cache\CappedMemoryCache; use OC\User\Manager; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Config\ICachedMountInfo; diff --git a/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php b/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php index 5dc93660d9c..7ce87140122 100644 --- a/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php +++ b/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php @@ -201,17 +201,17 @@ class ObjectHomeMountProviderTest extends \Test\TestCase { } public function testMultiBucketConfigFirstFallBackSingle() { - $this->config->expects($this->at(0)) - ->method('getSystemValue') - ->with($this->equalTo('objectstore_multibucket')) - ->willReturn(''); - - $this->config->expects($this->at(1)) + $this->config->expects($this->exactly(2)) ->method('getSystemValue') - ->with($this->equalTo('objectstore')) - ->willReturn([ - 'class' => 'Test\Files\Mount\FakeObjectStore', - ]); + ->withConsecutive( + [$this->equalTo('objectstore_multibucket')], + [$this->equalTo('objectstore')], + )->willReturnOnConsecutiveCalls( + '', + [ + 'class' => 'Test\Files\Mount\FakeObjectStore', + ], + ); $this->user->method('getUID') ->willReturn('uid'); diff --git a/tests/lib/Files/Node/RootTest.php b/tests/lib/Files/Node/RootTest.php index ee86eab5675..5d8e2a4ac62 100644 --- a/tests/lib/Files/Node/RootTest.php +++ b/tests/lib/Files/Node/RootTest.php @@ -8,7 +8,7 @@ namespace Test\Files\Node; -use OC\Cache\CappedMemoryCache; +use OCP\Cache\CappedMemoryCache; use OC\Files\FileInfo; use OC\Files\Mount\Manager; use OC\Files\Node\Folder; diff --git a/tests/lib/Files/Storage/Wrapper/EncryptionTest.php b/tests/lib/Files/Storage/Wrapper/EncryptionTest.php index d26e5c499e7..ebb97a25c77 100644 --- a/tests/lib/Files/Storage/Wrapper/EncryptionTest.php +++ b/tests/lib/Files/Storage/Wrapper/EncryptionTest.php @@ -5,6 +5,7 @@ namespace Test\Files\Storage\Wrapper; use OC\Encryption\Exceptions\ModuleDoesNotExistsException; use OC\Encryption\Update; use OC\Encryption\Util; +use OC\Files\Cache\CacheEntry; use OC\Files\Storage\Temporary; use OC\Files\Storage\Wrapper\Encryption; use OC\Files\View; @@ -259,7 +260,7 @@ class EncryptionTest extends Storage { ->method('get') ->willReturnCallback( function ($path) use ($encrypted) { - return ['encrypted' => $encrypted, 'path' => $path, 'size' => 0, 'fileid' => 1]; + return new CacheEntry(['encrypted' => $encrypted, 'path' => $path, 'size' => 0, 'fileid' => 1]); } ); @@ -332,7 +333,7 @@ class EncryptionTest extends Storage { ->disableOriginalConstructor()->getMock(); $cache->expects($this->any()) ->method('get') - ->willReturn(['encrypted' => true, 'path' => '/test.txt', 'size' => 0, 'fileid' => 1]); + ->willReturn(new CacheEntry(['encrypted' => true, 'path' => '/test.txt', 'size' => 0, 'fileid' => 1])); $this->instance = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Encryption') ->setConstructorArgs( @@ -910,7 +911,7 @@ class EncryptionTest extends Storage { if ($copyResult) { $cache->expects($this->once())->method('get') ->with($sourceInternalPath) - ->willReturn(['encrypted' => $encrypted, 'size' => 42]); + ->willReturn(new CacheEntry(['encrypted' => $encrypted, 'size' => 42])); if ($encrypted) { $instance->expects($this->once())->method('updateUnencryptedSize') ->with($mountPoint . $targetInternalPath, 42); diff --git a/tests/lib/Files/ViewTest.php b/tests/lib/Files/ViewTest.php index 7b735720ff1..86101d79a1e 100644 --- a/tests/lib/Files/ViewTest.php +++ b/tests/lib/Files/ViewTest.php @@ -7,7 +7,7 @@ namespace Test\Files; -use OC\Cache\CappedMemoryCache; +use OCP\Cache\CappedMemoryCache; use OC\Files\Cache\Watcher; use OC\Files\Filesystem; use OC\Files\Mount\MountPoint; @@ -2643,44 +2643,31 @@ class ViewTest extends \Test\TestCase { ]) ->getMock(); - $view - ->expects($this->at(0)) - ->method('is_file') - ->with('/new') - ->willReturn(false); - $view - ->expects($this->at(1)) - ->method('file_exists') - ->with('/new') - ->willReturn(true); - $view - ->expects($this->at(2)) - ->method('is_file') - ->with('/new/folder') - ->willReturn(false); - $view - ->expects($this->at(3)) - ->method('file_exists') - ->with('/new/folder') - ->willReturn(false); - $view - ->expects($this->at(4)) - ->method('mkdir') - ->with('/new/folder'); - $view - ->expects($this->at(5)) + $view->expects($this->exactly(3)) ->method('is_file') - ->with('/new/folder/structure') + ->withConsecutive( + ['/new'], + ['/new/folder'], + ['/new/folder/structure'], + ) ->willReturn(false); - $view - ->expects($this->at(6)) + $view->expects($this->exactly(3)) ->method('file_exists') - ->with('/new/folder/structure') - ->willReturn(false); - $view - ->expects($this->at(7)) + ->withConsecutive( + ['/new'], + ['/new/folder'], + ['/new/folder/structure'], + )->willReturnOnConsecutiveCalls( + true, + false, + false, + ); + $view->expects($this->exactly(2)) ->method('mkdir') - ->with('/new/folder/structure'); + ->withConsecutive( + ['/new/folder'], + ['/new/folder/structure'], + ); $this->assertTrue(self::invokePrivate($view, 'createParentDirectories', ['/new/folder/structure'])); } diff --git a/tests/lib/HelperStorageTest.php b/tests/lib/HelperStorageTest.php index 6d7ea513d3f..d3f480502b2 100644 --- a/tests/lib/HelperStorageTest.php +++ b/tests/lib/HelperStorageTest.php @@ -104,6 +104,9 @@ class HelperStorageTest extends \Test\TestCase { $extStorage->file_put_contents('extfile.txt', 'abcdefghijklmnopq'); $extStorage->getScanner()->scan(''); // update root size + $config = \OC::$server->getConfig(); + $config->setSystemValue('quota_include_external_storage', false); + \OC\Files\Filesystem::mount($extStorage, [], '/' . $this->user . '/files/ext'); $storageInfo = \OC_Helper::getStorageInfo(''); diff --git a/tests/lib/Http/Client/ClientTest.php b/tests/lib/Http/Client/ClientTest.php index 63835a4d4cd..141c6190cd9 100644 --- a/tests/lib/Http/Client/ClientTest.php +++ b/tests/lib/Http/Client/ClientTest.php @@ -75,35 +75,33 @@ class ClientTest extends \Test\TestCase { public function testGetProxyUriProxyHostWithPassword(): void { $this->config - ->expects($this->at(0)) + ->expects($this->exactly(3)) ->method('getSystemValue') - ->with( - $this->equalTo('proxy'), - $this->callback(function ($input) { - return $input === ''; - }) + ->withConsecutive( + [ + $this->equalTo('proxy'), + $this->callback(function ($input) { + return $input === ''; + }) + ], + [ + $this->equalTo('proxyuserpwd'), + $this->callback(function ($input) { + return $input === ''; + }) + ], + [ + $this->equalTo('proxyexclude'), + $this->callback(function ($input) { + return $input === []; + }) + ], ) - ->willReturn('foo'); - $this->config - ->expects($this->at(1)) - ->method('getSystemValue') - ->with( - $this->equalTo('proxyuserpwd'), - $this->callback(function ($input) { - return $input === ''; - }) - ) - ->willReturn('username:password'); - $this->config - ->expects($this->at(2)) - ->method('getSystemValue') - ->with( - $this->equalTo('proxyexclude'), - $this->callback(function ($input) { - return $input === []; - }) - ) - ->willReturn([]); + ->willReturnOnConsecutiveCalls( + 'foo', + 'username:password', + [], + ); $this->assertEquals([ 'http' => 'username:password@foo', 'https' => 'username:password@foo' @@ -112,35 +110,33 @@ class ClientTest extends \Test\TestCase { public function testGetProxyUriProxyHostWithPasswordAndExclude(): void { $this->config - ->expects($this->at(0)) - ->method('getSystemValue') - ->with( - $this->equalTo('proxy'), - $this->callback(function ($input) { - return $input === ''; - }) - ) - ->willReturn('foo'); - $this->config - ->expects($this->at(1)) + ->expects($this->exactly(3)) ->method('getSystemValue') - ->with( - $this->equalTo('proxyuserpwd'), - $this->callback(function ($input) { - return $input === ''; - }) + ->withConsecutive( + [ + $this->equalTo('proxy'), + $this->callback(function ($input) { + return $input === ''; + }) + ], + [ + $this->equalTo('proxyuserpwd'), + $this->callback(function ($input) { + return $input === ''; + }) + ], + [ + $this->equalTo('proxyexclude'), + $this->callback(function ($input) { + return $input === []; + }) + ], ) - ->willReturn('username:password'); - $this->config - ->expects($this->at(2)) - ->method('getSystemValue') - ->with( - $this->equalTo('proxyexclude'), - $this->callback(function ($input) { - return $input === []; - }) - ) - ->willReturn(['bar']); + ->willReturnOnConsecutiveCalls( + 'foo', + 'username:password', + ['bar'], + ); $this->assertEquals([ 'http' => 'username:password@foo', 'https' => 'username:password@foo', @@ -469,10 +465,16 @@ class ClientTest extends \Test\TestCase { public function testSetDefaultOptionsWithNotInstalled(): void { $this->config - ->expects($this->at(1)) + ->expects($this->exactly(2)) ->method('getSystemValue') - ->with('installed', false) - ->willReturn(false); + ->withConsecutive( + ['proxy', ''], + ['installed', false], + ) + ->willReturnOnConsecutiveCalls( + '', + false, + ); $this->certificateManager ->expects($this->never()) ->method('listCertificates'); @@ -500,20 +502,20 @@ class ClientTest extends \Test\TestCase { public function testSetDefaultOptionsWithProxy(): void { $this->config - ->expects($this->at(0)) + ->expects($this->exactly(4)) ->method('getSystemValue') - ->with('proxy', null) - ->willReturn('foo'); - $this->config - ->expects($this->at(1)) - ->method('getSystemValue') - ->with('proxyuserpwd', null) - ->willReturn(null); - $this->config - ->expects($this->at(2)) - ->method('getSystemValue') - ->with('proxyexclude', []) - ->willReturn([]); + ->withConsecutive( + ['proxy', ''], + ['proxyuserpwd', ''], + ['proxyexclude', []], + ['installed', false], + ) + ->willReturnOnConsecutiveCalls( + 'foo', + '', + [], + true, + ); $this->certificateManager ->expects($this->once()) ->method('getAbsoluteBundlePath') @@ -547,20 +549,20 @@ class ClientTest extends \Test\TestCase { public function testSetDefaultOptionsWithProxyAndExclude(): void { $this->config - ->expects($this->at(0)) + ->expects($this->exactly(4)) ->method('getSystemValue') - ->with('proxy', null) - ->willReturn('foo'); - $this->config - ->expects($this->at(1)) - ->method('getSystemValue') - ->with('proxyuserpwd', null) - ->willReturn(null); - $this->config - ->expects($this->at(2)) - ->method('getSystemValue') - ->with('proxyexclude', []) - ->willReturn(['bar']); + ->withConsecutive( + ['proxy', ''], + ['proxyuserpwd', ''], + ['proxyexclude', []], + ['installed', false], + ) + ->willReturnOnConsecutiveCalls( + 'foo', + '', + ['bar'], + true, + ); $this->certificateManager ->expects($this->once()) ->method('getAbsoluteBundlePath') diff --git a/tests/lib/Http/Client/LocalAddressCheckerTest.php b/tests/lib/Http/Client/LocalAddressCheckerTest.php index 0bba1cee5f4..9f2f6c72993 100644 --- a/tests/lib/Http/Client/LocalAddressCheckerTest.php +++ b/tests/lib/Http/Client/LocalAddressCheckerTest.php @@ -96,6 +96,8 @@ class LocalAddressCheckerTest extends \Test\TestCase { ['10.0.0.1'], ['::'], ['::1'], + ['100.100.100.200'], + ['192.0.0.1'], ]; } @@ -116,6 +118,9 @@ class LocalAddressCheckerTest extends \Test\TestCase { ['another-host.local'], ['service.localhost'], ['!@#$'], // test invalid url + ['100.100.100.200'], + ['192.0.0.1'], + ['randomdomain.internal'], ]; } diff --git a/tests/lib/InstallerTest.php b/tests/lib/InstallerTest.php index c49f8bf76a5..352580337ad 100644 --- a/tests/lib/InstallerTest.php +++ b/tests/lib/InstallerTest.php @@ -340,7 +340,7 @@ u/spPSSVhaun5BA1FlphB2TkgnzlCmxJa63nFY045e/Jq+IKMcqqZl/092gbI2EQ $realTmpFile = \OC::$server->getTempManager()->getTemporaryFile('.tar.gz'); copy(__DIR__ . '/../data/testapp.tar.gz', $realTmpFile); $this->tempManager - ->expects($this->at(0)) + ->expects($this->once()) ->method('getTemporaryFile') ->with('.tar.gz') ->willReturn($realTmpFile); @@ -418,14 +418,14 @@ YwDVP+QmNRzx72jtqAN/Kc3CvQ9nkgYhU65B95aX0xA=', $realTmpFile = \OC::$server->getTempManager()->getTemporaryFile('.tar.gz'); copy(__DIR__ . '/../data/testapp1.tar.gz', $realTmpFile); $this->tempManager - ->expects($this->at(0)) + ->expects($this->once()) ->method('getTemporaryFile') ->with('.tar.gz') ->willReturn($realTmpFile); $realTmpFolder = \OC::$server->getTempManager()->getTemporaryFolder(); mkdir($realTmpFolder . '/testfolder'); $this->tempManager - ->expects($this->at(1)) + ->expects($this->once()) ->method('getTemporaryFolder') ->willReturn($realTmpFolder); $client = $this->createMock(IClient::class); @@ -502,13 +502,13 @@ YwDVP+QmNRzx72jtqAN/Kc3CvQ9nkgYhU65B95aX0xA=', $realTmpFile = \OC::$server->getTempManager()->getTemporaryFile('.tar.gz'); copy(__DIR__ . '/../data/testapp1.tar.gz', $realTmpFile); $this->tempManager - ->expects($this->at(0)) + ->expects($this->once()) ->method('getTemporaryFile') ->with('.tar.gz') ->willReturn($realTmpFile); $realTmpFolder = \OC::$server->getTempManager()->getTemporaryFolder(); $this->tempManager - ->expects($this->at(1)) + ->expects($this->once()) ->method('getTemporaryFolder') ->willReturn($realTmpFolder); $client = $this->createMock(IClient::class); @@ -575,30 +575,30 @@ MPLX6f5V9tCJtlH6ztmEcDROfvuVc0U3rEhqx2hphoyo+MZrPFpdcJL8KkIdMKbY ], ]; $this->appFetcher - ->expects($this->at(0)) + ->expects($this->atLeastOnce()) ->method('get') - ->willReturn($appArray); + ->willReturnOnConsecutiveCalls($appArray); $realTmpFile = \OC::$server->getTempManager()->getTemporaryFile('.tar.gz'); copy(__DIR__ . '/../data/testapp.tar.gz', $realTmpFile); $this->tempManager - ->expects($this->at(0)) + ->expects($this->atLeastOnce()) ->method('getTemporaryFile') ->with('.tar.gz') - ->willReturn($realTmpFile); + ->willReturnOnConsecutiveCalls($realTmpFile); $realTmpFolder = \OC::$server->getTempManager()->getTemporaryFolder(); $this->tempManager - ->expects($this->at(1)) + ->expects($this->atLeastOnce()) ->method('getTemporaryFolder') - ->willReturn($realTmpFolder); + ->willReturnOnConsecutiveCalls($realTmpFolder); $client = $this->createMock(IClient::class); $client ->expects($this->once()) ->method('get') ->with('https://example.com', ['sink' => $realTmpFile, 'timeout' => 120]); $this->clientService - ->expects($this->at(0)) + ->expects($this->atLeastOnce()) ->method('newClient') - ->willReturn($client); + ->willReturnOnConsecutiveCalls($client); $installer = $this->getInstaller(); $installer->downloadApp('testapp'); diff --git a/tests/lib/IntegrityCheck/CheckerTest.php b/tests/lib/IntegrityCheck/CheckerTest.php index 6f0c8e8ae85..37f6885c0ac 100644 --- a/tests/lib/IntegrityCheck/CheckerTest.php +++ b/tests/lib/IntegrityCheck/CheckerTest.php @@ -21,6 +21,7 @@ namespace Test\IntegrityCheck; +use OC\Core\Command\Maintenance\Mimetype\GenerateMimetypeFileBuilder; use OC\IntegrityCheck\Checker; use OC\IntegrityCheck\Helpers\AppLocator; use OC\IntegrityCheck\Helpers\EnvironmentHelper; @@ -87,12 +88,12 @@ class CheckerTest extends TestCase { $this->expectExceptionMessage('Exception message'); $this->fileAccessHelper - ->expects($this->at(0)) + ->expects($this->once()) ->method('assertDirectoryExists') ->with('NotExistingApp/appinfo') ->willThrowException(new \Exception('Exception message')); $this->fileAccessHelper - ->expects($this->at(1)) + ->expects($this->once()) ->method('is_writable') ->with('NotExistingApp/appinfo') ->willReturn(true); @@ -201,19 +202,16 @@ class CheckerTest extends TestCase { "certificate": "-----BEGIN CERTIFICATE-----\r\nMIIEvjCCAqagAwIBAgIUc\/0FxYrsgSs9rDxp03EJmbjN0NwwDQYJKoZIhvcNAQEF\r\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTEw\r\nMzIxMDMzM1oXDTE2MTEwMzIxMDMzM1owDzENMAsGA1UEAwwEY29yZTCCAiIwDQYJ\r\nKoZIhvcNAQEBBQADggIPADCCAgoCggIBALb6EgHpkAqZbO5vRO8XSh7G7XGWHw5s\r\niOf4RwPXR6SE9bWZEm\/b72SfWk\/\/J6Ab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5UUEo4Wg2STQiiX\r\nuVSRQxK1LE1yg84bs3NZk9FSQh4B8vZVuRr5FaJsZZkwlFlhRO\/\/+TJtXRbyNgsf\r\noMRZGi8DLGU2SGEAHcRH\/QZHq\/XDUWVzdxrSBYcy7GSpT7UDVzGv1rEJUrn5veP1\r\n0KmauAqtiIaYRm4f6YBsn0INcZxzIPZ0p8qFtVZBPeHhvQtvOt0iXI\/XUxEWOa2F\r\nK2EqhErgMK\/N07U1JJJay5tYZRtvkGq46oP\/5kQG8hYST0MDK6VihJoPpvCmAm4E\r\npEYKQ96x6A4EH9Y9mZlYozH\/eqmxPbTK8n89\/p7Ydun4rI+B2iiLnY8REWWy6+UQ\r\nV204fGUkJqW5CrKy3P3XvY9X\r\n-----END CERTIFICATE-----" }'; $this->fileAccessHelper - ->expects($this->at(0)) - ->method('file_get_contents') - ->with( - \OC::$SERVERROOT . '/tests/data/integritycheck/app//appinfo/signature.json' - ) - ->willReturn($signatureDataFile); - $this->fileAccessHelper - ->expects($this->at(1)) - ->method('file_get_contents') - ->with( - '/resources/codesigning/root.crt' - ) - ->willReturn(file_get_contents(__DIR__ .'/../../data/integritycheck/root.crt')); + ->expects($this->exactly(2)) + ->method('file_get_contents') + ->withConsecutive( + [\OC::$SERVERROOT . '/tests/data/integritycheck/app//appinfo/signature.json'], + ['/resources/codesigning/root.crt'], + ) + ->willReturnOnConsecutiveCalls( + $signatureDataFile, + file_get_contents(__DIR__ .'/../../data/integritycheck/root.crt') + ); $this->assertSame([], $this->checker->verifyAppSignature('SomeApp')); } @@ -243,19 +241,16 @@ class CheckerTest extends TestCase { "certificate": "-----BEGIN CERTIFICATE-----\r\nMIIEwTCCAqmgAwIBAgIUWv0iujufs5lUr0svCf\/qTQvoyKAwDQYJKoZIhvcNAQEF\r\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTEw\r\nMzIyNDk1M1oXDTE2MTEwMzIyNDk1M1owEjEQMA4GA1U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h1bIG0CVvFBE58esGzjEYLhOydgKFnEP94kVPgJD5ds9C3\r\npPhEpo1dRpiXaF7WGIV1X6DI\/ipWvfrF7CEy6I\/kP1InY\/vMDjQjeDnJ\/VrXIWXO\r\nyZvHXVaN\/m+1RlETsH7YO\/QmxRue9ZHN3gvvWtmpCeA95sfpepOk7UcHxHZYyQbF\r\n49\/au8j+5tsr4A83xzsT1JbcKRxkAaQ7WDJpOnE5O1+H0fB+BaLakTg6XX9d4Fo7\r\n7Gin7hVWX7pL+JIyxMzME3LhfI61+CRcqZQIrpyaafUziPQbWIPfEs7h8tCOWyvW\r\nUO8ZLervYCB3j44ivkrxPlcBklDCqqKKBzDP9dYOtS\/P4RB1NkHA9+NTvmBpTonS\r\nSFXdg9fFMD7VfjDE3Vnk+8DWkVH5wBYowTAD7w9Wuzr7DumiAULexnP\/Y7xwxLv7\r\n4B+pXTAcRK0zECDEaX3npS8xWzrB\r\n-----END CERTIFICATE-----" }'; $this->fileAccessHelper - ->expects($this->at(0)) - ->method('file_get_contents') - ->with( - \OC::$SERVERROOT . '/tests/data/integritycheck/app//appinfo/signature.json' - ) - ->willReturn($signatureDataFile); - $this->fileAccessHelper - ->expects($this->at(1)) - ->method('file_get_contents') - ->with( - '/resources/codesigning/root.crt' - ) - ->willReturn(file_get_contents(__DIR__ .'/../../data/integritycheck/root.crt')); + ->expects($this->exactly(2)) + ->method('file_get_contents') + ->withConsecutive( + [\OC::$SERVERROOT . '/tests/data/integritycheck/app//appinfo/signature.json'], + ['/resources/codesigning/root.crt'], + ) + ->willReturnOnConsecutiveCalls( + $signatureDataFile, + file_get_contents(__DIR__ .'/../../data/integritycheck/root.crt') + ); $expected = [ 'EXCEPTION' => [ @@ -291,19 +286,16 @@ class CheckerTest extends TestCase { "certificate": "-----BEGIN CERTIFICATE-----\r\nMIIEvjCCAqagAwIBAgIUc\/0FxYrsgSs9rDxp03EJmbjN0NwwDQYJKoZIhvcNAQEF\r\nBQAwIzEhMB8GA1UECgwYb3duQ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X2ZrKFWmcgZFDUSRd\r\n9Uj26vtUhCC4bU4jgu6hIrR9IuxOBLQUxGTRZyAcXvj7obqRAEZwFAKQgFpfpqTb\r\nH+kjcbZSaAlLVSF7vBc1syyI8RGYbqpwvtREqJtl5IEIwe6huEqJ3zPnlP2th\/55\r\ncf3Fovj6JJgbb9XFxrdnsOsDOu\/tpnaRWlvv5ib4+SzG5wWFT5UUEo4Wg2STQiiX\r\nuVSRQxK1LE1yg84bs3NZk9FSQh4B8vZVuRr5FaJsZZkwlFlhRO\/\/+TJtXRbyNgsf\r\noMRZGi8DLGU2SGEAHcRH\/QZHq\/XDUWVzdxrSBYcy7GSpT7UDVzGv1rEJUrn5veP1\r\n0KmauAqtiIaYRm4f6YBsn0INcZxzIPZ0p8qFtVZBPeHhvQtvOt0iXI\/XUxEWOa2F\r\nK2EqhErgMK\/N07U1JJJay5tYZRtvkGq46oP\/5kQG8hYST0MDK6VihJoPpvCmAm4E\r\npEYKQ96x6A4EH9Y9mZlYozH\/eqmxPbTK8n89\/p7Ydun4rI+B2iiLnY8REWWy6+UQ\r\nV204fGUkJqW5CrKy3P3XvY9X\r\n-----END CERTIFICATE-----" }'; $this->fileAccessHelper - ->expects($this->at(0)) - ->method('file_get_contents') - ->with( - \OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//appinfo/signature.json' - ) - ->willReturn($signatureDataFile); - $this->fileAccessHelper - ->expects($this->at(1)) - ->method('file_get_contents') - ->with( - '/resources/codesigning/root.crt' - ) - ->willReturn(file_get_contents(__DIR__ .'/../../data/integritycheck/root.crt')); + ->expects($this->exactly(2)) + ->method('file_get_contents') + ->withConsecutive( + [\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//appinfo/signature.json'], + ['/resources/codesigning/root.crt'], + ) + ->willReturnOnConsecutiveCalls( + $signatureDataFile, + file_get_contents(__DIR__ .'/../../data/integritycheck/root.crt') + ); $expected = [ @@ -354,19 +346,16 @@ class CheckerTest extends TestCase { "certificate": "-----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rIqZ3iiQTUBQGTKBsTnAqE1H7QgUSV9vSd+8rgvHkyZsRjmtyR1e3A6Ji\r\noNCXUbExC\/0iCPUqdHZIVb+Lc\/vWuv4ByFMybGPydgtLoEUX2ZrKFWmcgZFDUSRd\r\n9Uj26vtUhCC4bU4jgu6hIrR9IuxOBLQUxGTRZyAcXvj7obqRAEZwFAKQgFpfpqTb\r\nH+kjcbZSaAlLVSF7vBc1syyI8RGYbqpwvtREqJtl5IEIwe6huEqJ3zPnlP2th\/55\r\ncf3Fovj6JJgbb9XFxrdnsOsDOu\/tpnaRWlvv5ib4+SzG5wWFT5UUEo4Wg2STQiiX\r\nuVSRQxK1LE1yg84bs3NZk9FSQh4B8vZVuRr5FaJsZZkwlFlhRO\/\/+TJtXRbyNgsf\r\noMRZGi8DLGU2SGEAHcRH\/QZHq\/XDUWVzdxrSBYcy7GSpT7UDVzGv1rEJUrn5veP1\r\n0KmauAqtiIaYRm4f6YBsn0INcZxzIPZ0p8qFtVZBPeHhvQtvOt0iXI\/XUxEWOa2F\r\nK2EqhErgMK\/N07U1JJJay5tYZRtvkGq46oP\/5kQG8hYST0MDK6VihJoPpvCmAm4E\r\npEYKQ96x6A4EH9Y9mZlYozH\/eqmxPbTK8n89\/p7Ydun4rI+B2iiLnY8REWWy6+UQ\r\nV204fGUkJqW5CrKy3P3XvY9X\r\n-----END CERTIFICATE-----" }'; $this->fileAccessHelper - ->expects($this->at(0)) - ->method('file_get_contents') - ->with( - \OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//appinfo/signature.json' - ) - ->willReturn($signatureDataFile); - $this->fileAccessHelper - ->expects($this->at(1)) - ->method('file_get_contents') - ->with( - '/resources/codesigning/root.crt' - ) - ->willReturn(file_get_contents(__DIR__ .'/../../data/integritycheck/root.crt')); + ->expects($this->exactly(2)) + ->method('file_get_contents') + ->withConsecutive( + [\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//appinfo/signature.json'], + ['/resources/codesigning/root.crt'], + ) + ->willReturnOnConsecutiveCalls( + $signatureDataFile, + file_get_contents(__DIR__ .'/../../data/integritycheck/root.crt') + ); $expected = [ @@ -418,17 +407,15 @@ class CheckerTest extends TestCase { "certificate": "-----BEGIN CERTIFICATE-----\r\nMIIExjCCAq6gAwIBAgIUHSJjhJqMwr+3TkoiQFg4SVVYQ1gwDQYJKoZIhvcNAQEF\r\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTEw\r\nMzIzMjc1NVoXDTE2MTEwMzIzMjc1NVowFzEVMBMGA1UEAwwMQW5vdGhlclNjb3Bl\r\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA33npb5RmUkXrDT+TbwMf\r\n0zQ33SlzsjoGxCrbSwJOn6leGGInJ6ZrdzLL0WTi\/dTpg+Y\/JS+72XWm5NSjaTxo\r\n7OHc3cQBwXQj4tN6j\/y5qqY0GDLYufEkx2rpazqt9lBSJ72u1bGl2yoOXzYCz5i0\r\n60KsJXC9K44LKzGsarzbwAgskSVNkjAsPgjnCWZmcl6icpLi5Fz9rs2UMOWbdvdI\r\nAROsn0eC9E\/akmXTy5YMu6bAIGpvjZFHzyA83FQRbvv5o1V5Gsye\/VQLEgh7rqfz\r\nT\/jgWifP+JgoeB6otzuRZ3fFsmbBiyCIRtIOzQQflozhUlWtmiEGwg4GySuMUjEH\r\nA1LF86LO+ZzDQgd2oYNKmrQ8O+EcLqx9BpV4AFhEvqdk7uycJYPHs6yl+yfbzTeJ\r\n2Xd0yVAfd9r\/iDr36clLj2bzEObdl9xzKjcCIXE4Q0G4Pur41\/BJUDK9PI390ccQ\r\nnFjjVYBMsC859OwW64tMP0zkM9Vv72LCaEzaR8jqH0j11catqxunr+StfMcmxLTN\r\nbqBJbSEq4ER3mJxCTI2UrIVmdQ7+wRxgv3QTDNOZyqrz2L8A1Rpb3h0APxtQv+oA\r\n8KIZYID5\/qsS2V2jITkMQ8Nd1W3b0cZhZ600z+znh3jLJ0TYLvwN6\/qBQTUDaM2o\r\ng1+icMqXIXIeKuoPCVVsG7cCAwEAATANBgkqhkiG9w0BAQUFAAOCAgEAHc4F\/kOV\r\nHc8In5MmGg2YtjwZzjdeoC5TIPZczRqz0B+wRbJzN6aYryKZKLmP+wKpgRnJWDzp\r\nrgKGyyEQIAfK63DEv4B9p4N1B+B3aeMKsSpVcw7wbFTD57V5A7pURGoo31d0mw5L\r\nUIXZ2u+TUfGbzucMxLdFhTwjGpz9M6Kkm\/POxmV0tvLija5LdbdKnYR9BFmyu4IX\r\nqyoIAtComATNLl+3URu3SZxhE3NxhzMz+eAeNfh1KuIf2gWIIeDCXalVSJLym+OQ\r\nHFDpqRhJqfTMprrRlmmU7Zntgbj8\/RRZuXnBvH9cQ2KykLOb4UoCPlGUqOqKyP9m\r\nDJSFRiMJfpgMQUaJk1TLhKF+IR6FnmwURLEtkONJumtDQju9KaWPlhueONdyGi0p\r\nqxLVUo1Vb52XnPhk2GEEduxpDc9V5ePJ+pdcEdMifY\/uPNBRuBj2c87yq1DLH+U4\r\n3XzP1MlwjnBWZYuoFo0j6Jq0r\/MG6HjGdmkGIsRoheRi8Z8Scz5AW5QRkNz8pKop\r\nTELFqQy9g6TyQzzC8t6HZcpNe842ZUk4raEAbCZe\/XqxWMw5svPgNceBqM3fh7sZ\r\nBSykOHLaL8kiRO\/IS3y1yZEAuiWBvtxcTNLzBb+hdRpm2y8\/qH\/pKo+CMj1VzjNT\r\nD8YRQg0cjmDytJzHDrtV\/aTc9W1aPHun0vw=\r\n-----END CERTIFICATE-----" }'; $this->fileAccessHelper - ->expects($this->at(0)) - ->method('file_get_contents') - ->with(\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//appinfo/signature.json') - ->willReturn($signatureDataFile); - $this->fileAccessHelper - ->expects($this->at(1)) - ->method('file_get_contents') - ->with( - '/resources/codesigning/root.crt' - ) - ->willReturn(file_get_contents(__DIR__ .'/../../data/integritycheck/root.crt')); + ->expects($this->exactly(2)) + ->method('file_get_contents') + ->withConsecutive( + [\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//appinfo/signature.json'], + ['/resources/codesigning/root.crt'], + )->willReturnOnConsecutiveCalls( + $signatureDataFile, + file_get_contents(__DIR__ .'/../../data/integritycheck/root.crt') + ); $expected = [ 'EXCEPTION' => [ @@ -464,17 +451,15 @@ class CheckerTest extends TestCase { "certificate": "-----BEGIN CERTIFICATE-----\r\nMIIEvjCCAqagAwIBAgIUc\/0FxYrsgSs9rDxp03EJmbjN0NwwDQYJKoZIhvcNAQEF\r\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTEw\r\nMzIxMDMzM1oXDTE2MTEwMzIxMDMzM1owDzENMAsGA1UEAwwEY29yZTCCAiIwDQYJ\r\nKoZIhvcNAQEBBQADggIPADCCAgoCggIBALb6EgHpkAqZbO5vRO8XSh7G7XGWHw5s\r\niOf4RwPXR6SE9bWZEm\/b72SfWk\/\/J6AbrD8WiOzBuT\/ODy6k5T1arEdHO+Pux0W1\r\nMxYJJI4kH74KKgMpC0SB0Rt+8WrMqV1r3hhJ46df6Xr\/xolP3oD+eLbShPcblhdS\r\nVtkZEkoev8Sh6L2wDCeHDyPxzvj1w2dTdGVO9Kztn0xIlyfEBakqvBWtcxyi3Ln0\r\nklnxlMx3tPDUE4kqvpia9qNiB1AN2PV93eNr5\/2riAzIssMFSCarWCx0AKYb54+d\r\nxLpcYFyqPJ0ydBCkF78DD45RCZet6PNYkdzgbqlUWEGGomkuDoJbBg4wzgzO0D77\r\nH87KFhYW8tKFFvF1V3AHl\/sFQ9tDHaxM9Y0pZ2jPp\/ccdiqnmdkBxBDqsiRvHvVB\r\nCn6qpb4vWGFC7vHOBfYspmEL1zLlKXZv3ezMZEZw7O9ZvUP3VO\/wAtd2vUW8UFiq\r\ns2v1QnNLN6jNh51obcwmrBvWhJy9vQIdtIjQbDxqWTHh1zUSrw9wrlklCBZ\/zrM0\r\ni8nfCFwTxWRxp3H9KoECzO\/zS5R5KIS7s3\/wq\/w9T2Ie4rcecgXwDizwnn0C\/aKc\r\nbDIjujpL1s9HO05pcD\/V3wKcPZ1izymBkmMyIbL52iRVN5FTVHeZdXPpFuq+CTQJ\r\nQ238lC+A\/KOVAgMBAAEwDQYJKoZIhvcNAQEFBQADggIBAGoKTnh8RfJV4sQItVC2\r\nAvfJagkrIqZ3iiQTUBQGTKBsTnAqE1H7QgUSV9vSd+8rgvHkyZsRjmtyR1e3A6Ji\r\noNCXUbExC\/0iCPUqdHZIVb+Lc\/vWuv4ByFMybGPydgtLoEUX2ZrKFWmcgZFDUSRd\r\n9Uj26vtUhCC4bU4jgu6hIrR9IuxOBLQUxGTRZyAcXvj7obqRAEZwFAKQgFpfpqTb\r\nH+kjcbZSaAlLVSF7vBc1syyI8RGYbqpwvtREqJtl5IEIwe6huEqJ3zPnlP2th\/55\r\ncf3Fovj6JJgbb9XFxrdnsOsDOu\/tpnaRWlvv5ib4+SzG5wWFT5UUEo4Wg2STQiiX\r\nuVSRQxK1LE1yg84bs3NZk9FSQh4B8vZVuRr5FaJsZZkwlFlhRO\/\/+TJtXRbyNgsf\r\noMRZGi8DLGU2SGEAHcRH\/QZHq\/XDUWVzdxrSBYcy7GSpT7UDVzGv1rEJUrn5veP1\r\n0KmauAqtiIaYRm4f6YBsn0INcZxzIPZ0p8qFtVZBPeHhvQtvOt0iXI\/XUxEWOa2F\r\nK2EqhErgMK\/N07U1JJJay5tYZRtvkGq46oP\/5kQG8hYST0MDK6VihJoPpvCmAm4E\r\npEYKQ96x6A4EH9Y9mZlYozH\/eqmxPbTK8n89\/p7Ydun4rI+B2iiLnY8REWWy6+UQ\r\nV204fGUkJqW5CrKy3P3XvY9X\r\n-----END CERTIFICATE-----" }'; $this->fileAccessHelper - ->expects($this->at(0)) - ->method('file_get_contents') - ->with(\OC::$SERVERROOT . '/tests/data/integritycheck/app//appinfo/signature.json') - ->willReturn($signatureDataFile); - $this->fileAccessHelper - ->expects($this->at(1)) - ->method('file_get_contents') - ->with( - '/resources/codesigning/root.crt' - ) - ->willReturn(file_get_contents(__DIR__ .'/../../data/integritycheck/root.crt')); + ->expects($this->exactly(2)) + ->method('file_get_contents') + ->withConsecutive( + [\OC::$SERVERROOT . '/tests/data/integritycheck/app//appinfo/signature.json'], + ['/resources/codesigning/root.crt'], + )->willReturnOnConsecutiveCalls( + $signatureDataFile, + file_get_contents(__DIR__ .'/../../data/integritycheck/root.crt') + ); $this->assertSame([], $this->checker->verifyAppSignature('SomeApp')); } @@ -485,11 +470,11 @@ class CheckerTest extends TestCase { $this->expectExceptionMessage('Exception message'); $this->fileAccessHelper - ->expects($this->at(0)) + ->expects($this->once()) ->method('assertDirectoryExists') ->will($this->throwException(new \Exception('Exception message'))); $this->fileAccessHelper - ->expects($this->at(1)) + ->expects($this->once()) ->method('is_writable') ->with(__DIR__ . '/core') ->willReturn(true); @@ -509,11 +494,11 @@ class CheckerTest extends TestCase { $this->expectExceptionMessageMatches('/[a-zA-Z\\/_-]+ is not writable/'); $this->fileAccessHelper - ->expects($this->at(0)) + ->expects($this->once()) ->method('assertDirectoryExists') ->will($this->throwException(new \Exception('Exception message'))); $this->fileAccessHelper - ->expects($this->at(1)) + ->expects($this->once()) ->method('is_writable') ->with(__DIR__ . '/core') ->willReturn(false); @@ -706,19 +691,15 @@ class CheckerTest extends TestCase { "certificate": "-----BEGIN CERTIFICATE-----\r\nMIIEvjCCAqagAwIBAgIUc\/0FxYrsgSs9rDxp03EJmbjN0NwwDQYJKoZIhvcNAQEF\r\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTEw\r\nMzIxMDMzM1oXDTE2MTEwMzIxMDMzM1owDzENMAsGA1UEAwwEY29yZTCCAiIwDQYJ\r\nKoZIhvcNAQEBBQADggIPADCCAgoCggIBALb6EgHpkAqZbO5vRO8XSh7G7XGWHw5s\r\niOf4RwPXR6SE9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pnaRWlvv5ib4+SzG5wWFT5UUEo4Wg2STQiiX\r\nuVSRQxK1LE1yg84bs3NZk9FSQh4B8vZVuRr5FaJsZZkwlFlhRO\/\/+TJtXRbyNgsf\r\noMRZGi8DLGU2SGEAHcRH\/QZHq\/XDUWVzdxrSBYcy7GSpT7UDVzGv1rEJUrn5veP1\r\n0KmauAqtiIaYRm4f6YBsn0INcZxzIPZ0p8qFtVZBPeHhvQtvOt0iXI\/XUxEWOa2F\r\nK2EqhErgMK\/N07U1JJJay5tYZRtvkGq46oP\/5kQG8hYST0MDK6VihJoPpvCmAm4E\r\npEYKQ96x6A4EH9Y9mZlYozH\/eqmxPbTK8n89\/p7Ydun4rI+B2iiLnY8REWWy6+UQ\r\nV204fGUkJqW5CrKy3P3XvY9X\r\n-----END CERTIFICATE-----" }'; $this->fileAccessHelper - ->expects($this->at(0)) - ->method('file_get_contents') - ->with( - \OC::$SERVERROOT . '/tests/data/integritycheck/app//core/signature.json' - ) - ->willReturn($signatureDataFile); - $this->fileAccessHelper - ->expects($this->at(1)) - ->method('file_get_contents') - ->with( - \OC::$SERVERROOT . '/tests/data/integritycheck/app//resources/codesigning/root.crt' - ) - ->willReturn(file_get_contents(__DIR__ .'/../../data/integritycheck/root.crt')); + ->expects($this->exactly(2)) + ->method('file_get_contents') + ->withConsecutive( + [\OC::$SERVERROOT . '/tests/data/integritycheck/app//core/signature.json'], + [\OC::$SERVERROOT . '/tests/data/integritycheck/app//resources/codesigning/root.crt'], + )->willReturnOnConsecutiveCalls( + $signatureDataFile, + file_get_contents(__DIR__ .'/../../data/integritycheck/root.crt') + ); $this->assertSame([], $this->checker->verifyCoreSignature()); } @@ -747,24 +728,46 @@ class CheckerTest extends TestCase { "certificate": "-----BEGIN CERTIFICATE-----\r\nMIIEvjCCAqagAwIBAgIUc\/0FxYrsgSs9rDxp03EJmbjN0NwwDQYJKoZIhvcNAQEF\r\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nI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uj26vtUhCC4bU4jgu6hIrR9IuxOBLQUxGTRZyAcXvj7obqRAEZwFAKQgFpfpqTb\r\nH+kjcbZSaAlLVSF7vBc1syyI8RGYbqpwvtREqJtl5IEIwe6huEqJ3zPnlP2th\/55\r\ncf3Fovj6JJgbb9XFxrdnsOsDOu\/tpnaRWlvv5ib4+SzG5wWFT5UUEo4Wg2STQiiX\r\nuVSRQxK1LE1yg84bs3NZk9FSQh4B8vZVuRr5FaJsZZkwlFlhRO\/\/+TJtXRbyNgsf\r\noMRZGi8DLGU2SGEAHcRH\/QZHq\/XDUWVzdxrSBYcy7GSpT7UDVzGv1rEJUrn5veP1\r\n0KmauAqtiIaYRm4f6YBsn0INcZxzIPZ0p8qFtVZBPeHhvQtvOt0iXI\/XUxEWOa2F\r\nK2EqhErgMK\/N07U1JJJay5tYZRtvkGq46oP\/5kQG8hYST0MDK6VihJoPpvCmAm4E\r\npEYKQ96x6A4EH9Y9mZlYozH\/eqmxPbTK8n89\/p7Ydun4rI+B2iiLnY8REWWy6+UQ\r\nV204fGUkJqW5CrKy3P3XvY9X\r\n-----END CERTIFICATE-----" }'; $this->fileAccessHelper - ->expects($this->at(0)) - ->method('file_get_contents') - ->with( - \OC::$SERVERROOT . '/tests/data/integritycheck/htaccessWithValidModifiedContent/core/signature.json' - ) - ->willReturn($signatureDataFile); - $this->fileAccessHelper - ->expects($this->at(1)) + ->expects($this->exactly(2)) ->method('file_get_contents') - ->with( - \OC::$SERVERROOT . '/tests/data/integritycheck/htaccessWithValidModifiedContent/resources/codesigning/root.crt' + ->withConsecutive( + [\OC::$SERVERROOT . '/tests/data/integritycheck/htaccessWithValidModifiedContent/core/signature.json'], + [\OC::$SERVERROOT . '/tests/data/integritycheck/htaccessWithValidModifiedContent/resources/codesigning/root.crt'], ) - ->willReturn(file_get_contents(__DIR__ .'/../../data/integritycheck/root.crt')); + ->willReturnOnConsecutiveCalls( + $signatureDataFile, + file_get_contents(__DIR__ .'/../../data/integritycheck/root.crt') + ); $this->assertSame([], $this->checker->verifyCoreSignature()); } + /** + * See inline instruction on how to update the test assets when changing mimetypealiases.dist.json + */ public function testVerifyCoreSignatureWithModifiedMimetypelistSignatureData() { + $shippedMimetypeAliases = (array)json_decode(file_get_contents(\OC::$SERVERROOT . '/resources/config/mimetypealiases.dist.json')); + $allAliases = array_merge($shippedMimetypeAliases, ['my-custom/mimetype' => 'custom']); + + $this->mimeTypeDetector + ->method('getOnlyDefaultAliases') + ->willReturn($shippedMimetypeAliases); + + $this->mimeTypeDetector + ->method('getAllAliases') + ->willReturn($allAliases); + + $oldMimetypeList = new GenerateMimetypeFileBuilder(); + $all = $this->mimeTypeDetector->getAllAliases(); + $newFile = $oldMimetypeList->generateFile($all); + + // When updating the mimetype list the test assets need to be updated as well + // 1. Update core/js/mimetypelist.js with the new generated js by running the test with the next line uncommented: + // file_put_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/mimetypeListModified/core/js/mimetypelist.js', $newFile); + // 2. Update signature.json using the following occ command: + // occ integrity:sign-core --privateKey=./tests/data/integritycheck/core.key --certificate=./tests/data/integritycheck/core.crt --path=./tests/data/integritycheck/mimetypeListModified + self::assertEquals($newFile, file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/mimetypeListModified/core/js/mimetypelist.js')); + $this->environmentHelper ->expects($this->once()) ->method('getChannel') @@ -775,264 +778,18 @@ class CheckerTest extends TestCase { ->with('integrity.check.disabled', false) ->willReturn(false); - $this->mimeTypeDetector - ->expects($this->once()) - ->method('getOnlyDefaultAliases') - ->willReturn( - [ - '_comment' => 'Array of mimetype aliases.', - '_comment2' => 'Any changes you make here will be overwritten on an update of Nextcloud.', - '_comment3' => 'Put any custom mappings in a new file mimetypealiases.json in the config/ folder of Nextcloud', - '_comment4' => 'After any change to mimetypealiases.json run:', - '_comment5' => './occ maintenance:mimetype:update-js', - '_comment6' => 'Otherwise your update won\'t propagate through the system.', - 'application/coreldraw' => 'image', - 'application/epub+zip' => 'text', - 'application/font-sfnt' => 'image', - 'application/font-woff' => 'image', - 'application/gpx+xml' => 'location', - 'application/illustrator' => 'image', - 'application/javascript' => 'text/code', - 'application/json' => 'text/code', - 'application/msaccess' => 'file', - 'application/msexcel' => 'x-office/spreadsheet', - 'application/msonenote' => 'x-office/document', - 'application/mspowerpoint' => 'x-office/presentation', - 'application/msword' => 'x-office/document', - 'application/octet-stream' => 'file', - 'application/postscript' => 'image', - 'application/rss+xml' => 'application/xml', - 'application/vnd.android.package-archive' => 'package/x-generic', - 'application/vnd.lotus-wordpro' => 'x-office/document', - 'application/vnd.garmin.tcx+xml' => 'location', - 'application/vnd.google-earth.kml+xml' => 'location', - 'application/vnd.google-earth.kmz' => 'location', - 'application/vnd.ms-excel' => 'x-office/spreadsheet', - 'application/vnd.ms-excel.addin.macroEnabled.12' => 'x-office/spreadsheet', - 'application/vnd.ms-excel.sheet.binary.macroEnabled.12' => 'x-office/spreadsheet', - 'application/vnd.ms-excel.sheet.macroEnabled.12' => 'x-office/spreadsheet', - 'application/vnd.ms-excel.template.macroEnabled.12' => 'x-office/spreadsheet', - 'application/vnd.ms-fontobject' => 'image', - 'application/vnd.ms-powerpoint' => 'x-office/presentation', - 'application/vnd.ms-powerpoint.addin.macroEnabled.12' => 'x-office/presentation', - 'application/vnd.ms-powerpoint.presentation.macroEnabled.12' => 'x-office/presentation', - 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12' => 'x-office/presentation', - 'application/vnd.ms-powerpoint.template.macroEnabled.12' => 'x-office/presentation', - 'application/vnd.ms-visio.drawing.macroEnabled.12' => 'application/vnd.visio', - 'application/vnd.ms-visio.drawing' => 'application/vnd.visio', - 'application/vnd.ms-visio.stencil.macroEnabled.12' => 'application/vnd.visio', - 'application/vnd.ms-visio.stencil' => 'application/vnd.visio', - 'application/vnd.ms-visio.template.macroEnabled.12' => 'application/vnd.visio', - 'application/vnd.ms-visio.template' => 'application/vnd.visio', - 'application/vnd.ms-word.document.macroEnabled.12' => 'x-office/document', - 'application/vnd.ms-word.template.macroEnabled.12' => 'x-office/document', - 'application/vnd.oasis.opendocument.presentation' => 'x-office/presentation', - 'application/vnd.oasis.opendocument.presentation-template' => 'x-office/presentation', - 'application/vnd.oasis.opendocument.spreadsheet' => 'x-office/spreadsheet', - 'application/vnd.oasis.opendocument.spreadsheet-template' => 'x-office/spreadsheet', - 'application/vnd.oasis.opendocument.text' => 'x-office/document', - 'application/vnd.oasis.opendocument.text-master' => 'x-office/document', - 'application/vnd.oasis.opendocument.text-template' => 'x-office/document', - 'application/vnd.oasis.opendocument.graphics' => 'x-office/drawing', - 'application/vnd.oasis.opendocument.graphics-template' => 'x-office/drawing', - 'application/vnd.oasis.opendocument.text-web' => 'x-office/document', - 'application/vnd.oasis.opendocument.text-flat-xml' => 'x-office/document', - 'application/vnd.oasis.opendocument.spreadsheet-flat-xml' => 'x-office/spreadsheet', - 'application/vnd.oasis.opendocument.graphics-flat-xml' => 'x-office/drawing', - 'application/vnd.oasis.opendocument.presentation-flat-xml' => 'x-office/presentation', - 'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'x-office/presentation', - 'application/vnd.openxmlformats-officedocument.presentationml.slideshow' => 'x-office/presentation', - 'application/vnd.openxmlformats-officedocument.presentationml.template' => 'x-office/presentation', - 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'x-office/spreadsheet', - 'application/vnd.openxmlformats-officedocument.spreadsheetml.template' => 'x-office/spreadsheet', - 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'x-office/document', - 'application/vnd.openxmlformats-officedocument.wordprocessingml.template' => 'x-office/document', - 'application/vnd.visio' => 'x-office/document', - 'application/vnd.wordperfect' => 'x-office/document', - 'application/x-7z-compressed' => 'package/x-generic', - 'application/x-bzip2' => 'package/x-generic', - 'application/x-cbr' => 'text', - 'application/x-compressed' => 'package/x-generic', - 'application/x-dcraw' => 'image', - 'application/x-deb' => 'package/x-generic', - 'application/x-fictionbook+xml' => 'text', - 'application/x-font' => 'image', - 'application/x-gimp' => 'image', - 'application/x-gzip' => 'package/x-generic', - 'application/x-iwork-keynote-sffkey' => 'x-office/presentation', - 'application/x-iwork-numbers-sffnumbers' => 'x-office/spreadsheet', - 'application/x-iwork-pages-sffpages' => 'x-office/document', - 'application/x-mobipocket-ebook' => 'text', - 'application/x-perl' => 'text/code', - 'application/x-photoshop' => 'image', - 'application/x-php' => 'text/code', - 'application/x-rar-compressed' => 'package/x-generic', - 'application/x-tar' => 'package/x-generic', - 'application/x-tex' => 'text', - 'application/xml' => 'text/html', - 'application/yaml' => 'text/code', - 'application/zip' => 'package/x-generic', - 'database' => 'file', - 'httpd/unix-directory' => 'dir', - 'text/css' => 'text/code', - 'text/csv' => 'x-office/spreadsheet', - 'text/html' => 'text/code', - 'text/x-c' => 'text/code', - 'text/x-c++src' => 'text/code', - 'text/x-h' => 'text/code', - 'text/x-java-source' => 'text/code', - 'text/x-ldif' => 'text/code', - 'text/x-python' => 'text/code', - 'text/x-shellscript' => 'text/code', - 'web' => 'text/code', - 'application/internet-shortcut' => 'link', - 'application/km' => 'mindmap', - 'application/x-freemind' => 'mindmap', - 'application/vnd.xmind.workbook' => 'mindmap' - ]); - - $this->mimeTypeDetector - ->expects($this->once()) - ->method('getAllAliases') - ->willReturn( - [ - '_comment' => 'Array of mimetype aliases.', - '_comment2' => 'Any changes you make here will be overwritten on an update of Nextcloud.', - '_comment3' => 'Put any custom mappings in a new file mimetypealiases.json in the config/ folder of Nextcloud', - '_comment4' => 'After any change to mimetypealiases.json run:', - '_comment5' => './occ maintenance:mimetype:update-js', - '_comment6' => 'Otherwise your update won\'t propagate through the system.', - 'application/coreldraw' => 'image', - 'application/test' => 'image', - 'application/epub+zip' => 'text', - 'application/font-sfnt' => 'image', - 'application/font-woff' => 'image', - 'application/gpx+xml' => 'location', - 'application/illustrator' => 'image', - 'application/javascript' => 'text/code', - 'application/json' => 'text/code', - 'application/msaccess' => 'file', - 'application/msexcel' => 'x-office/spreadsheet', - 'application/msonenote' => 'x-office/document', - 'application/mspowerpoint' => 'x-office/presentation', - 'application/msword' => 'x-office/document', - 'application/octet-stream' => 'file', - 'application/postscript' => 'image', - 'application/rss+xml' => 'application/xml', - 'application/vnd.android.package-archive' => 'package/x-generic', - 'application/vnd.lotus-wordpro' => 'x-office/document', - 'application/vnd.garmin.tcx+xml' => 'location', - 'application/vnd.google-earth.kml+xml' => 'location', - 'application/vnd.google-earth.kmz' => 'location', - 'application/vnd.ms-excel' => 'x-office/spreadsheet', - 'application/vnd.ms-excel.addin.macroEnabled.12' => 'x-office/spreadsheet', - 'application/vnd.ms-excel.sheet.binary.macroEnabled.12' => 'x-office/spreadsheet', - 'application/vnd.ms-excel.sheet.macroEnabled.12' => 'x-office/spreadsheet', - 'application/vnd.ms-excel.template.macroEnabled.12' => 'x-office/spreadsheet', - 'application/vnd.ms-fontobject' => 'image', - 'application/vnd.ms-powerpoint' => 'x-office/presentation', - 'application/vnd.ms-powerpoint.addin.macroEnabled.12' => 'x-office/presentation', - 'application/vnd.ms-powerpoint.presentation.macroEnabled.12' => 'x-office/presentation', - 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12' => 'x-office/presentation', - 'application/vnd.ms-powerpoint.template.macroEnabled.12' => 'x-office/presentation', - 'application/vnd.ms-visio.drawing.macroEnabled.12' => 'application/vnd.visio', - 'application/vnd.ms-visio.drawing' => 'application/vnd.visio', - 'application/vnd.ms-visio.stencil.macroEnabled.12' => 'application/vnd.visio', - 'application/vnd.ms-visio.stencil' => 'application/vnd.visio', - 'application/vnd.ms-visio.template.macroEnabled.12' => 'application/vnd.visio', - 'application/vnd.ms-visio.template' => 'application/vnd.visio', - 'application/vnd.ms-word.document.macroEnabled.12' => 'x-office/document', - 'application/vnd.ms-word.template.macroEnabled.12' => 'x-office/document', - 'application/vnd.oasis.opendocument.presentation' => 'x-office/presentation', - 'application/vnd.oasis.opendocument.presentation-template' => 'x-office/presentation', - 'application/vnd.oasis.opendocument.spreadsheet' => 'x-office/spreadsheet', - 'application/vnd.oasis.opendocument.spreadsheet-template' => 'x-office/spreadsheet', - 'application/vnd.oasis.opendocument.text' => 'x-office/document', - 'application/vnd.oasis.opendocument.text-master' => 'x-office/document', - 'application/vnd.oasis.opendocument.text-template' => 'x-office/document', - 'application/vnd.oasis.opendocument.graphics' => 'x-office/drawing', - 'application/vnd.oasis.opendocument.graphics-template' => 'x-office/drawing', - 'application/vnd.oasis.opendocument.text-web' => 'x-office/document', - 'application/vnd.oasis.opendocument.text-flat-xml' => 'x-office/document', - 'application/vnd.oasis.opendocument.spreadsheet-flat-xml' => 'x-office/spreadsheet', - 'application/vnd.oasis.opendocument.graphics-flat-xml' => 'x-office/drawing', - 'application/vnd.oasis.opendocument.presentation-flat-xml' => 'x-office/presentation', - 'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'x-office/presentation', - 'application/vnd.openxmlformats-officedocument.presentationml.slideshow' => 'x-office/presentation', - 'application/vnd.openxmlformats-officedocument.presentationml.template' => 'x-office/presentation', - 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'x-office/spreadsheet', - 'application/vnd.openxmlformats-officedocument.spreadsheetml.template' => 'x-office/spreadsheet', - 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'x-office/document', - 'application/vnd.openxmlformats-officedocument.wordprocessingml.template' => 'x-office/document', - 'application/vnd.visio' => 'x-office/document', - 'application/vnd.wordperfect' => 'x-office/document', - 'application/x-7z-compressed' => 'package/x-generic', - 'application/x-bzip2' => 'package/x-generic', - 'application/x-cbr' => 'text', - 'application/x-compressed' => 'package/x-generic', - 'application/x-dcraw' => 'image', - 'application/x-deb' => 'package/x-generic', - 'application/x-fictionbook+xml' => 'text', - 'application/x-font' => 'image', - 'application/x-gimp' => 'image', - 'application/x-gzip' => 'package/x-generic', - 'application/x-iwork-keynote-sffkey' => 'x-office/presentation', - 'application/x-iwork-numbers-sffnumbers' => 'x-office/spreadsheet', - 'application/x-iwork-pages-sffpages' => 'x-office/document', - 'application/x-mobipocket-ebook' => 'text', - 'application/x-perl' => 'text/code', - 'application/x-photoshop' => 'image', - 'application/x-php' => 'text/code', - 'application/x-rar-compressed' => 'package/x-generic', - 'application/x-tar' => 'package/x-generic', - 'application/x-tex' => 'text', - 'application/xml' => 'text/html', - 'application/yaml' => 'text/code', - 'application/zip' => 'package/x-generic', - 'database' => 'file', - 'httpd/unix-directory' => 'dir', - 'text/css' => 'text/code', - 'text/csv' => 'x-office/spreadsheet', - 'text/html' => 'text/code', - 'text/x-c' => 'text/code', - 'text/x-c++src' => 'text/code', - 'text/x-h' => 'text/code', - 'text/x-java-source' => 'text/code', - 'text/x-ldif' => 'text/code', - 'text/x-python' => 'text/code', - 'text/x-shellscript' => 'text/code', - 'web' => 'text/code', - 'application/internet-shortcut' => 'link', - 'application/km' => 'mindmap', - 'application/x-freemind' => 'mindmap', - 'application/vnd.xmind.workbook' => 'mindmap' - ]); - $this->environmentHelper ->expects($this->any()) ->method('getServerRoot') ->willReturn(\OC::$SERVERROOT . '/tests/data/integritycheck/mimetypeListModified'); - $signatureDataFile = '{ - "hashes": { - "core\/js\/mimetypelist.js": "94195a260a005dac543c3f6aa504f1b28e0078297fe94a4f52f012c16c109f0323eecc9f767d6949f860dfe454625fcaf1dc56f87bb8350975d8f006bbbdf14a" - }, - "signature": "BYPMrU+2vzSOOjSFcRPsWphv0uXQ+Vu6yC7FL6V0iM4WXcAkTK1e5OjkHFqUBNIDxg0AWB14ogUFRGDr+Qh+AqDRaX1u2ST2BhO1mgVh4JaqVOhlnDgWg8NPRMaVqvMy6Rfmyj57D1vmDmbVGQmnaIxEot84mOx4MP6sgZIVOMEe2itlmNwp1ogG6t61wpj4dFe73tYPDePWh0j+TmW8a\/Ry67wIhWHHhSGWIhhYRi8NmfW0oLhL1tgze5+Oo4pvgIgJq47BOYGu4YnfY3w8PB\/sQ5bPIvd\/+CTt\/1RASoadEfLd0MjLFEVEAj3uVGMq1kv7gK4bisXrKJS\/dbCwM+iJQfVFIVjwzuPH1QLbvSEsVUkJKVM4iS4a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FICATE-----" -}'; - $this->fileAccessHelper - ->expects($this->at(0)) - ->method('file_get_contents') - ->with( - \OC::$SERVERROOT . '/tests/data/integritycheck/mimetypeListModified/core/signature.json' - ) - ->willReturn($signatureDataFile); + + $signatureDataFile = file_get_contents(__DIR__ .'/../../data/integritycheck/mimetypeListModified/core/signature.json'); $this->fileAccessHelper - ->expects($this->at(1)) ->method('file_get_contents') - ->with( - \OC::$SERVERROOT . '/tests/data/integritycheck/mimetypeListModified/resources/codesigning/root.crt' - ) - ->willReturn(file_get_contents(__DIR__ .'/../../data/integritycheck/root.crt')); + ->willReturnMap([ + [\OC::$SERVERROOT . '/tests/data/integritycheck/mimetypeListModified/core/signature.json', $signatureDataFile], + [\OC::$SERVERROOT . '/tests/data/integritycheck/mimetypeListModified/resources/codesigning/root.crt', file_get_contents(__DIR__ .'/../../data/integritycheck/root.crt')], + ]); $this->assertSame([], $this->checker->verifyCoreSignature()); } @@ -1061,19 +818,15 @@ class CheckerTest extends TestCase { "certificate": "-----BEGIN CERTIFICATE-----\r\nMIIEvjCCAqagAwIBAgIUc\/0FxYrsgSs9rDxp03EJmbjN0NwwDQYJKoZIhvcNAQEF\r\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTEw\r\nMzIxMDMzM1oXDTE2MTEwMzIxMDMzM1owDzENMAsGA1UEAwwEY29yZTCCAiIwDQYJ\r\nKoZIhvcNAQEBBQADggIPADCCAgoCggIBALb6EgHpkAqZbO5vRO8XSh7G7XGWHw5s\r\niOf4RwPXR6SE9bWZEm\/b72SfWk\/\/J6AbrD8WiOzBuT\/ODy6k5T1arEdHO+Pux0W1\r\nMxYJJI4kH74KKgMpC0SB0Rt+8WrMqV1r3hhJ46df6Xr\/xolP3oD+eLbShPcblhdS\r\nVtkZEkoev8Sh6L2wDCeHDyPxzvj1w2dTdGVO9Kztn0xIlyfEBakqvBWtcxyi3Ln0\r\nklnxlMx3tPDUE4kqvpia9qNiB1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BPeHhvQtvOt0iXI\/XUxEWOa2F\r\nK2EqhErgMK\/N07U1JJJay5tYZRtvkGq46oP\/5kQG8hYST0MDK6VihJoPpvCmAm4E\r\npEYKQ96x6A4EH9Y9mZlYozH\/eqmxPbTK8n89\/p7Ydun4rI+B2iiLnY8REWWy6+UQ\r\nV204fGUkJqW5CrKy3P3XvY9X\r\n-----END CERTIFICATE-----" }'; $this->fileAccessHelper - ->expects($this->at(0)) - ->method('file_get_contents') - ->with( - \OC::$SERVERROOT . '/tests/data/integritycheck/app//core/signature.json' - ) - ->willReturn($signatureDataFile); - $this->fileAccessHelper - ->expects($this->at(1)) - ->method('file_get_contents') - ->with( - \OC::$SERVERROOT . '/tests/data/integritycheck/app//resources/codesigning/root.crt' - ) - ->willReturn(file_get_contents(__DIR__ .'/../../data/integritycheck/root.crt')); + ->expects($this->exactly(2)) + ->method('file_get_contents') + ->withConsecutive( + [\OC::$SERVERROOT . '/tests/data/integritycheck/app//core/signature.json'], + [\OC::$SERVERROOT . '/tests/data/integritycheck/app//resources/codesigning/root.crt'], + )->willReturnOnConsecutiveCalls( + $signatureDataFile, + file_get_contents(__DIR__ .'/../../data/integritycheck/root.crt') + ); $this->assertSame([], $this->checker->verifyCoreSignature()); } @@ -1102,19 +855,15 @@ class CheckerTest extends TestCase { "certificate": "-----BEGIN CERTIFICATE-----\r\nMIIEvjCCAqagAwIBAgIUc\/0FxYrsgSs9rDxp03EJmbjN0NwwDQYJKoZIhvcNAQEF\r\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTEw\r\nMzIxMDMzM1oXDTE2MTEwMzIxMDMzM1owDzENMAsGA1UEAwwEY29yZTCCAiIwDQYJ\r\nKoZIhvcNAQEBBQADggIPADCCAgoCggIBALb6EgHpkAqZbO5vRO8XSh7G7XGWHw5s\r\niOf4RwPXR6SE9bWZEm\/b72SfWk\/\/J6AbrD8WiOzBuT\/ODy6k5T1arEdHO+Pux0W1\r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s3NZk9FSQh4B8vZVuRr5FaJsZZkwlFlhRO\/\/+TJtXRbyNgsf\r\noMRZGi8DLGU2SGEAHcRH\/QZHq\/XDUWVzdxrSBYcy7GSpT7UDVzGv1rEJUrn5veP1\r\n0KmauAqtiIaYRm4f6YBsn0INcZxzIPZ0p8qFtVZBPeHhvQtvOt0iXI\/XUxEWOa2F\r\nK2EqhErgMK\/N07U1JJJay5tYZRtvkGq46oP\/5kQG8hYST0MDK6VihJoPpvCmAm4E\r\npEYKQ96x6A4EH9Y9mZlYozH\/eqmxPbTK8n89\/p7Ydun4rI+B2iiLnY8REWWy6+UQ\r\nV204fGUkJqW5CrKy3P3XvY9X\r\n-----END CERTIFICATE-----" }'; $this->fileAccessHelper - ->expects($this->at(0)) - ->method('file_get_contents') - ->with( - \OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//core/signature.json' - ) - ->willReturn($signatureDataFile); - $this->fileAccessHelper - ->expects($this->at(1)) - ->method('file_get_contents') - ->with( - \OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//resources/codesigning/root.crt' - ) - ->willReturn(file_get_contents(__DIR__ .'/../../data/integritycheck/root.crt')); + ->expects($this->exactly(2)) + ->method('file_get_contents') + ->withConsecutive( + [\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//core/signature.json'], + [\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//resources/codesigning/root.crt'], + )->willReturnOnConsecutiveCalls( + $signatureDataFile, + file_get_contents(__DIR__ .'/../../data/integritycheck/root.crt') + ); $expected = [ 'EXCEPTION' => [ @@ -1149,19 +898,15 @@ class CheckerTest extends TestCase { "certificate": "-----BEGIN CERTIFICATE-----\r\nMIIEvjCCAqagAwIBAgIUc\/0FxYrsgSs9rDxp03EJmbjN0NwwDQYJKoZIhvcNAQEF\r\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTEw\r\nMzIxMDMzM1oXDTE2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ZyAcXvj7obqRAEZwFAKQgFpfpqTb\r\nH+kjcbZSaAlLVSF7vBc1syyI8RGYbqpwvtREqJtl5IEIwe6huEqJ3zPnlP2th\/55\r\ncf3Fovj6JJgbb9XFxrdnsOsDOu\/tpnaRWlvv5ib4+SzG5wWFT5UUEo4Wg2STQiiX\r\nuVSRQxK1LE1yg84bs3NZk9FSQh4B8vZVuRr5FaJsZZkwlFlhRO\/\/+TJtXRbyNgsf\r\noMRZGi8DLGU2SGEAHcRH\/QZHq\/XDUWVzdxrSBYcy7GSpT7UDVzGv1rEJUrn5veP1\r\n0KmauAqtiIaYRm4f6YBsn0INcZxzIPZ0p8qFtVZBPeHhvQtvOt0iXI\/XUxEWOa2F\r\nK2EqhErgMK\/N07U1JJJay5tYZRtvkGq46oP\/5kQG8hYST0MDK6VihJoPpvCmAm4E\r\npEYKQ96x6A4EH9Y9mZlYozH\/eqmxPbTK8n89\/p7Ydun4rI+B2iiLnY8REWWy6+UQ\r\nV204fGUkJqW5CrKy3P3XvY9X\r\n-----END CERTIFICATE-----" }'; $this->fileAccessHelper - ->expects($this->at(0)) - ->method('file_get_contents') - ->with( - \OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//core/signature.json' - ) - ->willReturn($signatureDataFile); - $this->fileAccessHelper - ->expects($this->at(1)) - ->method('file_get_contents') - ->with( - \OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//resources/codesigning/root.crt' - ) - ->willReturn(file_get_contents(__DIR__ .'/../../data/integritycheck/root.crt')); + ->expects($this->exactly(2)) + ->method('file_get_contents') + ->withConsecutive( + [\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//core/signature.json'], + [\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//resources/codesigning/root.crt'], + )->willReturnOnConsecutiveCalls( + $signatureDataFile, + file_get_contents(__DIR__ .'/../../data/integritycheck/root.crt') + ); $expected = [ 'INVALID_HASH' => [ @@ -1211,19 +956,15 @@ class CheckerTest ext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pgB1K67YvclNUyuU6NQ6zBJx1\/w1RnM7uxLcxiiWj1BbUhwZQ0ojmEHeUyi6O\r\nGrDVajwhTccDMmja3u5adhEncx65\/H+lD85IPRRkS2qBDssMDdJHhZ0uI+40nI7M\r\nMq1kFjl+6wiuqZXqps66DuLbk45g\/ZlrFIrIo3Ix5vj0OVqwT+gO4LYirJK6KgVS\r\nUttbcEsc\/yKU9ThnM8\/n4m2jstZXfzKPgOsJrQcZrFOtpj+CWmBzVElBSPlDT3Nh\r\nHSgOeTFJ8bQBxj2iG5dLA+JZJQKxyJ1gy2ZtxIJ2GyvLtSe8NUSqvfPWOaAKEUV2\r\ngniytnEFLr+PcD+9EGux6jZNuj6HmtWVThTfD5VGFmtlVU2z71ZRYY0kn6J3mmFc\r\nS2ecEcCUwqG5YNLncEUCyZhC2klWql2SHyGctCEyWWY7ikIDjVzYt2EbcFvLNBnP\r\ntybN1TYHRRZxlug00CCoOE9EZfk46FkZpDvU6KmqJRofkNZ5sj+SffyGcwYwNrDH\r\nKqe8m+9lHf3CRTIDeMu8r2xl1I6M6ZZfjabbmVP9Jd6WN4s6f1FlXDWzhlT1N0Qw\r\nGzJj6xB+SPtS3UV05tBlvbfA4e06D5G9uD7Q8ONcINtMS0xsSJ2oo82AqlpvlF\/q\r\noj7YKHsaTVGA+FxBktZHfoxD\r\n-----END CERTIFICATE-----" }'; $this->fileAccessHelper - ->expects($this->at(0)) - ->method('file_get_contents') - ->with( - \OC::$SERVERROOT . '/tests/data/integritycheck/app//core/signature.json' - ) - ->willReturn($signatureDataFile); - $this->fileAccessHelper - ->expects($this->at(1)) - ->method('file_get_contents') - ->with( - \OC::$SERVERROOT . '/tests/data/integritycheck/app//resources/codesigning/root.crt' - ) - ->willReturn(file_get_contents(__DIR__ .'/../../data/integritycheck/root.crt')); + ->expects($this->exactly(2)) + ->method('file_get_contents') + ->withConsecutive( + [\OC::$SERVERROOT . '/tests/data/integritycheck/app//core/signature.json'], + [\OC::$SERVERROOT . '/tests/data/integritycheck/app//resources/codesigning/root.crt'], + )->willReturnOnConsecutiveCalls( + $signatureDataFile, + file_get_contents(__DIR__ .'/../../data/integritycheck/root.crt') + ); $expected = [ 'EXCEPTION' => [ @@ -1258,19 +999,15 @@ class CheckerTest extends TestCase { "certificate": "-----BEGIN CERTIFICATE-----\r\nMIIEwTCCAqmgAwIBAgIUWv0iujufs5lUr0svCf\/qTQvoyKAwDQYJKoZIhvcNAQEF\r\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTEw\r\nMzIyNDk1M1oXDTE2MTEwMzIyNDk1M1owEjEQMA4GA1UEAwwHU29tZUFwcDCCAiIw\r\nDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK8q0x62agGSRBqeWsaeEwFfepMk\r\nF8cAobMMi50qHCv9IrOn\/ZH9l52xBrbIkErVmRjmly0d4JhD8Ymhidsh9ONKYl\/j\r\n+ishsZDM8eNNdp3Ew+fEYVvY1W7mR1qU24NWj0bzVsClI7hvPVIuw7AjfBDq1C5+\r\nA+ZSLSXYvOK2cEWjdxQfuNZwEZSjmA63DUllBIrm35IaTvfuyhU6BW9yHZxmb8+M\r\nw0xDv30D5UkE\/2N7Pa\/HQJLxCR+3zKibRK3nUyRDLSXxMkU9PnFNaPNX59VPgyj4\r\nGB1CFSToldJVPF4pzh7p36uGXZVxs8m3LFD4Ol8mhi7jkxDZjqFN46gzR0r23Py6\r\ndol9vfawGIoUwp9LvL0S7MvdRY0oazLXwClLP4OQ17zpSMAiCj7fgNT661JamPGj\r\nt5O7Zn2wA7I4ddDS\/HDTWCu98Zwc9fHIpsJPgCZ9awoqxi4Mnf7Pk9g5nnXhszGC\r\ncxxIASQKM+GhdzoRxKknax2RzUCwCzcPRtCj8AQT\/x\/mqN3PfRmlnFBNACUw9bpZ\r\nSOoNq2pCF9igftDWpSIXQ38pVpKLWowjjg3DVRmVKBgivHnUnVLyzYBahHPj0vaz\r\ntFtUFRaqXDnt+4qyUGyrT5h5pjZaTcHIcSB4PiarYwdVvgslgwnQzOUcGAzRWBD4\r\n6jV2brP5vFY3g6iPAgMBAAEwDQYJKoZIhvcNAQEFBQADggIBACTY3CCHC+Z28gCf\r\nFWGKQ3wAKs+k4+0yoti0qm2EKX7rSGQ0PHSas6uW79WstC4Rj+DYkDtIhGMSg8FS\r\nHVGZHGBCc0HwdX+BOAt3zi4p7Sf3oQef70\/4imPoKxbAVCpd\/cveVcFyDC19j1yB\r\nBapwu87oh+muoeaZxOlqQI4UxjBlR\/uRSMhOn2UGauIr3dWJgAF4pGt7TtIzt+1v\r\n0uA6FtN1Y4R5O8AaJPh1bIG0CVvFBE58esGzjEYLhOydgKFnEP94kVPgJD5ds9C3\r\npPhEpo1dRpiXaF7WGIV1X6DI\/ipWvfrF7CEy6I\/kP1InY\/vMDjQjeDnJ\/VrXIWXO\r\nyZvHXVaN\/m+1RlETsH7YO\/QmxRue9ZHN3gvvWtmpCeA95sfpepOk7UcHxHZYyQbF\r\n49\/au8j+5tsr4A83xzsT1JbcKRxkAaQ7WDJpOnE5O1+H0fB+BaLakTg6XX9d4Fo7\r\n7Gin7hVWX7pL+JIyxMzME3LhfI61+CRcqZQIrpyaafUziPQbWIPfEs7h8tCOWyvW\r\nUO8ZLervYCB3j44ivkrxPlcBklDCqqKKBzDP9dYOtS\/P4RB1NkHA9+NTvmBpTonS\r\nSFXdg9fFMD7VfjDE3Vnk+8DWkVH5wBYowTAD7w9Wuzr7DumiAULexnP\/Y7xwxLv7\r\n4B+pXTAcRK0zECDEaX3npS8xWzrB\r\n-----END CERTIFICATE-----" }'; $this->fileAccessHelper - ->expects($this->at(0)) - ->method('file_get_contents') - ->with( - \OC::$SERVERROOT . '/tests/data/integritycheck/app//core/signature.json' - ) - ->willReturn($signatureDataFile); - $this->fileAccessHelper - ->expects($this->at(1)) - ->method('file_get_contents') - ->with( - \OC::$SERVERROOT . '/tests/data/integritycheck/app//resources/codesigning/root.crt' - ) - ->willReturn(file_get_contents(__DIR__ .'/../../data/integritycheck/root.crt')); + ->expects($this->exactly(2)) + ->method('file_get_contents') + ->withConsecutive( + [\OC::$SERVERROOT . '/tests/data/integritycheck/app//core/signature.json'], + [\OC::$SERVERROOT . '/tests/data/integritycheck/app//resources/codesigning/root.crt'], + )->willReturnOnConsecutiveCalls( + $signatureDataFile, + file_get_contents(__DIR__ .'/../../data/integritycheck/root.crt') + ); $expected = [ 'EXCEPTION' => [ @@ -1299,10 +1036,10 @@ class CheckerTest extends TestCase { ->getMock(); $this->checker - ->expects($this->at(0)) + ->expects($this->once()) ->method('verifyCoreSignature'); $this->appLocator - ->expects($this->at(0)) + ->expects($this->once()) ->method('getAllApps') ->willReturn([ 'files', @@ -1311,57 +1048,47 @@ class CheckerTest extends TestCase { 'dav', ]); $this->appManager - ->expects($this->at(0)) + ->expects($this->exactly(4)) ->method('isShipped') - ->with('files') - ->willReturn(true); + ->withConsecutive( + ['files'], + ['calendar'], + ['contacts'], + ['dav'], + )->willReturnOnConsecutiveCalls( + true, + false, + false, + true, + ); $this->checker - ->expects($this->at(1)) + ->expects($this->exactly(3)) ->method('verifyAppSignature') - ->with('files'); - $this->appManager - ->expects($this->at(1)) - ->method('isShipped') - ->with('calendar') - ->willReturn(false); + ->withConsecutive( + ['files'], + ['calendar'], + ['dav'], + ); $this->appLocator - ->expects($this->at(1)) + ->expects($this->exactly(2)) ->method('getAppPath') - ->with('calendar') - ->willReturn('/apps/calendar'); + ->withConsecutive( + ['calendar'], + ['contacts'], + )->willReturnOnConsecutiveCalls( + '/apps/calendar', + '/apps/contacts', + ); $this->fileAccessHelper - ->expects($this->at(0)) + ->expects($this->exactly(2)) ->method('file_exists') - ->with('/apps/calendar/appinfo/signature.json') - ->willReturn(true); - $this->checker - ->expects($this->at(2)) - ->method('verifyAppSignature') - ->with('calendar'); - $this->appManager - ->expects($this->at(2)) - ->method('isShipped') - ->with('contacts') - ->willReturn(false); - $this->appLocator - ->expects($this->at(2)) - ->method('getAppPath') - ->with('contacts') - ->willReturn('/apps/contacts'); - $this->fileAccessHelper - ->expects($this->at(1)) - ->method('file_exists') - ->with('/apps/contacts/appinfo/signature.json') - ->willReturn(false); - $this->appManager - ->expects($this->at(3)) - ->method('isShipped') - ->with('dav') - ->willReturn(true); - $this->checker - ->expects($this->at(3)) - ->method('verifyAppSignature') - ->with('dav'); + ->withConsecutive( + ['/apps/calendar/appinfo/signature.json'], + ['/apps/contacts/appinfo/signature.json'], + )->willReturnOnConsecutiveCalls( + true, + false, + ); $this->config ->expects($this->once()) ->method('deleteAppValue') diff --git a/tests/lib/L10N/FactoryTest.php b/tests/lib/L10N/FactoryTest.php index a2c1e8b5261..faf9dff48cc 100644 --- a/tests/lib/L10N/FactoryTest.php +++ b/tests/lib/L10N/FactoryTest.php @@ -105,20 +105,26 @@ class FactoryTest extends TestCase { public function testFindLanguageWithNotExistingRequestLanguageAndExistingStoredUserLanguage(): void { $factory = $this->getFactory(['languageExists']); $this->invokePrivate($factory, 'requestLanguage', ['de']); - $factory->expects(self::at(0)) + $factory->expects($this->exactly(2)) ->method('languageExists') - ->with('MyApp', 'de') - ->willReturn(false); + ->withConsecutive( + ['MyApp', 'de'], + ['MyApp', 'jp'], + ) + ->willReturnOnConsecutiveCalls( + false, + true, + ); $this->config - ->expects(self::at(0)) + ->expects($this->exactly(2)) ->method('getSystemValue') - ->with('force_language', false) - ->willReturn(false); - $this->config - ->expects(self::at(1)) - ->method('getSystemValue') - ->with('installed', false) - ->willReturn(true); + ->withConsecutive( + ['force_language', false], + ['installed', false], + )->willReturnOnConsecutiveCalls( + false, + true, + ); $user = $this->getMockBuilder(IUser::class) ->getMock(); $user->expects(self::once()) @@ -133,10 +139,6 @@ class FactoryTest extends TestCase { ->method('getUserValue') ->with('MyUserUid', 'core', 'lang', null) ->willReturn('jp'); - $factory->expects(self::at(1)) - ->method('languageExists') - ->with('MyApp', 'jp') - ->willReturn(true); self::assertSame('jp', $factory->findLanguage('MyApp')); } diff --git a/tests/lib/Log/ExceptionSerializerTest.php b/tests/lib/Log/ExceptionSerializerTest.php new file mode 100644 index 00000000000..209214a6832 --- /dev/null +++ b/tests/lib/Log/ExceptionSerializerTest.php @@ -0,0 +1,84 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2021 Arthur Schiwon <blizzz@arthur-schiwon.de> + * + * @author Arthur Schiwon <blizzz@arthur-schiwon.de> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + * + */ + +namespace lib\Log; + +use OC\Log\ExceptionSerializer; +use OC\SystemConfig; +use Test\TestCase; + +class ExceptionSerializerTest extends TestCase { + private ExceptionSerializer $serializer; + + public function setUp(): void { + parent::setUp(); + + $config = $this->createMock(SystemConfig::class); + $this->serializer = new ExceptionSerializer($config); + } + + private function emit($arguments) { + \call_user_func_array([$this, 'bind'], $arguments); + } + + private function bind(array &$myValues): void { + throw new \Exception('my exception'); + } + + private function customMagicAuthThing(string $login, string $parole): void { + throw new \Exception('expected custom auth exception'); + } + + /** + * this test ensures that the serializer does not overwrite referenced + * variables. It is crafted after a scenario we experienced: the DAV server + * emitting the "validateTokens" event, of which later on a handled + * exception was passed to the logger. The token was replaced, the original + * variable overwritten. + */ + public function testSerializer() { + try { + $secret = ['Secret']; + $this->emit([&$secret]); + } catch (\Exception $e) { + $serializedData = $this->serializer->serializeException($e); + $this->assertSame(['Secret'], $secret); + $this->assertSame(ExceptionSerializer::SENSITIVE_VALUE_PLACEHOLDER, $serializedData['Trace'][0]['args'][0]); + } + } + + public function testSerializerWithRegisteredMethods() { + $this->serializer->enlistSensitiveMethods(self::class, ['customMagicAuthThing']); + try { + $this->customMagicAuthThing('u57474', 'Secret'); + } catch (\Exception $e) { + $serializedData = $this->serializer->serializeException($e); + $this->assertSame('customMagicAuthThing', $serializedData['Trace'][0]['function']); + $this->assertSame(ExceptionSerializer::SENSITIVE_VALUE_PLACEHOLDER, $serializedData['Trace'][0]['args'][0]); + $this->assertFalse(isset($serializedData['Trace'][0]['args'][1])); + } + } +} diff --git a/tests/lib/Log/FileTest.php b/tests/lib/Log/FileTest.php index 937b3c75448..703c4280f24 100644 --- a/tests/lib/Log/FileTest.php +++ b/tests/lib/Log/FileTest.php @@ -1,6 +1,8 @@ <?php /** * + * @author Thomas Citharel <nextcloud@tcit.fr> + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE * License as published by the Free Software Foundation; either @@ -18,6 +20,7 @@ namespace Test\Log; use OC\Log\File; +use OCP\IConfig; use OCP\ILogger; use Test\TestCase; @@ -36,7 +39,7 @@ class FileTest extends TestCase { $config = \OC::$server->getSystemConfig(); $this->restore_logfile = $config->getValue("logfile"); $this->restore_logdateformat = $config->getValue('logdateformat'); - + $config->setValue("logfile", $config->getValue('datadirectory') . "/logtest.log"); $this->logFile = new File($config->getValue('datadirectory') . '/logtest.log', '', $config); } @@ -55,7 +58,28 @@ class FileTest extends TestCase { $this->logFile = new File($this->restore_logfile, '', $config); parent::tearDown(); } - + + public function testLogging() { + $config = \OC::$server->get(IConfig::class); + # delete old logfile + unlink($config->getSystemValue('logfile')); + + # set format & write log line + $config->setSystemValue('logdateformat', 'u'); + $this->logFile->write('code', ['something' => 'extra', 'message' => 'Testing logging'], ILogger::ERROR); + + # read log line + $handle = @fopen($config->getSystemValue('logfile'), 'r'); + $line = fread($handle, 1000); + fclose($handle); + + # check log has data content + $values = (array) json_decode($line, true); + $this->assertArrayNotHasKey('message', $values['data']); + $this->assertEquals('extra', $values['data']['something']); + $this->assertEquals('Testing logging', $values['message']); + } + public function testMicrosecondsLogTimestamp() { $config = \OC::$server->getConfig(); # delete old logfile @@ -69,7 +93,7 @@ class FileTest extends TestCase { $handle = @fopen($config->getSystemValue('logfile'), 'r'); $line = fread($handle, 1000); fclose($handle); - + # check timestamp has microseconds part $values = (array) json_decode($line); $microseconds = $values['time']; diff --git a/tests/lib/LoggerTest.php b/tests/lib/LoggerTest.php index 9b44fe198e2..bec2119a8ad 100644 --- a/tests/lib/LoggerTest.php +++ b/tests/lib/LoggerTest.php @@ -1,6 +1,9 @@ <?php /** * Copyright (c) 2014 Thomas Müller <thomas.mueller@tmit.eu> + * + * @author Thomas Citharel <nextcloud@tcit.fr> + * * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. @@ -9,29 +12,32 @@ namespace Test; use OC\Log; +use OC\SystemConfig; use OCP\ILogger; use OCP\Log\IWriter; +use OCP\Support\CrashReport\IRegistry; +use PHPUnit\Framework\MockObject\MockObject; class LoggerTest extends TestCase implements IWriter { - /** @var \OC\SystemConfig|\PHPUnit\Framework\MockObject\MockObject */ + /** @var SystemConfig|MockObject */ private $config; - /** @var \OCP\Support\CrashReport\IRegistry|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IRegistry|MockObject */ private $registry; - /** @var \OCP\ILogger */ + /** @var ILogger */ private $logger; /** @var array */ - private $logs = []; + private array $logs = []; protected function setUp(): void { parent::setUp(); $this->logs = []; - $this->config = $this->createMock(\OC\SystemConfig::class); - $this->registry = $this->createMock(\OCP\Support\CrashReport\IRegistry::class); + $this->config = $this->createMock(SystemConfig::class); + $this->registry = $this->createMock(IRegistry::class); $this->logger = new Log($this, $this->config, null, $this->registry); } @@ -63,12 +69,23 @@ class LoggerTest extends TestCase implements IWriter { $this->assertEquals($expected, $this->getLogs()); } - private function getLogs() { + public function testLoggingWithDataArray(): void { + $writerMock = $this->createMock(IWriter::class); + $logFile = new Log($writerMock, $this->config); + $writerMock->expects($this->once())->method('write')->with('no app in context', ['something' => 'extra', 'message' => 'Testing logging with john']); + $logFile->error('Testing logging with {user}', ['something' => 'extra', 'user' => 'john']); + } + + private function getLogs(): array { return $this->logs; } public function write(string $app, $message, int $level) { - $this->logs[] = "$level $message"; + $textMessage = $message; + if (is_array($message)) { + $textMessage = $message['message']; + } + $this->logs[] = $level . " " . $textMessage; } public function userAndPasswordData(): array { diff --git a/tests/lib/Metadata/FileMetadataMapperTest.php b/tests/lib/Metadata/FileMetadataMapperTest.php index 8e385351be2..1a005f24b8a 100644 --- a/tests/lib/Metadata/FileMetadataMapperTest.php +++ b/tests/lib/Metadata/FileMetadataMapperTest.php @@ -24,6 +24,7 @@ namespace Test\Metadata; use OC\Metadata\FileMetadataMapper; use OC\Metadata\FileMetadata; +use PHPUnit\Framework\MockObject\MockObject; /** * @group DB @@ -33,9 +34,12 @@ class FileMetadataMapperTest extends \Test\TestCase { /** @var IDBConnection */ protected $connection; - /** @var SystemConfig|\PHPUnit\Framework\MockObject\MockObject */ + /** @var SystemConfig|MockObject */ protected $config; + /** @var FileMetadataMapper|MockObject */ + protected $mapper; + protected function setUp(): void { parent::setUp(); diff --git a/tests/lib/Preview/GeneratorTest.php b/tests/lib/Preview/GeneratorTest.php index 43f5c1e0d36..1e38afd7744 100644 --- a/tests/lib/Preview/GeneratorTest.php +++ b/tests/lib/Preview/GeneratorTest.php @@ -95,6 +95,7 @@ class GeneratorTest extends \Test\TestCase { $maxPreview = $this->createMock(ISimpleFile::class); $maxPreview->method('getName') ->willReturn('1000-1000-max.png'); + $maxPreview->method('getSize')->willReturn(1000); $maxPreview->method('getMimeType') ->willReturn('image/png'); @@ -102,6 +103,7 @@ class GeneratorTest extends \Test\TestCase { ->willReturn([$maxPreview]); $previewFile = $this->createMock(ISimpleFile::class); + $previewFile->method('getSize')->willReturn(1000); $previewFolder->method('getFile') ->with($this->equalTo('256-256.png')) @@ -203,8 +205,10 @@ class GeneratorTest extends \Test\TestCase { $maxPreview = $this->createMock(ISimpleFile::class); $maxPreview->method('getName')->willReturn('2048-2048-max.png'); $maxPreview->method('getMimeType')->willReturn('image/png'); + $maxPreview->method('getSize')->willReturn(1000); $previewFile = $this->createMock(ISimpleFile::class); + $previewFile->method('getSize')->willReturn(1000); $previewFolder->method('getDirectoryListing') ->willReturn([]); @@ -313,6 +317,7 @@ class GeneratorTest extends \Test\TestCase { $maxPreview = $this->createMock(ISimpleFile::class); $maxPreview->method('getName') ->willReturn('2048-2048-max.png'); + $maxPreview->method('getSize')->willReturn(1000); $maxPreview->method('getMimeType') ->willReturn('image/png'); @@ -320,6 +325,7 @@ class GeneratorTest extends \Test\TestCase { ->willReturn([$maxPreview]); $preview = $this->createMock(ISimpleFile::class); + $preview->method('getSize')->willReturn(1000); $previewFolder->method('getFile') ->with($this->equalTo('1024-512-crop.png')) ->willReturn($preview); @@ -471,6 +477,7 @@ class GeneratorTest extends \Test\TestCase { ->willReturn($maxX . '-' . $maxY . '-max.png'); $maxPreview->method('getMimeType') ->willReturn('image/png'); + $maxPreview->method('getSize')->willReturn(1000); $previewFolder->method('getDirectoryListing') ->willReturn([$maxPreview]); @@ -490,6 +497,7 @@ class GeneratorTest extends \Test\TestCase { ->willReturn($image); $preview = $this->createMock(ISimpleFile::class); + $preview->method('getSize')->willReturn(1000); $previewFolder->method('newFile') ->with($this->equalTo($filename)) ->willReturn($preview); diff --git a/tests/lib/Repair/RepairMimeTypesTest.php b/tests/lib/Repair/RepairMimeTypesTest.php index 26a52459c24..53c8e53d486 100644 --- a/tests/lib/Repair/RepairMimeTypesTest.php +++ b/tests/lib/Repair/RepairMimeTypesTest.php @@ -36,7 +36,6 @@ class RepairMimeTypesTest extends \Test\TestCase { protected function setUp(): void { parent::setUp(); - $this->savedMimetypeLoader = \OC::$server->getMimeTypeLoader(); $this->mimetypeLoader = \OC::$server->getMimeTypeLoader(); /** @var IConfig | \PHPUnit\Framework\MockObject\MockObject $config */ diff --git a/tests/lib/Settings/ManagerTest.php b/tests/lib/Settings/ManagerTest.php index 96711e75cab..29ae33c3c93 100644 --- a/tests/lib/Settings/ManagerTest.php +++ b/tests/lib/Settings/ManagerTest.php @@ -21,7 +21,7 @@ * */ -namespace OCA\Settings\Tests\AppInfo; +namespace OC\Settings\Tests\AppInfo; use OC\Settings\AuthorizedGroupMapper; use OC\Settings\Manager; @@ -82,16 +82,26 @@ class ManagerTest extends TestCase { public function testGetAdminSections() { $this->manager->registerSection('admin', \OCA\WorkflowEngine\Settings\Section::class); + $section = \OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class); + $this->container->method('get') + ->with(\OCA\WorkflowEngine\Settings\Section::class) + ->willReturn($section); + $this->assertEquals([ - 55 => [\OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class)], + 55 => [$section], ], $this->manager->getAdminSections()); } public function testGetPersonalSections() { $this->manager->registerSection('personal', \OCA\WorkflowEngine\Settings\Section::class); + $section = \OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class); + $this->container->method('get') + ->with(\OCA\WorkflowEngine\Settings\Section::class) + ->willReturn($section); + $this->assertEquals([ - 55 => [\OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class)], + 55 => [$section], ], $this->manager->getPersonalSections()); } @@ -181,14 +191,16 @@ class ManagerTest extends TestCase { $this->manager->registerSetting('personal', 'section1'); $this->manager->registerSetting('personal', 'section2'); - $this->container->expects($this->at(0)) + $this->container->expects($this->exactly(2)) ->method('get') - ->with('section1') - ->willReturn($section); - $this->container->expects($this->at(1)) - ->method('get') - ->with('section2') - ->willReturn($section2); + ->withConsecutive( + ['section1'], + ['section2'] + ) + ->willReturnMap([ + ['section1', $section], + ['section2', $section2], + ]); $settings = $this->manager->getPersonalSettings('security'); @@ -212,12 +224,18 @@ class ManagerTest extends TestCase { $this->manager->registerSection('personal', \OCA\WorkflowEngine\Settings\Section::class); $this->manager->registerSection('admin', \OCA\WorkflowEngine\Settings\Section::class); + + $section = \OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class); + $this->container->method('get') + ->with(\OCA\WorkflowEngine\Settings\Section::class) + ->willReturn($section); + $this->assertEquals([ - 55 => [\OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class)], + 55 => [$section], ], $this->manager->getPersonalSections()); $this->assertEquals([ - 55 => [\OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class)], + 55 => [$section], ], $this->manager->getAdminSections()); } } diff --git a/tests/lib/Share20/DefaultShareProviderTest.php b/tests/lib/Share20/DefaultShareProviderTest.php index 03e1bdb4346..ed2bc2a4eda 100644 --- a/tests/lib/Share20/DefaultShareProviderTest.php +++ b/tests/lib/Share20/DefaultShareProviderTest.php @@ -23,6 +23,7 @@ namespace Test\Share20; use OC\Share20\DefaultShareProvider; +use OC\Share20\ShareAttributes; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\Defaults; use OCP\Files\File; @@ -703,6 +704,11 @@ class DefaultShareProviderTest extends \Test\TestCase { $share->setSharedWithDisplayName('Displayed Name'); $share->setSharedWithAvatar('/path/to/image.svg'); $share->setPermissions(1); + + $attrs = new ShareAttributes(); + $attrs->setAttribute('permissions', 'download', true); + $share->setAttributes($attrs); + $share->setTarget('/target'); $share2 = $this->provider->create($share); @@ -723,6 +729,17 @@ class DefaultShareProviderTest extends \Test\TestCase { $this->assertSame('/path/to/image.svg', $share->getSharedWithAvatar()); $this->assertSame(null, $share2->getSharedWithDisplayName()); $this->assertSame(null, $share2->getSharedWithAvatar()); + + $this->assertSame( + [ + [ + 'scope' => 'permissions', + 'key' => 'download', + 'enabled' => true + ] + ], + $share->getAttributes()->toArray() + ); } public function testCreateGroupShare() { @@ -760,6 +777,9 @@ class DefaultShareProviderTest extends \Test\TestCase { $share->setSharedWithDisplayName('Displayed Name'); $share->setSharedWithAvatar('/path/to/image.svg'); $share->setTarget('/target'); + $attrs = new ShareAttributes(); + $attrs->setAttribute('permissions', 'download', true); + $share->setAttributes($attrs); $share2 = $this->provider->create($share); @@ -779,6 +799,17 @@ class DefaultShareProviderTest extends \Test\TestCase { $this->assertSame('/path/to/image.svg', $share->getSharedWithAvatar()); $this->assertSame(null, $share2->getSharedWithDisplayName()); $this->assertSame(null, $share2->getSharedWithAvatar()); + + $this->assertSame( + [ + [ + 'scope' => 'permissions', + 'key' => 'download', + 'enabled' => true + ] + ], + $share->getAttributes()->toArray() + ); } public function testCreateLinkShare() { diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index 2ed99519df6..4e613d1cf5c 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -593,7 +593,7 @@ class ManagerTest extends \Test\TestCase { } public function createShare($id, $type, $path, $sharedWith, $sharedBy, $shareOwner, - $permissions, $expireDate = null, $password = null) { + $permissions, $expireDate = null, $password = null, $attributes = null) { $share = $this->createMock(IShare::class); $share->method('getShareType')->willReturn($type); @@ -602,6 +602,7 @@ class ManagerTest extends \Test\TestCase { $share->method('getShareOwner')->willReturn($shareOwner); $share->method('getNode')->willReturn($path); $share->method('getPermissions')->willReturn($permissions); + $share->method('getAttributes')->willReturn($attributes); $share->method('getExpirationDate')->willReturn($expireDate); $share->method('getPassword')->willReturn($password); @@ -1914,13 +1915,31 @@ class ManagerTest extends \Test\TestCase { } - public function testLinkCreateChecksNoPublicUpload() { + public function testFileLinkCreateChecksNoPublicUpload() { + $share = $this->manager->newShare(); + + $share->setPermissions(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE); + $share->setNodeType('file'); + + $this->config + ->method('getAppValue') + ->willReturnMap([ + ['core', 'shareapi_allow_links', 'yes', 'yes'], + ['core', 'shareapi_allow_public_upload', 'yes', 'no'] + ]); + + self::invokePrivate($this->manager, 'linkCreateChecks', [$share]); + $this->addToAssertionCount(1); + } + + public function testFolderLinkCreateChecksNoPublicUpload() { $this->expectException(\Exception::class); $this->expectExceptionMessage('Public upload is not allowed'); $share = $this->manager->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE); + $share->setNodeType('folder'); $this->config ->method('getAppValue') @@ -1936,6 +1955,9 @@ class ManagerTest extends \Test\TestCase { $share = $this->manager->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE); + $share->setSharedWith('sharedWith'); + $folder = $this->createMock(\OC\Files\Node\Folder::class); + $share->setNode($folder); $this->config ->method('getAppValue') @@ -1952,6 +1974,9 @@ class ManagerTest extends \Test\TestCase { $share = $this->manager->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_READ); + $share->setSharedWith('sharedWith'); + $folder = $this->createMock(\OC\Files\Node\Folder::class); + $share->setNode($folder); $this->config ->method('getAppValue') @@ -2946,6 +2971,9 @@ class ManagerTest extends \Test\TestCase { $share = $this->manager->newShare(); $share->setShareType(IShare::TYPE_LINK) ->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE); + $share->setSharedWith('sharedWith'); + $folder = $this->createMock(\OC\Files\Node\Folder::class); + $share->setNode($folder); $this->config ->expects($this->at(1)) @@ -3039,6 +3067,8 @@ class ManagerTest extends \Test\TestCase { $manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare); $share = $this->manager->newShare(); + $attrs = $this->manager->newShare()->newAttributes(); + $attrs->setAttribute('app1', 'perm1', true); $share->setProviderId('foo') ->setId('42') ->setShareType(IShare::TYPE_USER); @@ -3129,6 +3159,8 @@ class ManagerTest extends \Test\TestCase { $manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare); $share = $this->manager->newShare(); + $attrs = $this->manager->newShare()->newAttributes(); + $attrs->setAttribute('app1', 'perm1', true); $share->setProviderId('foo') ->setId('42') ->setShareType(IShare::TYPE_USER) @@ -3136,6 +3168,7 @@ class ManagerTest extends \Test\TestCase { ->setShareOwner('newUser') ->setSharedBy('sharer') ->setPermissions(31) + ->setAttributes($attrs) ->setNode($node); $this->defaultProvider->expects($this->once()) @@ -3160,6 +3193,7 @@ class ManagerTest extends \Test\TestCase { 'uidOwner' => 'sharer', 'permissions' => 31, 'path' => '/myPath', + 'attributes' => $attrs->toArray(), ]); $manager->updateShare($share); diff --git a/tests/lib/Share20/ShareByMailProviderTest.php b/tests/lib/Share20/ShareByMailProviderTest.php new file mode 100644 index 00000000000..3558be93a8b --- /dev/null +++ b/tests/lib/Share20/ShareByMailProviderTest.php @@ -0,0 +1,312 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2022 Richard Steinmetz <richard@steinmetz.cloud> + * + * @author Richard Steinmetz <richard@steinmetz.cloud> + * + * @license AGPL-3.0-or-later + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace Test\Share20; + +use OC\Files\Node\Node; +use OCA\ShareByMail\Settings\SettingsManager; +use OCA\ShareByMail\ShareByMailProvider; +use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\Defaults; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\IRootFolder; +use OCP\IConfig; +use OCP\IDBConnection; +use OCP\IL10N; +use OCP\ILogger; +use OCP\IURLGenerator; +use OCP\IUserManager; +use OCP\Mail\IMailer; +use OCP\Security\IHasher; +use OCP\Security\ISecureRandom; +use OCP\Share\IShare; +use PHPUnit\Framework\MockObject\MockObject; +use Test\TestCase; + +/** + * Class ShareByMailProviderTest + * + * @package Test\Share20 + * @group DB + */ +class ShareByMailProviderTest extends TestCase { + + /** @var IDBConnection */ + protected $dbConn; + + /** @var IUserManager | \PHPUnit\Framework\MockObject\MockObject */ + protected $userManager; + + /** @var IRootFolder | \PHPUnit\Framework\MockObject\MockObject */ + protected $rootFolder; + + /** @var ShareByMailProvider */ + protected $provider; + + /** @var \PHPUnit\Framework\MockObject\MockObject|IMailer */ + protected $mailer; + + /** @var \PHPUnit\Framework\MockObject\MockObject|IL10N */ + protected $l10n; + + /** @var \PHPUnit\Framework\MockObject\MockObject|Defaults */ + protected $defaults; + + /** @var \PHPUnit\Framework\MockObject\MockObject|IURLGenerator */ + protected $urlGenerator; + + /** @var IConfig|MockObject */ + protected $config; + + /** @var ILogger|MockObject */ + private $logger; + + /** @var IHasher|MockObject */ + private $hasher; + + /** @var \OCP\Activity\IManager|MockObject */ + private $activityManager; + + /** @var IEventDispatcher|MockObject */ + private $eventDispatcher; + + /** @var \OCP\Share\IManager|MockObject */ + private $shareManager; + + /** @var ISecureRandom|MockObject */ + private $secureRandom; + + /** @var SettingsManager|MockObject */ + private $settingsManager; + + protected function setUp(): void { + $this->dbConn = \OC::$server->getDatabaseConnection(); + $this->userManager = $this->createMock(IUserManager::class); + $this->rootFolder = $this->createMock(IRootFolder::class); + $this->mailer = $this->createMock(IMailer::class); + $this->l10n = $this->createMock(IL10N::class); + $this->defaults = $this->getMockBuilder(Defaults::class)->disableOriginalConstructor()->getMock(); + $this->urlGenerator = $this->createMock(IURLGenerator::class); + $this->logger = $this->createMock(ILogger::class); + $this->activityManager = $this->createMock(\OCP\Activity\IManager::class); + $this->settingsManager = $this->createMock(SettingsManager::class); + $this->hasher = $this->createMock(IHasher::class); + $this->eventDispatcher = $this->createMock(IEventDispatcher::class); + $this->shareManager = $this->createMock(\OCP\Share\IManager::class); + $this->secureRandom = $this->createMock(ISecureRandom::class); + $this->config = $this->createMock(IConfig::class); + + // Empty share table + $this->dbConn->getQueryBuilder()->delete('share')->execute(); + + $this->provider = new ShareByMailProvider( + $this->config, + $this->dbConn, + $this->secureRandom, + $this->userManager, + $this->rootFolder, + $this->l10n, + $this->logger, + $this->mailer, + $this->urlGenerator, + $this->activityManager, + $this->settingsManager, + $this->defaults, + $this->hasher, + $this->eventDispatcher, + $this->shareManager, + ); + } + + protected function tearDown(): void { + $this->dbConn->getQueryBuilder()->delete('share')->execute(); + $this->dbConn->getQueryBuilder()->delete('filecache')->execute(); + $this->dbConn->getQueryBuilder()->delete('storages')->execute(); + } + + /** + * @param int $shareType + * @param string $sharedWith + * @param string $sharedBy + * @param string $shareOwner + * @param string $itemType + * @param int $fileSource + * @param string $fileTarget + * @param int $permissions + * @param $token + * @param $expiration + * @param $parent + * @return int + * + * @throws \OCP\DB\Exception + */ + private function addShareToDB($shareType, $sharedWith, $sharedBy, $shareOwner, + $itemType, $fileSource, $fileTarget, $permissions, $token, $expiration, + $parent) { + $qb = $this->dbConn->getQueryBuilder(); + $qb->insert('share'); + + if ($shareType) { + $qb->setValue('share_type', $qb->expr()->literal($shareType)); + } + if ($sharedWith) { + $qb->setValue('share_with', $qb->expr()->literal($sharedWith)); + } + if ($sharedBy) { + $qb->setValue('uid_initiator', $qb->expr()->literal($sharedBy)); + } + if ($shareOwner) { + $qb->setValue('uid_owner', $qb->expr()->literal($shareOwner)); + } + if ($itemType) { + $qb->setValue('item_type', $qb->expr()->literal($itemType)); + } + if ($fileSource) { + $qb->setValue('file_source', $qb->expr()->literal($fileSource)); + } + if ($fileTarget) { + $qb->setValue('file_target', $qb->expr()->literal($fileTarget)); + } + if ($permissions) { + $qb->setValue('permissions', $qb->expr()->literal($permissions)); + } + if ($token) { + $qb->setValue('token', $qb->expr()->literal($token)); + } + if ($expiration) { + $qb->setValue('expiration', $qb->createNamedParameter($expiration, IQueryBuilder::PARAM_DATE)); + } + if ($parent) { + $qb->setValue('parent', $qb->expr()->literal($parent)); + } + + $this->assertEquals(1, $qb->execute()); + return $qb->getLastInsertId(); + } + + public function testGetSharesByWithResharesAndNoNode() { + $this->addShareToDB( + IShare::TYPE_EMAIL, + 'external.one@domain.tld', + 'user1', + 'user1', + 'folder', + 42, + null, + 17, + 'foobar', + null, + null, + ); + $this->addShareToDB( + IShare::TYPE_EMAIL, + 'external.two@domain.tld', + 'user2', + 'user2', + 'folder', + 42, + null, + 17, + 'barfoo', + null, + null, + ); + + // Return own shares only if not asked for a specific node + /** @var IShare[] $actual */ + $actual = $this->provider->getSharesBy( + 'user1', + IShare::TYPE_EMAIL, + null, + true, + -1, + 0, + ); + + $this->assertCount(1, $actual); + + $this->assertEquals(IShare::TYPE_EMAIL, $actual[0]->getShareType()); + $this->assertEquals('user1', $actual[0]->getSharedBy()); + $this->assertEquals('user1', $actual[0]->getShareOwner()); + $this->assertEquals('external.one@domain.tld', $actual[0]->getSharedWith()); + } + + public function testGetSharesByWithResharesAndNode() { + $this->addShareToDB( + IShare::TYPE_EMAIL, + 'external.one@domain.tld', + 'user1', + 'user1', + 'folder', + 42, + null, + 17, + 'foobar', + null, + null, + ); + $this->addShareToDB( + IShare::TYPE_EMAIL, + 'external.two@domain.tld', + 'user2', + 'user2', + 'folder', + 42, + null, + 17, + 'barfoo', + null, + null, + ); + + $node = $this->createMock(Node::class); + $node->expects($this->once()) + ->method('getId') + ->willReturn(42); + + // Return all shares if asked for specific node + /** @var IShare[] $actual */ + $actual = $this->provider->getSharesBy( + 'user1', + IShare::TYPE_EMAIL, + $node, + true, + -1, + 0, + ); + + $this->assertCount(2, $actual); + + $this->assertEquals(IShare::TYPE_EMAIL, $actual[0]->getShareType()); + $this->assertEquals('user1', $actual[0]->getSharedBy()); + $this->assertEquals('user1', $actual[0]->getShareOwner()); + $this->assertEquals('external.one@domain.tld', $actual[0]->getSharedWith()); + + $this->assertEquals(IShare::TYPE_EMAIL, $actual[1]->getShareType()); + $this->assertEquals('user2', $actual[1]->getSharedBy()); + $this->assertEquals('user2', $actual[1]->getShareOwner()); + $this->assertEquals('external.two@domain.tld', $actual[1]->getSharedWith()); + } +} diff --git a/tests/lib/UrlGeneratorTest.php b/tests/lib/UrlGeneratorTest.php index 9e5795fc41e..7fdbb7fb37e 100644 --- a/tests/lib/UrlGeneratorTest.php +++ b/tests/lib/UrlGeneratorTest.php @@ -297,7 +297,7 @@ class UrlGeneratorTest extends \Test\TestCase { $this->assertEquals('http://localhost' . \OC::$WEBROOT . $expectedPath, $this->urlGenerator->linkToDefaultPageUrl()); } - public function provideDefaultApps() { + public function provideDefaultApps(): array { return [ // none specified, default to files [ @@ -321,4 +321,18 @@ class UrlGeneratorTest extends \Test\TestCase { ], ]; } + + public function imagePathProvider(): array { + return [ + ['core', 'favicon-mask.svg', \OC::$WEBROOT . '/core/img/favicon-mask.svg'], + ['files', 'external.svg', \OC::$WEBROOT . '/apps/files/img/external.svg'], + ]; + } + + /** + * @dataProvider imagePathProvider + */ + public function testImagePath(string $appName, string $file, string $result): void { + $this->assertSame($result, $this->urlGenerator->imagePath($appName, $file)); + } } diff --git a/tests/lib/User/ManagerTest.php b/tests/lib/User/ManagerTest.php index 26fc39a1e31..cef578e9555 100644 --- a/tests/lib/User/ManagerTest.php +++ b/tests/lib/User/ManagerTest.php @@ -608,7 +608,7 @@ class ManagerTest extends TestCase { public function testCountUsersOnlySeen() { $manager = \OC::$server->getUserManager(); // count other users in the db before adding our own - $countBefore = $manager->countUsers(true); + $countBefore = $manager->countSeenUsers(); //Add test users $user1 = $manager->createUser('testseencount1', 'testseencount1'); @@ -622,7 +622,7 @@ class ManagerTest extends TestCase { $user4 = $manager->createUser('testseencount4', 'testseencount4'); $user4->updateLastLoginTimestamp(); - $this->assertEquals($countBefore + 3, $manager->countUsers(true)); + $this->assertEquals($countBefore + 3, $manager->countSeenUsers()); //cleanup $user1->delete(); diff --git a/tests/lib/User/SessionTest.php b/tests/lib/User/SessionTest.php index 0e199e5d5b5..735a3b3d06a 100644 --- a/tests/lib/User/SessionTest.php +++ b/tests/lib/User/SessionTest.php @@ -43,6 +43,8 @@ use OC\Security\CSRF\CsrfTokenManager; class SessionTest extends \Test\TestCase { /** @var ITimeFactory|MockObject */ private $timeFactory; + /** @var IProvider|MockObject */ + private $tokenProvider; /** @var IConfig|MockObject */ private $config; /** @var Throttler|MockObject */ diff --git a/tests/lib/User/UserTest.php b/tests/lib/User/UserTest.php index 7fab7ececca..cc65fbf3356 100644 --- a/tests/lib/User/UserTest.php +++ b/tests/lib/User/UserTest.php @@ -16,6 +16,7 @@ use OC\User\User; use OCP\Comments\ICommentsManager; use OCP\Files\Storage\IStorageFactory; use OCP\IConfig; +use OCP\IURLGenerator; use OCP\IUser; use OCP\Notification\IManager as INotificationManager; use OCP\Notification\INotification; @@ -43,7 +44,7 @@ class UserTest extends TestCase { public function testDisplayName() { /** - * @var \OC\User\Backend | \PHPUnit\Framework\MockObject\MockObject $backend + * @var \OC\User\Backend | MockObject $backend */ $backend = $this->createMock(\OC\User\Backend::class); $backend->expects($this->once()) @@ -65,7 +66,7 @@ class UserTest extends TestCase { */ public function testDisplayNameEmpty() { /** - * @var \OC\User\Backend | \PHPUnit\Framework\MockObject\MockObject $backend + * @var \OC\User\Backend | MockObject $backend */ $backend = $this->createMock(\OC\User\Backend::class); $backend->expects($this->once()) @@ -84,7 +85,7 @@ class UserTest extends TestCase { public function testDisplayNameNotSupported() { /** - * @var \OC\User\Backend | \PHPUnit\Framework\MockObject\MockObject $backend + * @var \OC\User\Backend | MockObject $backend */ $backend = $this->createMock(\OC\User\Backend::class); $backend->expects($this->never()) @@ -101,7 +102,7 @@ class UserTest extends TestCase { public function testSetPassword() { /** - * @var Backend | \PHPUnit\Framework\MockObject\MockObject $backend + * @var Backend | MockObject $backend */ $backend = $this->createMock(\Test\Util\User\Dummy::class); $backend->expects($this->once()) @@ -124,7 +125,7 @@ class UserTest extends TestCase { public function testSetPasswordNotSupported() { /** - * @var Backend | \PHPUnit\Framework\MockObject\MockObject $backend + * @var Backend | MockObject $backend */ $backend = $this->createMock(\Test\Util\User\Dummy::class); $backend->expects($this->never()) @@ -140,7 +141,7 @@ class UserTest extends TestCase { public function testChangeAvatarSupportedYes() { /** - * @var Backend | \PHPUnit\Framework\MockObject\MockObject $backend + * @var Backend | MockObject $backend */ $backend = $this->createMock(AvatarUserDummy::class); $backend->expects($this->once()) @@ -164,7 +165,7 @@ class UserTest extends TestCase { public function testChangeAvatarSupportedNo() { /** - * @var Backend | \PHPUnit\Framework\MockObject\MockObject $backend + * @var Backend | MockObject $backend */ $backend = $this->createMock(AvatarUserDummy::class); $backend->expects($this->once()) @@ -188,7 +189,7 @@ class UserTest extends TestCase { public function testChangeAvatarNotSupported() { /** - * @var Backend | \PHPUnit\Framework\MockObject\MockObject $backend + * @var Backend | MockObject $backend */ $backend = $this->createMock(AvatarUserDummy::class); $backend->expects($this->never()) @@ -204,7 +205,7 @@ class UserTest extends TestCase { public function testDelete() { /** - * @var Backend | \PHPUnit\Framework\MockObject\MockObject $backend + * @var Backend | MockObject $backend */ $backend = $this->createMock(\Test\Util\User\Dummy::class); $backend->expects($this->once()) @@ -227,11 +228,11 @@ class UserTest extends TestCase { } /** - * @var Backend | \PHPUnit\Framework\MockObject\MockObject $backend + * @var Backend | MockObject $backend */ $backend = $this->createMock(\Test\Util\User\Dummy::class); - $backend->expects($this->at(0)) + $backend->expects($this->once()) ->method('implementsActions') ->willReturnCallback(function ($actions) { if ($actions === \OC\User\Backend::GET_HOME) { @@ -244,12 +245,12 @@ class UserTest extends TestCase { // important: getHome MUST be called before deleteUser because // once the user is deleted, getHome implementations might not // return anything - $backend->expects($this->at(1)) + $backend->expects($this->once()) ->method('getHome') ->with($this->equalTo('foo')) ->willReturn('/home/foo'); - $backend->expects($this->at(2)) + $backend->expects($this->once()) ->method('deleteUser') ->with($this->equalTo('foo')); @@ -259,7 +260,7 @@ class UserTest extends TestCase { public function testGetHome() { /** - * @var Backend | \PHPUnit\Framework\MockObject\MockObject $backend + * @var Backend | MockObject $backend */ $backend = $this->createMock(\Test\Util\User\Dummy::class); $backend->expects($this->once()) @@ -290,7 +291,7 @@ class UserTest extends TestCase { public function testGetHomeNotSupported() { /** - * @var Backend | \PHPUnit\Framework\MockObject\MockObject $backend + * @var Backend | MockObject $backend */ $backend = $this->createMock(\Test\Util\User\Dummy::class); $backend->expects($this->never()) @@ -317,7 +318,7 @@ class UserTest extends TestCase { public function testCanChangePassword() { /** - * @var Backend | \PHPUnit\Framework\MockObject\MockObject $backend + * @var Backend | MockObject $backend */ $backend = $this->createMock(\Test\Util\User\Dummy::class); @@ -337,7 +338,7 @@ class UserTest extends TestCase { public function testCanChangePasswordNotSupported() { /** - * @var Backend | \PHPUnit\Framework\MockObject\MockObject $backend + * @var Backend | MockObject $backend */ $backend = $this->createMock(\Test\Util\User\Dummy::class); @@ -351,7 +352,7 @@ class UserTest extends TestCase { public function testCanChangeDisplayName() { /** - * @var Backend | \PHPUnit\Framework\MockObject\MockObject $backend + * @var Backend | MockObject $backend */ $backend = $this->createMock(\Test\Util\User\Dummy::class); @@ -371,7 +372,7 @@ class UserTest extends TestCase { public function testCanChangeDisplayNameNotSupported() { /** - * @var Backend | \PHPUnit\Framework\MockObject\MockObject $backend + * @var Backend | MockObject $backend */ $backend = $this->createMock(\Test\Util\User\Dummy::class); @@ -385,7 +386,7 @@ class UserTest extends TestCase { public function testSetDisplayNameSupported() { /** - * @var Backend | \PHPUnit\Framework\MockObject\MockObject $backend + * @var Backend | MockObject $backend */ $backend = $this->createMock(\OC\User\Database::class); @@ -414,7 +415,7 @@ class UserTest extends TestCase { */ public function testSetDisplayNameEmpty() { /** - * @var Backend | \PHPUnit\Framework\MockObject\MockObject $backend + * @var Backend | MockObject $backend */ $backend = $this->createMock(\OC\User\Database::class); @@ -435,7 +436,7 @@ class UserTest extends TestCase { public function testSetDisplayNameNotSupported() { /** - * @var Backend | \PHPUnit\Framework\MockObject\MockObject $backend + * @var Backend | MockObject $backend */ $backend = $this->createMock(\OC\User\Database::class); @@ -456,7 +457,7 @@ class UserTest extends TestCase { $test = $this; /** - * @var Backend | \PHPUnit\Framework\MockObject\MockObject $backend + * @var Backend | MockObject $backend */ $backend = $this->createMock(\Test\Util\User\Dummy::class); $backend->expects($this->once()) @@ -509,7 +510,7 @@ class UserTest extends TestCase { $test = $this; /** - * @var Backend | \PHPUnit\Framework\MockObject\MockObject $backend + * @var Backend | MockObject $backend */ $backend = $this->createMock(\Test\Util\User\Dummy::class); $backend->expects($this->once()) @@ -587,26 +588,30 @@ class UserTest extends TestCase { $this->assertEquals($expectedHooks, $hooksCalled); } - public function testGetCloudId() { - /** - * @var Backend | \PHPUnit\Framework\MockObject\MockObject $backend - */ + public function dataGetCloudId(): array { + return [ + ['https://localhost:8888/nextcloud', 'foo@localhost:8888/nextcloud'], + ['http://localhost:8888/nextcloud', 'foo@http://localhost:8888/nextcloud'], + ]; + } + + /** + * @dataProvider dataGetCloudId + */ + public function testGetCloudId(string $absoluteUrl, string $cloudId): void { + /** @var Backend|MockObject $backend */ $backend = $this->createMock(\Test\Util\User\Dummy::class); - $urlGenerator = $this->getMockBuilder('\OC\URLGenerator') - ->setMethods(['getAbsoluteURL']) - ->disableOriginalConstructor()->getMock(); - $urlGenerator - ->expects($this->any()) - ->method('getAbsoluteURL') - ->withAnyParameters() - ->willReturn('http://localhost:8888/owncloud'); + $urlGenerator = $this->createMock(IURLGenerator::class); + $urlGenerator->method('getAbsoluteURL') + ->withAnyParameters() + ->willReturn($absoluteUrl); $user = new User('foo', $backend, $this->dispatcher, null, null, $urlGenerator); - $this->assertEquals('foo@localhost:8888/owncloud', $user->getCloudId()); + $this->assertEquals($cloudId, $user->getCloudId()); } public function testSetEMailAddressEmpty() { /** - * @var Backend | \PHPUnit\Framework\MockObject\MockObject $backend + * @var Backend | MockObject $backend */ $backend = $this->createMock(\Test\Util\User\Dummy::class); @@ -642,7 +647,7 @@ class UserTest extends TestCase { public function testSetEMailAddress() { /** - * @var UserInterface | \PHPUnit\Framework\MockObject\MockObject $backend + * @var UserInterface | MockObject $backend */ $backend = $this->createMock(\Test\Util\User\Dummy::class); @@ -679,11 +684,11 @@ class UserTest extends TestCase { public function testSetEMailAddressNoChange() { /** - * @var UserInterface | \PHPUnit\Framework\MockObject\MockObject $backend + * @var UserInterface | MockObject $backend */ $backend = $this->createMock(\Test\Util\User\Dummy::class); - /** @var PublicEmitter|\PHPUnit\Framework\MockObject\MockObject $emitter */ + /** @var PublicEmitter|MockObject $emitter */ $emitter = $this->createMock(PublicEmitter::class); $emitter->expects($this->never()) ->method('emit'); @@ -704,7 +709,7 @@ class UserTest extends TestCase { public function testSetQuota() { /** - * @var UserInterface | \PHPUnit\Framework\MockObject\MockObject $backend + * @var UserInterface | MockObject $backend */ $backend = $this->createMock(\Test\Util\User\Dummy::class); @@ -741,11 +746,11 @@ class UserTest extends TestCase { public function testGetDefaultUnlimitedQuota() { /** - * @var UserInterface | \PHPUnit\Framework\MockObject\MockObject $backend + * @var UserInterface | MockObject $backend */ $backend = $this->createMock(\Test\Util\User\Dummy::class); - /** @var PublicEmitter|\PHPUnit\Framework\MockObject\MockObject $emitter */ + /** @var PublicEmitter|MockObject $emitter */ $emitter = $this->createMock(PublicEmitter::class); $emitter->expects($this->never()) ->method('emit'); @@ -772,11 +777,11 @@ class UserTest extends TestCase { public function testGetDefaultUnlimitedQuotaForbidden() { /** - * @var UserInterface | \PHPUnit\Framework\MockObject\MockObject $backend + * @var UserInterface | MockObject $backend */ $backend = $this->createMock(\Test\Util\User\Dummy::class); - /** @var PublicEmitter|\PHPUnit\Framework\MockObject\MockObject $emitter */ + /** @var PublicEmitter|MockObject $emitter */ $emitter = $this->createMock(PublicEmitter::class); $emitter->expects($this->never()) ->method('emit'); @@ -806,11 +811,11 @@ class UserTest extends TestCase { public function testSetQuotaAddressNoChange() { /** - * @var UserInterface | \PHPUnit\Framework\MockObject\MockObject $backend + * @var UserInterface | MockObject $backend */ $backend = $this->createMock(\Test\Util\User\Dummy::class); - /** @var PublicEmitter|\PHPUnit\Framework\MockObject\MockObject $emitter */ + /** @var PublicEmitter|MockObject $emitter */ $emitter = $this->createMock(PublicEmitter::class); $emitter->expects($this->never()) ->method('emit'); @@ -828,7 +833,7 @@ class UserTest extends TestCase { public function testGetLastLogin() { /** - * @var Backend | \PHPUnit\Framework\MockObject\MockObject $backend + * @var Backend | MockObject $backend */ $backend = $this->createMock(\Test\Util\User\Dummy::class); @@ -848,7 +853,7 @@ class UserTest extends TestCase { public function testSetEnabled() { /** - * @var Backend | \PHPUnit\Framework\MockObject\MockObject $backend + * @var Backend | MockObject $backend */ $backend = $this->createMock(\Test\Util\User\Dummy::class); @@ -868,7 +873,7 @@ class UserTest extends TestCase { public function testSetDisabled() { /** - * @var Backend | \PHPUnit\Framework\MockObject\MockObject $backend + * @var Backend | MockObject $backend */ $backend = $this->createMock(\Test\Util\User\Dummy::class); @@ -908,7 +913,7 @@ class UserTest extends TestCase { public function testSetDisabledAlreadyDisabled() { /** - * @var Backend | \PHPUnit\Framework\MockObject\MockObject $backend + * @var Backend | MockObject $backend */ $backend = $this->createMock(\Test\Util\User\Dummy::class); @@ -938,7 +943,7 @@ class UserTest extends TestCase { public function testGetEMailAddress() { /** - * @var Backend | \PHPUnit\Framework\MockObject\MockObject $backend + * @var Backend | MockObject $backend */ $backend = $this->createMock(\Test\Util\User\Dummy::class); |