You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SharingTest.php 8.9KB

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