2016-08-15 17:24:56 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
|
|
|
|
*
|
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
|
|
|
*
|
|
|
|
* @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
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Test\Settings\Admin;
|
|
|
|
|
|
|
|
use OC\Settings\Admin\Sharing;
|
|
|
|
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;
|
2019-03-22 11:46:41 +03:00
|
|
|
use OCP\L10N\IFactory;
|
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;
|
2017-12-01 13:35:01 +03:00
|
|
|
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $l10n;
|
2018-11-02 01:18:44 +03:00
|
|
|
/** @var IManager|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $shareManager;
|
2016-08-15 17:24:56 +03:00
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
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
|
|
|
|
|
|
|
$l10Factory = $this->createMock(IFactory::class);
|
|
|
|
$l10Factory->method('get')
|
|
|
|
->willReturn($this->l10n);
|
|
|
|
|
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,
|
2019-03-22 11:46:41 +03:00
|
|
|
$l10Factory,
|
2018-11-02 01:18:44 +03:00
|
|
|
$this->shareManager
|
2016-08-15 17:24:56 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetFormWithoutExcludedGroups() {
|
|
|
|
$this->config
|
|
|
|
->expects($this->at(0))
|
|
|
|
->method('getAppValue')
|
|
|
|
->with('core', 'shareapi_exclude_groups_list', '')
|
|
|
|
->willReturn('');
|
|
|
|
$this->config
|
|
|
|
->expects($this->at(1))
|
|
|
|
->method('getAppValue')
|
2016-08-16 19:59:45 +03:00
|
|
|
->with('core', 'shareapi_allow_group_sharing', 'yes')
|
2016-08-15 17:24:56 +03:00
|
|
|
->willReturn('yes');
|
|
|
|
$this->config
|
|
|
|
->expects($this->at(2))
|
|
|
|
->method('getAppValue')
|
2016-08-16 19:59:45 +03:00
|
|
|
->with('core', 'shareapi_allow_links', 'yes')
|
|
|
|
->willReturn('yes');
|
|
|
|
$this->config
|
|
|
|
->expects($this->at(3))
|
|
|
|
->method('getAppValue')
|
|
|
|
->with('core', 'shareapi_allow_public_upload', 'yes')
|
|
|
|
->willReturn('yes');
|
|
|
|
$this->config
|
2016-11-02 13:37:25 +03:00
|
|
|
->expects($this->at(4))
|
2016-08-16 19:59:45 +03:00
|
|
|
->method('getAppValue')
|
|
|
|
->with('core', 'shareapi_allow_resharing', 'yes')
|
|
|
|
->willReturn('yes');
|
|
|
|
$this->config
|
2016-11-02 13:37:25 +03:00
|
|
|
->expects($this->at(5))
|
2016-08-16 19:59:45 +03:00
|
|
|
->method('getAppValue')
|
|
|
|
->with('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes')
|
|
|
|
->willReturn('yes');
|
|
|
|
$this->config
|
2016-11-02 13:37:25 +03:00
|
|
|
->expects($this->at(6))
|
2016-08-16 19:59:45 +03:00
|
|
|
->method('getAppValue')
|
|
|
|
->with('core', 'shareapi_enabled', 'yes')
|
|
|
|
->willReturn('yes');
|
|
|
|
$this->config
|
2016-11-02 13:37:25 +03:00
|
|
|
->expects($this->at(7))
|
2016-08-16 19:59:45 +03:00
|
|
|
->method('getAppValue')
|
2016-08-15 17:24:56 +03:00
|
|
|
->with('core', 'shareapi_default_expire_date', 'no')
|
|
|
|
->willReturn('no');
|
|
|
|
$this->config
|
2016-11-02 13:37:25 +03:00
|
|
|
->expects($this->at(8))
|
2016-08-15 17:24:56 +03:00
|
|
|
->method('getAppValue')
|
|
|
|
->with('core', 'shareapi_expire_after_n_days', '7')
|
|
|
|
->willReturn('7');
|
|
|
|
$this->config
|
2016-11-02 13:37:25 +03:00
|
|
|
->expects($this->at(9))
|
2016-08-15 17:24:56 +03:00
|
|
|
->method('getAppValue')
|
|
|
|
->with('core', 'shareapi_enforce_expire_date', 'no')
|
|
|
|
->willReturn('no');
|
|
|
|
$this->config
|
2016-11-02 13:37:25 +03:00
|
|
|
->expects($this->at(10))
|
2016-08-15 17:24:56 +03:00
|
|
|
->method('getAppValue')
|
|
|
|
->with('core', 'shareapi_exclude_groups', 'no')
|
|
|
|
->willReturn('no');
|
2016-09-08 10:13:59 +03:00
|
|
|
$this->config
|
2016-11-02 13:37:25 +03:00
|
|
|
->expects($this->at(11))
|
2016-09-08 10:13:59 +03:00
|
|
|
->method('getAppValue')
|
|
|
|
->with('core', 'shareapi_public_link_disclaimertext', null)
|
|
|
|
->willReturn('Lorem ipsum');
|
2017-04-03 11:54:25 +03:00
|
|
|
$this->config
|
|
|
|
->expects($this->at(12))
|
|
|
|
->method('getAppValue')
|
|
|
|
->with('core', 'shareapi_enable_link_password_by_default', 'no')
|
|
|
|
->willReturn('yes');
|
2017-12-01 17:50:29 +03:00
|
|
|
$this->config
|
|
|
|
->expects($this->at(13))
|
|
|
|
->method('getAppValue')
|
|
|
|
->with('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL)
|
|
|
|
->willReturn(Constants::PERMISSION_ALL);
|
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
|
|
|
[
|
2016-08-16 19:59:45 +03:00
|
|
|
'allowGroupSharing' => 'yes',
|
|
|
|
'allowLinks' => 'yes',
|
|
|
|
'allowPublicUpload' => 'yes',
|
|
|
|
'allowResharing' => 'yes',
|
|
|
|
'allowShareDialogUserEnumeration' => 'yes',
|
|
|
|
'enforceLinkPassword' => false,
|
|
|
|
'onlyShareWithGroupMembers' => false,
|
|
|
|
'shareAPIEnabled' => 'yes',
|
|
|
|
'shareDefaultExpireDateSet' => 'no',
|
|
|
|
'shareExpireAfterNDays' => '7',
|
|
|
|
'shareEnforceExpireDate' => 'no',
|
|
|
|
'shareExcludeGroups' => false,
|
|
|
|
'shareExcludedGroupsList' => '',
|
2017-04-03 11:54:25 +03:00
|
|
|
'publicShareDisclaimerText' => 'Lorem ipsum',
|
2017-12-01 17:50:29 +03:00
|
|
|
'enableLinkPasswordByDefault' => 'yes',
|
|
|
|
'shareApiDefaultPermissions' => Constants::PERMISSION_ALL,
|
|
|
|
'shareApiDefaultPermissionsCheckboxes' => $this->invokePrivate($this->admin, 'getSharePermissionList', [])
|
2016-08-15 17:24:56 +03:00
|
|
|
],
|
|
|
|
''
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $this->admin->getForm());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetFormWithExcludedGroups() {
|
|
|
|
$this->config
|
|
|
|
->expects($this->at(0))
|
|
|
|
->method('getAppValue')
|
|
|
|
->with('core', 'shareapi_exclude_groups_list', '')
|
|
|
|
->willReturn('["NoSharers","OtherNoSharers"]');
|
|
|
|
$this->config
|
|
|
|
->expects($this->at(1))
|
|
|
|
->method('getAppValue')
|
2016-08-16 19:59:45 +03:00
|
|
|
->with('core', 'shareapi_allow_group_sharing', 'yes')
|
2016-08-15 17:24:56 +03:00
|
|
|
->willReturn('yes');
|
|
|
|
$this->config
|
|
|
|
->expects($this->at(2))
|
|
|
|
->method('getAppValue')
|
2016-08-16 19:59:45 +03:00
|
|
|
->with('core', 'shareapi_allow_links', 'yes')
|
|
|
|
->willReturn('yes');
|
|
|
|
$this->config
|
|
|
|
->expects($this->at(3))
|
|
|
|
->method('getAppValue')
|
|
|
|
->with('core', 'shareapi_allow_public_upload', 'yes')
|
|
|
|
->willReturn('yes');
|
|
|
|
$this->config
|
2016-11-02 13:37:25 +03:00
|
|
|
->expects($this->at(4))
|
2016-08-16 19:59:45 +03:00
|
|
|
->method('getAppValue')
|
|
|
|
->with('core', 'shareapi_allow_resharing', 'yes')
|
|
|
|
->willReturn('yes');
|
|
|
|
$this->config
|
2016-11-02 13:37:25 +03:00
|
|
|
->expects($this->at(5))
|
2016-08-16 19:59:45 +03:00
|
|
|
->method('getAppValue')
|
|
|
|
->with('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes')
|
|
|
|
->willReturn('yes');
|
|
|
|
$this->config
|
2016-11-02 13:37:25 +03:00
|
|
|
->expects($this->at(6))
|
2016-08-16 19:59:45 +03:00
|
|
|
->method('getAppValue')
|
|
|
|
->with('core', 'shareapi_enabled', 'yes')
|
|
|
|
->willReturn('yes');
|
|
|
|
$this->config
|
2016-11-02 13:37:25 +03:00
|
|
|
->expects($this->at(7))
|
2016-08-16 19:59:45 +03:00
|
|
|
->method('getAppValue')
|
2016-08-15 17:24:56 +03:00
|
|
|
->with('core', 'shareapi_default_expire_date', 'no')
|
|
|
|
->willReturn('no');
|
|
|
|
$this->config
|
2016-11-02 13:37:25 +03:00
|
|
|
->expects($this->at(8))
|
2016-08-15 17:24:56 +03:00
|
|
|
->method('getAppValue')
|
|
|
|
->with('core', 'shareapi_expire_after_n_days', '7')
|
|
|
|
->willReturn('7');
|
|
|
|
$this->config
|
2016-11-02 13:37:25 +03:00
|
|
|
->expects($this->at(9))
|
2016-08-15 17:24:56 +03:00
|
|
|
->method('getAppValue')
|
|
|
|
->with('core', 'shareapi_enforce_expire_date', 'no')
|
|
|
|
->willReturn('no');
|
|
|
|
$this->config
|
2016-11-02 13:37:25 +03:00
|
|
|
->expects($this->at(10))
|
2016-08-15 17:24:56 +03:00
|
|
|
->method('getAppValue')
|
|
|
|
->with('core', 'shareapi_exclude_groups', 'no')
|
|
|
|
->willReturn('yes');
|
2016-09-08 10:13:59 +03:00
|
|
|
$this->config
|
2016-11-02 13:37:25 +03:00
|
|
|
->expects($this->at(11))
|
2016-09-08 10:13:59 +03:00
|
|
|
->method('getAppValue')
|
|
|
|
->with('core', 'shareapi_public_link_disclaimertext', null)
|
|
|
|
->willReturn('Lorem ipsum');
|
2017-04-03 11:54:25 +03:00
|
|
|
$this->config
|
|
|
|
->expects($this->at(12))
|
|
|
|
->method('getAppValue')
|
|
|
|
->with('core', 'shareapi_enable_link_password_by_default', 'no')
|
|
|
|
->willReturn('yes');
|
2017-12-01 17:50:29 +03:00
|
|
|
$this->config
|
|
|
|
->expects($this->at(13))
|
|
|
|
->method('getAppValue')
|
|
|
|
->with('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL)
|
|
|
|
->willReturn(Constants::PERMISSION_ALL);
|
|
|
|
|
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
|
|
|
[
|
2016-08-16 19:59:45 +03:00
|
|
|
'allowGroupSharing' => 'yes',
|
|
|
|
'allowLinks' => 'yes',
|
|
|
|
'allowPublicUpload' => 'yes',
|
|
|
|
'allowResharing' => 'yes',
|
|
|
|
'allowShareDialogUserEnumeration' => 'yes',
|
|
|
|
'enforceLinkPassword' => false,
|
|
|
|
'onlyShareWithGroupMembers' => false,
|
|
|
|
'shareAPIEnabled' => 'yes',
|
|
|
|
'shareDefaultExpireDateSet' => 'no',
|
|
|
|
'shareExpireAfterNDays' => '7',
|
|
|
|
'shareEnforceExpireDate' => 'no',
|
|
|
|
'shareExcludeGroups' => true,
|
|
|
|
'shareExcludedGroupsList' => 'NoSharers|OtherNoSharers',
|
2017-04-03 11:54:25 +03:00
|
|
|
'publicShareDisclaimerText' => 'Lorem ipsum',
|
2017-12-01 17:50:29 +03:00
|
|
|
'enableLinkPasswordByDefault' => 'yes',
|
|
|
|
'shareApiDefaultPermissions' => Constants::PERMISSION_ALL,
|
|
|
|
'shareApiDefaultPermissionsCheckboxes' => $this->invokePrivate($this->admin, 'getSharePermissionList', [])
|
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());
|
|
|
|
}
|
|
|
|
}
|