WIP on sharing test - now actually working with other tests after

This commit is contained in:
nathangray 2018-02-20 15:32:37 -07:00
parent d76a08b434
commit 529991e283
2 changed files with 83 additions and 36 deletions

View File

@ -174,6 +174,9 @@ abstract class LoggedInTest extends TestCase
$GLOBALS['egw'] = new Api\Egw(array_keys($GLOBALS['egw_domain']));
}
// Make sure user is properly set
$GLOBALS['egw_info']['user'] = $GLOBALS['egw']->session->read_repositories();
// Disable asyc while we test
$GLOBALS['egw_info']['server']['asyncservice'] = 'off';

View File

@ -35,7 +35,13 @@ class SharingTest extends LoggedInTest
public function tearDown()
{
$_SERVER += $this->original_server;
$GLOBALS['egw']->session->destroy($GLOBALS['egw']->session->sessionid, $GLOBALS['egw']->session->kp3);
LoggedInTest::setupBeforeClass();
// Need to ask about mounts, or other tests fail
Vfs::mount();
foreach($this->shares as $share)
{
Sharing::delete($share);
@ -43,6 +49,63 @@ class SharingTest extends LoggedInTest
}
/**
* Test to make sure a readonly link to home gives just readonly access,
* and just to user's home
*/
public function testHomeReadonly()
{
$dir = Vfs::get_home_dir();
$logged_in_files = array_map(
function($path) use ($dir) {return str_replace($dir, '/', $path);},
Vfs::find($dir)
);
$this->shareLink($dir, Sharing::READONLY);
$files = Vfs::find(Vfs::get_home_dir());
// Make sure files are the same
$this->assertEquals($logged_in_files, $files);
// Make sure all are readonly
foreach($files as $file)
{
$this->assertFalse(Vfs::is_writable($file));
}
}
/**
* Test to make sure a writable link to home gives write access, but just
* to user's home
*/
public function testHomeWritable()
{
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
return;
// trearDown still not completely cleaning up, vfs fstab stays
$dir = Vfs::get_home_dir();
var_dump(Vfs::mount());
$logged_in_files = array_map(
function($path) use ($dir) {return str_replace($dir, '/', $path);},
Vfs::find($dir)
);
$this->shareLink($dir, Sharing::WRITABLE);
$files = Vfs::find(Vfs::get_home_dir());
// Make sure files are the same
$this->assertEquals($logged_in_files, $files);
// Make sure all are writable
foreach($files as $file)
{
$this->assertTrue(Vfs::is_writable($file), $file . ' was not writable');
}
}
/**
* Test that readable shares are actually readable
*
@ -50,26 +113,29 @@ class SharingTest extends LoggedInTest
*/
public function createShare($path, $mode)
{
$this->assertTrue(Vfs::touch($path));
// 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));
}
// Create share
$this->shares[] = $share = Sharing::create($path, $mode, $name, $recipients, $extra=array());
return $share;
}
/**
* Test that a readable link can be made, and that only that path is available
* Test that a share link can be made, and that only that path is available
*
* @param string $path
*/
public function readableLink($path, $mode)
public function shareLink($path, $mode)
{
// Setup - create path and share
$share = $this->createShare($path, $mode);
$link = Vfs\Sharing::share2link($share);
echo __METHOD__ . " LINK: $link\n";
var_dump($share);
// Setup for share to load
$_SERVER['REQUEST_URI'] = $link;
preg_match('|^https?://[^/]+(/.*)share.php/'.$share['share_token'].'$|', $path_info=$_SERVER['REQUEST_URI'], $matches);
@ -84,40 +150,15 @@ class SharingTest extends LoggedInTest
$this->checkDirectoryLink($link, $share);
}
// Load share
$this->setup_info();
// Our path should be mounted to root
$this->assertTrue(Vfs::is_readable('/'));
}
/**
* Test to make sure a readonly link to home gives just readonly access,
* and just to user's home
*/
public function testHomeReadonly()
{
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
return;
$dir = '/home/'.$GLOBALS['egw_info']['user']['account_lid'];
$logged_in_files = array_map(
function($path) use ($dir) {return str_replace($dir, '/', $path);},
Vfs::find($dir)
);
$this->readableLink($dir, Sharing::READONLY);
$files = Vfs::find('/');
// Make sure files are the same
$this->assertEquals($logged_in_files, $files);
// Make sure all are readonly
foreach($files as $file)
{
$this->assertFalse(Vfs::is_writable($file));
}
// Check other paths
$this->assertFalse(Vfs::is_readable($path));
$this->assertFalse(Vfs::is_readable($path . '../'));
}
/**
@ -129,13 +170,16 @@ class SharingTest extends LoggedInTest
*/
public function checkDirectoryLink($link, $share)
{
// Set up curl
$curl = curl_init($link);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
$html = curl_exec($curl);
curl_close($curl);
// Parse & check for nextmatch
$dom = new \DOMDocument();
@$dom->loadHTML($html); //convert character asing
@$dom->loadHTML($html);
$xpath = new \DOMXPath($dom);
$form = $xpath->query ('//form')->item(0);
$data = json_decode($form->getAttribute('data-etemplate'));