Fix some test issues

- Fix ProppatchTest
- Some methods went missing?
This commit is contained in:
nathangray 2020-09-18 11:37:38 -06:00
parent 1f8a003d03
commit 9c4942957f
3 changed files with 92 additions and 1 deletions

View File

@ -57,6 +57,23 @@ class StreamWrapperTest extends Vfs\StreamWrapperBase
parent::testNoReadAccess();
}
public function testWithAccess(): void
{
$info_id = $this->make_infolog();
$this->files[] = $this->test_file = $this->getFilename(null, $info_id);
parent::testWithAccess();
}
protected function allowAccess(string $test_name, string $test_file, int $test_user, string $needed)
{
// We'll allow access by putting test user in responsible
$so = new \infolog_so();
$element = $so->read($this->entries[0]);
$element['info_responsible'] = [$test_user];
$so->write($so);
}
/**
* Make an infolog entry
*/

View File

@ -19,7 +19,7 @@ use EGroupware\Api\Vfs;
use EGroupware\Stylite\Vfs\Versioning;
class ProppatchTest extends StreamWrapperBase
class ProppatchTest extends LoggedInTest
{
protected function setUp() : void
{
@ -113,4 +113,17 @@ class ProppatchTest extends StreamWrapperBase
);
}
/**
* Make a filename that reflects the current test
*/
protected function getFilename($path = null)
{
if(is_null($path)) $path = Vfs::get_home_dir().'/';
if(substr($path,-1,1) !== '/') $path = $path . '/';
$reflect = new \ReflectionClass($this);
return $path . $reflect->getShortName() . '_' . $this->getName(false) . '.txt';
}
}

View File

@ -261,6 +261,67 @@ class StreamWrapperBase extends LoggedInTest
}
/**
* Check that a user with permission to a file can access the file
*
* @depends testSimpleReadWrite
* @throws Api\Exception\AssertionFailed
*/
public function testWithAccess() : void
{
if(!$this->test_file)
{
$this->markTestSkipped("No test file set - set it in setUp() or overriding test");
}
// Check that the file is not there
$pre_start = Vfs::stat($this->test_file);
$this->assertEquals(null,$pre_start,
"File '$this->test_file' was there before we started, check clean up"
);
// Write
$file = $this->test_file;
$contents = $this->getName() . "\nJust a test ;)\n";
$this->assertNotFalse(
file_put_contents(Vfs::PREFIX . $file, $contents),
"Could not write file $file"
);
$pre = Vfs::stat($this->test_file);
// Create another user who has no access to our file
$user_b = $this->makeUser();
// Allow access
$this->allowAccess(
$this->getName(false),
$file,
$user_b,
'r'
);
// Log in as them
$this->switchUser($this->account['account_lid'], $this->account['account_passwd']);
// Check the file
$post = Vfs::stat($file);
$this->assertNotNull($post,
"File '$file' was not accessible by another user who had permission"
);
$this->assertEquals(
$contents,
file_get_contents(Vfs::PREFIX . $file),
"Problem reading someone else's file with permission"
);
$this->assertTrue(
Vfs::is_readable($file),
"Vfs says $file is not readable. It should be."
);
}
////// Handy functions ///////
/**