diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e617397..75390db 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,14 +17,13 @@ on: jobs: run-on-linux: name: Run on Linux - runs-on: ${{ matrix.operating-system }} + runs-on: ubuntu-22.04 strategy: fail-fast: false matrix: - operating-system: [ ubuntu-18.04 ] - php: [ '7.4', '8.0', '8.1' ] + eccube_version: [ '4.2', '4.3' ] + php: [ '7.4', '8.0', '8.1', '8.2', '8.3'] db: [ 'mysql', 'mysql8', 'pgsql' ] - eccube_version: [ '4.2' ] plugin_code: [ 'Api42' ] include: - db: mysql @@ -39,6 +38,15 @@ jobs: database_url: postgres://postgres:password@127.0.0.1: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 @@ -72,7 +80,6 @@ jobs: - 1080:1080 - 1025:1025 steps: - - run: sudo apt-get purge -y hhvm - name: Checkout uses: actions/checkout@v2 @@ -167,7 +174,7 @@ jobs: working-directory: 'ec-cube' run: | bin/console cache:clear --no-warmup - bin/phpunit -c app/Plugin/${PLUGIN_CODE}/phpunit.xml.dist app/Plugin/${PLUGIN_CODE}/Tests + ./vendor/bin/phpunit -c app/Plugin/${PLUGIN_CODE}/phpunit.xml.dist app/Plugin/${PLUGIN_CODE}/Tests - name: Disable Plugin diff --git a/Bundle/ApiBundle.php b/Bundle/ApiBundle.php index 76e0657..8a18f7a 100644 --- a/Bundle/ApiBundle.php +++ b/Bundle/ApiBundle.php @@ -16,6 +16,7 @@ use Plugin\Api42\DependencyInjection\ApiExtension; use Plugin\Api42\DependencyInjection\Compiler\ApiCompilerPass; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; use Symfony\Component\HttpKernel\Bundle\Bundle; class ApiBundle extends Bundle @@ -27,7 +28,7 @@ public function build(ContainerBuilder $container) $container->addCompilerPass(new ApiCompilerPass()); } - public function getContainerExtension() + public function getContainerExtension(): ?ExtensionInterface { return new ApiExtension(); } diff --git a/Controller/Admin/OAuthController.php b/Controller/Admin/OAuthController.php index ab49663..cf51af0 100644 --- a/Controller/Admin/OAuthController.php +++ b/Controller/Admin/OAuthController.php @@ -27,9 +27,9 @@ use League\Bundle\OAuth2ServerBundle\Manager\RefreshTokenManagerInterface; use League\Bundle\OAuth2ServerBundle\Model\AuthorizationCode; use League\Bundle\OAuth2ServerBundle\Model\Client; -use League\Bundle\OAuth2ServerBundle\Model\Grant; -use League\Bundle\OAuth2ServerBundle\Model\RedirectUri; -use League\Bundle\OAuth2ServerBundle\Model\Scope; +use League\Bundle\OAuth2ServerBundle\ValueObject\Grant; +use League\Bundle\OAuth2ServerBundle\ValueObject\RedirectUri; +use League\Bundle\OAuth2ServerBundle\ValueObject\Scope; use League\Bundle\OAuth2ServerBundle\OAuth2Grants; class OAuthController extends AbstractController diff --git a/EventListener/AuthorizationRequestResolveListener.php b/EventListener/AuthorizationRequestResolveListener.php index ca3437d..5208fd6 100644 --- a/EventListener/AuthorizationRequestResolveListener.php +++ b/EventListener/AuthorizationRequestResolveListener.php @@ -98,7 +98,7 @@ public function onAuthorizationRequestResolve(AuthorizationRequestResolveEvent $ $event->resolveAuthorization(AuthorizationRequestResolveEvent::AUTHORIZATION_DENIED); } } else { - $event->setResponse(Response::create($content)); + $event->setResponse(new Response($content)); } } } diff --git a/EventListener/UserResolveListener.php b/EventListener/UserResolveListener.php index 58a446b..ef5d7c3 100644 --- a/EventListener/UserResolveListener.php +++ b/EventListener/UserResolveListener.php @@ -13,7 +13,7 @@ namespace Plugin\Api42\EventListener; -use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; +use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; use Symfony\Component\Security\Core\User\UserProviderInterface; use League\Bundle\OAuth2ServerBundle\Event\UserResolveEvent; @@ -25,18 +25,18 @@ final class UserResolveListener private $userProvider; /** - * @var UserPasswordEncoderInterface + * @var UserPasswordHasherInterface */ - private $userPasswordEncoder; + private $userPasswordHasher; /** * @param UserProviderInterface $userProvider - * @param UserPasswordEncoderInterface $userPasswordEncoder + * @param UserPasswordHasherInterface $userPasswordHasher */ - public function __construct(UserProviderInterface $userProvider, UserPasswordEncoderInterface $userPasswordEncoder) + public function __construct(UserProviderInterface $userProvider, UserPasswordHasherInterface $userPasswordHasher) { $this->userProvider = $userProvider; - $this->userPasswordEncoder = $userPasswordEncoder; + $this->userPasswordHasher = $userPasswordHasher; } /** @@ -50,7 +50,7 @@ public function onUserResolve(UserResolveEvent $event): void return; } - if (!$this->userPasswordEncoder->isPasswordValid($user, $event->getPassword())) { + if (!$this->userPasswordHasher->isPasswordValid($user, $event->getPassword())) { return; } diff --git a/PluginManager.php b/PluginManager.php index 30c80e5..0402fdc 100644 --- a/PluginManager.php +++ b/PluginManager.php @@ -18,7 +18,7 @@ use Eccube\Entity\Master\Authority; use Eccube\Plugin\AbstractPluginManager; use Eccube\Repository\AuthorityRoleRepository; -use Symfony\Component\DependencyInjection\ContainerInterface; +use Psr\Container\ContainerInterface; class PluginManager extends AbstractPluginManager { diff --git a/Resource/config/services.yaml b/Resource/config/services.yaml index b5d6348..377b248 100644 --- a/Resource/config/services.yaml +++ b/Resource/config/services.yaml @@ -42,7 +42,7 @@ services: Plugin\Api42\EventListener\UserResolveListener: arguments: - '@Eccube\Security\Core\User\MemberProvider' - - '@Plugin\Api42\Security\Core\Encoder\UserPasswordEncoder' + - '@Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface' tags: - { name: kernel.event_listener, event: league.oauth2_server.event.user_resolve, method: onUserResolve } diff --git a/Resource/config/services_test.yaml b/Resource/config/services_test.yaml new file mode 100644 index 0000000..ef20c11 --- /dev/null +++ b/Resource/config/services_test.yaml @@ -0,0 +1,3 @@ +services: + _defaults: + public: true \ No newline at end of file diff --git a/Security/Core/Encoder/UserPasswordEncoder.php b/Security/Core/Encoder/UserPasswordEncoder.php index 99ccdd5..694e4d5 100644 --- a/Security/Core/Encoder/UserPasswordEncoder.php +++ b/Security/Core/Encoder/UserPasswordEncoder.php @@ -17,7 +17,7 @@ use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; use Symfony\Component\Security\Core\User\UserInterface; -class UserPasswordEncoder implements UserPasswordEncoderInterface +class UserPasswordEncoder { /** * @var PasswordEncoder diff --git a/Service/WebHookService.php b/Service/WebHookService.php index 625e1a2..e40e9e7 100644 --- a/Service/WebHookService.php +++ b/Service/WebHookService.php @@ -31,17 +31,17 @@ class WebHookService implements EventSubscriberInterface /** * @var RouterInterface */ - private $router; + private RouterInterface $router; /** * @var WebHookRepository */ - private $webHookRepository; + private WebHookRepository $webHookRepository; /** * @var WebHookEvents */ - private $webHookEvents; + private WebHookEvents $webHookEvents; /** * WebHookService constructor. diff --git a/Tests/GraphQL/Mutation/UpdateProductStockMutationTest.php b/Tests/GraphQL/Mutation/UpdateProductStockMutationTest.php index b21d5c7..b1d0941 100644 --- a/Tests/GraphQL/Mutation/UpdateProductStockMutationTest.php +++ b/Tests/GraphQL/Mutation/UpdateProductStockMutationTest.php @@ -31,8 +31,8 @@ class UpdateProductStockMutationTest extends EccubeTestCase public function setUp(): void { parent::setUp(); - $types = self::$container->get(Types::class); - $this->productClassRepository = self::$container->get(ProductClassRepository::class); + $types = self::getContainer()->get(Types::class); + $this->productClassRepository = self::getContainer()->get(ProductClassRepository::class); $this->updateProductStockMutation = new UpdateProductStockMutation($types, $this->productClassRepository, $this->entityManager); // テスト用の商品を作成 diff --git a/Tests/GraphQL/Mutation/UpdateShippedMutationTest.php b/Tests/GraphQL/Mutation/UpdateShippedMutationTest.php index 6d2034b..082a446 100644 --- a/Tests/GraphQL/Mutation/UpdateShippedMutationTest.php +++ b/Tests/GraphQL/Mutation/UpdateShippedMutationTest.php @@ -42,11 +42,11 @@ public function setUp(): void { parent::setUp(); - $mailService = self::$container->get(MailService::class); - $orderStateMachine = self::$container->get(OrderStateMachine::class); - $orderStatusRepository = self::$container->get(OrderStatusRepository::class); - $types = self::$container->get(Types::class); - $shippingRepository = self::$container->get(ShippingRepository::class); + $mailService = self::getContainer()->get(MailService::class); + $orderStateMachine = self::getContainer()->get(OrderStateMachine::class); + $orderStatusRepository = self::getContainer()->get(OrderStatusRepository::class); + $types = self::getContainer()->get(Types::class); + $shippingRepository = self::getContainer()->get(ShippingRepository::class); $this->updateShippedMutation = new UpdateShippedMutation( $this->eccubeConfig, diff --git a/Tests/GraphQL/SchemaTest.php b/Tests/GraphQL/SchemaTest.php index a694bd6..21265c4 100644 --- a/Tests/GraphQL/SchemaTest.php +++ b/Tests/GraphQL/SchemaTest.php @@ -428,7 +428,7 @@ private function executeQuery($query, $variables = null, $readonly = false) { $op = OperationParams::create(['query' => $query, 'variables' => $variables], $readonly); $helper = new Helper(); - $config = ServerConfig::create()->setSchema(self::$container->get(Schema::class)); + $config = ServerConfig::create()->setSchema(self::getContainer()->get(Schema::class)); $result = $helper->executeOperation($config, $op); self::assertInstanceOf(ExecutionResult::class, $result); diff --git a/Tests/GraphQL/TypesTest.php b/Tests/GraphQL/TypesTest.php index c1293f7..88bed96 100644 --- a/Tests/GraphQL/TypesTest.php +++ b/Tests/GraphQL/TypesTest.php @@ -28,7 +28,7 @@ class TypesTest extends EccubeTestCase public function setUp(): void { parent::setUp(); - $this->types = self::$container->get(Types::class); + $this->types = self::getContainer()->get(Types::class); } /** diff --git a/Tests/Service/WebHookServiceTest.php b/Tests/Service/WebHookServiceTest.php index ad281b5..04bb5d2 100644 --- a/Tests/Service/WebHookServiceTest.php +++ b/Tests/Service/WebHookServiceTest.php @@ -23,13 +23,13 @@ class WebHookServiceTest extends EccubeTestCase { /** @var WebHookService */ - private $service; + private ?WebHookService $service; public function setUp(): void { parent::setUp(); - $this->service = self::$container->get(WebHookService::class); + $this->service = self::getContainer()->get(WebHookService::class); } public function testCreateRequest_withSecret() diff --git a/Tests/Web/Admin/LoginControllerTest.php b/Tests/Web/Admin/LoginControllerTest.php index 4bafe9f..ff2005f 100644 --- a/Tests/Web/Admin/LoginControllerTest.php +++ b/Tests/Web/Admin/LoginControllerTest.php @@ -41,7 +41,7 @@ public function testRoutingAdminLoginCheck() ] ); - $this->assertNotNull(self::$container->get('security.token_storage')->getToken(), 'ログインしているかどうか'); + $this->assertNotNull(self::getContainer()->get('security.token_storage')->getToken(), 'ログインしているかどうか'); } public function testRoutingAdminLogin_ログインしていない場合はログイン画面を表示() diff --git a/Tests/Web/Admin/OAuthControllerTest.php b/Tests/Web/Admin/OAuthControllerTest.php index bc91d8b..8cd9db3 100644 --- a/Tests/Web/Admin/OAuthControllerTest.php +++ b/Tests/Web/Admin/OAuthControllerTest.php @@ -32,7 +32,7 @@ public function setUp(): void { parent::setUp(); - $this->clientManager = self::$container->get(ClientManager::class); + $this->clientManager = self::getContainer()->get(ClientManager::class); } public function testRoutingAdminSettingSystemOAuth2Client() diff --git a/Tests/Web/ApiControllerTest.php b/Tests/Web/ApiControllerTest.php index 5bd4764..a04eade 100644 --- a/Tests/Web/ApiControllerTest.php +++ b/Tests/Web/ApiControllerTest.php @@ -13,11 +13,13 @@ namespace Plugin\Api42\Tests\Web; +use Eccube\Common\EccubeConfig; use Eccube\Tests\Web\AbstractWebTestCase; use League\OAuth2\Server\AuthorizationServer; use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; use League\OAuth2\Server\Repositories\ClientRepositoryInterface; +use League\OAuth2\Server\Repositories\ScopeRepositoryInterface; use League\Bundle\OAuth2ServerBundle\Entity\AccessToken; use League\Bundle\OAuth2ServerBundle\Entity\Scope; use League\Bundle\OAuth2ServerBundle\Manager\Doctrine\ClientManager; @@ -26,24 +28,28 @@ class ApiControllerTest extends AbstractWebTestCase { /** @var ClientManager */ - private $clientManager; + private ?ClientManager $clientManager; /** @var ClientRepositoryInterface */ - private $clientRepository; + private ?ClientRepositoryInterface $clientRepository; /** @var AccessTokenRepositoryInterface */ - private $accessTokenRepository; + private ?AccessTokenRepositoryInterface $accessTokenRepository; + + /** @var ScopeRepositoryInterface */ + private ?ScopeRepositoryInterface $scopeRepositoryInterface; /** @var AuthorizationServer */ - private $authorizationServer; + private ?AuthorizationServer $authorizationServer; public function setUp(): void { parent::setUp(); - $this->clientManager = self::$container->get(ClientManager::class); - $this->clientRepository = self::$container->get(ClientRepositoryInterface::class); - $this->accessTokenRepository = self::$container->get(AccessTokenRepositoryInterface::class); - $this->authorizationServer = self::$container->get(AuthorizationServer::class); + $this->clientManager = self::getContainer()->get(ClientManager::class); + $this->clientRepository = self::getContainer()->get(ClientRepositoryInterface::class); + $this->accessTokenRepository = self::getContainer()->get(AccessTokenRepositoryInterface::class); + $this->authorizationServer = self::getContainer()->get(AuthorizationServer::class); + $this->scopeRepositoryInterface = self::getContainer()->get(ScopeRepositoryInterface::class); } /** @@ -89,7 +95,7 @@ private function newAccessToken($scopes) $client = new Client('', $identifier, $secret); $client->setScopes(...array_map(function ($s) { - return new \League\Bundle\OAuth2ServerBundle\Model\Scope($s); + return new \League\Bundle\OAuth2ServerBundle\ValueObject\Scope($s); }, $scopes)); $this->clientManager->save($client); $clientEntity = $this->clientRepository->getClientEntity($identifier, 'authorization_code', $secret); @@ -99,7 +105,7 @@ private function newAccessToken($scopes) $accessTokenEntity->setClient($clientEntity); $accessTokenEntity->setExpiryDateTime(new \DateTimeImmutable('+1 days', new \DateTimeZone('Asia/Tokyo'))); $accessTokenEntity->setUserIdentifier('admin'); - $accessTokenEntity->setPrivateKey(new CryptKey(self::$container->getParameter('kernel.project_dir').'/app/PluginData/Api42/oauth/private.key')); + $accessTokenEntity->setPrivateKey(new CryptKey(self::getContainer()->get(EccubeConfig::class)->get('kernel.project_dir').'/app/PluginData/Api42/oauth/private.key')); array_walk($scopes, function ($s) use ($accessTokenEntity) { $scope = new Scope(); diff --git a/composer.json b/composer.json index 759b3a3..4ecf0da 100644 --- a/composer.json +++ b/composer.json @@ -1,12 +1,13 @@ { "name": "ec-cube/api42", - "version": "4.2.3", + "version": "4.3.0", "description": "Web API", "type": "eccube-plugin", "require": { "ec-cube/plugin-installer": "^2.0", - "league/oauth2-server-bundle": "^0.3", + "league/oauth2-server-bundle": "^0.5", "nyholm/psr7": "^1.2", + "php-http/message-factory": "*", "webonyx/graphql-php": "^14.0" }, "extra": {