summaryrefslogtreecommitdiffstats
path: root/tests/lib/appframework/middleware
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2015-02-09 11:41:48 +0100
committerLukas Reschke <lukas@owncloud.com>2015-02-09 11:53:11 +0100
commit770fa761b8bf8452ff17a2036ca8413e74935a3d (patch)
treeecce3b7443278b0ebdac588ba40840190a3aadcd /tests/lib/appframework/middleware
parent0e604aa875a677f76b2bf326631646ac31fbadbd (diff)
downloadnextcloud-server-770fa761b8bf8452ff17a2036ca8413e74935a3d.tar.gz
nextcloud-server-770fa761b8bf8452ff17a2036ca8413e74935a3d.zip
Respect `mod_unique_id` and refactor `OC_Request::getRequestId`
When `mod_unique_id` is enabled the ID generated by it will be used for logging. This allows for correlation of the Apache logs and the ownCloud logs. Testplan: - [ ] When `mod_unique_id` is enabled the request ID equals the one generated by `mod_unique_id`. - [ ] When `mod_unique_id` is not available the request ID is a 20 character long random string - [ ] The generated Id is stable over the lifespan of one request Changeset looks a little bit larger since I had to adjust every unit test using the HTTP\Request class for proper DI. Fixes https://github.com/owncloud/core/issues/13366
Diffstat (limited to 'tests/lib/appframework/middleware')
-rw-r--r--tests/lib/appframework/middleware/MiddlewareDispatcherTest.php12
-rw-r--r--tests/lib/appframework/middleware/MiddlewareTest.php10
-rw-r--r--tests/lib/appframework/middleware/security/CORSMiddlewareTest.php23
-rw-r--r--tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php12
-rw-r--r--tests/lib/appframework/middleware/sessionmiddlewaretest.php5
5 files changed, 49 insertions, 13 deletions
diff --git a/tests/lib/appframework/middleware/MiddlewareDispatcherTest.php b/tests/lib/appframework/middleware/MiddlewareDispatcherTest.php
index be8765afd39..078543c7b59 100644
--- a/tests/lib/appframework/middleware/MiddlewareDispatcherTest.php
+++ b/tests/lib/appframework/middleware/MiddlewareDispatcherTest.php
@@ -126,8 +126,16 @@ class MiddlewareDispatcherTest extends \Test\TestCase {
private function getControllerMock(){
- return $this->getMock('OCP\AppFramework\Controller', array('method'),
- array('app', new Request(array('method' => 'GET'))));
+ return $this->getMock(
+ 'OCP\AppFramework\Controller',
+ ['method'],
+ ['app',
+ new Request(
+ ['method' => 'GET'],
+ $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock()
+ )
+ ]
+ );
}
diff --git a/tests/lib/appframework/middleware/MiddlewareTest.php b/tests/lib/appframework/middleware/MiddlewareTest.php
index b41ec33eb15..fcc0c300a8a 100644
--- a/tests/lib/appframework/middleware/MiddlewareTest.php
+++ b/tests/lib/appframework/middleware/MiddlewareTest.php
@@ -51,8 +51,14 @@ class MiddlewareTest extends \Test\TestCase {
->disableOriginalConstructor()
->getMock();
- $this->controller = $this->getMock('OCP\AppFramework\Controller',
- array(), array($this->api, new Request()));
+ $this->controller = $this->getMock(
+ 'OCP\AppFramework\Controller',
+ [],
+ [
+ $this->api,
+ new Request([], $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock())
+ ]
+ );
$this->exception = new \Exception();
$this->response = $this->getMock('OCP\AppFramework\Http\Response');
}
diff --git a/tests/lib/appframework/middleware/security/CORSMiddlewareTest.php b/tests/lib/appframework/middleware/security/CORSMiddlewareTest.php
index b4bbcce5ad7..57a7c524abe 100644
--- a/tests/lib/appframework/middleware/security/CORSMiddlewareTest.php
+++ b/tests/lib/appframework/middleware/security/CORSMiddlewareTest.php
@@ -32,7 +32,12 @@ class CORSMiddlewareTest extends \Test\TestCase {
*/
public function testSetCORSAPIHeader() {
$request = new Request(
- array('server' => array('HTTP_ORIGIN' => 'test'))
+ [
+ 'server' => [
+ 'HTTP_ORIGIN' => 'test'
+ ]
+ ],
+ $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock()
);
$this->reflector->reflect($this, __FUNCTION__);
$middleware = new CORSMiddleware($request, $this->reflector);
@@ -45,7 +50,12 @@ class CORSMiddlewareTest extends \Test\TestCase {
public function testNoAnnotationNoCORSHEADER() {
$request = new Request(
- array('server' => array('HTTP_ORIGIN' => 'test'))
+ [
+ 'server' => [
+ 'HTTP_ORIGIN' => 'test'
+ ]
+ ],
+ $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock()
);
$middleware = new CORSMiddleware($request, $this->reflector);
@@ -59,7 +69,7 @@ class CORSMiddlewareTest extends \Test\TestCase {
* @CORS
*/
public function testNoOriginHeaderNoCORSHEADER() {
- $request = new Request();
+ $request = new Request([], $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock());
$this->reflector->reflect($this, __FUNCTION__);
$middleware = new CORSMiddleware($request, $this->reflector);
@@ -75,7 +85,12 @@ class CORSMiddlewareTest extends \Test\TestCase {
*/
public function testCorsIgnoredIfWithCredentialsHeaderPresent() {
$request = new Request(
- array('server' => array('HTTP_ORIGIN' => 'test'))
+ [
+ 'server' => [
+ 'HTTP_ORIGIN' => 'test'
+ ]
+ ],
+ $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock()
);
$this->reflector->reflect($this, __FUNCTION__);
$middleware = new CORSMiddleware($request, $this->reflector);
diff --git a/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php b/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php
index a8925403a95..3acba7ce1d8 100644
--- a/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php
+++ b/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php
@@ -314,10 +314,14 @@ class SecurityMiddlewareTest extends \Test\TestCase {
public function testAfterExceptionReturnsRedirect(){
$this->request = new Request(
- array('server' =>
- array('HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
- 'REQUEST_URI' => 'owncloud/index.php/apps/specialapp')
- )
+ [
+ 'server' =>
+ [
+ 'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
+ 'REQUEST_URI' => 'owncloud/index.php/apps/specialapp'
+ ]
+ ],
+ $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock()
);
$this->middleware = $this->getMiddleware(true, true);
$response = $this->middleware->afterException($this->controller, 'test',
diff --git a/tests/lib/appframework/middleware/sessionmiddlewaretest.php b/tests/lib/appframework/middleware/sessionmiddlewaretest.php
index 344b555ec3c..c417225d908 100644
--- a/tests/lib/appframework/middleware/sessionmiddlewaretest.php
+++ b/tests/lib/appframework/middleware/sessionmiddlewaretest.php
@@ -33,7 +33,10 @@ class SessionMiddlewareTest extends \Test\TestCase {
protected function setUp() {
parent::setUp();
- $this->request = new Request();
+ $this->request = new Request(
+ [],
+ $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock()
+ );
$this->reflector = new ControllerMethodReflector();
}