1
0

SharingTest.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Bjoern Schiessle <bjoern@schiessle.org>
  7. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  8. * @author Daniel Kesselberg <mail@danielkesselberg.de>
  9. * @author Joas Schilling <coding@schilljs.com>
  10. * @author Lukas Reschke <lukas@statuscode.ch>
  11. * @author Morris Jobke <hey@morrisjobke.de>
  12. * @author Robin Appelman <robin@icewind.nl>
  13. * @author Roeland Jago Douma <roeland@famdouma.nl>
  14. * @author Vincent Petry <vincent@nextcloud.com>
  15. *
  16. * @license GNU AGPL version 3 or any later version
  17. *
  18. * This program is free software: you can redistribute it and/or modify
  19. * it under the terms of the GNU Affero General Public License as
  20. * published by the Free Software Foundation, either version 3 of the
  21. * License, or (at your option) any later version.
  22. *
  23. * This program is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU Affero General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU Affero General Public License
  29. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. *
  31. */
  32. namespace OCA\Settings\Tests\Settings\Admin;
  33. use OCA\Settings\Settings\Admin\Sharing;
  34. use OCP\App\IAppManager;
  35. use OCP\AppFramework\Http\TemplateResponse;
  36. use OCP\AppFramework\Services\IInitialState;
  37. use OCP\Constants;
  38. use OCP\IConfig;
  39. use OCP\IL10N;
  40. use OCP\IURLGenerator;
  41. use OCP\Share\IManager;
  42. use PHPUnit\Framework\MockObject\MockObject;
  43. use Test\TestCase;
  44. class SharingTest extends TestCase {
  45. /** @var Sharing */
  46. private $admin;
  47. /** @var IConfig */
  48. private $config;
  49. /** @var IL10N|MockObject */
  50. private $l10n;
  51. /** @var IManager|MockObject */
  52. private $shareManager;
  53. /** @var IAppManager|MockObject */
  54. private $appManager;
  55. /** @var IURLGenerator|MockObject */
  56. private $urlGenerator;
  57. /** @var IInitialState|MockObject */
  58. private $initialState;
  59. protected function setUp(): void {
  60. parent::setUp();
  61. /** @var IConfig|MockObject */
  62. $this->config = $this->getMockBuilder(IConfig::class)->getMock();
  63. /** @var IL10N|MockObject */
  64. $this->l10n = $this->getMockBuilder(IL10N::class)->getMock();
  65. /** @var IManager|MockObject */
  66. $this->shareManager = $this->getMockBuilder(IManager::class)->getMock();
  67. /** @var IAppManager|MockObject */
  68. $this->appManager = $this->getMockBuilder(IAppManager::class)->getMock();
  69. /** @var IURLGenerator|MockObject */
  70. $this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)->getMock();
  71. /** @var IInitialState|MockObject */
  72. $this->initialState = $this->getMockBuilder(IInitialState::class)->getMock();
  73. $this->admin = new Sharing(
  74. $this->config,
  75. $this->l10n,
  76. $this->shareManager,
  77. $this->appManager,
  78. $this->urlGenerator,
  79. $this->initialState,
  80. "settings",
  81. );
  82. }
  83. public function testGetFormWithoutExcludedGroups(): void {
  84. $this->config
  85. ->method('getAppValue')
  86. ->willReturnMap([
  87. ['core', 'shareapi_exclude_groups_list', '', ''],
  88. ['core', 'shareapi_allow_links_exclude_groups', '', ''],
  89. ['core', 'shareapi_allow_group_sharing', 'yes', 'yes'],
  90. ['core', 'shareapi_allow_links', 'yes', 'yes'],
  91. ['core', 'shareapi_allow_public_upload', 'yes', 'yes'],
  92. ['core', 'shareapi_allow_resharing', 'yes', 'yes'],
  93. ['core', 'shareapi_allow_share_dialog_user_enumeration', 'yes', 'yes'],
  94. ['core', 'shareapi_restrict_user_enumeration_to_group', 'no', 'no'],
  95. ['core', 'shareapi_restrict_user_enumeration_to_phone', 'no', 'no'],
  96. ['core', 'shareapi_restrict_user_enumeration_full_match', 'yes', 'yes'],
  97. ['core', 'shareapi_restrict_user_enumeration_full_match_userid', 'yes', 'yes'],
  98. ['core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes', 'yes'],
  99. ['core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn', 'no', 'no'],
  100. ['core', 'shareapi_enabled', 'yes', 'yes'],
  101. ['core', 'shareapi_default_expire_date', 'no', 'no'],
  102. ['core', 'shareapi_expire_after_n_days', '7', '7'],
  103. ['core', 'shareapi_enforce_expire_date', 'no', 'no'],
  104. ['core', 'shareapi_exclude_groups', 'no', 'no'],
  105. ['core', 'shareapi_public_link_disclaimertext', null, 'Lorem ipsum'],
  106. ['core', 'shareapi_enable_link_password_by_default', 'no', 'yes'],
  107. ['core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL, Constants::PERMISSION_ALL],
  108. ['core', 'shareapi_default_internal_expire_date', 'no', 'no'],
  109. ['core', 'shareapi_internal_expire_after_n_days', '7', '7'],
  110. ['core', 'shareapi_enforce_internal_expire_date', 'no', 'no'],
  111. ['core', 'shareapi_default_remote_expire_date', 'no', 'no'],
  112. ['core', 'shareapi_remote_expire_after_n_days', '7', '7'],
  113. ['core', 'shareapi_enforce_remote_expire_date', 'no', 'no'],
  114. ['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
  115. ]);
  116. $this->shareManager->method('shareWithGroupMembersOnly')
  117. ->willReturn(false);
  118. $this->appManager->method('isEnabledForUser')->with('files_sharing')->willReturn(false);
  119. $this->initialState
  120. ->expects($this->exactly(3))
  121. ->method('provideInitialState')
  122. ->withConsecutive(
  123. ['sharingAppEnabled', false],
  124. ['sharingDocumentation', ''],
  125. [
  126. 'sharingSettings',
  127. [
  128. 'allowGroupSharing' => true,
  129. 'allowLinks' => true,
  130. 'allowPublicUpload' => true,
  131. 'allowResharing' => true,
  132. 'allowShareDialogUserEnumeration' => true,
  133. 'restrictUserEnumerationToGroup' => false,
  134. 'restrictUserEnumerationToPhone' => false,
  135. 'restrictUserEnumerationFullMatch' => true,
  136. 'restrictUserEnumerationFullMatchUserId' => true,
  137. 'restrictUserEnumerationFullMatchEmail' => true,
  138. 'restrictUserEnumerationFullMatchIgnoreSecondDN' => false,
  139. 'enforceLinksPassword' => false,
  140. 'onlyShareWithGroupMembers' => false,
  141. 'enabled' => true,
  142. 'defaultExpireDate' => false,
  143. 'expireAfterNDays' => '7',
  144. 'enforceExpireDate' => false,
  145. 'excludeGroups' => false,
  146. 'excludeGroupsList' => [],
  147. 'publicShareDisclaimerText' => 'Lorem ipsum',
  148. 'enableLinkPasswordByDefault' => true,
  149. 'defaultPermissions' => Constants::PERMISSION_ALL,
  150. 'defaultInternalExpireDate' => false,
  151. 'internalExpireAfterNDays' => '7',
  152. 'enforceInternalExpireDate' => false,
  153. 'defaultRemoteExpireDate' => false,
  154. 'remoteExpireAfterNDays' => '7',
  155. 'enforceRemoteExpireDate' => false,
  156. 'allowLinksExcludeGroups' => [],
  157. 'passwordExcludedGroups' => [],
  158. 'passwordExcludedGroupsFeatureEnabled' => false,
  159. ]
  160. ],
  161. );
  162. $expected = new TemplateResponse(
  163. 'settings',
  164. 'settings/admin/sharing',
  165. [],
  166. ''
  167. );
  168. $this->assertEquals($expected, $this->admin->getForm());
  169. }
  170. public function testGetFormWithExcludedGroups(): void {
  171. $this->config
  172. ->method('getAppValue')
  173. ->willReturnMap([
  174. ['core', 'shareapi_exclude_groups_list', '', '["NoSharers","OtherNoSharers"]'],
  175. ['core', 'shareapi_allow_links_exclude_groups', '', ''],
  176. ['core', 'shareapi_allow_group_sharing', 'yes', 'yes'],
  177. ['core', 'shareapi_allow_links', 'yes', 'yes'],
  178. ['core', 'shareapi_allow_public_upload', 'yes', 'yes'],
  179. ['core', 'shareapi_allow_resharing', 'yes', 'yes'],
  180. ['core', 'shareapi_allow_share_dialog_user_enumeration', 'yes', 'yes'],
  181. ['core', 'shareapi_restrict_user_enumeration_to_group', 'no', 'no'],
  182. ['core', 'shareapi_restrict_user_enumeration_to_phone', 'no', 'no'],
  183. ['core', 'shareapi_restrict_user_enumeration_full_match', 'yes', 'yes'],
  184. ['core', 'shareapi_restrict_user_enumeration_full_match_userid', 'yes', 'yes'],
  185. ['core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes', 'yes'],
  186. ['core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn', 'no', 'no'],
  187. ['core', 'shareapi_enabled', 'yes', 'yes'],
  188. ['core', 'shareapi_default_expire_date', 'no', 'no'],
  189. ['core', 'shareapi_expire_after_n_days', '7', '7'],
  190. ['core', 'shareapi_enforce_expire_date', 'no', 'no'],
  191. ['core', 'shareapi_exclude_groups', 'no', 'yes'],
  192. ['core', 'shareapi_public_link_disclaimertext', null, 'Lorem ipsum'],
  193. ['core', 'shareapi_enable_link_password_by_default', 'no', 'yes'],
  194. ['core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL, Constants::PERMISSION_ALL],
  195. ['core', 'shareapi_default_internal_expire_date', 'no', 'no'],
  196. ['core', 'shareapi_internal_expire_after_n_days', '7', '7'],
  197. ['core', 'shareapi_enforce_internal_expire_date', 'no', 'no'],
  198. ['core', 'shareapi_default_remote_expire_date', 'no', 'no'],
  199. ['core', 'shareapi_remote_expire_after_n_days', '7', '7'],
  200. ['core', 'shareapi_enforce_remote_expire_date', 'no', 'no'],
  201. ['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
  202. ]);
  203. $this->shareManager->method('shareWithGroupMembersOnly')
  204. ->willReturn(false);
  205. $this->appManager->method('isEnabledForUser')->with('files_sharing')->willReturn(true);
  206. $this->initialState
  207. ->expects($this->exactly(3))
  208. ->method('provideInitialState')
  209. ->withConsecutive(
  210. ['sharingAppEnabled', true],
  211. ['sharingDocumentation', ''],
  212. [
  213. 'sharingSettings',
  214. [
  215. 'allowGroupSharing' => true,
  216. 'allowLinks' => true,
  217. 'allowPublicUpload' => true,
  218. 'allowResharing' => true,
  219. 'allowShareDialogUserEnumeration' => true,
  220. 'restrictUserEnumerationToGroup' => false,
  221. 'restrictUserEnumerationToPhone' => false,
  222. 'restrictUserEnumerationFullMatch' => true,
  223. 'restrictUserEnumerationFullMatchUserId' => true,
  224. 'restrictUserEnumerationFullMatchEmail' => true,
  225. 'restrictUserEnumerationFullMatchIgnoreSecondDN' => false,
  226. 'enforceLinksPassword' => false,
  227. 'onlyShareWithGroupMembers' => false,
  228. 'enabled' => true,
  229. 'defaultExpireDate' => false,
  230. 'expireAfterNDays' => '7',
  231. 'enforceExpireDate' => false,
  232. 'excludeGroups' => true,
  233. 'excludeGroupsList' => ['NoSharers','OtherNoSharers'],
  234. 'publicShareDisclaimerText' => 'Lorem ipsum',
  235. 'enableLinkPasswordByDefault' => true,
  236. 'defaultPermissions' => Constants::PERMISSION_ALL,
  237. 'defaultInternalExpireDate' => false,
  238. 'internalExpireAfterNDays' => '7',
  239. 'enforceInternalExpireDate' => false,
  240. 'defaultRemoteExpireDate' => false,
  241. 'remoteExpireAfterNDays' => '7',
  242. 'enforceRemoteExpireDate' => false,
  243. 'allowLinksExcludeGroups' => [],
  244. 'passwordExcludedGroups' => [],
  245. 'passwordExcludedGroupsFeatureEnabled' => false,
  246. ]
  247. ],
  248. );
  249. $expected = new TemplateResponse(
  250. 'settings',
  251. 'settings/admin/sharing',
  252. [],
  253. ''
  254. );
  255. $this->assertEquals($expected, $this->admin->getForm());
  256. }
  257. public function testGetSection(): void {
  258. $this->assertSame('sharing', $this->admin->getSection());
  259. }
  260. public function testGetPriority(): void {
  261. $this->assertSame(0, $this->admin->getPriority());
  262. }
  263. }