Skip to content

fix Auth0Extension #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions .github/actions/composer/action.yaml

This file was deleted.

69 changes: 30 additions & 39 deletions .github/workflows/phpstan.yaml
Original file line number Diff line number Diff line change
@@ -1,56 +1,47 @@
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
runs-on: ubuntu-latest
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.0.1
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 }}
command: 'composer config --no-plugins allow-plugins.php-http/discovery false'
107 changes: 12 additions & 95 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -70,95 +69,13 @@ 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-test@v1.0.1
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 }}
command: 'composer config --no-plugins allow-plugins.php-http/discovery false'
7 changes: 7 additions & 0 deletions DependencyInjection/Auth0Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

class Auth0Extension extends Extension implements PrependExtensionInterface
{
public const PLUGIN_NAME = 'Auth0';

/**
* @param array $configs
* @param ContainerBuilder $container
Expand All @@ -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);
Expand Down
21 changes: 21 additions & 0 deletions Tests/DependencyInjection/Auth0ExtensionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Plugin\Auth0\Tests\DependencyInjection;

use Plugin\Auth0\DependencyInjection\Auth0Extension;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class Auth0ExtensionTest extends KernelTestCase
{
public function testプラグインが無効化されていたらAuth0Authenticatorは追加されない()
{
$container = $this->createMock(ContainerBuilder::class);
$container->expects($this->once())
->method('getParameter')
->willReturn([]);

$extension = new Auth0Extension();
$extension->prepend($container);
}
}