From a3f5f65e2cd465b1cb81c3a6ad29353c819d5481 Mon Sep 17 00:00:00 2001 From: kurozumi Date: Mon, 17 Jun 2024 13:28:12 +0900 Subject: [PATCH 1/6] fix Auth0Extension --- DependencyInjection/Auth0Extension.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/DependencyInjection/Auth0Extension.php b/DependencyInjection/Auth0Extension.php index 126dd88..aa2af5e 100644 --- a/DependencyInjection/Auth0Extension.php +++ b/DependencyInjection/Auth0Extension.php @@ -20,6 +20,8 @@ class Auth0Extension extends Extension implements PrependExtensionInterface { + public const PLUGIN_NAME = 'Auth0'; + /** * @param array $configs * @param ContainerBuilder $container @@ -37,6 +39,11 @@ public function load(array $configs, ContainerBuilder $container): void */ public function prepend(ContainerBuilder $container): void { + $enabledPlugins = $container->getParameter('eccube.plugins.enabled'); + if (!in_array(static::PLUGIN_NAME, $enabledPlugins, true)) { + return; + } + // セキュリティ設定にAuth0Authenticator追加 $extensionConfigsRefl = new \ReflectionProperty(ContainerBuilder::class, 'extensionConfigs'); $extensionConfigsRefl->setAccessible(true); From 47c493429f22bdb0b1ca3c961e438dce0cd6b0e9 Mon Sep 17 00:00:00 2001 From: kurozumi Date: Mon, 17 Jun 2024 14:04:55 +0900 Subject: [PATCH 2/6] fix workflows --- .github/actions/composer/action.yaml | 25 ----- .github/workflows/phpstan.yaml | 68 +++++------ .github/workflows/test.yaml | 106 ++---------------- .../Auth0ExtensionTest.php | 21 ++++ 4 files changed, 61 insertions(+), 159 deletions(-) delete mode 100644 .github/actions/composer/action.yaml create mode 100644 Tests/DependencyInjection/Auth0ExtensionTest.php diff --git a/.github/actions/composer/action.yaml b/.github/actions/composer/action.yaml deleted file mode 100644 index 5345114..0000000 --- a/.github/actions/composer/action.yaml +++ /dev/null @@ -1,25 +0,0 @@ -runs: - using: "Composite" - steps: - - name: Get Composer Cache Directory - id: composer-cache - run: | - echo "::set-output name=dir::$(composer config cache-files-dir)" - shell: bash - - - uses: actions/cache@v4 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-composer- - - - name: composer install - working-directory: ${{ env.WORKING_DIRECTORY }} - run: | - composer install --dev --no-interaction -o --apcu-autoloader - composer config --no-plugins allow-plugins.php-http/discovery false - composer require knpuniversity/oauth2-client-bundle - composer require riskio/oauth2-auth0 - composer require auth0/auth0-php - shell: bash diff --git a/.github/workflows/phpstan.yaml b/.github/workflows/phpstan.yaml index d72a438..9fcc3b9 100644 --- a/.github/workflows/phpstan.yaml +++ b/.github/workflows/phpstan.yaml @@ -1,8 +1,10 @@ name: PHPStan on: [workflow_dispatch, pull_request] + env: PLUGIN_CODE: Auth0 - PLUGIN_BRANCH: '4.2' + PLUGIN_PACKAGE_NAME: 'ec-cube/auth0' + jobs: phpstan: name: PHPStan @@ -10,47 +12,35 @@ jobs: strategy: fail-fast: false matrix: - eccube-versions: ['4.2', '4.3'] - php-versions: [ '7.4', '8.0', '8.1', '8.2', '8.3' ] - exclude: - - eccube-versions: 4.2 - php-versions: 8.2 - - eccube-versions: 4.2 - php-versions: 8.3 - - eccube-versions: 4.3 - php-versions: 7.4 - - eccube-versions: 4.3 - php-versions: 8.0 + eccube-versions: [ '4.2', '4.3' ] + php-versions: [ '8.1' ] + database: [ 'mysql8' ] + include: + - database: mysql8 + database_url: mysql://root:password@127.0.0.1:3308/eccube_db + database_server_version: 8 + database_charset: utf8mb4 + services: + mysql8: + image: mysql:8 + env: + MYSQL_ROOT_PASSWORD: password + ports: + - 3308:3306 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 steps: - - name: Checkout EC-CUBE - uses: actions/checkout@v4 - with: - repository: EC-CUBE/ec-cube - ref: ${{ matrix.eccube-versions }} - - - name: Setup PHP, with composer and extensions - uses: shivammathur/setup-php@master #https://github.com/shivammathur/setup-php - with: - php-version: ${{ matrix.php-versions }} - extensions: mbstring, xml, ctype, iconv, mysql, intl, :xdebug - tools: composer:v2 - - - name: composer install - run: | - composer install --dev --no-interaction -o --apcu-autoloader - composer config --no-plugins allow-plugins.php-http/discovery false - composer require knpuniversity/oauth2-client-bundle - composer require riskio/oauth2-auth0 - composer require auth0/auth0-php - - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: - path: app/Plugin/${{ env.PLUGIN_CODE }} ref: ${{ github.event.pull_request.head.sha }} - - name: PHPStan - run: | - composer require phpstan/phpstan --dev - ./vendor/bin/phpstan analyze app/Plugin/${{ env.PLUGIN_CODE }} -c "app/Plugin/${{ env.PLUGIN_CODE }}/phpstan.neon" --error-format=github + - uses: kurozumi/eccube-plugin-phpstan@v1 + with: + plugin-code: ${{ env.PLUGIN_CODE }} + plugin-package-name: ${{ env.PLUGIN_PACKAGE_NAME }} + eccube-versions: ${{ matrix.eccube-versions }} + php-versions: ${{ matrix.php-versions }} + database-url: ${{ matrix.database_url }} + database-server-version: ${{ matrix.database_server_version }} + database-charset: ${{ matrix.database_charset }} diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 043296e..5c2ce00 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,11 +1,10 @@ name: CI/CD for EC-CUBE4 Plugin on: [ workflow_dispatch, pull_request ] + env: PLUGIN_CODE: Auth0 - PACKAGE_NAME: 'ec-cube/auth0' - WORKING_DIRECTORY: 'ec-cube' - APP_ENV: 'test' - APP_DEBUG: 0 + PLUGIN_PACKAGE_NAME: 'ec-cube/auth0' + jobs: phpunit: name: PHPUnit @@ -70,95 +69,12 @@ jobs: with: ref: ${{ github.event.pull_request.head.sha }} - - name: Archive Plugin - run: | - tar cvzf ${GITHUB_WORKSPACE}/${{ env.PLUGIN_CODE }}.tar.gz ./* - - - name: Setup mock-package-api - run: | - mkdir -p /tmp/repos - cp ${GITHUB_WORKSPACE}/${{ env.PLUGIN_CODE }}.tar.gz /tmp/repos/${{ env.PLUGIN_CODE }}.tgz - docker run --name package-api -d -v /tmp/repos:/repos -e MOCK_REPO_DIR=/repos -p 8080:8080 eccube/mock-package-api:composer2 - - - name: Setup PHP, with composer and extensions - uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php + - uses: kurozumi/eccube-plugin-phpstan@v1 with: - php-version: ${{ matrix.php-versions }} - extensions: mbstring, xml, ctype, iconv, mysql, intl, :xdebug - tools: composer:v2 - - - name: Checkout EC-CUBE - uses: actions/checkout@v4 - with: - repository: EC-CUBE/ec-cube - ref: ${{ matrix.eccube-versions }} - path: ${{ env.WORKING_DIRECTORY }} - - - name: Initialize Composer - uses: ./.github/actions/composer - - - name: Setup EC-CUBE - working-directory: ${{ env.WORKING_DIRECTORY }} - run: | - bin/console doctrine:database:create - bin/console doctrine:schema:create - bin/console eccube:fixtures:load - env: - APP_ENV: ${{ env.APP_ENV }} - APP_DEBUG: ${{ env.APP_DEBUG }} - DATABASE_URL: ${{ matrix.database_url }} - DATABASE_SERVER_VERSION: ${{ matrix.database_server_version }} - DATABASE_CHARSET: ${{ matrix.database_charset }} - - - name: Setup Plugin - working-directory: ${{ env.WORKING_DIRECTORY }} - run: | - bin/console doctrine:query:sql "update dtb_base_info set authentication_key='dummy'" - bin/console eccube:composer:require ${{ env.PACKAGE_NAME }} - bin/console cache:clear --no-warmup - bin/console eccube:plugin:enable --code ${{ env.PLUGIN_CODE }} - bin/console cache:clear --no-warmup - env: - APP_ENV: ${{ env.APP_ENV }} - APP_DEBUG: ${{ env.APP_DEBUG }} - DATABASE_URL: ${{ matrix.database_url }} - DATABASE_SERVER_VERSION: ${{ matrix.database_server_version }} - DATABASE_CHARSET: ${{ matrix.database_charset }} - ECCUBE_PACKAGE_API_URL: 'http://127.0.0.1:8080' - USE_SELFSIGNED_SSL_CERTIFICATE: '1' - - - name: Run PHPUnit - working-directory: ${{ env.WORKING_DIRECTORY }} - run: | - bin/console cache:clear --no-warmup - ./vendor/bin/phpunit -c app/Plugin/${{ env.PLUGIN_CODE }}/phpunit.xml.dist app/Plugin/${{ env.PLUGIN_CODE }}/Tests - env: - APP_ENV: ${{ env.APP_ENV }} - APP_DEBUG: ${{ env.APP_DEBUG }} - DATABASE_URL: ${{ matrix.database_url }} - DATABASE_SERVER_VERSION: ${{ matrix.database_server_version }} - DATABASE_CHARSET: ${{ matrix.database_charset }} - - - name: Update Plugin - working-directory: ${{ env.WORKING_DIRECTORY }} - run: | - bin/console cache:clear --no-warmup - bin/console eccube:plugin:update ${{ env.PLUGIN_CODE }} - env: - APP_ENV: ${{ env.APP_ENV }} - APP_DEBUG: ${{ env.APP_DEBUG }} - DATABASE_URL: ${{ matrix.database_url }} - DATABASE_SERVER_VERSION: ${{ matrix.database_server_version }} - DATABASE_CHARSET: ${{ matrix.database_charset }} - - - name: Uninstall Plugin - working-directory: ${{ env.WORKING_DIRECTORY }} - run: | - bin/console cache:clear --no-warmup - bin/console eccube:plugin:uninstall --code=${{ env.PLUGIN_CODE }} - env: - APP_ENV: ${{ env.APP_ENV }} - APP_DEBUG: ${{ env.APP_DEBUG }} - DATABASE_URL: ${{ matrix.database_url }} - DATABASE_SERVER_VERSION: ${{ matrix.database_server_version }} - DATABASE_CHARSET: ${{ matrix.database_charset }} + plugin-code: ${{ env.PLUGIN_CODE }} + plugin-package-name: ${{ env.PLUGIN_PACKAGE_NAME }} + eccube-versions: ${{ matrix.eccube-versions }} + php-versions: ${{ matrix.php-versions }} + database-url: ${{ matrix.database_url }} + database-server-version: ${{ matrix.database_server_version }} + database-charset: ${{ matrix.database_charset }} diff --git a/Tests/DependencyInjection/Auth0ExtensionTest.php b/Tests/DependencyInjection/Auth0ExtensionTest.php new file mode 100644 index 0000000..0f5818c --- /dev/null +++ b/Tests/DependencyInjection/Auth0ExtensionTest.php @@ -0,0 +1,21 @@ +createMock(ContainerBuilder::class); + $container->expects($this->once()) + ->method('getParameter') + ->willReturn([]); + + $extension = new Auth0Extension(); + $extension->prepend($container); + } +} From 4b78b318d4293ec27623c65580f780ab5a7cddae Mon Sep 17 00:00:00 2001 From: kurozumi Date: Mon, 17 Jun 2024 14:13:59 +0900 Subject: [PATCH 3/6] fix --- .github/workflows/test.yaml | 2 +- Tests/DependencyInjection/Auth0ExtensionTest.php | 4 ++-- composer.json | 5 ----- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 5c2ce00..83cf363 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -69,7 +69,7 @@ jobs: with: ref: ${{ github.event.pull_request.head.sha }} - - uses: kurozumi/eccube-plugin-phpstan@v1 + - uses: kurozumi/eccube-plugin-test@v1 with: plugin-code: ${{ env.PLUGIN_CODE }} plugin-package-name: ${{ env.PLUGIN_PACKAGE_NAME }} diff --git a/Tests/DependencyInjection/Auth0ExtensionTest.php b/Tests/DependencyInjection/Auth0ExtensionTest.php index 0f5818c..fb31d18 100644 --- a/Tests/DependencyInjection/Auth0ExtensionTest.php +++ b/Tests/DependencyInjection/Auth0ExtensionTest.php @@ -2,11 +2,11 @@ namespace Plugin\Auth0\Tests\DependencyInjection; -use Eccube\Tests\EccubeTestCase; use Plugin\Auth0\DependencyInjection\Auth0Extension; +use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; -class Auth0ExtensionTest extends EccubeTestCase +class Auth0ExtensionTest extends KernelTestCase { public function testプラグインが無効化されていたらAuth0Authenticatorは追加されない() { diff --git a/composer.json b/composer.json index 0eacfaf..56f623d 100644 --- a/composer.json +++ b/composer.json @@ -11,10 +11,5 @@ }, "extra": { "code": "Auth0" - }, - "config": { - "allow-plugins": { - "php-http/discovery": false - } } } From e10775d7f7c159a3316d362b8ff8517bdee8f145 Mon Sep 17 00:00:00 2001 From: kurozumi Date: Mon, 17 Jun 2024 15:07:50 +0900 Subject: [PATCH 4/6] add composer command --- .github/workflows/phpstan.yaml | 1 + .github/workflows/test.yaml | 1 + composer.json | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/.github/workflows/phpstan.yaml b/.github/workflows/phpstan.yaml index 9fcc3b9..78ed7b2 100644 --- a/.github/workflows/phpstan.yaml +++ b/.github/workflows/phpstan.yaml @@ -44,3 +44,4 @@ jobs: database-url: ${{ matrix.database_url }} database-server-version: ${{ matrix.database_server_version }} database-charset: ${{ matrix.database_charset }} + composer-command: 'composer config --no-plugins allow-plugins.php-http/discovery false' diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 83cf363..02beba4 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -78,3 +78,4 @@ jobs: database-url: ${{ matrix.database_url }} database-server-version: ${{ matrix.database_server_version }} database-charset: ${{ matrix.database_charset }} + composer-command: 'composer config --no-plugins allow-plugins.php-http/discovery false' diff --git a/composer.json b/composer.json index 56f623d..0eacfaf 100644 --- a/composer.json +++ b/composer.json @@ -11,5 +11,10 @@ }, "extra": { "code": "Auth0" + }, + "config": { + "allow-plugins": { + "php-http/discovery": false + } } } From e3a4447457650de69ba869495f9b7ae388d224c8 Mon Sep 17 00:00:00 2001 From: kurozumi Date: Mon, 17 Jun 2024 15:14:54 +0900 Subject: [PATCH 5/6] fix --- .github/workflows/phpstan.yaml | 2 +- .github/workflows/test.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/phpstan.yaml b/.github/workflows/phpstan.yaml index 78ed7b2..5e923b7 100644 --- a/.github/workflows/phpstan.yaml +++ b/.github/workflows/phpstan.yaml @@ -35,7 +35,7 @@ jobs: with: ref: ${{ github.event.pull_request.head.sha }} - - uses: kurozumi/eccube-plugin-phpstan@v1 + - uses: kurozumi/eccube-plugin-phpstan@v1.0.1 with: plugin-code: ${{ env.PLUGIN_CODE }} plugin-package-name: ${{ env.PLUGIN_PACKAGE_NAME }} diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 02beba4..156ff36 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -69,7 +69,7 @@ jobs: with: ref: ${{ github.event.pull_request.head.sha }} - - uses: kurozumi/eccube-plugin-test@v1 + - uses: kurozumi/eccube-plugin-test@v1.0.1 with: plugin-code: ${{ env.PLUGIN_CODE }} plugin-package-name: ${{ env.PLUGIN_PACKAGE_NAME }} From 3bb673ffd23b4e398fda5f89f0214f93052e5b80 Mon Sep 17 00:00:00 2001 From: kurozumi Date: Mon, 17 Jun 2024 15:22:20 +0900 Subject: [PATCH 6/6] fix --- .github/workflows/phpstan.yaml | 2 +- .github/workflows/test.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/phpstan.yaml b/.github/workflows/phpstan.yaml index 5e923b7..cbea4ae 100644 --- a/.github/workflows/phpstan.yaml +++ b/.github/workflows/phpstan.yaml @@ -44,4 +44,4 @@ jobs: database-url: ${{ matrix.database_url }} database-server-version: ${{ matrix.database_server_version }} database-charset: ${{ matrix.database_charset }} - composer-command: 'composer config --no-plugins allow-plugins.php-http/discovery false' + command: 'composer config --no-plugins allow-plugins.php-http/discovery false' diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 156ff36..34bd7b1 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -78,4 +78,4 @@ jobs: database-url: ${{ matrix.database_url }} database-server-version: ${{ matrix.database_server_version }} database-charset: ${{ matrix.database_charset }} - composer-command: 'composer config --no-plugins allow-plugins.php-http/discovery false' + command: 'composer config --no-plugins allow-plugins.php-http/discovery false'