Merge pull request #6 from nextcloud/stable11

Make compatible with stable11
This commit is contained in:
Lukas Reschke 2017-07-14 12:36:23 +02:00 коммит произвёл GitHub
Родитель f2faefd908 e2ead0c101
Коммит 15d2d925bd
7 изменённых файлов: 167 добавлений и 13 удалений

Просмотреть файл

@ -23,6 +23,28 @@ pipeline:
when:
matrix:
TESTS: check-app-compatbility
check-app-compatbility-stable11:
image: nextcloudci/php5.6:php5.6-3
environment:
- APP_NAME=loginviapost
- CORE_BRANCH=stable11
- DB=sqlite
commands:
# Pre-setup steps
- wget https://raw.githubusercontent.com/nextcloud/travis_ci/master/before_install.sh
- bash ./before_install.sh $APP_NAME $CORE_BRANCH $DB
- cd ../server
- cd apps/$APP_NAME/
- rm -rf Tests
# Code checker
- cd ../../
- ./occ app:check-code $APP_NAME -c strong-comparison
- ./occ app:check-code $APP_NAME -c deprecation
- cd apps/$APP_NAME/
when:
matrix:
TESTS: check-app-compatbility-stable11
check-app-compatbility-stable12:
image: nextcloudci/php5.6:php5.6-3
environment:
@ -124,6 +146,49 @@ pipeline:
when:
matrix:
TESTS: php7.1
php5.6-stable11:
image: nextcloudci/php5.6:php5.6-3
environment:
- APP_NAME=loginviapost
- CORE_BRANCH=stable11
- DB=sqlite
commands:
- apt update && apt-get -y install php5-xdebug
# Pre-setup steps
- wget https://raw.githubusercontent.com/nextcloud/travis_ci/master/before_install.sh
- bash ./before_install.sh $APP_NAME $CORE_BRANCH $DB
- cd ../server/apps/$APP_NAME
# Run phpunit tests
- cd Tests/Unit/
- phpunit --configuration phpunit.xml
# Create coverage report
- wget https://codecov.io/bash -O codecov.sh
- sh -c "if [ '$DRONE_BUILD_EVENT' = 'pull_request' ]; then bash codecov.sh -B $DRONE_BRANCH -C $DRONE_COMMIT -P $DRONE_PULL_REQUEST -t 7b5aa41e-0493-4bd6-8a14-8bcd32a68c60 -f clover.xml; fi"
- sh -c "if [ '$DRONE_BUILD_EVENT' != 'pull_request' ]; then bash codecov.sh -B $DRONE_BRANCH -C $DRONE_COMMIT -t 7b5aa41e-0493-4bd6-8a14-8bcd32a68c60 -f clover.xml; fi"
when:
matrix:
TESTS: php5.6-stable11
php7.0-stable11:
image: nextcloudci/php7.0:php7.0-2
environment:
- APP_NAME=loginviapost
- CORE_BRANCH=stable11
- DB=sqlite
commands:
# Pre-setup steps
- wget https://raw.githubusercontent.com/nextcloud/travis_ci/master/before_install.sh
- bash ./before_install.sh $APP_NAME $CORE_BRANCH $DB
- cd ../server/apps/$APP_NAME
# Run phpunit tests
- cd Tests/Unit/
- phpunit --configuration phpunit.xml
when:
matrix:
TESTS: php7.0-stable11
php5.6-stable12:
image: nextcloudci/php5.6:php5.6-3
environment:
@ -208,6 +273,26 @@ pipeline:
when:
matrix:
TESTS: integration-tests
integration-tests-stable11:
image: nextcloudci/php7.0:php7.0-2
environment:
- APP_NAME=loginviapost
- CORE_BRANCH=stable11
- DB=sqlite
commands:
# Pre-setup steps
- wget https://raw.githubusercontent.com/nextcloud/travis_ci/master/before_install.sh
- bash ./before_install.sh $APP_NAME $CORE_BRANCH $DB
- cd ../server/
- ./occ app:enable loginviapost
- php -S localhost:8080 &
# Run behat tests
- cd apps/$APP_NAME/Tests/Integration/
- vendor/bin/behat
when:
matrix:
TESTS: integration-tests-stable11
integration-tests-stable12:
image: nextcloudci/php7.0:php7.0-2
environment:
@ -234,11 +319,15 @@ matrix:
- TESTS: php5.6
- TESTS: php7.0
- TESTS: php7.1
- TESTS: php5.6-stable11
- TESTS: php7.0-stable11
- TESTS: php5.6-stable12
- TESTS: php7.0-stable12
- TESTS: php7.1-stable12
- TESTS: check-app-compatbility
- TESTS: check-app-compatbility-stable11
- TESTS: check-app-compatbility-stable12
- TESTS: signed-off-check
- TESTS: integration-tests
- TESTS: integration-tests-stable11
- TESTS: integration-tests-stable12

