Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2016-07-07 13:03:34 +0300
committerMorris Jobke <hey@morrisjobke.de>2016-07-07 13:03:34 +0300
commit11e834ea74243518b4057f0f5f7cafe6f2761530 (patch)
treef500a6e459a61e9fcaa33114948803a61b4da7b2 /tests
parent64a15191e4397da9712d4d17675993a9acdab31e (diff)
parente5645a94ecf6a9e037c8475cb085f14b656b71ac (diff)
Merge branch 'stable9' into sync-stable9
Diffstat (limited to 'tests')
-rw-r--r--tests/core/command/encryption/changekeystorageroottest.php2
-rw-r--r--tests/core/controller/avatarcontrollertest.php2
-rw-r--r--tests/lib/appframework/db/mappertest.php4
-rw-r--r--tests/lib/appframework/http/RequestTest.php311
-rw-r--r--tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php91
-rw-r--r--tests/lib/files.php1
-rw-r--r--tests/lib/files/view.php2
-rw-r--r--tests/lib/notification/notificationtest.php2
-rw-r--r--tests/lib/preview/movie.php5
-rw-r--r--tests/lib/preview/office.php5
-rw-r--r--tests/lib/share20/managertest.php60
-rw-r--r--tests/lib/tempmanager.php2
-rw-r--r--tests/lib/updater.php24
-rw-r--r--tests/lib/user/database.php45
-rw-r--r--tests/lib/utilcheckserver.php1
-rw-r--r--tests/settings/controller/logsettingscontrollertest.php6
16 files changed, 488 insertions, 75 deletions
diff --git a/tests/core/command/encryption/changekeystorageroottest.php b/tests/core/command/encryption/changekeystorageroottest.php
index 6cb52cdea99..7308545d108 100644
--- a/tests/core/command/encryption/changekeystorageroottest.php
+++ b/tests/core/command/encryption/changekeystorageroottest.php
@@ -173,7 +173,7 @@ class ChangeKeyStorageRootTest extends TestCase {
$this->view->expects($this->once())->method('file_put_contents')
->with('newRoot/' . \OC\Encryption\Keys\Storage::KEY_STORAGE_MARKER,
- 'ownCloud will detect this folder as key storage root only if this file exists');
+ 'Nextcloud will detect this folder as key storage root only if this file exists');
$this->invokePrivate($this->changeKeyStorageRoot, 'prepareNewRoot', ['newRoot']);
}
diff --git a/tests/core/controller/avatarcontrollertest.php b/tests/core/controller/avatarcontrollertest.php
index 8e5e58904a7..c99b69228b1 100644
--- a/tests/core/controller/avatarcontrollertest.php
+++ b/tests/core/controller/avatarcontrollertest.php
@@ -93,7 +93,7 @@ class AvatarControllerTest extends \Test\TestCase {
$this->container['UserSession']->method('getUser')->willReturn($this->userMock);
$this->avatarFile = $this->getMock('OCP\Files\File');
- $this->avatarFile->method('getContnet')->willReturn('image data');
+ $this->avatarFile->method('getContent')->willReturn('image data');
$this->avatarFile->method('getMimeType')->willReturn('image type');
$this->avatarFile->method('getEtag')->willReturn('my etag');
}
diff --git a/tests/lib/appframework/db/mappertest.php b/tests/lib/appframework/db/mappertest.php
index c8b999ad62c..e2a70d9423a 100644
--- a/tests/lib/appframework/db/mappertest.php
+++ b/tests/lib/appframework/db/mappertest.php
@@ -236,7 +236,9 @@ class MapperTest extends MapperTestUtility {
$entity->resetUpdatedFields();
$this->db->expects($this->never())
- ->method('prepareQuery');
+ ->method('prepare');
+ $this->db->expects($this->never())
+ ->method('prepare');
$this->mapper->update($entity);
}
diff --git a/tests/lib/appframework/http/RequestTest.php b/tests/lib/appframework/http/RequestTest.php
index 3f1d09c2a93..335a7e9c8e2 100644
--- a/tests/lib/appframework/http/RequestTest.php
+++ b/tests/lib/appframework/http/RequestTest.php
@@ -1,15 +1,16 @@
<?php
/**
* @copyright 2013 Thomas Tanghus (thomas@tanghus.net)
- * @copyright 2015 Lukas Reschke lukas@owncloud.com
+ * @copyright 2016 Lukas Reschke lukas@owncloud.com
*
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
-namespace OC\AppFramework\Http;
+namespace Test\AppFramework\Http;
+use OC\AppFramework\Http\Request;
use OC\Security\CSRF\CsrfToken;
use OC\Security\CSRF\CsrfTokenManager;
use OCP\Security\ISecureRandom;
@@ -740,15 +741,15 @@ class RequestTest extends \Test\TestCase {
*/
public function testUserAgent($testAgent, $userAgent, $matches) {
$request = new Request(
- [
- 'server' => [
- 'HTTP_USER_AGENT' => $testAgent,
- ]
- ],
- $this->secureRandom,
- $this->config,
- $this->csrfTokenManager,
- $this->stream
+ [
+ 'server' => [
+ 'HTTP_USER_AGENT' => $testAgent,
+ ]
+ ],
+ $this->secureRandom,
+ $this->config,
+ $this->csrfTokenManager,
+ $this->stream
);
$this->assertSame($matches, $request->isUserAgent($userAgent));
@@ -762,11 +763,11 @@ class RequestTest extends \Test\TestCase {
*/
public function testUndefinedUserAgent($testAgent, $userAgent, $matches) {
$request = new Request(
- [],
- $this->secureRandom,
- $this->config,
- $this->csrfTokenManager,
- $this->stream
+ [],
+ $this->secureRandom,
+ $this->config,
+ $this->csrfTokenManager,
+ $this->stream
);
$this->assertFalse($request->isUserAgent($userAgent));
@@ -1322,6 +1323,10 @@ class RequestTest extends \Test\TestCase {
'get' => [
'requesttoken' => 'AAAHGxsTCTc3BgMQESAcNR0OAR0=:MyTotalSecretShareds',
],
+ 'cookies' => [
+ 'nc_sameSiteCookiestrict' => 'true',
+ 'nc_sameSiteCookielax' => 'true',
+ ],
],
$this->secureRandom,
$this->config,
@@ -1348,6 +1353,10 @@ class RequestTest extends \Test\TestCase {
'post' => [
'requesttoken' => 'AAAHGxsTCTc3BgMQESAcNR0OAR0=:MyTotalSecretShareds',
],
+ 'cookies' => [
+ 'nc_sameSiteCookiestrict' => 'true',
+ 'nc_sameSiteCookielax' => 'true',
+ ],
],
$this->secureRandom,
$this->config,
@@ -1357,10 +1366,10 @@ class RequestTest extends \Test\TestCase {
->getMock();
$token = new CsrfToken('AAAHGxsTCTc3BgMQESAcNR0OAR0=:MyTotalSecretShareds');
$this->csrfTokenManager
- ->expects($this->once())
- ->method('isTokenValid')
- ->with($token)
- ->willReturn(true);
+ ->expects($this->once())
+ ->method('isTokenValid')
+ ->with($token)
+ ->willReturn(true);
$this->assertTrue($request->passesCSRFCheck());
}
@@ -1374,6 +1383,10 @@ class RequestTest extends \Test\TestCase {
'server' => [
'HTTP_REQUESTTOKEN' => 'AAAHGxsTCTc3BgMQESAcNR0OAR0=:MyTotalSecretShareds',
],
+ 'cookies' => [
+ 'nc_sameSiteCookiestrict' => 'true',
+ 'nc_sameSiteCookielax' => 'true',
+ ],
],
$this->secureRandom,
$this->config,
@@ -1383,14 +1396,254 @@ class RequestTest extends \Test\TestCase {
->getMock();
$token = new CsrfToken('AAAHGxsTCTc3BgMQESAcNR0OAR0=:MyTotalSecretShareds');
$this->csrfTokenManager
- ->expects($this->once())
- ->method('isTokenValid')
- ->with($token)
- ->willReturn(true);
+ ->expects($this->once())
+ ->method('isTokenValid')
+ ->with($token)
+ ->willReturn(true);
+
+ $this->assertTrue($request->passesCSRFCheck());
+ }
+
+ public function testPassesCSRFCheckWithGetAndWithoutCookies() {
+ /** @var Request $request */
+ $request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
+ ->setMethods(['getScriptName'])
+ ->setConstructorArgs([
+ [
+ 'get' => [
+ 'requesttoken' => 'AAAHGxsTCTc3BgMQESAcNR0OAR0=:MyTotalSecretShareds',
+ ],
+ ],
+ $this->secureRandom,
+ $this->config,
+ $this->csrfTokenManager,
+ $this->stream
+ ])
+ ->getMock();
+ $this->csrfTokenManager
+ ->expects($this->once())
+ ->method('isTokenValid')
+ ->willReturn(true);
+
+ $this->assertTrue($request->passesCSRFCheck());
+ }
+
+ public function testPassesCSRFCheckWithPostAndWithoutCookies() {
+ /** @var Request $request */
+ $request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
+ ->setMethods(['getScriptName'])
+ ->setConstructorArgs([
+ [
+ 'post' => [
+ 'requesttoken' => 'AAAHGxsTCTc3BgMQESAcNR0OAR0=:MyTotalSecretShareds',
+ ],
+ ],
+ $this->secureRandom,
+ $this->config,
+ $this->csrfTokenManager,
+ $this->stream
+ ])
+ ->getMock();
+ $this->csrfTokenManager
+ ->expects($this->once())
+ ->method('isTokenValid')
+ ->willReturn(true);
$this->assertTrue($request->passesCSRFCheck());
}
+ public function testPassesCSRFCheckWithHeaderAndWithoutCookies() {
+ /** @var Request $request */
+ $request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
+ ->setMethods(['getScriptName'])
+ ->setConstructorArgs([
+ [
+ 'server' => [
+ 'HTTP_REQUESTTOKEN' => 'AAAHGxsTCTc3BgMQESAcNR0OAR0=:MyTotalSecretShareds',
+ ],
+ ],
+ $this->secureRandom,
+ $this->config,
+ $this->csrfTokenManager,
+ $this->stream
+ ])
+ ->getMock();
+ $this->csrfTokenManager
+ ->expects($this->once())
+ ->method('isTokenValid')
+ ->willReturn(true);
+
+ $this->assertTrue($request->passesCSRFCheck());
+ }
+
+ public function testFailsCSRFCheckWithHeaderAndNotAllChecksPassing() {
+ /** @var Request $request */
+ $request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
+ ->setMethods(['getScriptName'])
+ ->setConstructorArgs([
+ [
+ 'server' => [
+ 'HTTP_REQUESTTOKEN' => 'AAAHGxsTCTc3BgMQESAcNR0OAR0=:MyTotalSecretShareds',
+ ],
+ 'cookies' => [
+ 'nc_sameSiteCookiestrict' => 'true',
+ ],
+ ],
+ $this->secureRandom,
+ $this->config,
+ $this->csrfTokenManager,
+ $this->stream
+ ])
+ ->getMock();
+ $this->csrfTokenManager
+ ->expects($this->never())
+ ->method('isTokenValid');
+
+ $this->assertFalse($request->passesCSRFCheck());
+ }
+
+ public function testPassesStrictCookieCheckWithAllCookies() {
+ /** @var Request $request */
+ $request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
+ ->setMethods(['getScriptName'])
+ ->setConstructorArgs([
+ [
+ 'server' => [
+ 'HTTP_REQUESTTOKEN' => 'AAAHGxsTCTc3BgMQESAcNR0OAR0=:MyTotalSecretShareds',
+ ],
+ 'cookies' => [
+ 'nc_sameSiteCookiestrict' => 'true',
+ 'nc_sameSiteCookielax' => 'true',
+ ],
+ ],
+ $this->secureRandom,
+ $this->config,
+ $this->csrfTokenManager,
+ $this->stream
+ ])
+ ->getMock();
+
+ $this->assertTrue($request->passesStrictCookieCheck());
+ }
+
+ public function testFailsSRFCheckWithPostAndWithCookies() {
+ /** @var Request $request */
+ $request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
+ ->setMethods(['getScriptName'])
+ ->setConstructorArgs([
+ [
+ 'post' => [
+ 'requesttoken' => 'AAAHGxsTCTc3BgMQESAcNR0OAR0=:MyTotalSecretShareds',
+ ],
+ 'cookies' => [
+ 'foo' => 'bar',
+ ],
+ ],
+ $this->secureRandom,
+ $this->config,
+ $this->csrfTokenManager,
+ $this->stream
+ ])
+ ->getMock();
+ $this->csrfTokenManager
+ ->expects($this->never())
+ ->method('isTokenValid');
+
+ $this->assertFalse($request->passesCSRFCheck());
+ }
+
+ public function testFailStrictCookieCheckWithOnlyLaxCookie() {
+ /** @var Request $request */
+ $request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
+ ->setMethods(['getScriptName'])
+ ->setConstructorArgs([
+ [
+ 'server' => [
+ 'HTTP_REQUESTTOKEN' => 'AAAHGxsTCTc3BgMQESAcNR0OAR0=:MyTotalSecretShareds',
+ ],
+ 'cookies' => [
+ 'nc_sameSiteCookielax' => 'true',
+ ],
+ ],
+ $this->secureRandom,
+ $this->config,
+ $this->csrfTokenManager,
+ $this->stream
+ ])
+ ->getMock();
+
+ $this->assertFalse($request->passesStrictCookieCheck());
+ }
+
+ public function testFailStrictCookieCheckWithOnlyStrictCookie() {
+ /** @var Request $request */
+ $request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
+ ->setMethods(['getScriptName'])
+ ->setConstructorArgs([
+ [
+ 'server' => [
+ 'HTTP_REQUESTTOKEN' => 'AAAHGxsTCTc3BgMQESAcNR0OAR0=:MyTotalSecretShareds',
+ ],
+ 'cookies' => [
+ 'nc_sameSiteCookiestrict' => 'true',
+ ],
+ ],
+ $this->secureRandom,
+ $this->config,
+ $this->csrfTokenManager,
+ $this->stream
+ ])
+ ->getMock();
+
+ $this->assertFalse($request->passesStrictCookieCheck());
+ }
+
+ public function testPassesLaxCookieCheck() {
+ /** @var Request $request */
+ $request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
+ ->setMethods(['getScriptName'])
+ ->setConstructorArgs([
+ [
+ 'server' => [
+ 'HTTP_REQUESTTOKEN' => 'AAAHGxsTCTc3BgMQESAcNR0OAR0=:MyTotalSecretShareds',
+ ],
+ 'cookies' => [
+ 'nc_sameSiteCookielax' => 'true',
+ ],
+ ],
+ $this->secureRandom,
+ $this->config,
+ $this->csrfTokenManager,
+ $this->stream
+ ])
+ ->getMock();
+
+ $this->assertTrue($request->passesLaxCookieCheck());
+ }
+
+ public function testFailsLaxCookieCheckWithOnlyStrictCookie() {
+ /** @var Request $request */
+ $request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
+ ->setMethods(['getScriptName'])
+ ->setConstructorArgs([
+ [
+ 'server' => [
+ 'HTTP_REQUESTTOKEN' => 'AAAHGxsTCTc3BgMQESAcNR0OAR0=:MyTotalSecretShareds',
+ ],
+ 'cookies' => [
+ 'nc_sameSiteCookiestrict' => 'true',
+ ],
+ ],
+ $this->secureRandom,
+ $this->config,
+ $this->csrfTokenManager,
+ $this->stream
+ ])
+ ->getMock();
+
+ $this->assertFalse($request->passesLaxCookieCheck());
+ }
+
/**
* @return array
*/
@@ -1426,10 +1679,10 @@ class RequestTest extends \Test\TestCase {
$token = new CsrfToken($invalidToken);
$this->csrfTokenManager
- ->expects($this->any())
- ->method('isTokenValid')
- ->with($token)
- ->willReturn(false);
+ ->expects($this->any())
+ ->method('isTokenValid')
+ ->with($token)
+ ->willReturn(false);
$this->assertFalse($request->passesCSRFCheck());
}
@@ -1450,4 +1703,4 @@ class RequestTest extends \Test\TestCase {
$this->assertFalse($request->passesCSRFCheck());
}
-}
+} \ No newline at end of file
diff --git a/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php b/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php
index 9e71a3d0961..f7bb10c6880 100644
--- a/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php
+++ b/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php
@@ -31,6 +31,7 @@ use OC\Appframework\Middleware\Security\Exceptions\CrossSiteRequestForgeryExcept
use OC\Appframework\Middleware\Security\Exceptions\NotAdminException;
use OC\Appframework\Middleware\Security\Exceptions\NotLoggedInException;
use OC\AppFramework\Middleware\Security\Exceptions\SecurityException;
+use OC\Appframework\Middleware\Security\Exceptions\StrictCookieMissingException;
use OC\AppFramework\Utility\ControllerMethodReflector;
use OC\Security\CSP\ContentSecurityPolicy;
use OCP\AppFramework\Http\RedirectResponse;
@@ -255,7 +256,9 @@ class SecurityMiddlewareTest extends \Test\TestCase {
$this->request->expects($this->once())
->method('passesCSRFCheck')
->will($this->returnValue(false));
-
+ $this->request->expects($this->once())
+ ->method('passesStrictCookieCheck')
+ ->will($this->returnValue(true));
$this->reader->reflect(__CLASS__, __FUNCTION__);
$this->middleware->beforeController(__CLASS__, __FUNCTION__);
}
@@ -274,19 +277,81 @@ class SecurityMiddlewareTest extends \Test\TestCase {
$this->middleware->beforeController(__CLASS__, __FUNCTION__);
}
+ /**
+ * @PublicPage
+ */
+ public function testPassesCsrfCheck(){
+ $this->request->expects($this->once())
+ ->method('passesCSRFCheck')
+ ->will($this->returnValue(true));
+ $this->request->expects($this->once())
+ ->method('passesStrictCookieCheck')
+ ->will($this->returnValue(true));
+
+ $this->reader->reflect(__CLASS__, __FUNCTION__);
+ $this->middleware->beforeController(__CLASS__, __FUNCTION__);
+ }
/**
* @PublicPage
+ * @expectedException \OC\AppFramework\Middleware\Security\Exceptions\CrossSiteRequestForgeryException
*/
public function testFailCsrfCheck(){
$this->request->expects($this->once())
->method('passesCSRFCheck')
+ ->will($this->returnValue(false));
+ $this->request->expects($this->once())
+ ->method('passesStrictCookieCheck')
->will($this->returnValue(true));
$this->reader->reflect(__CLASS__, __FUNCTION__);
$this->middleware->beforeController(__CLASS__, __FUNCTION__);
}
+ /**
+ * @PublicPage
+ * @StrictCookieRequired
+ * @expectedException \OC\Appframework\Middleware\Security\Exceptions\StrictCookieMissingException
+ */
+ public function testStrictCookieRequiredCheck() {
+ $this->request->expects($this->never())
+ ->method('passesCSRFCheck');
+ $this->request->expects($this->once())
+ ->method('passesStrictCookieCheck')
+ ->will($this->returnValue(false));
+
+ $this->reader->reflect(__CLASS__, __FUNCTION__);
+ $this->middleware->beforeController(__CLASS__, __FUNCTION__);
+ }
+
+
+ /**
+ * @PublicPage
+ * @NoCSRFRequired
+ */
+ public function testNoStrictCookieRequiredCheck() {
+ $this->request->expects($this->never())
+ ->method('passesStrictCookieCheck')
+ ->will($this->returnValue(false));
+
+ $this->reader->reflect(__CLASS__, __FUNCTION__);
+ $this->middleware->beforeController(__CLASS__, __FUNCTION__);
+ }
+
+ /**
+ * @PublicPage
+ * @NoCSRFRequired
+ * @StrictCookieRequired
+ */
+ public function testPassesStrictCookieRequiredCheck() {
+ $this->request
+ ->expects($this->once())
+ ->method('passesStrictCookieCheck')
+ ->willReturn(true);
+
+ $this->reader->reflect(__CLASS__, __FUNCTION__);
+ $this->middleware->beforeController(__CLASS__, __FUNCTION__);
+ }
/**
* @NoCSRFRequired
@@ -360,6 +425,30 @@ class SecurityMiddlewareTest extends \Test\TestCase {
$this->assertEquals($expected , $response);
}
+ public function testAfterExceptionRedirectsToWebRootAfterStrictCookieFail() {
+ $this->request = new Request(
+ [
+ 'server' => [
+ 'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
+ 'REQUEST_URI' => 'owncloud/index.php/apps/specialapp',
+ ],
+ ],
+ $this->getMock('\OCP\Security\ISecureRandom'),
+ $this->getMock('\OCP\IConfig')
+ );
+
+ $this->middleware = $this->getMiddleware(false, false);
+ $response = $this->middleware->afterException(
+ $this->controller,
+ 'test',
+ new StrictCookieMissingException()
+ );
+
+ $expected = new RedirectResponse(\OC::$WEBROOT);
+ $this->assertEquals($expected , $response);
+ }
+
+
/**
* @return array
*/
diff --git a/tests/lib/files.php b/tests/lib/files.php
index 6808b3e9f64..1fcb176dcfd 100644
--- a/tests/lib/files.php
+++ b/tests/lib/files.php
@@ -102,6 +102,7 @@ class Files extends \Test\TestCase {
$setSize, $expectedSize,
$htaccessStr, $userIniStr
) {
+ $this->markTestSkipped('TODO: Disable because fails on drone');
$files = $this->getUploadLimitTestFiles();
chmod($files['.htaccess'], ($htaccessWritable ? 0644 : 0444));
chmod($files['.user.ini'], ($userIniWritable ? 0644 : 0444));
diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php
index 86413c61aa1..66edd3164ef 100644
--- a/tests/lib/files/view.php
+++ b/tests/lib/files/view.php
@@ -74,6 +74,8 @@ class View extends \Test\TestCase {
protected function setUp() {
parent::setUp();
\OC_Hook::clear();
+ $storageFactory = \OC\Files\Filesystem::getLoader();
+ $this->invokePrivate($storageFactory, 'storageWrappers', [[]]);
\OC_User::clearBackends();
\OC_User::useBackend(new \Test\Util\User\Dummy());
diff --git a/tests/lib/notification/notificationtest.php b/tests/lib/notification/notificationtest.php
index ee9454c77a0..bb9440a34d9 100644
--- a/tests/lib/notification/notificationtest.php
+++ b/tests/lib/notification/notificationtest.php
@@ -517,6 +517,7 @@ class NotificationTest extends TestCase {
->setMethods([
'isValidCommon',
'getSubject',
+ 'getParsedSubject',
])
->getMock();
@@ -547,6 +548,7 @@ class NotificationTest extends TestCase {
$notification = $this->getMockBuilder('\OC\Notification\Notification')
->setMethods([
'isValidCommon',
+ 'getSubject',
'getParsedSubject',
])
->getMock();
diff --git a/tests/lib/preview/movie.php b/tests/lib/preview/movie.php
index c6b0c0f7322..ef290092fc2 100644
--- a/tests/lib/preview/movie.php
+++ b/tests/lib/preview/movie.php
@@ -21,6 +21,11 @@
namespace Test\Preview;
+/**
+ * Class Movie
+ * @package Test\Preview
+ * @group DB
+ */
class Movie extends Provider {
public function setUp() {
diff --git a/tests/lib/preview/office.php b/tests/lib/preview/office.php
index 22eeb0aed33..9fcdd621031 100644
--- a/tests/lib/preview/office.php
+++ b/tests/lib/preview/office.php
@@ -21,6 +21,11 @@
namespace Test\Preview;
+/**
+ * Class Office
+ * @package Test\Preview
+ * @group DB
+ */
class Office extends Provider {
public function setUp() {
diff --git a/tests/lib/share20/managertest.php b/tests/lib/share20/managertest.php
index 029c8cd8543..8f3417d53fd 100644
--- a/tests/lib/share20/managertest.php
+++ b/tests/lib/share20/managertest.php
@@ -20,6 +20,7 @@
*/
namespace Test\Share20;
+use OC\HintException;
use OCP\Files\IRootFolder;
use OCP\IUserManager;
use OCP\Share\Exceptions\ShareNotFound;
@@ -37,6 +38,8 @@ use OCP\Security\ISecureRandom;
use OCP\Security\IHasher;
use OCP\Files\Mount\IMountManager;
use OCP\IGroupManager;
+use Symfony\Component\EventDispatcher\EventDispatcher;
+use Symfony\Component\EventDispatcher\GenericEvent;
/**
* Class ManagerTest
@@ -70,9 +73,11 @@ class ManagerTest extends \Test\TestCase {
protected $userManager;
/** @var IRootFolder | \PHPUnit_Framework_MockObject_MockObject */
protected $rootFolder;
+ /** @var EventDispatcher | \PHPUnit_Framework_MockObject_MockObject */
+ protected $eventDispatcher;
public function setUp() {
-
+
$this->logger = $this->getMock('\OCP\ILogger');
$this->config = $this->getMock('\OCP\IConfig');
$this->secureRandom = $this->getMock('\OCP\Security\ISecureRandom');
@@ -81,6 +86,7 @@ class ManagerTest extends \Test\TestCase {
$this->groupManager = $this->getMock('\OCP\IGroupManager');
$this->userManager = $this->getMock('\OCP\IUserManager');
$this->rootFolder = $this->getMock('\OCP\Files\IRootFolder');
+ $this->eventDispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcher');
$this->l = $this->getMock('\OCP\IL10N');
$this->l->method('t')
@@ -100,7 +106,8 @@ class ManagerTest extends \Test\TestCase {
$this->l,
$this->factory,
$this->userManager,
- $this->rootFolder
+ $this->rootFolder,
+ $this->eventDispatcher
);
$this->defaultProvider = $this->getMockBuilder('\OC\Share20\DefaultShareProvider')
@@ -127,7 +134,8 @@ class ManagerTest extends \Test\TestCase {
$this->l,
$this->factory,
$this->userManager,
- $this->rootFolder
+ $this->rootFolder,
+ $this->eventDispatcher
]);
}
@@ -146,7 +154,7 @@ class ManagerTest extends \Test\TestCase {
$group = $this->getMock('\OCP\IGroup');
$group->method('getGID')->willReturn('sharedWithGroup');
-
+
return [
[\OCP\Share::SHARE_TYPE_USER, 'sharedWithUser'],
[\OCP\Share::SHARE_TYPE_GROUP, 'sharedWithGroup'],
@@ -543,17 +551,13 @@ class ManagerTest extends \Test\TestCase {
['core', 'shareapi_enforce_links_password', 'no', 'no'],
]));
- $hookListner = $this->getMockBuilder('Dummy')->setMethods(['listner'])->getMock();
- \OCP\Util::connectHook('\OC\Share', 'verifyPassword', $hookListner, 'listner');
-
- $hookListner->expects($this->once())
- ->method('listner')
- ->with([
- 'password' => 'password',
- 'accepted' => true,
- 'message' => ''
- ]);
-
+ $this->eventDispatcher->expects($this->once())->method('dispatch')
+ ->willReturnCallback(
+ function($eventName, GenericEvent $event) {
+ $this->assertSame('OCP\PasswordPolicy::validate', $eventName);
+ $this->assertSame('password', $event->getSubject());
+ }
+ );
$result = $this->invokePrivate($this->manager, 'verifyPassword', ['password']);
$this->assertNull($result);
}
@@ -567,8 +571,15 @@ class ManagerTest extends \Test\TestCase {
['core', 'shareapi_enforce_links_password', 'no', 'no'],
]));
- $dummy = new DummyPassword();
- \OCP\Util::connectHook('\OC\Share', 'verifyPassword', $dummy, 'listner');
+ $this->eventDispatcher->expects($this->once())->method('dispatch')
+ ->willReturnCallback(
+ function($eventName, GenericEvent $event) {
+ $this->assertSame('OCP\PasswordPolicy::validate', $eventName);
+ $this->assertSame('password', $event->getSubject());
+ throw new HintException('message', 'password not accepted');
+ }
+ );
+
$this->invokePrivate($this->manager, 'verifyPassword', ['password']);
}
@@ -579,7 +590,7 @@ class ManagerTest extends \Test\TestCase {
$share->method('getShareType')->willReturn($type);
$share->method('getSharedWith')->willReturn($sharedWith);
$share->method('getSharedBy')->willReturn($sharedBy);
- $share->method('getSharedOwner')->willReturn($shareOwner);
+ $share->method('getShareOwner')->willReturn($shareOwner);
$share->method('getNode')->willReturn($path);
$share->method('getPermissions')->willReturn($permissions);
$share->method('getExpirationDate')->willReturn($expireDate);
@@ -670,7 +681,6 @@ class ManagerTest extends \Test\TestCase {
$data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $allPermssions, $user2, $user0, $user0, 30, null, null), 'Shares need at least read permissions', true];
$data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $allPermssions, $group0, $user0, $user0, 2, null, null), 'Shares need at least read permissions', true];
- $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $allPermssions, null, $user0, $user0, 16, null, null), 'Shares need at least read permissions', true];
$data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $allPermssions, $user2, $user0, $user0, 31, null, null), null, false];
$data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $allPermssions, $group0, $user0, $user0, 3, null, null), null, false];
@@ -2023,7 +2033,8 @@ class ManagerTest extends \Test\TestCase {
$this->l,
$factory,
$this->userManager,
- $this->rootFolder
+ $this->rootFolder,
+ $this->eventDispatcher
);
$share = $this->getMock('\OCP\Share\IShare');
@@ -2466,13 +2477,6 @@ class ManagerTest extends \Test\TestCase {
}
}
-class DummyPassword {
- public function listner($array) {
- $array['accepted'] = false;
- $array['message'] = 'password not accepted';
- }
-}
-
class DummyFactory implements IProviderFactory {
/** @var IShareProvider */
@@ -2504,4 +2508,4 @@ class DummyFactory implements IProviderFactory {
public function getProviderForType($shareType) {
return $this->provider;
}
-} \ No newline at end of file
+}
diff --git a/tests/lib/tempmanager.php b/tests/lib/tempmanager.php
index 8faf804a203..f45caf10ba2 100644
--- a/tests/lib/tempmanager.php
+++ b/tests/lib/tempmanager.php
@@ -141,6 +141,7 @@ class TempManager extends \Test\TestCase {
if (\OC_Util::runningOnWindows()) {
$this->markTestSkipped('[Windows] chmod() does not work as intended on Windows.');
}
+ $this->markTestSkipped('TODO: Disable because fails on drone');
$logger = $this->getMock('\Test\NullLogger');
$manager = $this->getManager($logger);
@@ -155,6 +156,7 @@ class TempManager extends \Test\TestCase {
if (\OC_Util::runningOnWindows()) {
$this->markTestSkipped('[Windows] chmod() does not work as intended on Windows.');
}
+ $this->markTestSkipped('TODO: Disable because fails on drone');
$logger = $this->getMock('\Test\NullLogger');
$manager = $this->getManager($logger);
diff --git a/tests/lib/updater.php b/tests/lib/updater.php
index 4b6205a42c7..1363fb735ca 100644
--- a/tests/lib/updater.php
+++ b/tests/lib/updater.php
@@ -222,8 +222,8 @@ class UpdaterTest extends \Test\TestCase {
$this->config
->expects($this->at(1))
->method('getSystemValue')
- ->with('updater.server.url', 'https://updates.owncloud.com/server/')
- ->willReturn('https://updates.owncloud.com/server/');
+ ->with('updater.server.url', 'https://updates.nextcloud.org/server/')
+ ->willReturn('https://updates.nextcloud.org/server/');
$this->config
->expects($this->at(2))
->method('setAppValue')
@@ -253,7 +253,7 @@ class UpdaterTest extends \Test\TestCase {
$this->httpHelper
->expects($this->once())
->method('getUrlContent')
- ->with($this->buildUpdateUrl('https://updates.owncloud.com/server/'))
+ ->with($this->buildUpdateUrl('https://updates.nextcloud.org/server/'))
->will($this->returnValue($updateXml));
$this->assertSame($expectedResult, $this->updater->check());
@@ -268,8 +268,8 @@ class UpdaterTest extends \Test\TestCase {
$this->config
->expects($this->at(1))
->method('getSystemValue')
- ->with('updater.server.url', 'https://updates.owncloud.com/server/')
- ->willReturn('https://updates.owncloud.com/server/');
+ ->with('updater.server.url', 'https://updates.nextcloud.org/server/')
+ ->willReturn('https://updates.nextcloud.org/server/');
$this->config
->expects($this->at(2))
->method('setAppValue')
@@ -293,7 +293,7 @@ class UpdaterTest extends \Test\TestCase {
$this->httpHelper
->expects($this->once())
->method('getUrlContent')
- ->with($this->buildUpdateUrl('https://updates.owncloud.com/server/'))
+ ->with($this->buildUpdateUrl('https://updates.nextcloud.org/server/'))
->will($this->returnValue($updateXml));
$this->assertSame([], $this->updater->check());
@@ -315,8 +315,8 @@ class UpdaterTest extends \Test\TestCase {
$this->config
->expects($this->at(1))
->method('getSystemValue')
- ->with('updater.server.url', 'https://updates.owncloud.com/server/')
- ->willReturn('https://updates.owncloud.com/server/');
+ ->with('updater.server.url', 'https://updates.nextcloud.org/server/')
+ ->willReturn('https://updates.nextcloud.org/server/');
$this->config
->expects($this->at(2))
->method('setAppValue')
@@ -342,7 +342,7 @@ class UpdaterTest extends \Test\TestCase {
$this->httpHelper
->expects($this->once())
->method('getUrlContent')
- ->with($this->buildUpdateUrl('https://updates.owncloud.com/server/'))
+ ->with($this->buildUpdateUrl('https://updates.nextcloud.org/server/'))
->will($this->returnValue($updateXml));
$this->assertSame($expectedResult, $this->updater->check());
@@ -359,8 +359,8 @@ class UpdaterTest extends \Test\TestCase {
$this->config
->expects($this->at(1))
->method('getSystemValue')
- ->with('updater.server.url', 'https://updates.owncloud.com/server/')
- ->willReturn('https://updates.owncloud.com/server/');
+ ->with('updater.server.url', 'https://updates.nextcloud.org/server/')
+ ->willReturn('https://updates.nextcloud.org/server/');
$this->config
->expects($this->at(2))
->method('setAppValue')
@@ -384,7 +384,7 @@ class UpdaterTest extends \Test\TestCase {
$this->httpHelper
->expects($this->once())
->method('getUrlContent')
- ->with($this->buildUpdateUrl('https://updates.owncloud.com/server/'))
+ ->with($this->buildUpdateUrl('https://updates.nextcloud.org/server/'))
->will($this->returnValue($updateXml));
$this->assertSame($expectedResult, $this->updater->check());
diff --git a/tests/lib/user/database.php b/tests/lib/user/database.php
index ba44d333a8c..e239ea9c3e4 100644
--- a/tests/lib/user/database.php
+++ b/tests/lib/user/database.php
@@ -19,6 +19,9 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
+use OC\HintException;
+use Symfony\Component\EventDispatcher\EventDispatcher;
+use Symfony\Component\EventDispatcher\GenericEvent;
/**
* Class Test_User_Database
@@ -28,6 +31,8 @@
class Test_User_Database extends Test_User_Backend {
/** @var array */
private $users;
+ /** @var EventDispatcher | PHPUnit_Framework_MockObject_MockObject */
+ private $eventDispatcher;
public function getUser() {
$user = parent::getUser();
@@ -37,7 +42,8 @@ class Test_User_Database extends Test_User_Backend {
protected function setUp() {
parent::setUp();
- $this->backend=new OC_User_Database();
+ $this->eventDispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcher');
+ $this->backend=new OC_User_Database($this->eventDispatcher);
}
protected function tearDown() {
@@ -49,4 +55,41 @@ class Test_User_Database extends Test_User_Backend {
}
parent::tearDown();
}
+
+ public function testVerifyPasswordEvent() {
+ $user = $this->getUser();
+ $this->backend->createUser($user, 'pass1');
+
+ $this->eventDispatcher->expects($this->once())->method('dispatch')
+ ->willReturnCallback(
+ function ($eventName, GenericEvent $event) {
+ $this->assertSame('OCP\PasswordPolicy::validate', $eventName);
+ $this->assertSame('newpass', $event->getSubject());
+ }
+ );
+
+ $this->backend->setPassword($user, 'newpass');
+ $this->assertSame($user, $this->backend->checkPassword($user, 'newpass'));
+ }
+
+ /**
+ * @expectedException \OC\HintException
+ * @expectedExceptionMessage password change failed
+ */
+ public function testVerifyPasswordEventFail() {
+ $user = $this->getUser();
+ $this->backend->createUser($user, 'pass1');
+
+ $this->eventDispatcher->expects($this->once())->method('dispatch')
+ ->willReturnCallback(
+ function ($eventName, GenericEvent $event) {
+ $this->assertSame('OCP\PasswordPolicy::validate', $eventName);
+ $this->assertSame('newpass', $event->getSubject());
+ throw new HintException('password change failed', 'password change failed');
+ }
+ );
+
+ $this->backend->setPassword($user, 'newpass');
+ $this->assertSame($user, $this->backend->checkPassword($user, 'newpass'));
+ }
}
diff --git a/tests/lib/utilcheckserver.php b/tests/lib/utilcheckserver.php
index 94e7fd2f779..3a8dc4a28a7 100644
--- a/tests/lib/utilcheckserver.php
+++ b/tests/lib/utilcheckserver.php
@@ -146,6 +146,7 @@ class Test_Util_CheckServer extends \Test\TestCase {
if (\OC_Util::runningOnWindows()) {
$this->markTestSkipped('[Windows] chmod() does not work as intended on Windows.');
}
+ $this->markTestSkipped('TODO: Disable because fails on drone');
chmod($this->datadir, 0300);
$result = \OC_Util::checkServer($this->getConfig(array(
diff --git a/tests/settings/controller/logsettingscontrollertest.php b/tests/settings/controller/logsettingscontrollertest.php
index 60680ba4647..3c290767e07 100644
--- a/tests/settings/controller/logsettingscontrollertest.php
+++ b/tests/settings/controller/logsettingscontrollertest.php
@@ -11,6 +11,7 @@ namespace Test\Settings\Controller;
use \OC\Settings\Application;
use OC\Settings\Controller\LogSettingsController;
+use OCP\AppFramework\Http\StreamResponse;
/**
* @package OC\Settings\Controller
@@ -69,6 +70,9 @@ class LogSettingsControllerTest extends \Test\TestCase {
public function testDownload() {
$response = $this->logSettingsController->download();
- $this->assertInstanceOf('\OCP\AppFramework\Http\StreamResponse', $response);
+ $expected = new StreamResponse(\OC_Log_Owncloud::getLogFilePath());
+ $expected->addHeader('Content-Type', 'application/octet-stream');
+ $expected->addHeader('Content-Disposition', 'attachment; filename="nextcloud.log"');
+ $this->assertEquals($expected, $response);
}
}