2018-02-07 18:22:00 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests for sharing files and directories
|
|
|
|
*
|
2018-04-04 18:25:42 +02:00
|
|
|
* We systematically test the various Vfs backends with files, subdirectories
|
|
|
|
* and symlinks. A backend is mounted (if needed) and test files are created.
|
|
|
|
* Then we create the share (readable, writable) log out and check what the share
|
|
|
|
* gives. This is compared against what should be available, and we check the
|
|
|
|
* access on each.
|
2018-03-14 17:23:17 +01:00
|
|
|
*
|
2018-02-07 18:22:00 +01:00
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Nathan Gray
|
|
|
|
* @copyright (c) 2018 Nathan Gray
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace EGroupware\Api\Vfs;
|
|
|
|
|
2018-04-04 23:00:47 +02:00
|
|
|
require_once __DIR__ . '/SharingBase.php';
|
|
|
|
|
2018-02-07 18:22:00 +01:00
|
|
|
use EGroupware\Api\Vfs;
|
|
|
|
use EGroupware\Api\LoggedInTest as LoggedInTest;
|
|
|
|
|
|
|
|
|
2018-04-04 18:25:42 +02:00
|
|
|
class SharingTest extends SharingBase
|
2018-02-07 18:22:00 +01:00
|
|
|
{
|
2018-02-20 23:32:37 +01:00
|
|
|
/**
|
|
|
|
* Test to make sure a readonly link to home gives just readonly access,
|
|
|
|
* and just to user's home
|
|
|
|
*/
|
2018-03-23 19:58:55 +01:00
|
|
|
public function testHomeReadonly()
|
2018-02-20 23:32:37 +01:00
|
|
|
{
|
2018-03-21 16:44:42 +01:00
|
|
|
$dir = Vfs::get_home_dir().'/';
|
2018-02-20 23:32:37 +01:00
|
|
|
|
2018-03-22 18:09:09 +01:00
|
|
|
$this->checkDirectory($dir, Sharing::READONLY);
|
2018-03-21 20:48:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test to make sure a writable link to home gives write access, but just
|
|
|
|
* to user's home
|
|
|
|
*/
|
2018-03-23 19:58:55 +01:00
|
|
|
public function testHomeWritable()
|
2018-03-21 20:48:10 +01:00
|
|
|
{
|
|
|
|
$dir = Vfs::get_home_dir().'/';
|
|
|
|
|
|
|
|
$this->checkDirectory($dir, Sharing::WRITABLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for a readonly share of a path with versioning turned on
|
|
|
|
*/
|
2018-03-23 19:58:55 +01:00
|
|
|
public function testVersioningReadonly()
|
2018-03-21 20:48:10 +01:00
|
|
|
{
|
|
|
|
$this->files[] = $dir = Vfs::get_home_dir().'/versioned/';
|
|
|
|
|
|
|
|
// Create versioned directory
|
|
|
|
if(Vfs::is_dir($dir)) Vfs::remove($dir);
|
|
|
|
Vfs::mkdir($dir);
|
|
|
|
$this->assertTrue(Vfs::is_writable($dir), "Unable to write to '$dir' as expected");
|
|
|
|
$this->mountVersioned($dir);
|
|
|
|
|
|
|
|
$this->checkDirectory($dir, Sharing::READONLY);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for a writable share of a path with versioning turned on
|
|
|
|
*/
|
2018-03-23 19:58:55 +01:00
|
|
|
public function testVersioningWritable()
|
2018-03-21 20:48:10 +01:00
|
|
|
{
|
|
|
|
$this->files[] = $dir = Vfs::get_home_dir().'/versioned/';
|
|
|
|
|
|
|
|
// Create versioned directory
|
|
|
|
if(Vfs::is_dir($dir)) Vfs::remove($dir);
|
|
|
|
Vfs::mkdir($dir);
|
|
|
|
$this->assertTrue(Vfs::is_writable($dir), "Unable to write to '$dir' as expected");
|
|
|
|
$this->mountVersioned($dir);
|
|
|
|
|
|
|
|
$this->checkDirectory($dir, Sharing::WRITABLE);
|
|
|
|
}
|
|
|
|
|
2018-03-22 18:09:09 +01:00
|
|
|
/**
|
|
|
|
* Test for a readonly share of a path from the filesystem
|
|
|
|
*/
|
2018-03-23 19:58:55 +01:00
|
|
|
public function testFilesystemReadonly()
|
2018-03-22 18:09:09 +01:00
|
|
|
{
|
|
|
|
// Don't add to files list or it deletes the folder from filesystem
|
|
|
|
$dir = '/filesystem/';
|
|
|
|
|
|
|
|
// Mount filesystem directory
|
|
|
|
if(Vfs::is_dir($dir)) Vfs::remove($dir);
|
|
|
|
$this->mountFilesystem($dir);
|
|
|
|
$this->assertTrue(Vfs::is_writable($dir), "Unable to write to '$dir' as expected");
|
|
|
|
|
|
|
|
$this->checkDirectory($dir, Sharing::READONLY);
|
|
|
|
|
|
|
|
// Test folder in filesystem already has this file in it
|
2018-03-22 18:13:05 +01:00
|
|
|
// It should be picked up normally, but an explicit check can't hurt
|
|
|
|
$this->checkOneFile('/filesystem_test.txt', Sharing::READONLY);
|
2018-03-22 18:09:09 +01:00
|
|
|
}
|
|
|
|
|
2018-03-22 18:19:16 +01:00
|
|
|
/**
|
|
|
|
* Test for a readonly share of a path from the filesystem
|
|
|
|
*/
|
2018-03-23 19:58:55 +01:00
|
|
|
public function testFilesystemWritable()
|
2018-03-22 18:19:16 +01:00
|
|
|
{
|
|
|
|
// Don't add to files list or it deletes the folder from filesystem
|
|
|
|
$dir = '/filesystem/';
|
|
|
|
|
|
|
|
// Mount filesystem directory
|
|
|
|
if(Vfs::is_dir($dir)) Vfs::remove($dir);
|
|
|
|
$this->mountFilesystem($dir);
|
|
|
|
$this->assertTrue(Vfs::is_writable($dir), "Unable to write to '$dir' as expected");
|
|
|
|
|
|
|
|
$this->checkDirectory($dir, Sharing::WRITABLE);
|
|
|
|
|
|
|
|
// Test folder in filesystem already has this file in it
|
|
|
|
// It should be picked up normally, but an explicit check can't hurt
|
|
|
|
$this->checkOneFile('/filesystem_test.txt', Sharing::WRITABLE);
|
|
|
|
}
|
|
|
|
|
2018-03-22 22:07:07 +01:00
|
|
|
/**
|
|
|
|
* Test for a readonly share of an application entry's filesystem (/apps)
|
|
|
|
*/
|
|
|
|
public function testLinksReadonly()
|
|
|
|
{
|
|
|
|
// Create an infolog entry for testing purposes
|
|
|
|
$info_id = $this->make_infolog();
|
|
|
|
$bo = new \infolog_bo();
|
|
|
|
$dir = "/apps/infolog/$info_id/";
|
|
|
|
|
|
|
|
$this->assertTrue(Vfs::is_writable($dir), "Unable to write to '$dir' as expected");
|
|
|
|
|
|
|
|
$this->checkDirectory($dir, Sharing::READONLY);
|
|
|
|
|
|
|
|
// Can't delete it here, we're still the anonymous user until after
|
|
|
|
$this->entries[] = Array(Array($bo, 'delete'), Array($info_id, false, false, true));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for a writable share of an application entry's filesystem (/apps)
|
|
|
|
*/
|
|
|
|
public function testLinksWritable()
|
|
|
|
{
|
|
|
|
// Create an infolog entry for testing purposes
|
|
|
|
$bo = new \infolog_bo();
|
|
|
|
$info_id = $this->make_infolog();
|
|
|
|
$dir = "/apps/infolog/$info_id/";
|
|
|
|
|
|
|
|
$this->assertTrue(Vfs::is_writable($dir), "Unable to write to '$dir' as expected");
|
|
|
|
|
|
|
|
$this->checkDirectory($dir, Sharing::WRITABLE);
|
|
|
|
|
|
|
|
// Can't delete it here, we're still the anonymous user until after
|
|
|
|
$this->entries[] = Array(Array($bo, 'delete'), Array($info_id, false, false, true));
|
|
|
|
}
|
|
|
|
|
2018-03-23 19:58:55 +01:00
|
|
|
/**
|
|
|
|
* Test merge stream wrapper
|
|
|
|
*/
|
|
|
|
public function testMergeReadonly()
|
|
|
|
{
|
|
|
|
if(!class_exists("\EGroupware\Stylite\Vfs\Merge\StreamWrapper"))
|
|
|
|
{
|
|
|
|
$this->markTestAsSkipped();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Don't add to files list or it deletes the folder from filesystem
|
|
|
|
$dir = '/merged/';
|
|
|
|
|
|
|
|
// Mount filesystem directory
|
|
|
|
if(Vfs::is_dir($dir)) Vfs::remove($dir);
|
|
|
|
$this->mountMerge($dir);
|
|
|
|
|
|
|
|
$this->assertTrue(
|
|
|
|
Vfs::is_writable($dir),
|
|
|
|
"Unable to write to '$dir' as expected, check {$GLOBALS['egw_info']['user']['account_lid']} is in Admin group (Merge requirement)"
|
|
|
|
);
|
|
|
|
$this->checkDirectory($dir, Sharing::READONLY);
|
|
|
|
|
|
|
|
// Test folder in filesystem already has this file in it
|
|
|
|
// It should be picked up normally, but an explicit check can't hurt
|
|
|
|
$this->checkOneFile('/filesystem_test.txt', Sharing::READONLY);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test merge stream wrapper
|
|
|
|
*/
|
|
|
|
public function testMergeWritable()
|
|
|
|
{
|
|
|
|
if(!class_exists("\EGroupware\Stylite\Vfs\Merge\StreamWrapper"))
|
|
|
|
{
|
|
|
|
$this->markTestAsSkipped();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Don't add to files list or it deletes the folder from filesystem
|
|
|
|
$dir = '/merged/';
|
|
|
|
|
|
|
|
// Mount filesystem directory
|
|
|
|
if(Vfs::is_dir($dir)) Vfs::remove($dir);
|
|
|
|
$this->mountMerge($dir);
|
|
|
|
|
|
|
|
$this->assertTrue(
|
|
|
|
Vfs::is_writable($dir),
|
|
|
|
"Unable to write to '$dir' as expected, check {$GLOBALS['egw_info']['user']['account_lid']} is in Admin group (Merge requirement)"
|
|
|
|
);
|
|
|
|
$this->checkDirectory($dir, Sharing::WRITABLE);
|
|
|
|
|
|
|
|
// Test folder in filesystem already has this file in it
|
|
|
|
// It should be picked up normally, but an explicit check can't hurt
|
|
|
|
$this->checkOneFile('/filesystem_test.txt', Sharing::WRITABLE);
|
|
|
|
}
|
2018-04-09 19:17:50 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that creating a share on a symlink actually creates the share on the
|
|
|
|
* link target instead.
|
|
|
|
*/
|
|
|
|
public function testSharingSymlinkActuallySharesTargetFile()
|
|
|
|
{
|
|
|
|
$target = Vfs::get_home_dir();
|
|
|
|
|
|
|
|
$this->files = $this->addFiles($target);
|
|
|
|
|
|
|
|
// Make symlink
|
|
|
|
$this->files[] = $symlink = $target.'/symlink.txt';
|
|
|
|
$file = $target.'/test_file.txt';
|
|
|
|
if(Vfs::file_exists($symlink)) Vfs::remove($symlink);
|
|
|
|
$this->assertTrue(
|
|
|
|
Vfs::symlink($file, $symlink),
|
|
|
|
"Unable to create symlink $symlink => $file"
|
|
|
|
);
|
|
|
|
|
|
|
|
// Create share
|
|
|
|
$this->shares[] = $created_share = Sharing::create($symlink, Sharing::READONLY, '', '');
|
|
|
|
|
|
|
|
$this->assertEquals($file, $created_share['share_path']);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that creating a share on a symlink actually creates the share on the
|
|
|
|
* link target instead.
|
|
|
|
*/
|
|
|
|
public function testSharingSymlinkActuallySharesTargetDirectory()
|
|
|
|
{
|
|
|
|
$target = Vfs::get_home_dir();
|
|
|
|
|
|
|
|
$this->files = $this->addFiles($target);
|
|
|
|
|
|
|
|
// Make symlink
|
|
|
|
$this->files[] = $symlink = $target.'/symlinked_dir';
|
|
|
|
$file = $target.'/sub_dir';
|
|
|
|
if(Vfs::file_exists($symlink)) Vfs::remove($symlink);
|
|
|
|
$this->assertTrue(
|
|
|
|
Vfs::symlink($file, $symlink),
|
|
|
|
"Unable to create symlink $symlink => $file"
|
|
|
|
);
|
|
|
|
|
|
|
|
// Create share
|
|
|
|
$this->shares[] = $created_share = Sharing::create($symlink, Sharing::READONLY, '', '');
|
|
|
|
|
|
|
|
$this->assertEquals($file, $created_share['share_path']);
|
|
|
|
}
|
2018-02-07 18:22:00 +01:00
|
|
|
}
|