Skip to content

Commit

Permalink
Merge pull request #55 from luoweiwang/migration-4.3
Browse files Browse the repository at this point in the history
Migration to Ec-cube 4.3
  • Loading branch information
chihiro-adachi authored Mar 19, 2024
2 parents 5e9df9a + 5bcf263 commit 903938b
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 13 deletions.
175 changes: 175 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
name: CI for TwoFactorAuthCustomer42
on:
push:
branches:
- '*'
tags:
- '*'
paths:
- '**'
- '!*.md'
pull_request:
branches:
- '*'
paths:
- '**'
- '!*.md'
jobs:
run-on-linux:
name: Run on Linux
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
eccube_version: [ '4.2','4.3' ]
php: [ '7.4', '8.0', '8.1','8.2', '8.3' ]
db: [ 'mysql', 'mysql8', 'pgsql' ]
plugin_code: [ 'TwoFactorAuthCustomer42' ]
include:
- db: mysql
database_url: mysql://root:[email protected]:3306/eccube_db
database_server_version: 5.7
database_charset: utf8mb4
- db: mysql8
database_url: mysql://root:[email protected]:3308/eccube_db
database_server_version: 8
database_charset: utf8mb4
- db: pgsql
database_url: postgres://postgres:[email protected]:5432/eccube_db
database_server_version: 14
database_charset: utf8
exclude:
- eccube_version: 4.2
php: 8.2
- eccube_version: 4.2
php: 8.3
- eccube_version: 4.3
php: 7.4
- eccube_version: 4.3
php: 8.0
services:
mysql:
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: ${{ matrix.dbname }}
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
mysql8:
image: mysql:8
env:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: ${{ matrix.dbname }}
ports:
- 3308:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
postgres:
image: postgres:14
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: ${{ matrix.dbname }}
ports:
- 5432:5432
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
mailcatcher:
image: schickling/mailcatcher
ports:
- 1080:1080
- 1025:1025
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: nanasess/setup-php@master
with:
php-version: ${{ matrix.php }}

