2018-02-07 18:22:00 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests for sharing files and directories
|
|
|
|
*
|
2018-03-14 17:23:17 +01:00
|
|
|
* This is a bit of a mess, but I think we probably want to automatically test
|
|
|
|
* this to make sure we don't expose more than desired.
|
|
|
|
*
|
2018-02-07 18:22:00 +01:00
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Nathan Gray
|
|
|
|
* @package
|
|
|
|
* @copyright (c) 2018 Nathan Gray
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace EGroupware\Api\Vfs;
|
|
|
|
|
|
|
|
use EGroupware\Api;
|
|
|
|
use EGroupware\Api\Vfs;
|
|
|
|
use EGroupware\Api\LoggedInTest as LoggedInTest;
|
2018-03-21 20:48:10 +01:00
|
|
|
use EGroupware\Stylite\Vfs\Versioning;
|
2018-02-07 18:22:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
class SharingTest extends LoggedInTest
|
|
|
|
{
|
2018-03-22 18:09:09 +01:00
|
|
|
/**
|
|
|
|
* How much should be logged to the console (stdout)
|
|
|
|
*
|
|
|
|
* 0 = Nothing
|
|
|
|
* 1 = info
|
|
|
|
* 2 = debug
|
|
|
|
*/
|
|
|
|
const LOG_LEVEL = 0;
|
2018-02-07 18:22:00 +01:00
|
|
|
|
2018-03-21 20:48:10 +01:00
|
|
|
/**
|
|
|
|
* Keep track of shares to remove after
|
|
|
|
*/
|
2018-02-07 18:22:00 +01:00
|
|
|
protected $shares = Array();
|
|
|
|
|
2018-03-21 20:48:10 +01:00
|
|
|
/**
|
|
|
|
* Keep track of files to remove after
|
|
|
|
* @var Array
|
|
|
|
*/
|
2018-03-20 22:44:27 +01:00
|
|
|
protected $files = Array();
|
|
|
|
|
2018-03-22 18:09:09 +01:00
|
|
|
/**
|
|
|
|
* Keep track of mounts to remove after
|
|
|
|
*/
|
|
|
|
protected $mounts = Array();
|
|
|
|
|
2018-03-22 22:07:07 +01:00
|
|
|
/**
|
|
|
|
* Entries that have to be deleted after
|
|
|
|
*/
|
|
|
|
protected $entries = Array();
|
|
|
|
|
2018-03-21 20:48:10 +01:00
|
|
|
/**
|
|
|
|
* Options for searching the Vfs (Vfs::find())
|
|
|
|
*/
|
|
|
|
const VFS_OPTIONS = array(
|
|
|
|
'maxdepth' => 5
|
|
|
|
);
|
|
|
|
|
2018-02-07 18:22:00 +01:00
|
|
|
public function setUp()
|
|
|
|
{
|
2018-03-21 16:44:42 +01:00
|
|
|
|
2018-02-07 18:22:00 +01:00
|
|
|
}
|
2018-03-21 16:44:42 +01:00
|
|
|
|
2018-02-07 18:22:00 +01:00
|
|
|
public function tearDown()
|
|
|
|
{
|
2018-03-20 22:44:27 +01:00
|
|
|
LoggedInTest::tearDownAfterClass();
|
2018-02-15 17:37:48 +01:00
|
|
|
LoggedInTest::setupBeforeClass();
|
2018-03-20 22:44:27 +01:00
|
|
|
|
2018-03-21 16:44:42 +01:00
|
|
|
// Re-init, since they look at user, fstab, etc.
|
|
|
|
// Also, further tests that access the filesystem fail if we don't
|
|
|
|
Vfs::clearstatcache();
|
|
|
|
Vfs::init_static();
|
|
|
|
Vfs\StreamWrapper::init_static();
|
2018-02-20 23:32:37 +01:00
|
|
|
|
|
|
|
// Need to ask about mounts, or other tests fail
|
|
|
|
Vfs::mount();
|
|
|
|
|
2018-03-21 20:48:10 +01:00
|
|
|
$backup = Vfs::$is_root;
|
|
|
|
Vfs::$is_root = true;
|
2018-03-22 18:09:09 +01:00
|
|
|
|
|
|
|
// Remove any added files (as root to limit versioning issues)
|
2018-03-21 20:48:10 +01:00
|
|
|
Vfs::remove($this->files);
|
2018-03-22 18:09:09 +01:00
|
|
|
|
|
|
|
// Remove any mounts
|
|
|
|
foreach($this->mounts as $mount)
|
|
|
|
{
|
|
|
|
Vfs::umount($mount);
|
|
|
|
}
|
2018-03-20 22:44:27 +01:00
|
|
|
|
|
|
|
// Remove any added shares
|
2018-02-07 18:22:00 +01:00
|
|
|
foreach($this->shares as $share)
|
|
|
|
{
|
2018-03-20 22:44:27 +01:00
|
|
|
Sharing::delete($share);
|
2018-02-07 18:22:00 +01:00
|
|
|
}
|
2018-03-22 18:09:09 +01:00
|
|
|
|
2018-03-22 22:07:07 +01:00
|
|
|
foreach($this->entries as $entry)
|
|
|
|
{
|
|
|
|
list($callback, $params) = $entry;
|
|
|
|
call_user_func_array($callback, $params);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-22 18:09:09 +01:00
|
|
|
Vfs::$is_root = $backup;
|
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-22 22:07:07 +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-22 22:07:07 +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-22 22:07:07 +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-22 22:07:07 +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-22 22:07:07 +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-22 22:07:07 +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-21 20:48:10 +01:00
|
|
|
/**
|
|
|
|
* Check a given directory to see that a link to it works.
|
|
|
|
*
|
|
|
|
* We check
|
|
|
|
* - Files/directories available to original user are available through share
|
|
|
|
* - Permissions match share (Read / Write)
|
|
|
|
* - Files are not empty
|
|
|
|
*
|
|
|
|
* @param string $dir
|
|
|
|
* @param string $mode
|
|
|
|
*/
|
|
|
|
protected function checkDirectory($dir, $mode)
|
|
|
|
{
|
2018-03-22 18:09:09 +01:00
|
|
|
if(static::LOG_LEVEL)
|
|
|
|
{
|
|
|
|
echo "\n".__METHOD__ . "($dir, $mode)\n";
|
|
|
|
}
|
2018-03-21 20:48:10 +01:00
|
|
|
$this->files += $this->addFiles($dir);
|
|
|
|
|
2018-02-20 23:32:37 +01:00
|
|
|
$logged_in_files = array_map(
|
|
|
|
function($path) use ($dir) {return str_replace($dir, '/', $path);},
|
2018-03-21 20:48:10 +01:00
|
|
|
Vfs::find($dir, static::VFS_OPTIONS)
|
2018-02-20 23:32:37 +01:00
|
|
|
);
|
|
|
|
|
2018-03-22 18:09:09 +01:00
|
|
|
if(static::LOG_LEVEL > 1)
|
|
|
|
{
|
|
|
|
echo "\n".$this->getName();
|
|
|
|
echo "\nLogged in files:\n".implode("\n", $logged_in_files)."\n";
|
|
|
|
}
|
2018-03-21 20:48:10 +01:00
|
|
|
|
|
|
|
// Create and use link
|
|
|
|
$extra = array();
|
|
|
|
switch($mode)
|
|
|
|
{
|
|
|
|
case Sharing::WRITABLE:
|
|
|
|
$extra['share_writable'] = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$this->shareLink($dir, $mode, $extra);
|
|
|
|
|
|
|
|
$files = Vfs::find('/', static::VFS_OPTIONS);
|
|
|
|
|
2018-03-22 18:09:09 +01:00
|
|
|
if(static::LOG_LEVEL > 1)
|
|
|
|
{
|
|
|
|
echo "\nLinked files:\n".implode("\n", $files)."\n";
|
|
|
|
}
|
2018-02-20 23:32:37 +01:00
|
|
|
|
|
|
|
// Make sure files are the same
|
|
|
|
$this->assertEquals($logged_in_files, $files);
|
|
|
|
|
|
|
|
// Make sure all are readonly
|
|
|
|
foreach($files as $file)
|
|
|
|
{
|
2018-03-21 20:48:10 +01:00
|
|
|
$this->checkOneFile($file, $mode);
|
2018-02-20 23:32:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-03-21 20:48:10 +01:00
|
|
|
* Check the access permissions for one file/directory
|
|
|
|
*
|
|
|
|
* @param string $file
|
|
|
|
* @param string $mode
|
2018-02-20 23:32:37 +01:00
|
|
|
*/
|
2018-03-21 20:48:10 +01:00
|
|
|
protected function checkOneFile($file, $mode)
|
2018-02-20 23:32:37 +01:00
|
|
|
{
|
2018-03-22 18:09:09 +01:00
|
|
|
if(static::LOG_LEVEL > 1)
|
|
|
|
{
|
|
|
|
$stat = Vfs::stat($file);
|
|
|
|
echo "\t".Vfs::int2mode($stat['mode'])."\t$file\n";
|
|
|
|
}
|
|
|
|
|
2018-03-21 20:48:10 +01:00
|
|
|
// All the test files have something in them
|
|
|
|
if(!Vfs::is_dir($file))
|
|
|
|
{
|
|
|
|
$this->assertNotEmpty(file_get_contents(Vfs::PREFIX.$file), "$file was empty");
|
|
|
|
}
|
2018-03-14 17:23:17 +01:00
|
|
|
|
2018-03-21 20:48:10 +01:00
|
|
|
// Check permissions
|
|
|
|
switch($mode)
|
2018-03-14 17:23:17 +01:00
|
|
|
{
|
2018-03-21 20:48:10 +01:00
|
|
|
case Sharing::READONLY:
|
|
|
|
$this->assertFalse(Vfs::is_writable($file));
|
|
|
|
if(!Vfs::is_dir($file))
|
|
|
|
{
|
2018-03-22 18:09:09 +01:00
|
|
|
// We expect this to fail
|
|
|
|
$this->assertFalse(@file_put_contents(Vfs::PREFIX.$file, 'Writable check'));
|
2018-03-21 20:48:10 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Sharing::WRITABLE:
|
|
|
|
// Root is not writable
|
|
|
|
if($file == '/') continue;
|
|
|
|
|
|
|
|
$this->assertTrue(Vfs::is_writable($file), $file . ' was not writable');
|
|
|
|
if(!Vfs::is_dir($file))
|
|
|
|
{
|
|
|
|
$this->assertNotFalse(file_put_contents(Vfs::PREFIX.$file, 'Writable check'));
|
|
|
|
}
|
|
|
|
break;
|
2018-03-14 17:23:17 +01:00
|
|
|
}
|
|
|
|
|
2018-03-21 20:48:10 +01:00
|
|
|
}
|
|
|
|
|
2018-03-22 18:09:09 +01:00
|
|
|
/**
|
|
|
|
* Start versioning for the given path
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
*/
|
2018-03-21 20:48:10 +01:00
|
|
|
protected function mountVersioned($path)
|
|
|
|
{
|
|
|
|
if (!class_exists('EGroupware\Stylite\Vfs\Versioning\StreamWrapper'))
|
|
|
|
{
|
|
|
|
$this->markTestSkipped("No versioning available");
|
|
|
|
}
|
2018-03-22 18:09:09 +01:00
|
|
|
if(substr($path, -1) == '/') $path = substr($path, 0, -1);
|
2018-03-21 20:48:10 +01:00
|
|
|
$backup = Vfs::$is_root;
|
|
|
|
Vfs::$is_root = true;
|
|
|
|
$url = Versioning\StreamWrapper::PREFIX.$path;
|
|
|
|
$this->assertTrue(Vfs::mount($url,$path), "Unable to mount $path as versioned");
|
|
|
|
Vfs::$is_root = $backup;
|
2018-03-22 18:09:09 +01:00
|
|
|
|
|
|
|
$this->mounts[] = $path;
|
|
|
|
Vfs::clearstatcache();
|
|
|
|
Vfs::init_static();
|
|
|
|
Vfs\StreamWrapper::init_static();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function mountFilesystem($path)
|
|
|
|
{
|
|
|
|
// Vfs breaks if path has trailing /
|
|
|
|
if(substr($path, -1) == '/') $path = substr($path, 0, -1);
|
|
|
|
|
|
|
|
$backup = Vfs::$is_root;
|
|
|
|
Vfs::$is_root = true;
|
|
|
|
$url = Filesystem\StreamWrapper::SCHEME.'://default'. realpath(__DIR__ . '/../fixtures/Vfs/filesystem_mount'). '?group=Default&mode=775';
|
|
|
|
$this->assertTrue(Vfs::mount($url,$path), "Unable to mount $fs to $path");
|
|
|
|
Vfs::$is_root = $backup;
|
|
|
|
|
|
|
|
$this->mounts[] = $path;
|
|
|
|
Vfs::clearstatcache();
|
|
|
|
Vfs::init_static();
|
|
|
|
Vfs\StreamWrapper::init_static();
|
2018-03-21 20:48:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add some files to the given path so there's something to find.
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
*
|
|
|
|
* @return array of paths
|
|
|
|
*/
|
|
|
|
protected function addFiles($path)
|
|
|
|
{
|
|
|
|
$files = array();
|
|
|
|
|
|
|
|
// Plain file
|
|
|
|
$files[] = $file = $path.'test_file.txt';
|
2018-03-20 22:44:27 +01:00
|
|
|
$this->assertTrue(
|
|
|
|
file_put_contents(Vfs::PREFIX.$file, 'Test for ' . $this->getName() ."\n". Api\DateTime::to()) !== FALSE,
|
|
|
|
'Unable to write test file - check file permissions for CLI user'
|
|
|
|
);
|
2018-02-20 23:32:37 +01:00
|
|
|
|
2018-03-21 20:48:10 +01:00
|
|
|
// Subdirectory
|
|
|
|
$files[] = $dir = $path.'sub_dir/';
|
|
|
|
if(Vfs::is_dir($dir))
|
2018-02-20 23:32:37 +01:00
|
|
|
{
|
2018-03-21 20:48:10 +01:00
|
|
|
Vfs::remove($dir);
|
2018-02-20 23:32:37 +01:00
|
|
|
}
|
2018-03-21 20:48:10 +01:00
|
|
|
$this->assertTrue(
|
|
|
|
Vfs::mkdir($dir),
|
|
|
|
'Unable to create subdirectory ' . $dir
|
|
|
|
);
|
|
|
|
|
|
|
|
// File in a subdirectory
|
|
|
|
$files[] = $file = $dir.'subdir_test_file.txt';
|
|
|
|
$this->assertTrue(
|
|
|
|
file_put_contents(Vfs::PREFIX.$file, 'Test for ' . $this->getName() ."\n". Api\DateTime::to()) !== FALSE,
|
|
|
|
'Unable to write test file - check file permissions for CLI user'
|
|
|
|
);
|
2018-03-22 18:09:09 +01:00
|
|
|
|
|
|
|
// Symlinked file
|
|
|
|
/* Always says its empty
|
|
|
|
$files[] = $symlink = $path.'symlink.txt';
|
|
|
|
if(Vfs::file_exists($symlink)) Vfs::remove($symlink);
|
|
|
|
$this->assertTrue(
|
|
|
|
Vfs::symlink($file, $symlink),
|
|
|
|
'Unable to create symlink'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Symlinked dir
|
|
|
|
$files[] = $symlinked_dir = $path.'sym_dir/';
|
|
|
|
$this->assertTrue(
|
|
|
|
Vfs::symlink($dir, $symlinked_dir),
|
|
|
|
'Unable to create symlinked directory ' . $symlinked_dir
|
|
|
|
);
|
|
|
|
*/
|
2018-03-21 20:48:10 +01:00
|
|
|
return $files;
|
2018-02-20 23:32:37 +01:00
|
|
|
}
|
|
|
|
|
2018-02-07 18:22:00 +01:00
|
|
|
/**
|
|
|
|
* Test that readable shares are actually readable
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
*/
|
2018-03-20 22:44:27 +01:00
|
|
|
public function createShare($path, $mode, $extra = array())
|
2018-02-07 18:22:00 +01:00
|
|
|
{
|
2018-02-20 23:32:37 +01:00
|
|
|
// Make sure the path is there
|
|
|
|
if(!Vfs::is_readable($path))
|
|
|
|
{
|
|
|
|
$this->assertTrue(Vfs::is_dir($path) ? Vfs::mkdir($path,0750,true) : Vfs::touch($path));
|
|
|
|
}
|
2018-02-07 18:22:00 +01:00
|
|
|
|
2018-02-20 23:32:37 +01:00
|
|
|
// Create share
|
2018-03-20 22:44:27 +01:00
|
|
|
$this->shares[] = $share = Sharing::create($path, $mode, $name, $recipients, $extra);
|
2018-02-07 18:22:00 +01:00
|
|
|
|
|
|
|
return $share;
|
|
|
|
}
|
|
|
|
|
2018-03-22 22:07:07 +01:00
|
|
|
/**
|
|
|
|
* Make an infolog entry
|
|
|
|
*/
|
|
|
|
protected function make_infolog()
|
|
|
|
{
|
|
|
|
$bo = new \infolog_bo();
|
|
|
|
$element = array(
|
|
|
|
'info_subject' => "Test infolog for #{$this->getName()}",
|
|
|
|
'info_des' => 'Test element for ' . $this->getName() ."\n". Api\DateTime::to(),
|
|
|
|
'info_status' => 'open'
|
|
|
|
);
|
|
|
|
|
|
|
|
$element_id = $bo->write($element, true, true, true, true);
|
|
|
|
return $element_id;
|
|
|
|
}
|
|
|
|
|
2018-02-07 18:22:00 +01:00
|
|
|
/**
|
2018-02-20 23:32:37 +01:00
|
|
|
* Test that a share link can be made, and that only that path is available
|
2018-02-07 18:22:00 +01:00
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
*/
|
2018-03-20 22:44:27 +01:00
|
|
|
public function shareLink($path, $mode, $extra = array())
|
2018-02-07 18:22:00 +01:00
|
|
|
{
|
2018-03-22 18:09:09 +01:00
|
|
|
if(static::LOG_LEVEL > 1)
|
|
|
|
{
|
|
|
|
echo __METHOD__ . "('$path',$mode)\n";
|
|
|
|
}
|
2018-02-07 18:22:00 +01:00
|
|
|
// Setup - create path and share
|
2018-03-20 22:44:27 +01:00
|
|
|
$share = $this->createShare($path, $mode, $extra);
|
2018-02-07 18:22:00 +01:00
|
|
|
$link = Vfs\Sharing::share2link($share);
|
2018-03-20 22:44:27 +01:00
|
|
|
//echo __METHOD__ . " link: $link\n";
|
2018-03-22 18:09:09 +01:00
|
|
|
|
|
|
|
if(static::LOG_LEVEL)
|
|
|
|
{
|
|
|
|
echo __METHOD__ . " share: " . array2string($share)."\n";
|
|
|
|
}
|
2018-02-07 18:22:00 +01:00
|
|
|
|
2018-02-15 17:37:48 +01:00
|
|
|
// Setup for share to load
|
2018-02-07 18:22:00 +01:00
|
|
|
$_SERVER['REQUEST_URI'] = $link;
|
2018-02-15 17:37:48 +01:00
|
|
|
preg_match('|^https?://[^/]+(/.*)share.php/'.$share['share_token'].'$|', $path_info=$_SERVER['REQUEST_URI'], $matches);
|
|
|
|
$_SERVER['SCRIPT_NAME'] = $matches[1];
|
|
|
|
|
2018-03-21 16:44:42 +01:00
|
|
|
// Log out & clear cache
|
2018-02-15 17:37:48 +01:00
|
|
|
LoggedInTest::tearDownAfterClass();
|
2018-03-21 20:48:10 +01:00
|
|
|
|
|
|
|
// Re-init, since they look at user, fstab, etc.
|
|
|
|
// Also, further tests that access the filesystem fail if we don't
|
2018-03-21 16:44:42 +01:00
|
|
|
Vfs::clearstatcache();
|
2018-03-21 20:48:10 +01:00
|
|
|
Vfs::init_static();
|
|
|
|
Vfs\StreamWrapper::init_static();
|
|
|
|
|
2018-02-07 18:22:00 +01:00
|
|
|
|
2018-02-15 17:37:48 +01:00
|
|
|
// If it's a directory, check to make sure it gives the filemanager UI
|
2018-02-07 18:22:00 +01:00
|
|
|
if(Vfs::is_dir($path))
|
|
|
|
{
|
|
|
|
$this->checkDirectoryLink($link, $share);
|
|
|
|
}
|
|
|
|
|
2018-02-15 17:37:48 +01:00
|
|
|
// Load share
|
|
|
|
$this->setup_info();
|
|
|
|
|
2018-03-22 18:09:09 +01:00
|
|
|
|
|
|
|
if(static::LOG_LEVEL > 1)
|
|
|
|
{
|
|
|
|
echo "Sharing mounts:\n";
|
|
|
|
var_dump(Vfs::mount());
|
|
|
|
}
|
|
|
|
|
2018-02-20 23:32:37 +01:00
|
|
|
// Our path should be mounted to root
|
2018-03-22 18:09:09 +01:00
|
|
|
$this->assertTrue(Vfs::is_readable('/'), 'Could not read root (/) from link');
|
2018-02-15 17:37:48 +01:00
|
|
|
|
2018-02-20 23:32:37 +01:00
|
|
|
// Check other paths
|
|
|
|
$this->assertFalse(Vfs::is_readable($path));
|
|
|
|
$this->assertFalse(Vfs::is_readable($path . '../'));
|
2018-02-07 18:22:00 +01:00
|
|
|
}
|
|
|
|
|
2018-02-15 17:37:48 +01:00
|
|
|
/**
|
|
|
|
* Test to make sure that a directory link leads to a limited filemanager
|
|
|
|
* interface (not a file or 404).
|
|
|
|
*
|
|
|
|
* @param type $link
|
|
|
|
* @param type $share
|
|
|
|
*/
|
2018-02-07 18:22:00 +01:00
|
|
|
public function checkDirectoryLink($link, $share)
|
|
|
|
{
|
2018-02-20 23:32:37 +01:00
|
|
|
// Set up curl
|
2018-02-07 18:22:00 +01:00
|
|
|
$curl = curl_init($link);
|
|
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
|
|
|
|
$html = curl_exec($curl);
|
|
|
|
curl_close($curl);
|
2018-02-20 23:32:37 +01:00
|
|
|
|
2018-03-14 17:23:17 +01:00
|
|
|
if(!$html)
|
|
|
|
{
|
|
|
|
// No response - could mean something is terribly wrong, or it could
|
|
|
|
// mean we're running on Travis with no webserver to answer the
|
|
|
|
// request
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-20 23:32:37 +01:00
|
|
|
// Parse & check for nextmatch
|
2018-02-07 18:22:00 +01:00
|
|
|
$dom = new \DOMDocument();
|
2018-02-20 23:32:37 +01:00
|
|
|
@$dom->loadHTML($html);
|
2018-02-07 18:22:00 +01:00
|
|
|
$xpath = new \DOMXPath($dom);
|
|
|
|
$form = $xpath->query ('//form')->item(0);
|
2018-03-22 18:09:09 +01:00
|
|
|
if(!$form && static::LOG_LEVEL)
|
|
|
|
{
|
|
|
|
echo "Didn't find filemanager interface\n";
|
|
|
|
if(static::LOG_LEVEL > 1)
|
|
|
|
{
|
|
|
|
echo $form."\n\n";
|
|
|
|
}
|
|
|
|
}
|
2018-02-07 18:22:00 +01:00
|
|
|
$data = json_decode($form->getAttribute('data-etemplate'));
|
|
|
|
|
|
|
|
$this->assertEquals('filemanager.index', $data->name);
|
2018-03-14 17:23:17 +01:00
|
|
|
|
|
|
|
// Make sure we start at root, not somewhere else like the token mounted
|
|
|
|
// as a sub-directory
|
2018-02-07 18:22:00 +01:00
|
|
|
$this->assertEquals('/', $data->data->content->nm->path);
|
|
|
|
|
|
|
|
unset($data->data->content->nm->actions);
|
|
|
|
//var_dump($data->data->content->nm);
|
|
|
|
}
|
|
|
|
protected function setup_info()
|
|
|
|
{
|
|
|
|
// Copied from share.php
|
|
|
|
$GLOBALS['egw_info'] = array(
|
|
|
|
'flags' => array(
|
|
|
|
'disable_Template_class' => true,
|
|
|
|
'noheader' => true,
|
|
|
|
'nonavbar' => 'always', // true would cause eTemplate to reset it to false for non-popups!
|
|
|
|
'currentapp' => 'filemanager',
|
|
|
|
'autocreate_session_callback' => 'EGroupware\\Api\\Vfs\\Sharing::create_session',
|
|
|
|
'no_exception_handler' => 'basic_auth', // we use a basic auth exception handler (sends exception message as basic auth realm)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2018-02-21 23:03:45 +01:00
|
|
|
ob_start();
|
2018-02-15 17:37:48 +01:00
|
|
|
static::load_egw('anonymous','','',$GLOBALS['egw_info']);
|
2018-03-22 18:09:09 +01:00
|
|
|
if(static::LOG_LEVEL > 1)
|
|
|
|
{
|
|
|
|
ob_end_flush();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ob_end_clean();
|
|
|
|
}
|
2018-02-07 18:22:00 +01:00
|
|
|
}
|
|
|
|
}
|