Просмотреть файл

@ -60,8 +60,10 @@ class FeatureContext implements Context {
* @Then The URL should redirect to :url
*/
public function theUrlShouldRedirectTo($url) {
$url = str_replace('&redirect_url=', '', $url);
$realUrl = $this->response->getHeader(\GuzzleHttp\RedirectMiddleware::HISTORY_HEADER);
$realUrl = $realUrl[count($realUrl) - 1];
$realUrl = str_replace('&redirect_url=', '', $realUrl);
if($realUrl !== $url) {
throw new InvalidArgumentException("Expected $url, got $realUrl");
}

Просмотреть файл

@ -33,6 +33,9 @@ use OCP\IURLGenerator;
use OCP\IUserSession;
use Test\TestCase;
/**
* @group DB
*/
class LoginControllerTest extends TestCase {
/** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
private $request;

Просмотреть файл

@ -0,0 +1,43 @@
<?php
/**
* @copyright Copyright (c) 2017 Lukas Reschke <lukas@statuscode.ch>
*
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\LoginViaPost\Tests\Unit\appinfo;
use OC\AppFramework\Http\Request;
use Test\TestCase;
class AppTest extends TestCase {
public function setUp() {
parent::setUp();
}
public function testRegularPage() {
require __DIR__ . '/../../../appinfo/app.php';
$this->assertSame(Request::class, get_class(\OC::$server->getRequest()));
}
public function testLoginPage() {
define('PHPUNIT_BYPASS_URL', 'foo');
require __DIR__ . '/../../../appinfo/app.php';
$this->assertSame(\OCA\LoginViaPost\Request::class, get_class(\OC::$server->getRequest()));
}
}

Просмотреть файл

@ -25,12 +25,12 @@ $currentUrl = $serverContainer->getRequest()->getServerProtocol() . '://' .$serv
$expectedUrl = $serverContainer->getURLGenerator()->getAbsoluteURL('/index.php/apps/loginviapost/login');
// Only process on login URL
if($currentUrl !== $expectedUrl) {
if($currentUrl !== $expectedUrl && !defined('PHPUNIT_BYPASS_URL')) {
return;
}
// Register the request service again
$serverContainer->registerService(\OCP\IRequest::class, function() use ($serverContainer) {
$serverContainer->registerService('Request', function() use ($serverContainer) {
if (isset($serverContainer['urlParams'])) {
$urlParams = $this['urlParams'];
} else {

Просмотреть файл

@ -30,7 +30,7 @@ the following form explains the usage of this plugin:
<bugs>https://github.com/nextcloud/loginviapost/issues</bugs>
<repository>https://github.com/nextcloud/loginviapost</repository>
<dependencies>
<nextcloud min-version="12" max-version="13"/>
<nextcloud min-version="11" max-version="13"/>
</dependencies>
<types>
<session/>

Просмотреть файл

@ -98,18 +98,35 @@ class LoginController extends Controller {
* @return RedirectResponse
*/
public function login($username, $password) {
$class = new \ReflectionClass(\OC\Core\Controller\LoginController::class);
$parameters = $class->getConstructor()->getParameters();
/** @var \OC\Core\Controller\LoginController $loginController */
$loginController = new \OC\Core\Controller\LoginController(
if($parameters[8]->getName() === 'throttler') {
$loginController = new \OC\Core\Controller\LoginController(
'core',
$this->getMockedRequest(),
$this->userManager,
$this->config,
$this->session,
$this->userSession,
$this->urlGenerator,
$this->twoFactorAuthManager,
\OC::$server->getBruteForceThrottler()
);
} else {
$loginController = new \OC\Core\Controller\LoginController(
'core',
$this->getMockedRequest(),
$this->userManager,
$this->config,
$this->session,
$this->userSession,
$this->urlGenerator,
$this->logger,
$this->twoFactorAuthManager
);
$this->getMockedRequest(),
$this->userManager,
$this->config,
$this->session,
$this->userSession,
$this->urlGenerator,
$this->logger,
$this->twoFactorAuthManager
);
}
return $loginController->tryLogin($username, $password, '');
}