SharingTest.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. ]);
  98. $this->shareManager->method('shareWithGroupMembersOnly')
  99. ->willReturn(false);
  100. $this->appManager->method('isEnabledForUser')->with('files_sharing')->willReturn(false);
  101. $expected = new TemplateResponse(
  102. 'settings',
  103. 'settings/admin/sharing',
  104. [
  105. 'sharingAppEnabled' => false,
  106. 'allowGroupSharing' => 'yes',
  107. 'allowLinks' => 'yes',
  108. 'allowPublicUpload' => 'yes',
  109. 'allowResharing' => 'yes',
  110. 'allowShareDialogUserEnumeration' => 'yes',
  111. 'restrictUserEnumerationToGroup' => 'no',
  112. 'restrictUserEnumerationToPhone' => 'no',
  113. 'restrictUserEnumerationFullMatch' => 'yes',
  114. 'restrictUserEnumerationFullMatchUserId' => 'yes',
  115. 'restrictUserEnumerationFullMatchEmail' => 'yes',
  116. 'restrictUserEnumerationFullMatchIgnoreSecondDN' => 'no',
  117. 'enforceLinkPassword' => false,
  118. 'onlyShareWithGroupMembers' => false,
  119. 'shareAPIEnabled' => 'yes',
  120. 'shareDefaultExpireDateSet' => 'no',
  121. 'shareExpireAfterNDays' => '7',
  122. 'shareEnforceExpireDate' => 'no',
  123. 'shareExcludeGroups' => false,
  124. 'shareExcludedGroupsList' => '',
  125. 'publicShareDisclaimerText' => 'Lorem ipsum',
  126. 'enableLinkPasswordByDefault' => 'yes',
  127. 'shareApiDefaultPermissions' => Constants::PERMISSION_ALL,
  128. 'shareApiDefaultPermissionsCheckboxes' => self::invokePrivate($this->admin, 'getSharePermissionList', []),
  129. 'shareDefaultInternalExpireDateSet' => 'no',
  130. 'shareInternalExpireAfterNDays' => '7',
  131. 'shareInternalEnforceExpireDate' => 'no',
  132. 'shareDefaultRemoteExpireDateSet' => 'no',
  133. 'shareRemoteExpireAfterNDays' => '7',
  134. 'shareRemoteEnforceExpireDate' => 'no',
  135. 'allowLinksExcludeGroups' => '',
  136. 'passwordExcludedGroups' => '',
  137. 'passwordExcludedGroupsFeatureEnabled' => false,
  138. ],
  139. ''
  140. );
  141. $this->assertEquals($expected, $this->admin->getForm());
  142. }
  143. public function testGetFormWithExcludedGroups(): void {
  144. $this->config
  145. ->method('getAppValue')
  146. ->willReturnMap([
  147. ['core', 'shareapi_exclude_groups_list', '', '["NoSharers","OtherNoSharers"]'],
  148. ['core', 'shareapi_allow_links_exclude_groups', '', ''],
  149. ['core', 'shareapi_allow_group_sharing', 'yes', 'yes'],
  150. ['core', 'shareapi_allow_links', 'yes', 'yes'],
  151. ['core', 'shareapi_allow_public_upload', 'yes', 'yes'],
  152. ['core', 'shareapi_allow_resharing', 'yes', 'yes'],
  153. ['core', 'shareapi_allow_share_dialog_user_enumeration', 'yes', 'yes'],
  154. ['core', 'shareapi_restrict_user_enumeration_to_group', 'no', 'no'],
  155. ['core', 'shareapi_restrict_user_enumeration_to_phone', 'no', 'no'],
  156. ['core', 'shareapi_restrict_user_enumeration_full_match', 'yes', 'yes'],
  157. ['core', 'shareapi_restrict_user_enumeration_full_match_userid', 'yes', 'yes'],
  158. ['core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes', 'yes'],
  159. ['core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn', 'no', 'no'],
  160. ['core', 'shareapi_enabled', 'yes', 'yes'],
  161. ['core', 'shareapi_default_expire_date', 'no', 'no'],
  162. ['core', 'shareapi_expire_after_n_days', '7', '7'],
  163. ['core', 'shareapi_enforce_expire_date', 'no', 'no'],
  164. ['core', 'shareapi_exclude_groups', 'no', 'yes'],
  165. ['core', 'shareapi_public_link_disclaimertext', null, 'Lorem ipsum'],
  166. ['core', 'shareapi_enable_link_password_by_default', 'no', 'yes'],
  167. ['core', 'shareapi_default_permissions', Constants::PERMISSION_ALL, Constants::PERMISSION_ALL],
  168. ['core', 'shareapi_default_internal_expire_date', 'no', 'no'],
  169. ['core', 'shareapi_internal_expire_after_n_days', '7', '7'],
  170. ['core', 'shareapi_enforce_internal_expire_date', 'no', 'no'],
  171. ['core', 'shareapi_default_remote_expire_date', 'no', 'no'],
  172. ['core', 'shareapi_remote_expire_after_n_days', '7', '7'],
  173. ['core', 'shareapi_enforce_remote_expire_date', 'no', 'no'],
  174. ]);
  175. $this->shareManager->method('shareWithGroupMembersOnly')
  176. ->willReturn(false);
  177. $this->appManager->method('isEnabledForUser')->with('files_sharing')->willReturn(true);
  178. $expected = new TemplateResponse(
  179. 'settings',
  180. 'settings/admin/sharing',
  181. [
  182. 'sharingAppEnabled' => true,
  183. 'allowGroupSharing' => 'yes',
  184. 'allowLinks' => 'yes',
  185. 'allowPublicUpload' => 'yes',
  186. 'allowResharing' => 'yes',
  187. 'allowShareDialogUserEnumeration' => 'yes',
  188. 'restrictUserEnumerationToGroup' => 'no',
  189. 'restrictUserEnumerationToPhone' => 'no',
  190. 'restrictUserEnumerationFullMatch' => 'yes',
  191. 'restrictUserEnumerationFullMatchUserId' => 'yes',
  192. 'restrictUserEnumerationFullMatchEmail' => 'yes',
  193. 'restrictUserEnumerationFullMatchIgnoreSecondDN' => 'no',
  194. 'enforceLinkPassword' => false,
  195. 'onlyShareWithGroupMembers' => false,
  196. 'shareAPIEnabled' => 'yes',
  197. 'shareDefaultExpireDateSet' => 'no',
  198. 'shareExpireAfterNDays' => '7',
  199. 'shareEnforceExpireDate' => 'no',
  200. 'shareExcludeGroups' => true,
  201. 'shareExcludedGroupsList' => 'NoSharers|OtherNoSharers',
  202. 'publicShareDisclaimerText' => 'Lorem ipsum',
  203. 'enableLinkPasswordByDefault' => 'yes',
  204. 'shareApiDefaultPermissions' => Constants::PERMISSION_ALL,
  205. 'shareApiDefaultPermissionsCheckboxes' => self::invokePrivate($this->admin, 'getSharePermissionList', []),
  206. 'shareDefaultInternalExpireDateSet' => 'no',
  207. 'shareInternalExpireAfterNDays' => '7',
  208. 'shareInternalEnforceExpireDate' => 'no',
  209. 'shareDefaultRemoteExpireDateSet' => 'no',
  210. 'shareRemoteExpireAfterNDays' => '7',
  211. 'shareRemoteEnforceExpireDate' => 'no',
  212. 'allowLinksExcludeGroups' => '',
  213. 'passwordExcludedGroups' => '',
  214. 'passwordExcludedGroupsFeatureEnabled' => false,
  215. ],
  216. ''
  217. );
  218. $this->assertEquals($expected, $this->admin->getForm());
  219. }
  220. public function testGetSection(): void {
  221. $this->assertSame('sharing', $this->admin->getSection());
  222. }
  223. public function testGetPriority(): void {
  224. $this->assertSame(0, $this->admin->getPriority());
  225. }
  226. }