aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/InfoXmlTest.php
blob: 4e75ca7820353db53a5fa667969df111bb745707 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
/**
 * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
 *
 * @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 <http://www.gnu.org/licenses/>.
 *
 */

namespace Test;


/**
 * Class InfoXmlTest
 *
 * @group DB
 * @package Test
 */
class InfoXmlTest extends TestCase {

	public function dataApps() {
		return [
			['admin_audit'],
			['comments'],
			['dav'],
			['encryption'],
			['federatedfilesharing'],
			['federation'],
			['files'],
			['files_external'],
			['files_sharing'],
			['files_trashbin'],
			['files_versions'],
			['provisioning_api'],
			['systemtags'],
			['theming'],
			['twofactor_backupcodes'],
			['updatenotification'],
			['user_ldap'],
			['workflowengine'],
		];
	}

	/**
	 * @dataProvider dataApps
	 *
	 * @param string $app
	 */
	public function testClasses($app) {
		$appInfo = \OC_App::getAppInfo($app);
		$appPath = \OC_App::getAppPath($app);
		\OC_App::registerAutoloading($app, $appPath);

		if (isset($appInfo['background-jobs'])) {
			foreach ($appInfo['background-jobs'] as $job) {
				$this->assertTrue(class_exists($job), 'Asserting background job "' . $job . '" exists');
				$this->assertInstanceOf($job, \OC::$server->query($job));
			}
		}

		if (isset($appInfo['two-factor-providers'])) {
			foreach ($appInfo['two-factor-providers'] as $provider) {
				$this->assertTrue(class_exists($provider), 'Asserting two-factor providers "' . $provider . '" exists');
				$this->assertInstanceOf($provider, \OC::$server->query($provider));
			}
		}

		if (isset($appInfo['commands'])) {
			foreach ($appInfo['commands'] as $command) {
				$this->assertTrue(class_exists($command), 'Asserting command "' . $command . '" exists');
				$this->assertInstanceOf($command, \OC::$server->query($command));
			}
		}

		if (isset($appInfo['repair-steps']['pre-migration'])) {
			foreach ($appInfo['repair-steps']['pre-migration'] as $migration) {
				$this->assertTrue(class_exists($migration), 'Asserting pre-migration "' . $migration . '" exists');
				$this->assertInstanceOf($migration, \OC::$server->query($migration));
			}
		}

		if (isset($appInfo['repair-steps']['post-migration'])) {
			foreach ($appInfo['repair-steps']['post-migration'] as $migration) {
				$this->assertTrue(class_exists($migration), 'Asserting post-migration "' . $migration . '" exists');
				$this->assertInstanceOf($migration, \OC::$server->query($migration));
			}
		}

		if (isset($appInfo['repair-steps']['live-migration'])) {
			foreach ($appInfo['repair-steps']['live-migration'] as $migration) {
				$this->assertTrue(class_exists($migration), 'Asserting live-migration "' . $migration . '" exists');
				$this->assertInstanceOf($migration, \OC::$server->query($migration));
			}
		}

		if (isset($appInfo['repair-steps']['install'])) {
			foreach ($appInfo['repair-steps']['install'] as $migration) {
				$this->assertTrue(class_exists($migration), 'Asserting install-migration "' . $migration . '" exists');
				$this->assertInstanceOf($migration, \OC::$server->query($migration));
			}
		}

		if (isset($appInfo['repair-steps']['uninstall'])) {
			foreach ($appInfo['repair-steps']['uninstall'] as $migration) {
				$this->assertTrue(class_exists($migration), 'Asserting uninstall-migration "' . $migration . '" exists');
				$this->assertInstanceOf($migration, \OC::$server->query($migration));
			}
		}

		if (isset($appInfo['commands'])) {
			foreach ($appInfo['commands'] as $command) {
				$this->assertTrue(class_exists($command), 'Asserting command "'. $command . '"exists');
				$this->assertInstanceOf($command, \OC::$server->query($command));
			}
		}
	}
}
p">{ if ($attr['key'] === $key && $attr['scope'] === $scope) { $result = $attr['value']; } } return $result; }) ); return $shareAttributes; } private function makeMockShare($id, $nodeId, $owner = 'user2', $target = null, $permissions = 31, $attributes = null) { $share = $this->createMock(IShare::class); $share->expects($this->any()) ->method('getPermissions') ->willReturn($permissions); $share->expects($this->any()) ->method('getAttributes') ->will($this->returnValue($this->makeMockShareAttributes($attributes))); $share->expects($this->any()) ->method('getShareOwner') ->willReturn($owner); $share->expects($this->any()) ->method('getTarget') ->willReturn($target); $share->expects($this->any()) ->method('getId') ->willReturn($id); $share->expects($this->any()) ->method('getNodeId') ->willReturn($nodeId); $share->expects($this->any()) ->method('getShareTime') ->willReturn( // compute share time based on id, simulating share order new \DateTime('@' . (1469193980 + 1000 * $id)) ); return $share; } /** * Tests excluding shares from the current view. This includes: * - shares that were opted out of (permissions === 0) * - shares with a group in which the owner is already in */ public function testExcludeShares(): void { $rootFolder = $this->createMock(IRootFolder::class); $userManager = $this->createMock(IUserManager::class); $attr1 = []; $attr2 = [['scope' => 'permission', 'key' => 'download', 'value' => true]]; $userShares = [ $this->makeMockShare(1, 100, 'user2', '/share2', 0, $attr1), $this->makeMockShare(2, 100, 'user2', '/share2', 31, $attr2), ]; $groupShares = [ $this->makeMockShare(3, 100, 'user2', '/share2', 0, $attr1), $this->makeMockShare(4, 101, 'user2', '/share4', 31, $attr2), $this->makeMockShare(5, 100, 'user1', '/share4', 31, $attr2), ]; $roomShares = [ $this->makeMockShare(6, 102, 'user2', '/share6', 0), $this->makeMockShare(7, 102, 'user1', '/share6', 31), $this->makeMockShare(8, 102, 'user2', '/share6', 31), $this->makeMockShare(9, 102, 'user2', '/share6', 31), ]; $deckShares = [ $this->makeMockShare(10, 103, 'user2', '/share7', 0), $this->makeMockShare(11, 103, 'user1', '/share7', 31), $this->makeMockShare(12, 103, 'user2', '/share7', 31), $this->makeMockShare(13, 103, 'user2', '/share7', 31), ]; // tests regarding circles and sciencemesh are made in the apps themselves. $circleShares = []; $scienceMeshShares = []; $this->user->expects($this->any()) ->method('getUID') ->willReturn('user1'); $this->shareManager->expects($this->exactly(6)) ->method('getSharedWith') ->willReturnMap([ ['user1', IShare::TYPE_USER, null, -1, 0, $userShares], ['user1', IShare::TYPE_GROUP, null, -1, 0, $groupShares], ['user1', IShare::TYPE_CIRCLE, null, -1, 0, $circleShares], ['user1', IShare::TYPE_ROOM, null, -1, 0, $roomShares], ['user1', IShare::TYPE_DECK, null, -1, 0, $deckShares], ['user1', IShare::TYPE_SCIENCEMESH, null, -1, 0, $scienceMeshShares], ]); $this->shareManager->expects($this->any()) ->method('newShare') ->willReturnCallback(function () use ($rootFolder, $userManager) { return new Share($rootFolder, $userManager); }); $mounts = $this->provider->getMountsForUser($this->user, $this->loader); $this->assertCount(4, $mounts); $this->assertInstanceOf('OCA\Files_Sharing\SharedMount', $mounts[0]); $this->assertInstanceOf('OCA\Files_Sharing\SharedMount', $mounts[1]); $this->assertInstanceOf('OCA\Files_Sharing\SharedMount', $mounts[2]); $this->assertInstanceOf('OCA\Files_Sharing\SharedMount', $mounts[3]); /** @var OCA\Files_Sharing\SharedMount[] $mounts */ $mountedShare1 = $mounts[0]->getShare(); $this->assertEquals('2', $mountedShare1->getId()); $this->assertEquals('user2', $mountedShare1->getShareOwner()); $this->assertEquals(100, $mountedShare1->getNodeId()); $this->assertEquals('/share2', $mountedShare1->getTarget()); $this->assertEquals(31, $mountedShare1->getPermissions()); $this->assertEquals(true, $mountedShare1->getAttributes()->getAttribute('permission', 'download')); $mountedShare2 = $mounts[1]->getShare(); $this->assertEquals('4', $mountedShare2->getId()); $this->assertEquals('user2', $mountedShare2->getShareOwner()); $this->assertEquals(101, $mountedShare2->getNodeId()); $this->assertEquals('/share4', $mountedShare2->getTarget()); $this->assertEquals(31, $mountedShare2->getPermissions()); $this->assertEquals(true, $mountedShare2->getAttributes()->getAttribute('permission', 'download')); $mountedShare3 = $mounts[2]->getShare(); $this->assertEquals('8', $mountedShare3->getId()); $this->assertEquals('user2', $mountedShare3->getShareOwner()); $this->assertEquals(102, $mountedShare3->getNodeId()); $this->assertEquals('/share6', $mountedShare3->getTarget()); $this->assertEquals(31, $mountedShare3->getPermissions()); $mountedShare4 = $mounts[3]->getShare(); $this->assertEquals('12', $mountedShare4->getId()); $this->assertEquals('user2', $mountedShare4->getShareOwner()); $this->assertEquals(103, $mountedShare4->getNodeId()); $this->assertEquals('/share7', $mountedShare4->getTarget()); $this->assertEquals(31, $mountedShare4->getPermissions()); } public static function mergeSharesDataProvider(): array { // note: the user in the specs here is the shareOwner not recipient // the recipient is always "user1" return [ // #0: share as outsider with "group1" and "user1" with same permissions [ [ [1, 100, 'user2', '/share2', 31, null], ], [ [2, 100, 'user2', '/share2', 31, null], ], [ // combined, user share has higher priority ['1', 100, 'user2', '/share2', 31, []], ], ], // #1: share as outsider with "group1" and "user1" with different permissions [ [ [1, 100, 'user2', '/share', 31, [['scope' => 'permission', 'key' => 'download', 'value' => true], ['scope' => 'app', 'key' => 'attribute1', 'value' => true]]], ], [ [2, 100, 'user2', '/share', 15, [['scope' => 'permission', 'key' => 'download', 'value' => false], ['scope' => 'app', 'key' => 'attribute2', 'value' => false]]], ], [ // use highest permissions ['1', 100, 'user2', '/share', 31, [['scope' => 'permission', 'key' => 'download', 'value' => true], ['scope' => 'app', 'key' => 'attribute1', 'value' => true], ['scope' => 'app', 'key' => 'attribute2', 'value' => false]]], ], ], // #2: share as outsider with "group1" and "group2" with same permissions [ [ ], [ [1, 100, 'user2', '/share', 31, null], [2, 100, 'user2', '/share', 31, []], ], [ // combined, first group share has higher priority ['1', 100, 'user2', '/share', 31, []], ], ], // #3: share as outsider with "group1" and "group2" with different permissions [ [ ], [ [1, 100, 'user2', '/share', 31, [['scope' => 'permission', 'key' => 'download', 'value' => false]]], [2, 100, 'user2', '/share', 15, [['scope' => 'permission', 'key' => 'download', 'value' => true]]], ], [ // use higher permissions (most permissive) ['1', 100, 'user2', '/share', 31, [['scope' => 'permission', 'key' => 'download', 'value' => true]]], ], ], // #4: share as insider with "group1" [ [ ], [ [1, 100, 'user1', '/share', 31, []], ], [ // no received share since "user1" is the sharer/owner ], ], // #5: share as insider with "group1" and "group2" with different permissions [ [ ], [ [1, 100, 'user1', '/share', 31, [['scope' => 'permission', 'key' => 'download', 'value' => true]]], [2, 100, 'user1', '/share', 15, [['scope' => 'permission', 'key' => 'download', 'value' => false]]], ], [ // no received share since "user1" is the sharer/owner ], ], // #6: share as outside with "group1", recipient opted out [ [ ], [ [1, 100, 'user2', '/share', 0, []], ], [ // no received share since "user1" opted out ], ], // #7: share as outsider with "group1" and "user1" where recipient renamed in between [ [ [1, 100, 'user2', '/share2-renamed', 31, []], ], [ [2, 100, 'user2', '/share2', 31, []], ], [ // use target of least recent share ['1', 100, 'user2', '/share2-renamed', 31, []], ], ], // #8: share as outsider with "group1" and "user1" where recipient renamed in between [ [ [2, 100, 'user2', '/share2', 31, []], ], [ [1, 100, 'user2', '/share2-renamed', 31, []], ], [ // use target of least recent share ['1', 100, 'user2', '/share2-renamed', 31, []], ], ], // #9: share as outsider with "nullgroup" and "user1" where recipient renamed in between [ [ [2, 100, 'user2', '/share2', 31, []], ], [ [1, 100, 'nullgroup', '/share2-renamed', 31, []], ], [ // use target of least recent share ['1', 100, 'nullgroup', '/share2-renamed', 31, []], ], true ], ]; } /** * Tests merging shares. * * Happens when sharing the same entry to a user through multiple ways, * like several groups and also direct shares at the same time. * * @dataProvider mergeSharesDataProvider * * @param array $userShares array of user share specs * @param array $groupShares array of group share specs * @param array $expectedShares array of expected supershare specs */ public function testMergeShares($userShares, $groupShares, $expectedShares, $moveFails = false): void { $rootFolder = $this->createMock(IRootFolder::class); $userManager = $this->createMock(IUserManager::class); $userShares = array_map(function ($shareSpec) { return $this->makeMockShare($shareSpec[0], $shareSpec[1], $shareSpec[2], $shareSpec[3], $shareSpec[4], $shareSpec[5]); }, $userShares); $groupShares = array_map(function ($shareSpec) { return $this->makeMockShare($shareSpec[0], $shareSpec[1], $shareSpec[2], $shareSpec[3], $shareSpec[4], $shareSpec[5]); }, $groupShares); $this->user->expects($this->any()) ->method('getUID') ->willReturn('user1'); // tests regarding circles are made in the app itself. $circleShares = []; $roomShares = []; $deckShares = []; $scienceMeshShares = []; $this->shareManager->expects($this->exactly(6)) ->method('getSharedWith') ->willReturnMap([ ['user1', IShare::TYPE_USER, null, -1, 0, $userShares], ['user1', IShare::TYPE_GROUP, null, -1, 0, $groupShares], ['user1', IShare::TYPE_CIRCLE, null, -1, 0, $circleShares], ['user1', IShare::TYPE_ROOM, null, -1, 0, $roomShares], ['user1', IShare::TYPE_DECK, null, -1, 0, $deckShares], ['user1', IShare::TYPE_SCIENCEMESH, null, -1, 0, $scienceMeshShares], ]); $this->shareManager->expects($this->any()) ->method('newShare') ->willReturnCallback(function () use ($rootFolder, $userManager) { return new Share($rootFolder, $userManager); }); if ($moveFails) { $this->shareManager->expects($this->any()) ->method('moveShare') ->will($this->throwException(new \InvalidArgumentException())); } $mounts = $this->provider->getMountsForUser($this->user, $this->loader); $this->assertCount(count($expectedShares), $mounts); foreach ($mounts as $index => $mount) { $expectedShare = $expectedShares[$index]; $this->assertInstanceOf('OCA\Files_Sharing\SharedMount', $mount); // supershare /** @var OCA\Files_Sharing\SharedMount $mount */ $share = $mount->getShare(); $this->assertEquals($expectedShare[0], $share->getId()); $this->assertEquals($expectedShare[1], $share->getNodeId()); $this->assertEquals($expectedShare[2], $share->getShareOwner()); $this->assertEquals($expectedShare[3], $share->getTarget()); $this->assertEquals($expectedShare[4], $share->getPermissions()); if ($expectedShare[5] === null) { $this->assertNull($share->getAttributes()); } else { $this->assertEquals($expectedShare[5], $share->getAttributes()->toArray()); } } } }