fix cherrypicking

This commit is contained in:
Jörn Friedrich Dreyer 2015-04-09 14:03:30 +02:00 committed by Morris Jobke
parent 1427ea78d4
commit fafecd1c05
6 changed files with 56 additions and 44 deletions

View File

@ -30,10 +30,10 @@
namespace OCA\user_ldap\lib; namespace OCA\user_ldap\lib;
//magic properties (incomplete)
use OC\ServerNotAvailableException; use OC\ServerNotAvailableException;
/** /**
* magic properties (incomplete)
* responsible for LDAP connections in context with the provided configuration * responsible for LDAP connections in context with the provided configuration
* *
* @property string ldapUserFilter * @property string ldapUserFilter

View File

@ -145,6 +145,8 @@ class Test_User_Manager extends \Test\TestCase {
$manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc); $manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc);
$manager->setLdapAccess($access); $manager->setLdapAccess($access);
$user = $manager->get($inputDN); $user = $manager->get($inputDN);
$this->assertNull($user);
} }
public function testGetByUidExisting() { public function testGetByUidExisting() {
@ -192,6 +194,8 @@ class Test_User_Manager extends \Test\TestCase {
$manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc); $manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc);
$manager->setLdapAccess($access); $manager->setLdapAccess($access);
$user = $manager->get($uid); $user = $manager->get($uid);
$this->assertNull($user);
} }
} }

View File

@ -435,7 +435,7 @@ class Test_User_Ldap_Direct extends \Test\TestCase {
*/ */
public function testUserExistsForDeleted() { public function testUserExistsForDeleted() {
$access = $this->getAccessMock(); $access = $this->getAccessMock();
$backend = new UserLDAP($access); $backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
$this->prepareMockForUserExists($access); $this->prepareMockForUserExists($access);
$access->expects($this->any()) $access->expects($this->any())
@ -453,7 +453,7 @@ class Test_User_Ldap_Direct extends \Test\TestCase {
public function testUserExistsForNeverExisting() { public function testUserExistsForNeverExisting() {
$access = $this->getAccessMock(); $access = $this->getAccessMock();
$backend = new UserLDAP($access); $backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
$this->prepareMockForUserExists($access); $this->prepareMockForUserExists($access);
$access->expects($this->any()) $access->expects($this->any())
@ -495,7 +495,7 @@ class Test_User_Ldap_Direct extends \Test\TestCase {
*/ */
public function testUserExistsPublicAPIForDeleted() { public function testUserExistsPublicAPIForDeleted() {
$access = $this->getAccessMock(); $access = $this->getAccessMock();
$backend = new UserLDAP($access); $backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
$this->prepareMockForUserExists($access); $this->prepareMockForUserExists($access);
\OC_User::useBackend($backend); \OC_User::useBackend($backend);
@ -514,7 +514,7 @@ class Test_User_Ldap_Direct extends \Test\TestCase {
public function testUserExistsPublicAPIForNeverExisting() { public function testUserExistsPublicAPIForNeverExisting() {
$access = $this->getAccessMock(); $access = $this->getAccessMock();
$backend = new UserLDAP($access); $backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
$this->prepareMockForUserExists($access); $this->prepareMockForUserExists($access);
\OC_User::useBackend($backend); \OC_User::useBackend($backend);
@ -571,19 +571,15 @@ class Test_User_Ldap_Direct extends \Test\TestCase {
} }
})); }));
$datadir = '/my/data/dir';
$config->expects($this->once())
->method('getSystemValue')
->will($this->returnValue($datadir));
//absolut path //absolut path
$result = $backend->getHome('gunslinger'); $result = $backend->getHome('gunslinger');
$this->assertEquals('/tmp/rolandshome/', $result); $this->assertEquals('/tmp/rolandshome/', $result);
} }
public function testGetHomeDatadirRelative() { public function testGetHomeRelative() {
$access = $this->getAccessMock(); $access = $this->getAccessMock();
$backend = new UserLDAP($access); $config = $this->getMock('\OCP\IConfig');
$backend = new UserLDAP($access, $config);
$this->prepareMockForUserExists($access); $this->prepareMockForUserExists($access);
$access->connection->expects($this->any()) $access->connection->expects($this->any())
@ -610,9 +606,12 @@ class Test_User_Ldap_Direct extends \Test\TestCase {
} }
})); }));
//datadir-relativ path //datadir-relativ path
$datadir = '/my/data/dir';
$config->expects($this->once())
->method('getSystemValue')
->will($this->returnValue($datadir));
$result = $backend->getHome('ladyofshadows'); $result = $backend->getHome('ladyofshadows');
$datadir = \OCP\Config::getSystemValue('datadirectory',
\OC::$SERVERROOT.'/data');
$this->assertEquals($datadir.'/susannah/', $result); $this->assertEquals($datadir.'/susannah/', $result);
} }
@ -621,7 +620,7 @@ class Test_User_Ldap_Direct extends \Test\TestCase {
*/ */
public function testGetHomeNoPath() { public function testGetHomeNoPath() {
$access = $this->getAccessMock(); $access = $this->getAccessMock();
$backend = new UserLDAP($access); $backend = new UserLDAP($access, $this->getMock('\OCP\IConfig'));
$this->prepareMockForUserExists($access); $this->prepareMockForUserExists($access);
$access->connection->expects($this->any()) $access->connection->expects($this->any())

View File

@ -114,7 +114,7 @@ class OC_Hook{
OC_Log::write('hook', OC_Log::write('hook',
'error while running hook (' . $class . '::' . $i["name"] . '): ' . $message, 'error while running hook (' . $class . '::' . $i["name"] . '): ' . $message,
OC_Log::ERROR); OC_Log::ERROR);
if($e instanceof \OC\ServerNotAvailableException && $signalclass === 'OC_Filesystem' && $signalname === 'setup') { if($e instanceof \OC\ServerNotAvailableException && $signalClass === 'OC_Filesystem' && $signalName === 'setup') {
throw $e; throw $e;
} }
} }

View File

@ -25,6 +25,9 @@ namespace Test\Files;
use OC\User\NoUserException; use OC\User\NoUserException;
class Filesystem extends \Test\TestCase { class Filesystem extends \Test\TestCase {
const TEST_FILESYSTEM_USER1 = "test-filesystem-user1";
/** /**
* @var array tmpDirs * @var array tmpDirs
*/ */
@ -238,8 +241,14 @@ class Filesystem extends \Test\TestCase {
if (\OC\Files\Filesystem::getView()) { if (\OC\Files\Filesystem::getView()) {
$user = \OC_User::getUser(); $user = \OC_User::getUser();
} else { } else {
$user = $this->getUniqueID(); $user = self::TEST_FILESYSTEM_USER1;
$backend = new \OC_User_Dummy();
\OC_User::useBackend($backend);
$backend->createUser($user, $user);
$userObj = \OC::$server->getUserManager()->get($user);
\OC::$server->getUserSession()->setUser($userObj);
\OC\Files\Filesystem::init($user, '/' . $user . '/files'); \OC\Files\Filesystem::init($user, '/' . $user . '/files');
} }
\OC_Hook::clear('OC_Filesystem'); \OC_Hook::clear('OC_Filesystem');
\OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook'); \OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook');

View File

@ -10,10 +10,7 @@ namespace Test;
class Preview extends TestCase { class Preview extends TestCase {
/** const TEST_PREVIEW_USER1 = "test-preview-user1";
* @var string
*/
private $user;
/** /**
* @var \OC\Files\View * @var \OC\Files\View
@ -32,15 +29,18 @@ class Preview extends TestCase {
// create a new user with his own filesystem view // create a new user with his own filesystem view
// this gets called by each test in this test class // this gets called by each test in this test class
$this->user = $this->getUniqueID(); $backend = new \OC_User_Dummy();
\OC_User::setUserId($this->user); \OC_User::useBackend($backend);
\OC\Files\Filesystem::init($this->user, '/' . $this->user . '/files'); $backend->createUser(self::TEST_PREVIEW_USER1, self::TEST_PREVIEW_USER1);
$user = \OC::$server->getUserManager()->get(self::TEST_PREVIEW_USER1);
\OC::$server->getUserSession()->setUser($user);
\OC\Files\Filesystem::init(self::TEST_PREVIEW_USER1, '/' . self::TEST_PREVIEW_USER1 . '/files');
\OC\Files\Filesystem::mount('OC\Files\Storage\Temporary', array(), '/'); \OC\Files\Filesystem::mount('OC\Files\Storage\Temporary', array(), '/');
$this->rootView = new \OC\Files\View(''); $this->rootView = new \OC\Files\View('');
$this->rootView->mkdir('/'.$this->user); $this->rootView->mkdir('/'.self::TEST_PREVIEW_USER1);
$this->rootView->mkdir('/'.$this->user.'/files'); $this->rootView->mkdir('/'.self::TEST_PREVIEW_USER1.'/files');
} }
protected function tearDown() { protected function tearDown() {
@ -59,14 +59,14 @@ class Preview extends TestCase {
\OC::$server->getConfig()->setSystemValue('preview_max_y', $maxY); \OC::$server->getConfig()->setSystemValue('preview_max_y', $maxY);
// Sample is 1680x1050 JPEG // Sample is 1680x1050 JPEG
$sampleFile = '/' . $this->user . '/files/testimage.jpg'; $sampleFile = '/' . self::TEST_PREVIEW_USER1 . '/files/testimage.jpg';
$this->rootView->file_put_contents($sampleFile, file_get_contents(\OC::$SERVERROOT.'/tests/data/testimage.jpg')); $this->rootView->file_put_contents($sampleFile, file_get_contents(\OC::$SERVERROOT.'/tests/data/testimage.jpg'));
$fileInfo = $this->rootView->getFileInfo($sampleFile); $fileInfo = $this->rootView->getFileInfo($sampleFile);
$fileId = $fileInfo['fileid']; $fileId = $fileInfo['fileid'];
$largeX = 1920; $largeX = 1920;
$largeY = 1080; $largeY = 1080;
$preview = new \OC\Preview($this->user, 'files/', 'testimage.jpg', $largeX, $largeY); $preview = new \OC\Preview(self::TEST_PREVIEW_USER1, 'files/', 'testimage.jpg', $largeX, $largeY);
$this->assertEquals($preview->isFileValid(), true); $this->assertEquals($preview->isFileValid(), true);
@ -84,7 +84,7 @@ class Preview extends TestCase {
$this->assertEquals($image->height(), $maxY); $this->assertEquals($image->height(), $maxY);
// The max thumbnail should be created // The max thumbnail should be created
$maxThumbCacheFile = '/' . $this->user . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $maxX . '-' . $maxY . '-max.png'; $maxThumbCacheFile = '/' . self::TEST_PREVIEW_USER1 . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $maxX . '-' . $maxY . '-max.png';
$this->assertEquals($this->rootView->file_exists($maxThumbCacheFile), true); $this->assertEquals($this->rootView->file_exists($maxThumbCacheFile), true);
@ -100,7 +100,7 @@ class Preview extends TestCase {
// Smaller previews should be based on the cached max preview // Smaller previews should be based on the cached max preview
$smallX = 50; $smallX = 50;
$smallY = 50; $smallY = 50;
$preview = new \OC\Preview($this->user, 'files/', 'testimage.jpg', $smallX, $smallY); $preview = new \OC\Preview(self::TEST_PREVIEW_USER1, 'files/', 'testimage.jpg', $smallX, $smallY);
$isCached = $preview->isCached($fileId); $isCached = $preview->isCached($fileId);
$this->assertEquals(\OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $maxX . '-' . $maxY . '.png', $isCached); $this->assertEquals(\OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $maxX . '-' . $maxY . '.png', $isCached);
@ -111,7 +111,7 @@ class Preview extends TestCase {
$this->assertEquals($image->height(), $smallY); $this->assertEquals($image->height(), $smallY);
// The cache should contain the small preview // The cache should contain the small preview
$thumbCacheFile = '/' . $this->user . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $smallX . '-' . $smallY . '.png'; $thumbCacheFile = '/' . self::TEST_PREVIEW_USER1 . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $smallX . '-' . $smallY . '.png';
$this->assertEquals($this->rootView->file_exists($thumbCacheFile), true); $this->assertEquals($this->rootView->file_exists($thumbCacheFile), true);
@ -123,20 +123,20 @@ class Preview extends TestCase {
public function testIsPreviewDeleted() { public function testIsPreviewDeleted() {
$sampleFile = '/'.$this->user.'/files/test.txt'; $sampleFile = '/'.self::TEST_PREVIEW_USER1.'/files/test.txt';
$this->rootView->file_put_contents($sampleFile, 'dummy file data'); $this->rootView->file_put_contents($sampleFile, 'dummy file data');
$x = 50; $x = 50;
$y = 50; $y = 50;
$preview = new \OC\Preview($this->user, 'files/', 'test.txt', $x, $y); $preview = new \OC\Preview(self::TEST_PREVIEW_USER1, 'files/', 'test.txt', $x, $y);
$preview->getPreview(); $preview->getPreview();
$fileInfo = $this->rootView->getFileInfo($sampleFile); $fileInfo = $this->rootView->getFileInfo($sampleFile);
$fileId = $fileInfo['fileid']; $fileId = $fileInfo['fileid'];
$thumbCacheFile = '/' . $this->user . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $x . '-' . $y . '.png'; $thumbCacheFile = '/' . self::TEST_PREVIEW_USER1 . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $x . '-' . $y . '.png';
$this->assertEquals($this->rootView->file_exists($thumbCacheFile), true); $this->assertEquals($this->rootView->file_exists($thumbCacheFile), true);
@ -147,20 +147,20 @@ class Preview extends TestCase {
public function testAreAllPreviewsDeleted() { public function testAreAllPreviewsDeleted() {
$sampleFile = '/'.$this->user.'/files/test.txt'; $sampleFile = '/'.self::TEST_PREVIEW_USER1.'/files/test.txt';
$this->rootView->file_put_contents($sampleFile, 'dummy file data'); $this->rootView->file_put_contents($sampleFile, 'dummy file data');
$x = 50; $x = 50;
$y = 50; $y = 50;
$preview = new \OC\Preview($this->user, 'files/', 'test.txt', $x, $y); $preview = new \OC\Preview(self::TEST_PREVIEW_USER1, 'files/', 'test.txt', $x, $y);
$preview->getPreview(); $preview->getPreview();
$fileInfo = $this->rootView->getFileInfo($sampleFile); $fileInfo = $this->rootView->getFileInfo($sampleFile);
$fileId = $fileInfo['fileid']; $fileId = $fileInfo['fileid'];
$thumbCacheFolder = '/' . $this->user . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/'; $thumbCacheFolder = '/' . self::TEST_PREVIEW_USER1 . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/';
$this->assertEquals($this->rootView->is_dir($thumbCacheFolder), true); $this->assertEquals($this->rootView->is_dir($thumbCacheFolder), true);
@ -185,9 +185,9 @@ class Preview extends TestCase {
$x = 32; $x = 32;
$y = 32; $y = 32;
$sample = '/'.$this->user.'/files/test.'.$extension; $sample = '/'.self::TEST_PREVIEW_USER1.'/files/test.'.$extension;
$this->rootView->file_put_contents($sample, $data); $this->rootView->file_put_contents($sample, $data);
$preview = new \OC\Preview($this->user, 'files/', 'test.'.$extension, $x, $y); $preview = new \OC\Preview(self::TEST_PREVIEW_USER1, 'files/', 'test.'.$extension, $x, $y);
$image = $preview->getPreview(); $image = $preview->getPreview();
$resource = $image->resource(); $resource = $image->resource();
@ -203,7 +203,7 @@ class Preview extends TestCase {
public function testCreationFromCached() { public function testCreationFromCached() {
$sampleFile = '/'.$this->user.'/files/test.txt'; $sampleFile = '/'.self::TEST_PREVIEW_USER1.'/files/test.txt';
$this->rootView->file_put_contents($sampleFile, 'dummy file data'); $this->rootView->file_put_contents($sampleFile, 'dummy file data');
@ -211,22 +211,22 @@ class Preview extends TestCase {
$x = 150; $x = 150;
$y = 150; $y = 150;
$preview = new \OC\Preview($this->user, 'files/', 'test.txt', $x, $y); $preview = new \OC\Preview(self::TEST_PREVIEW_USER1, 'files/', 'test.txt', $x, $y);
$preview->getPreview(); $preview->getPreview();
$fileInfo = $this->rootView->getFileInfo($sampleFile); $fileInfo = $this->rootView->getFileInfo($sampleFile);
$fileId = $fileInfo['fileid']; $fileId = $fileInfo['fileid'];
$thumbCacheFile = '/' . $this->user . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $x . '-' . $y . '.png'; $thumbCacheFile = '/' . self::TEST_PREVIEW_USER1 . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/' . $x . '-' . $y . '.png';
$this->assertEquals($this->rootView->file_exists($thumbCacheFile), true); $this->assertEquals($this->rootView->file_exists($thumbCacheFile), true);
// create smaller previews // create smaller previews
$preview = new \OC\Preview($this->user, 'files/', 'test.txt', 50, 50); $preview = new \OC\Preview(self::TEST_PREVIEW_USER1, 'files/', 'test.txt', 50, 50);
$isCached = $preview->isCached($fileId); $isCached = $preview->isCached($fileId);
$this->assertEquals($this->user . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/150-150.png', $isCached); $this->assertEquals(self::TEST_PREVIEW_USER1 . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/150-150.png', $isCached);
} }
/* /*