- name: Archive Plugin
env:
PLUGIN_CODE: ${{ matrix.plugin_code }}
run: |
tar cvzf ${GITHUB_WORKSPACE}/${PLUGIN_CODE}.tar.gz ./*
- name: Setup mock-package-api
env:
PLUGIN_CODE: ${{ matrix.plugin_code }}
run: |
mkdir -p /tmp/repos
cp ${GITHUB_WORKSPACE}/${PLUGIN_CODE}.tar.gz /tmp/repos/${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: Checkout EC-CUBE
uses: actions/checkout@v2
with:
repository: 'EC-CUBE/ec-cube'
ref: ${{ matrix.eccube_version }}
path: 'ec-cube'

- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install to composer
working-directory: 'ec-cube'
run: composer install --no-interaction -o --apcu-autoloader

- name: Setup EC-CUBE
env:
APP_ENV: 'test'
APP_DEBUG: 0
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'
working-directory: 'ec-cube'
run: |
bin/console doctrine:database:create
bin/console doctrine:schema:create
bin/console eccube:fixtures:load
- name: Setup Plugin
env:
APP_ENV: 'test'
APP_DEBUG: 0
DATABASE_URL: ${{ matrix.database_url }}
DATABASE_SERVER_VERSION: ${{ matrix.database_server_version }}
DATABASE_CHARSET: ${{ matrix.database_charset }}
PLUGIN_CODE: ${{ matrix.plugin_code }}
ECCUBE_PACKAGE_API_URL: 'http://127.0.0.1:8080'
working-directory: 'ec-cube'
run: |
bin/console eccube:composer:require ec-cube/twofactorauthcustomer42
bin/console cache:clear --no-warmup
bin/console eccube:plugin:enable --code=${PLUGIN_CODE}
- name: Disable Plugin
working-directory: 'ec-cube'
env:
APP_ENV: 'test'
APP_DEBUG: 0
DATABASE_URL: ${{ matrix.database_url }}
DATABASE_SERVER_VERSION: ${{ matrix.database_server_version }}
DATABASE_CHARSET: ${{ matrix.database_charset }}
PLUGIN_CODE: ${{ matrix.plugin_code }}
ECCUBE_PACKAGE_API_URL: 'http://127.0.0.1:8080'
run: bin/console eccube:plugin:disable --code=${PLUGIN_CODE}

- name: Uninstall Plugin
env:
APP_ENV: 'test'
APP_DEBUG: 0
DATABASE_URL: ${{ matrix.database_url }}
DATABASE_SERVER_VERSION: ${{ matrix.database_server_version }}
DATABASE_CHARSET: ${{ matrix.database_charset }}
PLUGIN_CODE: ${{ matrix.plugin_code }}
ECCUBE_PACKAGE_API_URL: 'http://127.0.0.1:8080'
working-directory: 'ec-cube'
run: bin/console eccube:plugin:uninstall --code=${PLUGIN_CODE}
2 changes: 1 addition & 1 deletion Controller/CustomerPersonalValidationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ private function checkDeviceToken($Customer, $token): bool

// フォームからのハッシュしたワンタイムパスワードとDBに保存しているワンタイムパスワードのハッシュは一致しているかどうか
if (
$Customer->getDeviceAuthOneTimeToken() !== $this->customerTwoFactorAuthService->hashOneTimeToken($token) ||
!$this->customerTwoFactorAuthService->veriyOneTimeToken($Customer->getDeviceAuthOneTimeToken(), $token) ||
$Customer->getDeviceAuthOneTimeTokenExpire() < $now) {
return false;
}
Expand Down
9 changes: 4 additions & 5 deletions EventListener/CustomerTwoFactorAuthListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
use Plugin\TwoFactorAuthCustomer42\Service\CustomerTwoFactorAuthService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
Expand Down Expand Up @@ -83,7 +82,7 @@ class CustomerTwoFactorAuthListener implements EventSubscriberInterface
* @param TwoFactorAuthTypeRepository $twoFactorAuthTypeRepository
* @param TwoFactorAuthCustomerCookieRepository $twoFactorAuthCustomerCookieRepository
* @param BaseInfoRepository $baseInfoRepository
* @param SessionInterface $session
* @param RequestStack $requestStack
*/
public function __construct(
Context $requestContext,
Expand All @@ -92,15 +91,15 @@ public function __construct(
TwoFactorAuthTypeRepository $twoFactorAuthTypeRepository,
TwoFactorAuthCustomerCookieRepository $twoFactorAuthCustomerCookieRepository,
BaseInfoRepository $baseInfoRepository,
SessionInterface $session
RequestStack $requestStack
) {
$this->requestContext = $requestContext;
$this->router = $router;
$this->customerTwoFactorAuthService = $customerTwoFactorAuthService;
$this->baseInfo = $baseInfoRepository->find(1);
$this->twoFactorAuthTypeRepository = $twoFactorAuthTypeRepository;
$this->twoFactorAuthCustomerCookieRepository = $twoFactorAuthCustomerCookieRepository;
$this->session = $session;
$this->session = $requestStack->getSession();

$this->default_routes = $this->customerTwoFactorAuthService->getDefaultAuthRoutes();
$this->include_routes = $this->customerTwoFactorAuthService->getIncludeRoutes();
Expand Down
7 changes: 4 additions & 3 deletions PluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
use Eccube\Entity\Page;
use Eccube\Entity\PageLayout;
use Eccube\Plugin\AbstractPluginManager;
use Eccube\Common\EccubeConfig;
use Plugin\TwoFactorAuthCustomer42\Entity\TwoFactorAuthConfig;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Psr\Container\ContainerInterface;
use Symfony\Component\Filesystem\Filesystem;

/**
Expand Down Expand Up @@ -77,7 +78,7 @@ protected function createConfig(EntityManagerInterface $em)
protected function copyTwigFiles(ContainerInterface $container)
{
// テンプレートファイルコピー
$templatePath = $container->getParameter('eccube_theme_front_dir')
$templatePath = $container->get(EccubeConfig::class)->get('eccube_theme_front_dir')
. '/TwoFactorAuthCustomer42/Resource/template/default';
$fs = new Filesystem();
if ($fs->exists($templatePath)) {
Expand Down Expand Up @@ -143,7 +144,7 @@ public function disable(array $meta, ContainerInterface $container)
*/
protected function removeTwigFiles(ContainerInterface $container)
{
$templatePath = $container->getParameter('eccube_theme_front_dir')
$templatePath = $container->get(EccubeConfig::class)->get('eccube_theme_front_dir')
. '/TwoFactorAuthCustomer42';
$fs = new Filesystem();
$fs->remove($templatePath);
Expand Down
11 changes: 8 additions & 3 deletions Service/CustomerTwoFactorAuthService.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use Plugin\TwoFactorAuthCustomer42\Entity\TwoFactorAuthCustomerCookie;
use Plugin\TwoFactorAuthCustomer42\Repository\TwoFactorAuthConfigRepository;
use Plugin\TwoFactorAuthCustomer42\Repository\TwoFactorAuthCustomerCookieRepository;
use Psr\Container\ContainerInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
Expand All @@ -45,7 +45,7 @@ class CustomerTwoFactorAuthService
public const SESSION_CALL_BACK_URL = 'plugin_eccube_customer_2fa_call_back_url';

/**
* @var ContainerInterface
* @var ContainerBagInterface
*/
protected $container;
/**
Expand Down Expand Up @@ -176,7 +176,7 @@ public function getDefaultAuthRoutes()
/**
* @required
*/
public function setContainer(ContainerInterface $container): ?ContainerInterface
public function setContainer(ContainerBagInterface $container): ?ContainerBagInterface
{
$previous = $this->container;
$this->container = $container;
Expand Down Expand Up @@ -428,6 +428,11 @@ public function hashOneTimeToken(string $token): string
return $this->hashFactory->getPasswordHasher(Customer::class)->hash($token);
}

public function veriyOneTimeToken(string $hashedToken, string $token): bool
{
return $this->hashFactory->getPasswordHasher(Customer::class)->verify($hashedToken, $token);
}

/***
* @param string $haystack
* @param string $needle
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ec-cube/twofactorauthcustomer42",
"version": "1.0.0",
"version": "4.3.0",
"description": "2 factor authentication for Customers EC-CUBE42",
"type": "eccube-plugin",
"extra": {
Expand Down

0 comments on commit 903938b

Please sign in to comment.