2016-08-15 17:24:56 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
|
|
|
|
*
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
|
|
|
* @author Bjoern Schiessle <bjoern@schiessle.org>
|
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2020-03-31 11:49:10 +03:00
|
|
|
* @author Daniel Kesselberg <mail@danielkesselberg.de>
|
|
|
|
* @author Julius Härtl <jus@bitgrid.net>
|
2016-08-15 17:24:56 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2016-08-15 17:24:56 +03:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2016-08-15 17:24:56 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-09-17 17:33:27 +03:00
|
|
|
namespace OCA\Settings\Tests\Settings\Admin;
|
2016-08-15 17:24:56 +03:00
|
|
|
|
2020-01-31 18:55:17 +03:00
|
|
|
use OCA\Settings\Settings\Admin\Sharing;
|
2016-08-15 17:24:56 +03:00
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
2017-12-01 17:50:29 +03:00
|
|
|
use OCP\Constants;
|
2016-08-15 17:24:56 +03:00
|
|
|
use OCP\IConfig;
|
2017-12-01 13:35:01 +03:00
|
|
|
use OCP\IL10N;
|
2018-11-02 01:18:44 +03:00
|
|
|
use OCP\Share\IManager;
|
2016-08-15 17:24:56 +03:00
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
class SharingTest extends TestCase {
|
|
|
|
/** @var Sharing */
|
|
|
|
private $admin;
|
|
|
|
/** @var IConfig */
|
|
|
|
private $config;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
|
2017-12-01 13:35:01 +03:00
|
|
|
private $l10n;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
|
2018-11-02 01:18:44 +03:00
|
|
|
private $shareManager;
|
2016-08-15 17:24:56 +03:00
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
protected function setUp(): void {
|
2016-08-15 17:24:56 +03:00
|
|
|
parent::setUp();
|
2017-10-24 16:26:53 +03:00
|
|
|
$this->config = $this->getMockBuilder(IConfig::class)->getMock();
|
2017-12-01 13:35:01 +03:00
|
|
|
$this->l10n = $this->getMockBuilder(IL10N::class)->getMock();
|
2019-03-22 11:46:41 +03:00
|
|
|
|
2018-11-02 01:18:44 +03:00
|
|
|
$this->shareManager = $this->getMockBuilder(IManager::class)->getMock();
|
2016-08-15 17:24:56 +03:00
|
|
|
|
|
|
|
$this->admin = new Sharing(
|
2017-12-01 13:35:01 +03:00
|
|
|
$this->config,
|
2020-02-03 12:31:23 +03:00
|
|
|
$this->l10n,
|
2018-11-02 01:18:44 +03:00
|
|
|
$this->shareManager
|
2016-08-15 17:24:56 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetFormWithoutExcludedGroups() {
|
|
|
|
$this->config
|
|
|
|
->method('getAppValue')
|
2021-03-09 23:46:42 +03:00
|
|
|
->willReturnMap([
|
|
|
|
['core', 'shareapi_exclude_groups_list', '', ''],
|
|
|
|
['core', 'shareapi_allow_group_sharing', 'yes', 'yes'],
|
|
|
|
['core', 'shareapi_allow_links', 'yes', 'yes'],
|
|
|
|
['core', 'shareapi_allow_public_upload', 'yes', 'yes'],
|
|
|
|
['core', 'shareapi_allow_resharing', 'yes', 'yes'],
|
|
|
|
['core', 'shareapi_allow_share_dialog_user_enumeration', 'yes', 'yes'],
|
|
|
|
['core', 'shareapi_restrict_user_enumeration_to_group', 'no', 'no'],
|
|
|
|
['core', 'shareapi_restrict_user_enumeration_to_phone', 'no', 'no'],
|
2021-03-10 19:18:44 +03:00
|
|
|
['core', 'shareapi_restrict_user_enumeration_full_match', 'yes', 'yes'],
|
2021-03-09 23:46:42 +03:00
|
|
|
['core', 'shareapi_enabled', 'yes', 'yes'],
|
|
|
|
['core', 'shareapi_default_expire_date', 'no', 'no'],
|
|
|
|
['core', 'shareapi_expire_after_n_days', '7', '7'],
|
|
|
|
['core', 'shareapi_enforce_expire_date', 'no', 'no'],
|
|
|
|
['core', 'shareapi_exclude_groups', 'no', 'no'],
|
|
|
|
['core', 'shareapi_public_link_disclaimertext', null, 'Lorem ipsum'],
|
|
|
|
['core', 'shareapi_enable_link_password_by_default', 'no', 'yes'],
|
|
|
|
['core', 'shareapi_default_permissions', Constants::PERMISSION_ALL, Constants::PERMISSION_ALL],
|
|
|
|
['core', 'shareapi_default_internal_expire_date', 'no', 'no'],
|
|
|
|
['core', 'shareapi_internal_expire_after_n_days', '7', '7'],
|
|
|
|
['core', 'shareapi_enforce_internal_expire_date', 'no', 'no'],
|
2021-03-25 19:32:49 +03:00
|
|
|
['core', 'shareapi_default_remote_expire_date', 'no', 'no'],
|
|
|
|
['core', 'shareapi_remote_expire_after_n_days', '7', '7'],
|
|
|
|
['core', 'shareapi_enforce_remote_expire_date', 'no', 'no'],
|
2021-03-09 23:46:42 +03:00
|
|
|
]);
|
2016-08-15 17:24:56 +03:00
|
|
|
|
|
|
|
$expected = new TemplateResponse(
|
|
|
|
'settings',
|
2017-06-29 15:38:22 +03:00
|
|
|
'settings/admin/sharing',
|
2016-08-15 17:24:56 +03:00
|
|
|
[
|
2020-10-05 16:12:57 +03:00
|
|
|
'allowGroupSharing' => 'yes',
|
|
|
|
'allowLinks' => 'yes',
|
|
|
|
'allowPublicUpload' => 'yes',
|
|
|
|
'allowResharing' => 'yes',
|
2016-08-16 19:59:45 +03:00
|
|
|
'allowShareDialogUserEnumeration' => 'yes',
|
2020-10-05 16:12:57 +03:00
|
|
|
'restrictUserEnumerationToGroup' => 'no',
|
2021-03-09 23:46:42 +03:00
|
|
|
'restrictUserEnumerationToPhone' => 'no',
|
2021-03-10 19:18:44 +03:00
|
|
|
'restrictUserEnumerationFullMatch' => 'yes',
|
2020-10-05 16:12:57 +03:00
|
|
|
'enforceLinkPassword' => false,
|
|
|
|
'onlyShareWithGroupMembers' => false,
|
|
|
|
'shareAPIEnabled' => 'yes',
|
|
|
|
'shareDefaultExpireDateSet' => 'no',
|
|
|
|
'shareExpireAfterNDays' => '7',
|
|
|
|
'shareEnforceExpireDate' => 'no',
|
|
|
|
'shareExcludeGroups' => false,
|
|
|
|
'shareExcludedGroupsList' => '',
|
|
|
|
'publicShareDisclaimerText' => 'Lorem ipsum',
|
|
|
|
'enableLinkPasswordByDefault' => 'yes',
|
|
|
|
'shareApiDefaultPermissions' => Constants::PERMISSION_ALL,
|
2019-11-27 16:51:14 +03:00
|
|
|
'shareApiDefaultPermissionsCheckboxes' => $this->invokePrivate($this->admin, 'getSharePermissionList', []),
|
|
|
|
'shareDefaultInternalExpireDateSet' => 'no',
|
|
|
|
'shareInternalExpireAfterNDays' => '7',
|
|
|
|
'shareInternalEnforceExpireDate' => 'no',
|
2021-03-25 19:32:49 +03:00
|
|
|
'shareDefaultRemoteExpireDateSet' => 'no',
|
|
|
|
'shareRemoteExpireAfterNDays' => '7',
|
|
|
|
'shareRemoteEnforceExpireDate' => 'no',
|
2016-08-15 17:24:56 +03:00
|
|
|
],
|
|
|
|
''
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $this->admin->getForm());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetFormWithExcludedGroups() {
|
|
|
|
$this->config
|
|
|
|
->method('getAppValue')
|
2021-03-09 23:46:42 +03:00
|
|
|
->willReturnMap([
|
|
|
|
['core', 'shareapi_exclude_groups_list', '', '["NoSharers","OtherNoSharers"]'],
|
|
|
|
['core', 'shareapi_allow_group_sharing', 'yes', 'yes'],
|
|
|
|
['core', 'shareapi_allow_links', 'yes', 'yes'],
|
|
|
|
['core', 'shareapi_allow_public_upload', 'yes', 'yes'],
|
|
|
|
['core', 'shareapi_allow_resharing', 'yes', 'yes'],
|
|
|
|
['core', 'shareapi_allow_share_dialog_user_enumeration', 'yes', 'yes'],
|
|
|
|
['core', 'shareapi_restrict_user_enumeration_to_group', 'no', 'no'],
|
|
|
|
['core', 'shareapi_restrict_user_enumeration_to_phone', 'no', 'no'],
|
2021-03-10 19:18:44 +03:00
|
|
|
['core', 'shareapi_restrict_user_enumeration_full_match', 'yes', 'yes'],
|
2021-03-09 23:46:42 +03:00
|
|
|
['core', 'shareapi_enabled', 'yes', 'yes'],
|
|
|
|
['core', 'shareapi_default_expire_date', 'no', 'no'],
|
|
|
|
['core', 'shareapi_expire_after_n_days', '7', '7'],
|
|
|
|
['core', 'shareapi_enforce_expire_date', 'no', 'no'],
|
|
|
|
['core', 'shareapi_exclude_groups', 'no', 'yes'],
|
|
|
|
['core', 'shareapi_public_link_disclaimertext', null, 'Lorem ipsum'],
|
|
|
|
['core', 'shareapi_enable_link_password_by_default', 'no', 'yes'],
|
|
|
|
['core', 'shareapi_default_permissions', Constants::PERMISSION_ALL, Constants::PERMISSION_ALL],
|
|
|
|
['core', 'shareapi_default_internal_expire_date', 'no', 'no'],
|
|
|
|
['core', 'shareapi_internal_expire_after_n_days', '7', '7'],
|
|
|
|
['core', 'shareapi_enforce_internal_expire_date', 'no', 'no'],
|
2021-03-25 19:32:49 +03:00
|
|
|
['core', 'shareapi_default_remote_expire_date', 'no', 'no'],
|
|
|
|
['core', 'shareapi_remote_expire_after_n_days', '7', '7'],
|
|
|
|
['core', 'shareapi_enforce_remote_expire_date', 'no', 'no'],
|
2021-03-09 23:46:42 +03:00
|
|
|
]);
|
2016-08-15 17:24:56 +03:00
|
|
|
|
|
|
|
$expected = new TemplateResponse(
|
|
|
|
'settings',
|
2017-06-29 15:38:22 +03:00
|
|
|
'settings/admin/sharing',
|
2016-08-15 17:24:56 +03:00
|
|
|
[
|
2020-10-05 16:12:57 +03:00
|
|
|
'allowGroupSharing' => 'yes',
|
|
|
|
'allowLinks' => 'yes',
|
|
|
|
'allowPublicUpload' => 'yes',
|
|
|
|
'allowResharing' => 'yes',
|
2016-08-16 19:59:45 +03:00
|
|
|
'allowShareDialogUserEnumeration' => 'yes',
|
2020-10-05 16:12:57 +03:00
|
|
|
'restrictUserEnumerationToGroup' => 'no',
|
2021-03-09 23:46:42 +03:00
|
|
|
'restrictUserEnumerationToPhone' => 'no',
|
2021-03-10 19:18:44 +03:00
|
|
|
'restrictUserEnumerationFullMatch' => 'yes',
|
2020-10-05 16:12:57 +03:00
|
|
|
'enforceLinkPassword' => false,
|
|
|
|
'onlyShareWithGroupMembers' => false,
|
|
|
|
'shareAPIEnabled' => 'yes',
|
|
|
|
'shareDefaultExpireDateSet' => 'no',
|
|
|
|
'shareExpireAfterNDays' => '7',
|
|
|
|
'shareEnforceExpireDate' => 'no',
|
|
|
|
'shareExcludeGroups' => true,
|
|
|
|
'shareExcludedGroupsList' => 'NoSharers|OtherNoSharers',
|
|
|
|
'publicShareDisclaimerText' => 'Lorem ipsum',
|
|
|
|
'enableLinkPasswordByDefault' => 'yes',
|
|
|
|
'shareApiDefaultPermissions' => Constants::PERMISSION_ALL,
|
2019-11-27 16:51:14 +03:00
|
|
|
'shareApiDefaultPermissionsCheckboxes' => $this->invokePrivate($this->admin, 'getSharePermissionList', []),
|
|
|
|
'shareDefaultInternalExpireDateSet' => 'no',
|
|
|
|
'shareInternalExpireAfterNDays' => '7',
|
|
|
|
'shareInternalEnforceExpireDate' => 'no',
|
2021-03-25 19:32:49 +03:00
|
|
|
'shareDefaultRemoteExpireDateSet' => 'no',
|
|
|
|
'shareRemoteExpireAfterNDays' => '7',
|
|
|
|
'shareRemoteEnforceExpireDate' => 'no',
|
2016-08-15 17:24:56 +03:00
|
|
|
],
|
|
|
|
''
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $this->admin->getForm());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetSection() {
|
|
|
|
$this->assertSame('sharing', $this->admin->getSection());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPriority() {
|
|
|
|
$this->assertSame(0, $this->admin->getPriority());
|
|
|
|
}
|
|
|
|
}
|