nextcloud /
richdocuments
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * @copyright Copyright (c) 2017 Lukas Reschke <[email protected]> |
||
| 4 | * |
||
| 5 | * @license GNU AGPL version 3 or any later version |
||
| 6 | * |
||
| 7 | * This program is free software: you can redistribute it and/or modify |
||
| 8 | * it under the terms of the GNU Affero General Public License as |
||
| 9 | * published by the Free Software Foundation, either version 3 of the |
||
| 10 | * License, or (at your option) any later version. |
||
| 11 | * |
||
| 12 | * This program is distributed in the hope that it will be useful, |
||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 15 | * GNU Affero General Public License for more details. |
||
| 16 | * |
||
| 17 | * You should have received a copy of the GNU Affero General Public License |
||
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
| 19 | * |
||
| 20 | */ |
||
| 21 | |||
| 22 | namespace Tests\Richdocuments; |
||
| 23 | |||
| 24 | use OCA\Richdocuments\PermissionManager; |
||
| 25 | use OCP\IConfig; |
||
| 26 | use OCP\IGroupManager; |
||
| 27 | use OCP\IUser; |
||
| 28 | use PHPUnit\Framework\MockObject\MockBuilder; |
||
| 29 | use PHPUnit\Framework\MockObject\MockObject; |
||
| 30 | use Test\TestCase; |
||
| 31 | |||
| 32 | class PermissionManagerTest extends TestCase { |
||
| 33 | /** @var IConfig|MockObject */ |
||
| 34 | private $config; |
||
| 35 | /** @var IGroupManager|MockObject */ |
||
| 36 | private $groupManager; |
||
| 37 | /** @var PermissionManager */ |
||
| 38 | private $permissionManager; |
||
| 39 | |||
| 40 | public function setUp(): void { |
||
| 41 | parent::setUp(); |
||
| 42 | $this->config = $this->createMock(IConfig::class); |
||
| 43 | $this->groupManager = $this->createMock(IGroupManager::class); |
||
| 44 | $this->permissionManager = new PermissionManager($this->config, $this->groupManager); |
||
| 45 | } |
||
| 46 | |||
| 47 | public function testIsEnabledForUserEnabledNoRestrictions() { |
||
| 48 | /** @var IUser|MockObject $user */ |
||
| 49 | $user = $this->createMock(IUser::class); |
||
| 50 | |||
| 51 | $this->config |
||
|
0 ignored issues
–
show
|
|||
| 52 | ->expects($this->once()) |
||
| 53 | ->method('getAppValue') |
||
| 54 | ->with('richdocuments', 'use_groups', '') |
||
| 55 | ->willReturn(''); |
||
| 56 | |||
| 57 | $this->assertTrue($this->permissionManager->isEnabledForUser($user)); |
||
| 58 | } |
||
| 59 | |||
| 60 | public function testIsEnabledForUserEnabledNotInGroup() { |
||
| 61 | /** @var IUser|MockBuilder $user */ |
||
| 62 | $user = $this->createMock(IUser::class); |
||
| 63 | $user |
||
|
0 ignored issues
–
show
The method
expects() does not seem to exist on object<OCP\IUser>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 64 | ->expects($this->once()) |
||
| 65 | ->method('getUID') |
||
| 66 | ->willReturn('TestUser'); |
||
| 67 | |||
| 68 | $this->config |
||
|
0 ignored issues
–
show
The method
expects() does not seem to exist on object<OCP\IConfig>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 69 | ->expects($this->once()) |
||
| 70 | ->method('getAppValue') |
||
| 71 | ->with('richdocuments', 'use_groups', '') |
||
| 72 | ->willReturn('Enabled1|Enabled2|Enabled3'); |
||
| 73 | |||
| 74 | $this->groupManager |
||
|
0 ignored issues
–
show
The method
expects() does not seem to exist on object<OCP\IGroupManager>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 75 | ->expects($this->at(0)) |
||
| 76 | ->method('isInGroup') |
||
| 77 | ->with('TestUser', 'Enabled1') |
||
| 78 | ->willReturn(false); |
||
| 79 | $this->groupManager |
||
|
0 ignored issues
–
show
The method
expects() does not seem to exist on object<OCP\IGroupManager>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 80 | ->expects($this->at(1)) |
||
| 81 | ->method('isInGroup') |
||
| 82 | ->with('TestUser', 'Enabled2') |
||
| 83 | ->willReturn(false); |
||
| 84 | $this->groupManager |
||
|
0 ignored issues
–
show
The method
expects() does not seem to exist on object<OCP\IGroupManager>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 85 | ->expects($this->at(2)) |
||
| 86 | ->method('isInGroup') |
||
| 87 | ->with('TestUser', 'Enabled3') |
||
| 88 | ->willReturn(false); |
||
| 89 | |||
| 90 | $this->assertFalse($this->permissionManager->isEnabledForUser($user)); |
||
| 91 | } |
||
| 92 | |||
| 93 | public function testIsEnabledForUserEnabledInGroup() { |
||
| 94 | /** @var IUser|MockObject $user */ |
||
| 95 | $user = $this->createMock(IUser::class); |
||
| 96 | $user |
||
|
0 ignored issues
–
show
The method
expects() does not seem to exist on object<OCP\IUser>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 97 | ->expects($this->once()) |
||
| 98 | ->method('getUID') |
||
| 99 | ->willReturn('TestUser'); |
||
| 100 | |||
| 101 | $this->config |
||
|
0 ignored issues
–
show
The method
expects() does not seem to exist on object<OCP\IConfig>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 102 | ->expects($this->once()) |
||
| 103 | ->method('getAppValue') |
||
| 104 | ->with('richdocuments', 'use_groups', '') |
||
| 105 | ->willReturn('Enabled1|Enabled2|Enabled3'); |
||
| 106 | |||
| 107 | $this->groupManager |
||
|
0 ignored issues
–
show
The method
expects() does not seem to exist on object<OCP\IGroupManager>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 108 | ->expects($this->at(0)) |
||
| 109 | ->method('isInGroup') |
||
| 110 | ->with('TestUser', 'Enabled1') |
||
| 111 | ->willReturn(false); |
||
| 112 | $this->groupManager |
||
|
0 ignored issues
–
show
The method
expects() does not seem to exist on object<OCP\IGroupManager>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 113 | ->expects($this->at(1)) |
||
| 114 | ->method('isInGroup') |
||
| 115 | ->with('TestUser', 'Enabled2') |
||
| 116 | ->willReturn(true); |
||
| 117 | |||
| 118 | $this->assertTrue($this->permissionManager->isEnabledForUser($user)); |
||
| 119 | } |
||
| 120 | } |
||
| 121 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.