summaryrefslogtreecommitdiffstats
path: root/tests/lib/appframework/middleware
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2013-10-07 11:25:50 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2013-10-07 11:25:50 +0200
commit1e5012fc1d0fab73ce5694b513fe1308615961f0 (patch)
treee963e7e5fa3a7d681d3065f7239e85485e84360d /tests/lib/appframework/middleware
parentaefea2a408e0548ee1190923e7d2c42f49d26587 (diff)
downloadnextcloud-server-1e5012fc1d0fab73ce5694b513fe1308615961f0.tar.gz
nextcloud-server-1e5012fc1d0fab73ce5694b513fe1308615961f0.zip
fixing all appframework unit tests
Diffstat (limited to 'tests/lib/appframework/middleware')
-rw-r--r--tests/lib/appframework/middleware/MiddlewareDispatcherTest.php4
-rw-r--r--tests/lib/appframework/middleware/MiddlewareTest.php4
-rw-r--r--tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php66
3 files changed, 52 insertions, 22 deletions
diff --git a/tests/lib/appframework/middleware/MiddlewareDispatcherTest.php b/tests/lib/appframework/middleware/MiddlewareDispatcherTest.php
index dd85a9ad52f..5a43099ebb5 100644
--- a/tests/lib/appframework/middleware/MiddlewareDispatcherTest.php
+++ b/tests/lib/appframework/middleware/MiddlewareDispatcherTest.php
@@ -122,13 +122,13 @@ class MiddlewareDispatcherTest extends \PHPUnit_Framework_TestCase {
private function getAPIMock(){
- return $this->getMock('OC\AppFramework\Core\API',
+ return $this->getMock('OC\AppFramework\DependencyInjection\DIContainer',
array('getAppName'), array('app'));
}
private function getControllerMock(){
- return $this->getMock('OC\AppFramework\Controller\Controller', array('method'),
+ return $this->getMock('OCP\AppFramework\Controller\Controller', array('method'),
array($this->getAPIMock(), new Request()));
}
diff --git a/tests/lib/appframework/middleware/MiddlewareTest.php b/tests/lib/appframework/middleware/MiddlewareTest.php
index d0be7f7ca74..fde67fbd395 100644
--- a/tests/lib/appframework/middleware/MiddlewareTest.php
+++ b/tests/lib/appframework/middleware/MiddlewareTest.php
@@ -44,10 +44,10 @@ class MiddlewareTest extends \PHPUnit_Framework_TestCase {
protected function setUp(){
$this->middleware = new ChildMiddleware();
- $this->api = $this->getMock('OC\AppFramework\Core\API',
+ $this->api = $this->getMock('OC\AppFramework\DependencyInjection\DIContainer',
array(), array('test'));
- $this->controller = $this->getMock('OC\AppFramework\Controller\Controller',
+ $this->controller = $this->getMock('OCP\AppFramework\Controller\Controller',
array(), array($this->api, new Request()));
$this->exception = new \Exception();
$this->response = $this->getMock('OCP\AppFramework\Http\Response');
diff --git a/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php b/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php
index 3ed44282a7b..b647c01826b 100644
--- a/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php
+++ b/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php
@@ -39,8 +39,8 @@ class SecurityMiddlewareTest extends \PHPUnit_Framework_TestCase {
private $request;
public function setUp() {
- $api = $this->getMock('OC\AppFramework\Core\API', array(), array('test'));
- $this->controller = $this->getMock('OC\AppFramework\Controller\Controller',
+ $api = $this->getMock('OC\AppFramework\DependencyInjection\DIContainer', array(), array('test'));
+ $this->controller = $this->getMock('OCP\AppFramework\Controller\Controller',
array(), array($api, new Request()));
$this->request = new Request();
@@ -51,24 +51,19 @@ class SecurityMiddlewareTest extends \PHPUnit_Framework_TestCase {
private function getAPI(){
- return $this->getMock('OC\AppFramework\Core\API',
+ return $this->getMock('OC\AppFramework\DependencyInjection\DIContainer',
array('isLoggedIn', 'passesCSRFCheck', 'isAdminUser',
- 'isSubAdminUser', 'activateNavigationEntry',
- 'getUserId'),
+ 'isSubAdminUser', 'getUserId'),
array('app'));
}
- private function checkNavEntry($method, $shouldBeActivated=false){
+ private function checkNavEntry($method){
$api = $this->getAPI();
- if($shouldBeActivated){
- $api->expects($this->once())
- ->method('activateNavigationEntry');
- } else {
- $api->expects($this->never())
- ->method('activateNavigationEntry');
- }
+ $serverMock = $this->getMock('\OC\Server', array());
+ $api->expects($this->any())->method('getServer')
+ ->will($this->returnValue($serverMock));
$sec = new SecurityMiddleware($api, $this->request);
$sec->beforeController('\OC\AppFramework\Middleware\Security\SecurityMiddlewareTest', $method);
@@ -80,7 +75,7 @@ class SecurityMiddlewareTest extends \PHPUnit_Framework_TestCase {
* @NoCSRFRequired
*/
public function testSetNavigationEntry(){
- $this->checkNavEntry('testSetNavigationEntry', true);
+ $this->checkNavEntry('testSetNavigationEntry');
}
@@ -215,9 +210,33 @@ class SecurityMiddlewareTest extends \PHPUnit_Framework_TestCase {
/**
* @PublicPage
+ * @expectedException \OC\AppFramework\Middleware\Security\SecurityException
*/
public function testCsrfCheck(){
- $this->securityCheck('testCsrfCheck', 'passesCSRFCheck');
+ $api = $this->getAPI();
+ $request = $this->getMock('OC\AppFramework\Http\Request', array('passesCSRFCheck'));
+ $request->expects($this->once())
+ ->method('passesCSRFCheck')
+ ->will($this->returnValue(false));
+
+ $sec = new SecurityMiddleware($api, $request);
+ $sec->beforeController('\OC\AppFramework\Middleware\Security\SecurityMiddlewareTest', 'testCsrfCheck');
+ }
+
+
+ /**
+ * @PublicPage
+ * @NoCSRFRequired
+ */
+ public function testNoCsrfCheck(){
+ $api = $this->getAPI();
+ $request = $this->getMock('OC\AppFramework\Http\Request', array('passesCSRFCheck'));
+ $request->expects($this->never())
+ ->method('passesCSRFCheck')
+ ->will($this->returnValue(false));
+
+ $sec = new SecurityMiddleware($api, $request);
+ $sec->beforeController('\OC\AppFramework\Middleware\Security\SecurityMiddlewareTest', 'testNoCsrfCheck');
}
@@ -225,7 +244,14 @@ class SecurityMiddlewareTest extends \PHPUnit_Framework_TestCase {
* @PublicPage
*/
public function testFailCsrfCheck(){
- $this->securityCheck('testFailCsrfCheck', 'passesCSRFCheck', true);
+ $api = $this->getAPI();
+ $request = $this->getMock('OC\AppFramework\Http\Request', array('passesCSRFCheck'));
+ $request->expects($this->once())
+ ->method('passesCSRFCheck')
+ ->will($this->returnValue(true));
+
+ $sec = new SecurityMiddleware($api, $request);
+ $sec->beforeController('\OC\AppFramework\Middleware\Security\SecurityMiddlewareTest', 'testFailCsrfCheck');
}
@@ -271,8 +297,12 @@ class SecurityMiddlewareTest extends \PHPUnit_Framework_TestCase {
public function testAfterExceptionReturnsRedirect(){
- $api = $this->getMock('OC\AppFramework\Core\API', array(), array('test'));
- $this->controller = $this->getMock('OC\AppFramework\Controller\Controller',
+ $api = $this->getMock('OC\AppFramework\DependencyInjection\DIContainer', array(), array('test'));
+ $serverMock = $this->getMock('\OC\Server', array('getNavigationManager'));
+ $api->expects($this->once())->method('getServer')
+ ->will($this->returnValue($serverMock));
+
+ $this->controller = $this->getMock('OCP\AppFramework\Controller\Controller',
array(), array($api, new Request()));
$this->request = new Request(