diff options
author | Christoph Wurst <ChristophWurst@users.noreply.github.com> | 2021-01-22 19:03:36 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-22 19:03:36 +0300 |
commit | 0e3e3cb89a64c2b93ec9621c5fab45f17bb0a2e9 (patch) | |
tree | 8840da9936baaf4a4a2bc3239e0cc0855bc31d6f | |
parent | 78375a092490979623d18062519234fcf144c13a (diff) | |
parent | 93cdcbb8ca812fee521692f972bb29f9a0d543d3 (diff) |
Merge pull request #1061 from nextcloud/enhancement/drop-nextcloud-20
Drop Nextcloud 20 support
-rw-r--r-- | .github/workflows/lint.yml | 28 | ||||
-rw-r--r-- | .github/workflows/static-analysis.yml | 41 | ||||
-rw-r--r-- | .github/workflows/test.yml | 21 | ||||
-rw-r--r-- | appinfo/app.php | 22 | ||||
-rw-r--r-- | appinfo/info.xml | 2 | ||||
-rw-r--r-- | appinfo/routes.php | 2 | ||||
-rw-r--r-- | lib/AppInfo/Application.php | 28 | ||||
-rw-r--r-- | lib/Provider/TotpProvider.php | 12 | ||||
-rw-r--r-- | tests/Unit/Provider/TotpProviderTest.php | 5 |
9 files changed, 54 insertions, 107 deletions
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 521ec88..e96ba29 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-versions: [ 7.2, 7.3, 7.4 ] + php-versions: [ 7.3, 7.4, 8.0 ] name: php${{ matrix.php-versions }} lint steps: - name: Checkout @@ -42,36 +42,12 @@ jobs: uses: shivammathur/setup-php@master with: php-version: 7.4 - tools: composer:v1 coverage: none - name: Install dependencies run: composer i - name: Run coding standards check run: composer run cs:check - app-code-check: - runs-on: ubuntu-latest - strategy: - matrix: - nextcloud-versions: [ 'master' ] - name: Nextcloud ${{ matrix.nextcloud-versions }} app code check - steps: - - name: Set up php7.4 - uses: shivammathur/setup-php@master - with: - php-version: 7.4 - extensions: ctype,curl,dom,gd,iconv,intl,json,mbstring,openssl,posix,sqlite,xml,zip - - name: Checkout Nextcloud - run: git clone https://github.com/nextcloud/server.git --recursive --depth 1 -b ${{ matrix.nextcloud-versions }} nextcloud - - name: Run tests - run: php -f nextcloud/occ maintenance:install --database-name oc_autotest --database-user oc_autotest --admin-user admin --admin-pass admin --database sqlite --database-pass='' - - name: Checkout - uses: actions/checkout@master - with: - path: nextcloud/apps/twofactor_totp - - name: Run tests - run: php -f nextcloud/occ app:check-code twofactor_totp - node-linters: runs-on: ubuntu-latest name: ESLint @@ -80,7 +56,7 @@ jobs: - name: Set up Node uses: actions/setup-node@v1 with: - node-version: 12.x + node-version: 14.x - name: npm install run: npm ci - name: eslint diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index d1d0d44..2886c6a 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -1,25 +1,24 @@ name: Static analysis - -on: [pull_request] +on: [ pull_request ] jobs: static-psalm-analysis: - runs-on: ubuntu-latest - strategy: - matrix: - ocp-version: [ 'v20.0.4', 'dev-master' ] - name: Nextcloud ${{ matrix.ocp-version }} - steps: - - name: Checkout - uses: actions/checkout@master - - name: Set up php - uses: shivammathur/setup-php@master - with: - php-version: 7.4 - coverage: none - - name: Install dependencies - run: composer i - - name: Install dependencies - run: composer require --dev christophwurst/nextcloud:${{ matrix.ocp-version }} - - name: Run coding standards check - run: composer run psalm + runs-on: ubuntu-latest + strategy: + matrix: + ocp-version: [ 'v21.0.0-beta6', 'dev-master' ] + name: Nextcloud ${{ matrix.ocp-version }} + steps: + - name: Checkout + uses: actions/checkout@master + - name: Set up php + uses: shivammathur/setup-php@master + with: + php-version: 7.4 + coverage: none + - name: Install dependencies + run: composer i + - name: Install dependencies + run: composer require --dev christophwurst/nextcloud:${{ matrix.ocp-version }} + - name: Run coding standards check + run: composer run psalm diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 14ecd6f..c8ee106 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,10 +10,6 @@ jobs: php-version: [ 7.3, 7.4, 8.0 ] nextcloud-version: [ 'master' ] db: ['sqlite'] - include: - - php-version: 7.3 - nextcloud-version: 'stable20' - db: 'sqlite' name: Nextcloud ${{ matrix.nextcloud-version }} php${{ matrix.php-version }} unit tests steps: - name: Set up php${{ matrix.php-version }} @@ -33,10 +29,6 @@ jobs: - name: Install dependencies working-directory: nextcloud/apps/twofactor_totp run: composer install - - name: Fix php-parser on stable20 incompatibility with phpunit 9.3+ - if: ${{ matrix.nextcloud-version == 'stable20' }} - working-directory: nextcloud/3rdparty - run: composer require nikic/php-parser:4.10 - name: Run tests working-directory: nextcloud/apps/twofactor_totp run: composer run test:unit @@ -52,15 +44,10 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-version: [ 8.0 ] + php-version: [ 7.4, 8.0 ] nextcloud-version: [ 'master' ] browser: [ 'firefox', 'chrome' ] db: [ 'mysql' ] - include: - - nextcloud-version: 'stable20' - php-version: 7.4 - browser: chrome - db: mysql name: Nextcloud ${{ matrix.nextcloud-version }} acceptance tests on php${{ matrix.php-version }}/${{ matrix.browser }}/${{ matrix.db }} services: mysql-service: @@ -87,7 +74,7 @@ jobs: - name: Set up Node uses: actions/setup-node@v1 with: - node-version: 12.x + node-version: 14.x - name: Checkout Nextcloud run: git clone https://github.com/nextcloud/server.git --recursive --depth 1 -b ${{ matrix.nextcloud-version }} nextcloud - name: Install Nextcloud @@ -114,14 +101,14 @@ jobs: with: username: ${{ secrets.SAUCE_USERNAME }} accessKey: ${{ secrets.SAUCE_ACCESS_KEY }} - tunnelIdentifier: "${{ github.run_id }}-${{ matrix.nextcloud-version }}-${{ matrix.browser }}" + tunnelIdentifier: "${{ github.run_id }}-${{ matrix.nextcloud-version }}-php${{ matrix.php-version }}-${{ matrix.browser }}" - name: Run tests working-directory: nextcloud/apps/twofactor_totp run: composer run test:acceptance env: SAUCE_USERNAME: ${{ secrets.SAUCE_USERNAME }} SAUCE_ACCESS_KEY: ${{ secrets.SAUCE_ACCESS_KEY }} - SAUCE_TUNNEL_ID: "${{ github.run_id }}-${{ matrix.nextcloud-version }}-${{ matrix.browser }}" + SAUCE_TUNNEL_ID: "${{ github.run_id }}-${{ matrix.nextcloud-version }}-php${{ matrix.php-version }}-${{ matrix.browser }}" SELENIUM_BROWSER: ${{ matrix.browser }} env: CI: true diff --git a/appinfo/app.php b/appinfo/app.php deleted file mode 100644 index c0a9bf1..0000000 --- a/appinfo/app.php +++ /dev/null @@ -1,22 +0,0 @@ -<?php - -/** - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * - * Two-factor TOTP - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * 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, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ - -include_once __DIR__ . '/../vendor/autoload.php'; diff --git a/appinfo/info.xml b/appinfo/info.xml index e39a04b..1fb9d0a 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -18,7 +18,7 @@ <screenshot>https://raw.githubusercontent.com/nextcloud/twofactor_totp/dd1e48deec73a250886f35f3924186f5357f4c5f/screenshots/settings.png</screenshot> <dependencies> <php min-version="7.3" max-version="8.0" /> - <nextcloud min-version="20" max-version="21" /> + <nextcloud min-version="21" max-version="21" /> </dependencies> <two-factor-providers> <provider>OCA\TwoFactorTOTP\Provider\TotpProvider</provider> diff --git a/appinfo/routes.php b/appinfo/routes.php index 44444c6..76e7dbe 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /** * @author Christoph Wurst <christoph@winzerhof-wurst.at> * diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 4b95d87..ff5f7f4 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -30,21 +30,27 @@ use OCA\TwoFactorTOTP\Listener\StateChangeRegistryUpdater; use OCA\TwoFactorTOTP\Service\ITotp; use OCA\TwoFactorTOTP\Service\Totp; use OCP\AppFramework\App; -use OCP\EventDispatcher\IEventDispatcher; +use OCP\AppFramework\Bootstrap\IBootContext; +use OCP\AppFramework\Bootstrap\IBootstrap; +use OCP\AppFramework\Bootstrap\IRegistrationContext; -class Application extends App { +class Application extends App implements IBootstrap { public const APP_ID = 'twofactor_totp'; - public function __construct(array $urlParams = []) { - parent::__construct(self::APP_ID, $urlParams); + public function __construct() { + parent::__construct(self::APP_ID); + } + + public function register(IRegistrationContext $context): void { + include_once __DIR__ . '/../../vendor/autoload.php'; - $container = $this->getContainer(); - $container->registerAlias(ITotp::class, Totp::class); + $context->registerServiceAlias(ITotp::class, Totp::class); + + $context->registerEventListener(StateChanged::class, StateChangeActivity::class); + $context->registerEventListener(StateChanged::class, StateChangeRegistryUpdater::class); + $context->registerEventListener(DisabledByAdmin::class, StateChangeActivity::class); + } - /** @var IEventDispatcher $dispatcher */ - $dispatcher = $container->query(IEventDispatcher::class); - $dispatcher->addServiceListener(StateChanged::class, StateChangeActivity::class); - $dispatcher->addServiceListener(StateChanged::class, StateChangeRegistryUpdater::class); - $dispatcher->addServiceListener(DisabledByAdmin::class, StateChangeActivity::class); + public function boot(IBootContext $context): void { } } diff --git a/lib/Provider/TotpProvider.php b/lib/Provider/TotpProvider.php index c3b78ac..210caae 100644 --- a/lib/Provider/TotpProvider.php +++ b/lib/Provider/TotpProvider.php @@ -27,6 +27,7 @@ use OCA\TwoFactorTOTP\AppInfo\Application; use OCA\TwoFactorTOTP\Service\ITotp; use OCA\TwoFactorTOTP\Settings\Personal; use OCP\AppFramework\IAppContainer; +use OCP\AppFramework\Services\IInitialState; use OCP\Authentication\TwoFactorAuth\IActivatableAtLogin; use OCP\Authentication\TwoFactorAuth\IDeactivatableByAdmin; use OCP\Authentication\TwoFactorAuth\ILoginSetupProvider; @@ -34,7 +35,6 @@ use OCP\Authentication\TwoFactorAuth\IPersonalProviderSettings; use OCP\Authentication\TwoFactorAuth\IProvider; use OCP\Authentication\TwoFactorAuth\IProvidesIcons; use OCP\Authentication\TwoFactorAuth\IProvidesPersonalSettings; -use OCP\IInitialStateService; use OCP\IL10N; use OCP\IURLGenerator; use OCP\IUser; @@ -51,8 +51,8 @@ class TotpProvider implements IProvider, IProvidesIcons, IProvidesPersonalSettin /** @var IAppContainer */ private $container; - /** @var IInitialStateService */ - private $initialStateService; + /** @var IInitialState */ + private $initialState; /** @var IURLGenerator */ private $urlGenerator; @@ -60,12 +60,12 @@ class TotpProvider implements IProvider, IProvidesIcons, IProvidesPersonalSettin public function __construct(ITotp $totp, IL10N $l10n, IAppContainer $container, - IInitialStateService $initialStateService, + IInitialState $initialStateService, IURLGenerator $urlGenerator) { $this->totp = $totp; $this->l10n = $l10n; $this->container = $container; - $this->initialStateService = $initialStateService; + $this->initialState = $initialStateService; $this->urlGenerator = $urlGenerator; } @@ -121,7 +121,7 @@ class TotpProvider implements IProvider, IProvidesIcons, IProvidesPersonalSettin } public function getPersonalSettings(IUser $user): IPersonalProviderSettings { - $this->initialStateService->provideInitialState('twofactor_totp', 'state', $this->totp->hasSecret($user) ? ITotp::STATE_ENABLED : ITotp::STATE_DISABLED); + $this->initialState->provideInitialState('state', $this->totp->hasSecret($user) ? ITotp::STATE_ENABLED : ITotp::STATE_DISABLED); return new Personal(); } diff --git a/tests/Unit/Provider/TotpProviderTest.php b/tests/Unit/Provider/TotpProviderTest.php index e93e3cb..f630263 100644 --- a/tests/Unit/Provider/TotpProviderTest.php +++ b/tests/Unit/Provider/TotpProviderTest.php @@ -32,7 +32,7 @@ use OCA\TwoFactorTOTP\Provider\TotpProvider; use OCA\TwoFactorTOTP\Service\ITotp; use OCA\TwoFactorTOTP\Settings\Personal; use OCP\AppFramework\IAppContainer; -use OCP\IInitialStateService; +use OCP\AppFramework\Services\IInitialState; use OCP\IL10N; use OCP\IURLGenerator; use OCP\IUser; @@ -64,7 +64,7 @@ class TotpProviderTest extends TestCase { $this->totp = $this->createMock(ITotp::class); $this->l10n = $this->createMock(IL10N::class); $this->container = $this->createMock(IAppContainer::class); - $this->initialState = $this->createMock(IInitialStateService::class); + $this->initialState = $this->createMock(IInitialState::class); $this->urlGenerator = $this->createMock(IURLGenerator::class); $this->provider = new TotpProvider( @@ -136,7 +136,6 @@ class TotpProviderTest extends TestCase { $this->initialState->expects($this->once()) ->method('provideInitialState') ->with( - 'twofactor_totp', 'state', true ); |