2015-02-07 07:07:53 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 14:49:16 +00:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2016-01-12 14:02:16 +00:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2015-02-26 07:35:41 +00:00
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* 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, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
|
|
|
*/
|
2015-02-07 07:07:53 +00:00
|
|
|
namespace OCA\Files_Sharing\Tests;
|
|
|
|
|
|
|
|
use OCA\Files_Sharing\Capabilities;
|
|
|
|
use OCA\Files_Sharing\Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
2016-05-17 09:42:03 +00:00
|
|
|
* Class CapabilitiesTest
|
2015-11-03 00:52:41 +00:00
|
|
|
*
|
|
|
|
* @group DB
|
2015-02-07 07:07:53 +00:00
|
|
|
*/
|
2016-05-17 09:42:03 +00:00
|
|
|
class CapabilitiesTest extends \Test\TestCase {
|
2015-02-07 07:07:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for the general part in each return statement and assert.
|
|
|
|
* Strip of the general part on the way.
|
|
|
|
*
|
|
|
|
* @param string[] $data Capabilities
|
|
|
|
* @return string[]
|
|
|
|
*/
|
2015-03-11 15:30:54 +00:00
|
|
|
private function getFilesSharingPart(array $data) {
|
2015-03-21 19:12:55 +00:00
|
|
|
$this->assertArrayHasKey('files_sharing', $data);
|
|
|
|
return $data['files_sharing'];
|
2015-02-07 07:07:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a mock config object and insert the values in $map tot the getAppValue
|
|
|
|
* function. Then obtain the capabilities and extract the first few
|
|
|
|
* levels in the array
|
|
|
|
*
|
|
|
|
* @param (string[])[] $map Map of arguments to return types for the getAppValue function in the mock
|
|
|
|
* @return string[]
|
|
|
|
*/
|
2015-03-11 15:30:54 +00:00
|
|
|
private function getResults(array $map) {
|
2015-02-07 07:07:53 +00:00
|
|
|
$stub = $this->getMockBuilder('\OCP\IConfig')->disableOriginalConstructor()->getMock();
|
|
|
|
$stub->method('getAppValue')->will($this->returnValueMap($map));
|
|
|
|
$cap = new Capabilities($stub);
|
2015-03-21 19:12:55 +00:00
|
|
|
$result = $this->getFilesSharingPart($cap->getCapabilities());
|
2015-02-07 07:07:53 +00:00
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2015-09-25 09:24:23 +00:00
|
|
|
public function testEnabledSharingAPI() {
|
|
|
|
$map = [
|
|
|
|
['core', 'shareapi_enabled', 'yes', 'yes'],
|
|
|
|
];
|
|
|
|
$result = $this->getResults($map);
|
|
|
|
$this->assertTrue($result['api_enabled']);
|
|
|
|
$this->assertContains('public', $result);
|
|
|
|
$this->assertContains('user', $result);
|
|
|
|
$this->assertContains('resharing', $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDisabledSharingAPI() {
|
|
|
|
$map = [
|
|
|
|
['core', 'shareapi_enabled', 'yes', 'no'],
|
|
|
|
];
|
|
|
|
$result = $this->getResults($map);
|
|
|
|
$this->assertFalse($result['api_enabled']);
|
|
|
|
$this->assertNotContains('public', $result);
|
|
|
|
$this->assertNotContains('user', $result);
|
|
|
|
$this->assertNotContains('resharing', $result);
|
|
|
|
}
|
|
|
|
|
2015-02-07 07:07:53 +00:00
|
|
|
public function testNoLinkSharing() {
|
2015-02-26 07:39:55 +00:00
|
|
|
$map = [
|
2015-09-25 09:24:23 +00:00
|
|
|
['core', 'shareapi_enabled', 'yes', 'yes'],
|
2015-02-26 07:39:55 +00:00
|
|
|
['core', 'shareapi_allow_links', 'yes', 'no'],
|
|
|
|
];
|
2015-02-07 07:07:53 +00:00
|
|
|
$result = $this->getResults($map);
|
2015-02-09 13:26:49 +00:00
|
|
|
$this->assertInternalType('array', $result['public']);
|
|
|
|
$this->assertFalse($result['public']['enabled']);
|
2015-02-07 07:07:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testOnlyLinkSharing() {
|
2015-02-26 07:39:55 +00:00
|
|
|
$map = [
|
2015-09-25 09:24:23 +00:00
|
|
|
['core', 'shareapi_enabled', 'yes', 'yes'],
|
2015-02-26 07:39:55 +00:00
|
|
|
['core', 'shareapi_allow_links', 'yes', 'yes'],
|
|
|
|
];
|
2015-02-07 07:07:53 +00:00
|
|
|
$result = $this->getResults($map);
|
|
|
|
$this->assertInternalType('array', $result['public']);
|
2015-02-09 13:26:49 +00:00
|
|
|
$this->assertTrue($result['public']['enabled']);
|
2015-02-07 07:07:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testLinkPassword() {
|
2015-02-26 07:39:55 +00:00
|
|
|
$map = [
|
2015-09-25 09:24:23 +00:00
|
|
|
['core', 'shareapi_enabled', 'yes', 'yes'],
|
2015-02-26 07:39:55 +00:00
|
|
|
['core', 'shareapi_allow_links', 'yes', 'yes'],
|
2015-08-13 11:07:49 +00:00
|
|
|
['core', 'shareapi_enforce_links_password', 'no', 'yes'],
|
2015-02-26 07:39:55 +00:00
|
|
|
];
|
2015-02-07 07:07:53 +00:00
|
|
|
$result = $this->getResults($map);
|
2015-03-11 14:11:50 +00:00
|
|
|
$this->assertArrayHasKey('password', $result['public']);
|
|
|
|
$this->assertArrayHasKey('enforced', $result['public']['password']);
|
|
|
|
$this->assertTrue($result['public']['password']['enforced']);
|
2015-02-07 07:07:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testLinkNoPassword() {
|
2015-02-26 07:39:55 +00:00
|
|
|
$map = [
|
2015-09-25 09:24:23 +00:00
|
|
|
['core', 'shareapi_enabled', 'yes', 'yes'],
|
2015-02-26 07:39:55 +00:00
|
|
|
['core', 'shareapi_allow_links', 'yes', 'yes'],
|
2015-08-13 11:07:49 +00:00
|
|
|
['core', 'shareapi_enforce_links_password', 'no', 'no'],
|
2015-02-26 07:39:55 +00:00
|
|
|
];
|
2015-02-07 07:07:53 +00:00
|
|
|
$result = $this->getResults($map);
|
2015-03-11 14:11:50 +00:00
|
|
|
$this->assertArrayHasKey('password', $result['public']);
|
|
|
|
$this->assertArrayHasKey('enforced', $result['public']['password']);
|
|
|
|
$this->assertFalse($result['public']['password']['enforced']);
|
2015-02-07 07:07:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testLinkNoExpireDate() {
|
2015-02-26 07:39:55 +00:00
|
|
|
$map = [
|
2015-09-25 09:24:23 +00:00
|
|
|
['core', 'shareapi_enabled', 'yes', 'yes'],
|
2015-02-26 07:39:55 +00:00
|
|
|
['core', 'shareapi_allow_links', 'yes', 'yes'],
|
2015-08-13 11:07:49 +00:00
|
|
|
['core', 'shareapi_default_expire_date', 'no', 'no'],
|
2015-02-26 07:39:55 +00:00
|
|
|
];
|
2015-02-07 07:07:53 +00:00
|
|
|
$result = $this->getResults($map);
|
|
|
|
$this->assertArrayHasKey('expire_date', $result['public']);
|
2015-02-09 13:26:49 +00:00
|
|
|
$this->assertInternalType('array', $result['public']['expire_date']);
|
|
|
|
$this->assertFalse($result['public']['expire_date']['enabled']);
|
2015-02-07 07:07:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testLinkExpireDate() {
|
2015-02-26 07:39:55 +00:00
|
|
|
$map = [
|
2015-09-25 09:24:23 +00:00
|
|
|
['core', 'shareapi_enabled', 'yes', 'yes'],
|
2015-02-26 07:39:55 +00:00
|
|
|
['core', 'shareapi_allow_links', 'yes', 'yes'],
|
2015-08-13 11:07:49 +00:00
|
|
|
['core', 'shareapi_default_expire_date', 'no', 'yes'],
|
2015-02-26 07:39:55 +00:00
|
|
|
['core', 'shareapi_expire_after_n_days', '7', '7'],
|
2015-08-13 11:07:49 +00:00
|
|
|
['core', 'shareapi_enforce_expire_date', 'no', 'no'],
|
2015-02-26 07:39:55 +00:00
|
|
|
];
|
2015-02-07 07:07:53 +00:00
|
|
|
$result = $this->getResults($map);
|
|
|
|
$this->assertArrayHasKey('expire_date', $result['public']);
|
|
|
|
$this->assertInternalType('array', $result['public']['expire_date']);
|
2015-02-09 13:26:49 +00:00
|
|
|
$this->assertTrue($result['public']['expire_date']['enabled']);
|
2015-02-07 07:07:53 +00:00
|
|
|
$this->assertArrayHasKey('days', $result['public']['expire_date']);
|
2015-03-11 14:11:50 +00:00
|
|
|
$this->assertFalse($result['public']['expire_date']['enforced']);
|
2015-02-07 07:07:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testLinkExpireDateEnforced() {
|
2015-02-26 07:39:55 +00:00
|
|
|
$map = [
|
2015-09-25 09:24:23 +00:00
|
|
|
['core', 'shareapi_enabled', 'yes', 'yes'],
|
2015-02-26 07:39:55 +00:00
|
|
|
['core', 'shareapi_allow_links', 'yes', 'yes'],
|
2015-08-13 11:07:49 +00:00
|
|
|
['core', 'shareapi_default_expire_date', 'no', 'yes'],
|
|
|
|
['core', 'shareapi_enforce_expire_date', 'no', 'yes'],
|
2015-02-26 07:39:55 +00:00
|
|
|
];
|
2015-02-07 07:07:53 +00:00
|
|
|
$result = $this->getResults($map);
|
|
|
|
$this->assertArrayHasKey('expire_date', $result['public']);
|
|
|
|
$this->assertInternalType('array', $result['public']['expire_date']);
|
2015-03-11 14:11:50 +00:00
|
|
|
$this->assertTrue($result['public']['expire_date']['enforced']);
|
2015-02-07 07:07:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testLinkSendMail() {
|
2015-02-26 07:39:55 +00:00
|
|
|
$map = [
|
2015-09-25 09:24:23 +00:00
|
|
|
['core', 'shareapi_enabled', 'yes', 'yes'],
|
2015-02-26 07:39:55 +00:00
|
|
|
['core', 'shareapi_allow_links', 'yes', 'yes'],
|
2015-08-13 11:07:49 +00:00
|
|
|
['core', 'shareapi_allow_public_notification', 'no', 'yes'],
|
2015-02-26 07:39:55 +00:00
|
|
|
];
|
2015-02-07 07:07:53 +00:00
|
|
|
$result = $this->getResults($map);
|
|
|
|
$this->assertTrue($result['public']['send_mail']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testLinkNoSendMail() {
|
2015-02-26 07:39:55 +00:00
|
|
|
$map = [
|
2015-09-25 09:24:23 +00:00
|
|
|
['core', 'shareapi_enabled', 'yes', 'yes'],
|
2015-02-26 07:39:55 +00:00
|
|
|
['core', 'shareapi_allow_links', 'yes', 'yes'],
|
2015-08-13 11:07:49 +00:00
|
|
|
['core', 'shareapi_allow_public_notification', 'no', 'no'],
|
2015-02-26 07:39:55 +00:00
|
|
|
];
|
2015-02-07 07:07:53 +00:00
|
|
|
$result = $this->getResults($map);
|
|
|
|
$this->assertFalse($result['public']['send_mail']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUserSendMail() {
|
2015-02-26 07:39:55 +00:00
|
|
|
$map = [
|
2015-09-25 09:24:23 +00:00
|
|
|
['core', 'shareapi_enabled', 'yes', 'yes'],
|
2015-08-13 11:07:49 +00:00
|
|
|
['core', 'shareapi_allow_mail_notification', 'no', 'yes'],
|
2015-02-26 07:39:55 +00:00
|
|
|
];
|
2015-02-07 07:07:53 +00:00
|
|
|
$result = $this->getResults($map);
|
|
|
|
$this->assertTrue($result['user']['send_mail']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUserNoSendMail() {
|
2015-02-26 07:39:55 +00:00
|
|
|
$map = [
|
2015-09-25 09:24:23 +00:00
|
|
|
['core', 'shareapi_enabled', 'yes', 'yes'],
|
2015-08-13 11:07:49 +00:00
|
|
|
['core', 'shareapi_allow_mail_notification', 'no', 'no'],
|
2015-02-26 07:39:55 +00:00
|
|
|
];
|
2015-02-07 07:07:53 +00:00
|
|
|
$result = $this->getResults($map);
|
|
|
|
$this->assertFalse($result['user']['send_mail']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testResharing() {
|
2015-02-26 07:39:55 +00:00
|
|
|
$map = [
|
2015-09-25 09:24:23 +00:00
|
|
|
['core', 'shareapi_enabled', 'yes', 'yes'],
|
2015-02-26 07:39:55 +00:00
|
|
|
['core', 'shareapi_allow_resharing', 'yes', 'yes'],
|
|
|
|
];
|
2015-02-07 07:07:53 +00:00
|
|
|
$result = $this->getResults($map);
|
|
|
|
$this->assertTrue($result['resharing']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNoResharing() {
|
2015-02-26 07:39:55 +00:00
|
|
|
$map = [
|
2015-09-25 09:24:23 +00:00
|
|
|
['core', 'shareapi_enabled', 'yes', 'yes'],
|
2015-02-26 07:39:55 +00:00
|
|
|
['core', 'shareapi_allow_resharing', 'yes', 'no'],
|
|
|
|
];
|
2015-02-07 07:07:53 +00:00
|
|
|
$result = $this->getResults($map);
|
|
|
|
$this->assertFalse($result['resharing']);
|
|
|
|
}
|
2015-08-14 18:00:04 +00:00
|
|
|
|
|
|
|
public function testLinkPublicUpload() {
|
|
|
|
$map = [
|
2015-09-25 09:24:23 +00:00
|
|
|
['core', 'shareapi_enabled', 'yes', 'yes'],
|
2015-08-14 18:00:04 +00:00
|
|
|
['core', 'shareapi_allow_links', 'yes', 'yes'],
|
|
|
|
['core', 'shareapi_allow_public_upload', 'yes', 'yes'],
|
|
|
|
];
|
|
|
|
$result = $this->getResults($map);
|
|
|
|
$this->assertTrue($result['public']['upload']);
|
2016-08-13 12:00:44 +00:00
|
|
|
$this->assertTrue($result['public']['upload_files_drop']);
|
2015-08-14 18:00:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testLinkNoPublicUpload() {
|
|
|
|
$map = [
|
2015-09-25 09:24:23 +00:00
|
|
|
['core', 'shareapi_enabled', 'yes', 'yes'],
|
2015-08-14 18:00:04 +00:00
|
|
|
['core', 'shareapi_allow_links', 'yes', 'yes'],
|
|
|
|
['core', 'shareapi_allow_public_upload', 'yes', 'no'],
|
|
|
|
];
|
|
|
|
$result = $this->getResults($map);
|
|
|
|
$this->assertFalse($result['public']['upload']);
|
2016-08-13 12:00:44 +00:00
|
|
|
$this->assertFalse($result['public']['upload_files_drop']);
|
2015-08-14 18:00:04 +00:00
|
|
|
}
|
|
|
|
|
2016-03-31 07:27:38 +00:00
|
|
|
public function testNoGroupSharing() {
|
|
|
|
$map = [
|
|
|
|
['core', 'shareapi_enabled', 'yes', 'yes'],
|
|
|
|
['core', 'shareapi_allow_group_sharing', 'yes', 'no'],
|
|
|
|
];
|
|
|
|
$result = $this->getResults($map);
|
|
|
|
$this->assertFalse($result['group_sharing']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGroupSharing() {
|
|
|
|
$map = [
|
|
|
|
['core', 'shareapi_enabled', 'yes', 'yes'],
|
|
|
|
['core', 'shareapi_allow_group_sharing', 'yes', 'yes'],
|
|
|
|
];
|
|
|
|
$result = $this->getResults($map);
|
|
|
|
$this->assertTrue($result['group_sharing']);
|
|
|
|
}
|
|
|
|
|
2015-09-12 14:25:23 +00:00
|
|
|
public function testFederatedSharingIncomming() {
|
|
|
|
$map = [
|
|
|
|
['files_sharing', 'incoming_server2server_share_enabled', 'yes', 'yes'],
|
|
|
|
];
|
|
|
|
$result = $this->getResults($map);
|
|
|
|
$this->assertArrayHasKey('federation', $result);
|
|
|
|
$this->assertTrue($result['federation']['incoming']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFederatedSharingNoIncomming() {
|
|
|
|
$map = [
|
|
|
|
['files_sharing', 'incoming_server2server_share_enabled', 'yes', 'no'],
|
|
|
|
];
|
|
|
|
$result = $this->getResults($map);
|
|
|
|
$this->assertArrayHasKey('federation', $result);
|
|
|
|
$this->assertFalse($result['federation']['incoming']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFederatedSharingOutgoing() {
|
|
|
|
$map = [
|
|
|
|
['files_sharing', 'outgoing_server2server_share_enabled', 'yes', 'yes'],
|
|
|
|
];
|
|
|
|
$result = $this->getResults($map);
|
|
|
|
$this->assertArrayHasKey('federation', $result);
|
|
|
|
$this->assertTrue($result['federation']['outgoing']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFederatedSharingNoOutgoing() {
|
|
|
|
$map = [
|
|
|
|
['files_sharing', 'outgoing_server2server_share_enabled', 'yes', 'no'],
|
|
|
|
];
|
|
|
|
$result = $this->getResults($map);
|
|
|
|
$this->assertArrayHasKey('federation', $result);
|
|
|
|
$this->assertFalse($result['federation']['outgoing']);
|
|
|
|
}
|
2015-08-14 18:00:04 +00:00
|
|
|
|
2015-02-07 07:07:53 +00:00
|
|
|
}
|