From c521d44475ac6a5e154263565864074b09f1c6f6 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Thu, 13 Jul 2017 19:03:34 +0200 Subject: [PATCH] Override Request object in app.php Signed-off-by: Lukas Reschke --- Makefile | 2 +- .../features/bootstrap/FeatureContext.php | 1 - appinfo/app.php | 66 +++++++++++++++++++ appinfo/info.xml | 5 +- 4 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 appinfo/app.php diff --git a/Makefile b/Makefile index 3d940ea..c6d02f7 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ source_dir=$(build_dir)/source sign_dir=$(build_dir)/sign package_name=$(app_name) cert_dir=$(HOME)/.nextcloud/certificates -version+=1.0.5 +version+=1.0.6 all: appstore diff --git a/Tests/Integration/features/bootstrap/FeatureContext.php b/Tests/Integration/features/bootstrap/FeatureContext.php index 77b1109..c437bad 100644 --- a/Tests/Integration/features/bootstrap/FeatureContext.php +++ b/Tests/Integration/features/bootstrap/FeatureContext.php @@ -19,7 +19,6 @@ class FeatureContext implements Context { private function sendRequest($username, $password, $cookies = false) { - $params = []; if($cookies) { $params['cookies'] = \GuzzleHttp\Cookie\CookieJar::fromArray([ diff --git a/appinfo/app.php b/appinfo/app.php new file mode 100644 index 0000000..d01ce57 --- /dev/null +++ b/appinfo/app.php @@ -0,0 +1,66 @@ + + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +$serverContainer = \OC::$server; + +$currentUrl = $serverContainer->getRequest()->getServerProtocol() . '://' .$serverContainer->getRequest()->getServerHost() . $serverContainer->getRequest()->getRequestUri(); +$expectedUrl = $serverContainer->getURLGenerator()->getAbsoluteURL('/index.php/apps/loginviapost/login'); + +// Only process on login URL +if($currentUrl !== $expectedUrl) { + return; +} + +// Register the request service again +$serverContainer->registerService(\OCP\IRequest::class, function() use ($serverContainer) { + if (isset($serverContainer['urlParams'])) { + $urlParams = $this['urlParams']; + } else { + $urlParams = []; + } + + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN + && in_array('fakeinput', stream_get_wrappers()) + ) { + $stream = 'fakeinput://data'; + } else { + $stream = 'php://input'; + } + + return new \OCA\LoginViaPost\Request( + [ + 'get' => $_GET, + 'post' => $_POST, + 'files' => $_FILES, + 'server' => $_SERVER, + 'env' => $_ENV, + 'cookies' => $_COOKIE, + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) + ? $_SERVER['REQUEST_METHOD'] + : null, + 'urlParams' => $urlParams, + ], + $serverContainer->getSecureRandom(), + $serverContainer->getConfig(), + $serverContainer->getCsrfTokenManager(), + $stream + ); +}); diff --git a/appinfo/info.xml b/appinfo/info.xml index 8c9b398..165d5c0 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -22,7 +22,7 @@ the following form explains the usage of this plugin: ```]]> - 1.0.5 + 1.0.6 agpl Lukas Reschke LoginViaPost @@ -32,4 +32,7 @@ the following form explains the usage of this plugin: + + +