Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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\Constants;
  37. use OCP\IConfig;
  38. use OCP\IL10N;
  39. use OCP\Share\IManager;
  40. use PHPUnit\Framework\MockObject\MockObject;
  41. use Test\TestCase;
  42. class SharingTest extends TestCase {
  43. /** @var Sharing */
  44. private $admin;
  45. /** @var IConfig */
  46. private $config;
  47. /** @var IL10N|MockObject */
  48. private $l10n;
  49. /** @var IManager|MockObject */
  50. private $shareManager;
  51. /** @var IAppManager|MockObject */
  52. private $appManager;
  53. protected function setUp(): void {
  54. parent::setUp();
  55. $this->config = $this->getMockBuilder(IConfig::class)->getMock();
  56. $this->l10n = $this->getMockBuilder(IL10N::class)->getMock();
  57. $this->shareManager = $this->getMockBuilder(IManager::class)->getMock();
  58. $this->appManager = $this->getMockBuilder(IAppManager::class)->getMock();
  59. $this->admin = new Sharing(
  60. $this->config,
  61. $this->l10n,
  62. $this->shareManager,
  63. $this->appManager
  64. );
  65. }
  66. public function testGetFormWithoutExcludedGroups(): void {
  67. $this->config
  68. ->method('getAppValue')
  69. ->willReturnMap([
  70. ['core', 'shareapi_exclude_groups_list', '', ''],
  71. ['core', 'shareapi_allow_links_exclude_groups', '', ''],
  72. ['core', 'shareapi_allow_group_sharing', 'yes', 'yes'],
  73. ['core', 'shareapi_allow_links', 'yes', 'yes'],
  74. ['core', 'shareapi_allow_public_upload', 'yes', 'yes'],
  75. ['core', 'shareapi_allow_resharing', 'yes', 'yes'],
  76. ['core', 'shareapi_allow_share_dialog_user_enumeration', 'yes', 'yes'],
  77. ['core', 'shareapi_restrict_user_enumeration_to_group', 'no', 'no'],
  78. ['core', 'shareapi_restrict_user_enumeration_to_phone', 'no', 'no'],
  79. ['core', 'shareapi_restrict_user_enumeration_full_match', 'yes', 'yes'],
  80. ['core', 'shareapi_restrict_user_enumeration_full_match_userid', 'yes', 'yes'],
  81. ['core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes', 'yes'],
  82. ['core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn', 'no', 'no'],
  83. ['core', 'shareapi_enabled', 'yes', 'yes'],
  84. ['core', 'shareapi_default_expire_date', 'no', 'no'],
  85. ['core', 'shareapi_expire_after_n_days', '7', '7'],
  86. ['core', 'shareapi_enforce_expire_date', 'no', 'no'],
  87. ['core', 'shareapi_exclude_groups', 'no', 'no'],
  88. ['core', 'shareapi_public_link_disclaimertext', null, 'Lorem ipsum'],
  89. ['core', 'shareapi_enable_link_password_by_default', 'no', 'yes'],
  90. ['core', 'shareapi_default_permissions', Constants::PERMISSION_ALL, Constants::PERMISSION_ALL],
  91. ['core', 'shareapi_default_internal_expire_date', 'no', 'no'],
  92. ['core', 'shareapi_internal_expire_after_n_days', '7', '7'],
  93. ['core', 'shareapi_enforce_internal_expire_date', 'no', 'no'],
  94. ['core', 'shareapi_default_remote_expire_date', 'no', 'no'],
  95. ['core', 'shareapi_remote_expire_after_n_days', '7', '7'],
  96. ['core', 'shareapi_enforce_remote_expire_date', 'no', 'no'],
  97. ['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
  98. ]);
  99. $this->shareManager->method('shareWithGroupMembersOnly')
  100. ->willReturn(false);
  101. $this->appManager->method('isEnabledForUser')->with('files_sharing')->willReturn(false);
  102. $expected = new TemplateResponse(
  103. 'settings',
  104. 'settings/admin/sharing',
  105. [
  106. 'sharingAppEnabled' => false,
  107. 'allowGroupSharing' => 'yes',
  108. 'allowLinks' => 'yes',
  109. 'allowPublicUpload' => 'yes',
  110. 'allowResharing' => 'yes',
  111. 'allowShareDialogUserEnumeration' => 'yes',
  112. 'restrictUserEnumerationToGroup' => 'no',
  113. 'restrictUserEnumerationToPhone' => 'no',
  114. 'restrictUserEnumerationFullMatch' => 'yes',
  115. 'restrictUserEnumerationFullMatchUserId' => 'yes',
  116. 'restrictUserEnumerationFullMatchEmail' => 'yes',
  117. 'restrictUserEnumerationFullMatchIgnoreSecondDN' => 'no',
  118. 'enforceLinkPassword' => false,
  119. 'onlyShareWithGroupMembers' => false,
  120. 'shareAPIEnabled' => 'yes',
  121. 'shareDefaultExpireDateSet' => 'no',
  122. 'shareExpireAfterNDays' => '7',
  123. 'shareEnforceExpireDate' => 'no',
  124. 'shareExcludeGroups' => false,
  125. 'shareExcludedGroupsList' => '',
  126. 'publicShareDisclaimerText' => 'Lorem ipsum',
  127. 'enableLinkPasswordByDefault' => 'yes',
  128. 'shareApiDefaultPermissions' => Constants::PERMISSION_ALL,
  129. 'shareApiDefaultPermissionsCheckboxes' => self::invokePrivate($this->admin, 'getSharePermissionList', []),
  130. 'shareDefaultInternalExpireDateSet' => 'no',
  131. 'shareInternalExpireAfterNDays' => '7',
  132. 'shareInternalEnforceExpireDate' => 'no',
  133. 'shareDefaultRemoteExpireDateSet' => 'no',
  134. 'shareRemoteExpireAfterNDays' => '7',
  135. 'shareRemoteEnforceExpireDate' => 'no',
  136. 'allowLinksExcludeGroups' => '',
  137. 'passwordExcludedGroups' => '',
  138. 'passwordExcludedGroupsFeatureEnabled' => false,
  139. ],
  140. ''
  141. );
  142. $this->assertEquals($expected, $this->admin->getForm());
  143. }
  144. public function testGetFormWithExcludedGroups(): void {
  145. $this->config
  146. ->method('getAppValue')
  147. ->willReturnMap([
  148. ['core', 'shareapi_exclude_groups_list', '', '["NoSharers","OtherNoSharers"]'],
  149. ['core', 'shareapi_allow_links_exclude_groups', '', ''],
  150. ['core', 'shareapi_allow_group_sharing', 'yes', 'yes'],
  151. ['core', 'shareapi_allow_links', 'yes', 'yes'],
  152. ['core', 'shareapi_allow_public_upload', 'yes', 'yes'],
  153. ['core', 'shareapi_allow_resharing', 'yes', 'yes'],
  154. ['core', 'shareapi_allow_share_dialog_user_enumeration', 'yes', 'yes'],
  155. ['core', 'shareapi_restrict_user_enumeration_to_group', 'no', 'no'],
  156. ['core', 'shareapi_restrict_user_enumeration_to_phone', 'no', 'no'],
  157. ['core', 'shareapi_restrict_user_enumeration_full_match', 'yes', 'yes'],
  158. ['core', 'shareapi_restrict_user_enumeration_full_match_userid', 'yes', 'yes'],
  159. ['core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes', 'yes'],
  160. ['core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn', 'no', 'no'],
  161. ['core', 'shareapi_enabled', 'yes', 'yes'],
  162. ['core', 'shareapi_default_expire_date', 'no', 'no'],
  163. ['core', 'shareapi_expire_after_n_days', '7', '7'],
  164. ['core', 'shareapi_enforce_expire_date', 'no', 'no'],
  165. ['core', 'shareapi_exclude_groups', 'no', 'yes'],
  166. ['core', 'shareapi_public_link_disclaimertext', null, 'Lorem ipsum'],
  167. ['core', 'shareapi_enable_link_password_by_default', 'no', 'yes'],
  168. ['core', 'shareapi_default_permissions', Constants::PERMISSION_ALL, Constants::PERMISSION_ALL],
  169. ['core', 'shareapi_default_internal_expire_date', 'no', 'no'],
  170. ['core', 'shareapi_internal_expire_after_n_days', '7', '7'],
  171. ['core', 'shareapi_enforce_internal_expire_date', 'no', 'no'],
  172. ['core', 'shareapi_default_remote_expire_date', 'no', 'no'],
  173. ['core', 'shareapi_remote_expire_after_n_days', '7', '7'],
  174. ['core', 'shareapi_enforce_remote_expire_date', 'no', 'no'],
  175. ['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
  176. ]);
  177. $this->shareManager->method('shareWithGroupMembersOnly')
  178. ->willReturn(false);
  179. $this->appManager->method('isEnabledForUser')->with('files_sharing')->willReturn(true);
  180. $expected = new TemplateResponse(
  181. 'settings',
  182. 'settings/admin/sharing',
  183. [
  184. 'sharingAppEnabled' => true,
  185. 'allowGroupSharing' => 'yes',
  186. 'allowLinks' => 'yes',
  187. 'allowPublicUpload' => 'yes',
  188. 'allowResharing' => 'yes',
  189. 'allowShareDialogUserEnumeration' => 'yes',
  190. 'restrictUserEnumerationToGroup' => 'no',
  191. 'restrictUserEnumerationToPhone' => 'no',
  192. 'restrictUserEnumerationFullMatch' => 'yes',
  193. 'restrictUserEnumerationFullMatchUserId' => 'yes',
  194. 'restrictUserEnumerationFullMatchEmail' => 'yes',
  195. 'restrictUserEnumerationFullMatchIgnoreSecondDN' => 'no',
  196. 'enforceLinkPassword' => false,
  197. 'onlyShareWithGroupMembers' => false,
  198. 'shareAPIEnabled' => 'yes',
  199. 'shareDefaultExpireDateSet' => 'no',
  200. 'shareExpireAfterNDays' => '7',
  201. 'shareEnforceExpireDate' => 'no',
  202. 'shareExcludeGroups' => true,
  203. 'shareExcludedGroupsList' => 'NoSharers|OtherNoSharers',
  204. 'publicShareDisclaimerText' => 'Lorem ipsum',
  205. 'enableLinkPasswordByDefault' => 'yes',
  206. 'shareApiDefaultPermissions' => Constants::PERMISSION_ALL,
  207. 'shareApiDefaultPermissionsCheckboxes' => self::invokePrivate($this->admin, 'getSharePermissionList', []),
  208. 'shareDefaultInternalExpireDateSet' => 'no',
  209. 'shareInternalExpireAfterNDays' => '7',
  210. 'shareInternalEnforceExpireDate' => 'no',
  211. 'shareDefaultRemoteExpireDateSet' => 'no',
  212. 'shareRemoteExpireAfterNDays' => '7',
  213. 'shareRemoteEnforceExpireDate' => 'no',
  214. 'allowLinksExcludeGroups' => '',
  215. 'passwordExcludedGroups' => '',
  216. 'passwordExcludedGroupsFeatureEnabled' => false,
  217. ],
  218. ''
  219. );
  220. $this->assertEquals($expected, $this->admin->getForm());
  221. }
  222. public function testGetSection(): void {
  223. $this->assertSame('sharing', $this->admin->getSection());
  224. }
  225. public function testGetPriority(): void {
  226. $this->assertSame(0, $this->admin->getPriority());
  227. }
  228. }