From 3efec338789f8c27e38bd720fe215f41614035cd Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Fri, 18 Sep 2020 15:48:11 +0200 Subject: [PATCH] Upgrade to Sylius 1.8 --- .travis.yml | 1 - composer.json | 10 +-- .../SyliusRefundExtension.php | 6 +- tests/Application/.env | 6 ++ tests/Application/config/bundles.php | 9 +++ tests/Application/config/jwt/private-test.pem | 51 +++++++++++++++ tests/Application/config/jwt/public-test.pem | 14 +++++ .../packages/lexik_jwt_authentication.yaml | 4 ++ .../Application/config/packages/security.yaml | 63 +++++++++++++++++-- .../Application/config/routes/sylius_api.yaml | 3 + 10 files changed, 152 insertions(+), 15 deletions(-) create mode 100644 tests/Application/config/jwt/private-test.pem create mode 100644 tests/Application/config/jwt/public-test.pem create mode 100644 tests/Application/config/packages/lexik_jwt_authentication.yaml create mode 100644 tests/Application/config/routes/sylius_api.yaml diff --git a/.travis.yml b/.travis.yml index 903de1e1b..eec7a7bad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,7 +36,6 @@ jobs: - echo "extension = memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini - mkdir -p tests/Application/public/media/image/ - - cp migrations/* tests/Application/src/Migrations/ install: - composer update --no-interaction --prefer-dist diff --git a/composer.json b/composer.json index fbfda61d9..5780717a9 100644 --- a/composer.json +++ b/composer.json @@ -20,12 +20,10 @@ ], "require": { "php": "^7.2", - "doctrine/migrations": "^3.0@alpha", - "doctrine/doctrine-migrations-bundle": "^3.0@alpha", "knplabs/knp-snappy-bundle": "^1.5", "myclabs/php-enum": "^1.7", "sylius/resource-bundle": "^1.6", - "sylius/sylius": "dev-migrations-alpha", + "sylius/sylius": "~1.8.0", "symfony/messenger": "^4.3" }, "require-dev": { @@ -41,8 +39,8 @@ "lakion/mink-debug-extension": "^1.2.3", "leanphp/phpspec-code-coverage": "^4.2", "phpspec/phpspec": "^4.0", - "phpstan/phpstan-shim": "^0.11", - "phpstan/phpstan-webmozart-assert": "^0.11", + "phpstan/phpstan": "0.12.29", + "phpstan/phpstan-webmozart-assert": "0.12.6", "phpunit/phpunit": "^6.5", "sylius-labs/coding-standard": "^2.0", "symfony/browser-kit": "^4.3", @@ -57,8 +55,6 @@ "symfony/doctrine-bridge": "4.3.0", "symfony/framework-bundle": "4.3.0" }, - "minimum-stability": "alpha", - "prefer-stable": true, "autoload": { "psr-4": { "Sylius\\RefundPlugin\\": "src/", diff --git a/src/DependencyInjection/SyliusRefundExtension.php b/src/DependencyInjection/SyliusRefundExtension.php index 9c7270987..ba7444269 100644 --- a/src/DependencyInjection/SyliusRefundExtension.php +++ b/src/DependencyInjection/SyliusRefundExtension.php @@ -25,17 +25,17 @@ public function load(array $config, ContainerBuilder $container): void public function prepend(ContainerBuilder $container): void { - if (!$container->hasExtension('doctrine_migrations') || !$container->hasExtension('sylius_core')) { + if (!$container->hasExtension('doctrine_migrations') || !$container->hasExtension('sylius_labs_doctrine_migrations_extra')) { return; } $container->prependExtensionConfig('doctrine_migrations', [ 'migrations_paths' => [ - 'Sylius\RefundPlugin\Migrations' => __DIR__. '/../Migrations', + 'Sylius\RefundPlugin\Migrations' => __DIR__ . '/../Migrations', ], ]); - $container->prependExtensionConfig('sylius_core', [ + $container->prependExtensionConfig('sylius_labs_doctrine_migrations_extra', [ 'migrations' => [ 'Sylius\RefundPlugin\Migrations' => ['Sylius\Bundle\CoreBundle\Migrations'], ], diff --git a/tests/Application/.env b/tests/Application/.env index e394551c9..716bf2a31 100644 --- a/tests/Application/.env +++ b/tests/Application/.env @@ -25,3 +25,9 @@ MAILER_URL=smtp://localhost ###> knplabs/knp-snappy-bundle ### WKHTMLTOPDF_PATH=%kernel.project_dir%/etc/wkhtmltopdf ###< knplabs/knp-snappy-bundle ### + +###> lexik/jwt-authentication-bundle ### +JWT_SECRET_KEY=%kernel.project_dir%/config/jwt/private.pem +JWT_PUBLIC_KEY=%kernel.project_dir%/config/jwt/public.pem +JWT_PASSPHRASE=66d45daf91b2ed1031e62d81c81dba2e +###< lexik/jwt-authentication-bundle ### diff --git a/tests/Application/config/bundles.php b/tests/Application/config/bundles.php index a7640ae1a..7f29732db 100644 --- a/tests/Application/config/bundles.php +++ b/tests/Application/config/bundles.php @@ -1,5 +1,10 @@ ['all' => true], Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true], @@ -58,4 +63,8 @@ Sylius\RefundPlugin\SyliusRefundPlugin::class => ['all' => true], Knp\Bundle\SnappyBundle\KnpSnappyBundle::class => ['all' => true], FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle::class => ['test' => true, 'test_cached' => true], + ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true], + Sylius\Bundle\ApiBundle\SyliusApiBundle::class => ['all' => true], + Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle::class => ['all' => true], + SyliusLabs\DoctrineMigrationsExtraBundle\SyliusLabsDoctrineMigrationsExtraBundle::class => ['all' => true], ]; diff --git a/tests/Application/config/jwt/private-test.pem b/tests/Application/config/jwt/private-test.pem new file mode 100644 index 000000000..b5a5246db --- /dev/null +++ b/tests/Application/config/jwt/private-test.pem @@ -0,0 +1,51 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIJKAIBAAKCAgEAxuS1SudSNkjTQcP4H5SjzrdO29upko9KYZgUH6z5n+weDtIo +5tysdm7xY3nNAU9ixo7wrBvttuf7T1fDCVJjhzqX5iewaCZks7q9kYygCbvmrAoc +bx5D9EPZPH0sQQoa9gMuNou2nqWpVdTYCMAjxzVpqa2krioUzkBJzaWGDYiijv9q +KbjWvRUUoYFNOFIFXHFFDrK5ISBC155XiETKyBYhB1wZVWX1tHe1nDW609BHAAsr +1Ve3uiodzYzQ7S9Rw9Q6RCRSRgZRzFV1GTJEuyMpCCD51DA4otYeEPQf+8hvV3aK +bSNydzrQICY95kfB0p9HxorBPh8QHq0qKZOIle1Aglp0UV3OWgXLWncNc0m8e8hT +2I55l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gzm+Bk/AXaznRQ/L8poLFil5rKWDFgspcQY5YrWP3lq9AC1HOMA8X0wfC88 +MSXUHJGUZo2Bd8l1lUgFglhdvuHTeSOyuNRTwMGMzQqLjViVMb0KFouTNyW6Y1oi +QevKfQiNkUnO+m8L+gCYZkjOLL25bZKLxGufidINpx9gZRHSglApX05FTqEbC9fK +qnEhlemf6WQIFWmxrPu9O+wAx4wtjJqdjweuit7NqUH3HluZbjtfhTOaz50MXzqX +C2bwIBx8O74ylh4X4EN4JIfKgsbo+J7BAoIBAAJ72s6YSoHaQCYXynLhRGenVHtI +rj6wNkwnBEsIDk9j8vt5fMJA1xRNZ0kA1mDAgDqq9ad2RpGcZH1jjvI5IPdB0dKE +5fyKR5okRMNRMc2Sn5LOiLsSqnhHwZo1nEZP/UTcZvIKDqajy8t4cIvBEO1ol4D5 +DxiclH7UMAgwKemYbsBHOOscbN2Z3o41uzSKUhNlLV5GP3ZPMau+MHinIXtCjHdi +Xu9eGA3GDD4/sU4JZTl1g/Rs48JEn2H800pVgyzkn9Q01hJZ0dSqy+Agcu3Yw6Sr +XRaqXN38pEInJ+GAU6y+6/RsiHdF3YOOUOPUX6PCfu8BMLRFASAdMbwNBXk= +-----END RSA PRIVATE KEY----- diff --git a/tests/Application/config/jwt/public-test.pem b/tests/Application/config/jwt/public-test.pem new file mode 100644 index 000000000..e21c0559e --- /dev/null +++ b/tests/Application/config/jwt/public-test.pem @@ -0,0 +1,14 @@ +-----BEGIN PUBLIC KEY----- +MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAxuS1SudSNkjTQcP4H5Sj +zrdO29upko9KYZgUH6z5n+weDtIo5tysdm7xY3nNAU9ixo7wrBvttuf7T1fDCVJj +hzqX5iewaCZks7q9kYygCbvmrAocbx5D9EPZPH0sQQoa9gMuNou2nqWpVdTYCMAj +xzVpqa2krioUzkBJzaWGDYiijv9qKbjWvRUUoYFNOFIFXHFFDrK5ISBC155XiETK +yBYhB1wZVWX1tHe1nDW609BHAAsr1Ve3uiodzYzQ7S9Rw9Q6RCRSRgZRzFV1GTJE +uyMpCCD51DA4otYeEPQf+8hvV3aKbSNydzrQICY95kfB0p9HxorBPh8QHq0qKZOI +le1Aglp0UV3OWgXLWncNc0m8e8hT2I55lYkLio99/4PGfalAdJBPhKtTzbJllaER +HOnlMkEvwk7eggkbbXEN/Ay6usi0R8mRaxhMkS9i8MxubgQBDsOomtegRqA1EzSG +U/FJMS5g/I/gO9bjFu2l2LJwd6B4t/FZt/9mAIGYbIj5/Ykd0E1WIKYAIRUoyW1g +TrGe70yxdHEPEILnZZMRVJzDbkVYfgKAFUpAUqbHTtS+YI6p9tjFuxBrc6GZR/kp +pL/MkEARDX0ZX3n4sPLQf/vdR7+Ks8Yqws1IqsZ3h8iP8WpykbEwnd1w49A1ZBBi +nIXU3idf41EtQgawbpK5Oy0CAwEAAQ== +-----END PUBLIC KEY----- diff --git a/tests/Application/config/packages/lexik_jwt_authentication.yaml b/tests/Application/config/packages/lexik_jwt_authentication.yaml new file mode 100644 index 000000000..edfb69dc8 --- /dev/null +++ b/tests/Application/config/packages/lexik_jwt_authentication.yaml @@ -0,0 +1,4 @@ +lexik_jwt_authentication: + secret_key: '%env(resolve:JWT_SECRET_KEY)%' + public_key: '%env(resolve:JWT_PUBLIC_KEY)%' + pass_phrase: '%env(JWT_PASSPHRASE)%' diff --git a/tests/Application/config/packages/security.yaml b/tests/Application/config/packages/security.yaml index 830b03df2..19bc2a623 100644 --- a/tests/Application/config/packages/security.yaml +++ b/tests/Application/config/packages/security.yaml @@ -1,7 +1,13 @@ parameters: - sylius.security.admin_regex: "^/admin" + sylius.security.admin_regex: "^/%sylius_admin.path_name%" sylius.security.api_regex: "^/api" - sylius.security.shop_regex: "^/(?!admin|api/.*|api$|media/.*)[^/]++" + sylius.security.shop_regex: "^/(?!%sylius_admin.path_name%|new-api|api/.*|api$|media/.*)[^/]++" + sylius.security.new_api_route: "/new-api" + sylius.security.new_api_regex: "^%sylius.security.new_api_route%" + sylius.security.new_api_admin_route: "%sylius.security.new_api_route%/admin" + sylius.security.new_api_admin_regex: "^%sylius.security.new_api_admin_route%" + sylius.security.new_api_shop_route: "%sylius.security.new_api_route%/shop" + sylius.security.new_api_shop_regex: "^%sylius.security.new_api_shop_route%" security: providers: @@ -9,8 +15,15 @@ security: id: sylius.admin_user_provider.email_or_name_based sylius_shop_user_provider: id: sylius.shop_user_provider.email_or_name_based + sylius_api_admin_user_provider: + id: sylius.admin_user_provider.email_or_name_based + sylius_api_shop_user_provider: + id: sylius.shop_user_provider.email_or_name_based + sylius_api_chain_provider: + chain: + providers: [sylius_api_shop_user_provider, sylius_api_admin_user_provider] encoders: - Sylius\Component\User\Model\UserInterface: sha512 + Sylius\Component\User\Model\UserInterface: argon2i firewalls: admin: switch_user: true @@ -30,7 +43,7 @@ security: csrf_token_id: admin_authenticate remember_me: secret: "%env(APP_SECRET)%" - path: /admin + path: "/%sylius_admin.path_name%" name: APP_ADMIN_REMEMBER_ME lifetime: 31536000 remember_me_parameter: _remember_me @@ -39,6 +52,45 @@ security: target: sylius_admin_login anonymous: true + new_api_admin_user: + pattern: "%sylius.security.new_api_route%/admin-user-authentication-token" + provider: sylius_admin_user_provider + stateless: true + anonymous: true + json_login: + check_path: "%sylius.security.new_api_route%/admin-user-authentication-token" + username_path: email + password_path: password + success_handler: lexik_jwt_authentication.handler.authentication_success + failure_handler: lexik_jwt_authentication.handler.authentication_failure + guard: + authenticators: + - lexik_jwt_authentication.jwt_token_authenticator + + new_api_shop_user: + pattern: "%sylius.security.new_api_route%/shop-user-authentication-token" + provider: sylius_shop_user_provider + stateless: true + anonymous: true + json_login: + check_path: "%sylius.security.new_api_route%/shop-user-authentication-token" + username_path: email + password_path: password + success_handler: lexik_jwt_authentication.handler.authentication_success + failure_handler: lexik_jwt_authentication.handler.authentication_failure + guard: + authenticators: + - lexik_jwt_authentication.jwt_token_authenticator + + new_api: + pattern: "%sylius.security.new_api_regex%/*" + provider: sylius_api_chain_provider + stateless: true + anonymous: lazy + guard: + authenticators: + - lexik_jwt_authentication.jwt_token_authenticator + oauth_token: pattern: "%sylius.security.api_regex%/oauth/v2/token" security: false @@ -100,3 +152,6 @@ security: - { path: "%sylius.security.admin_regex%", role: ROLE_ADMINISTRATION_ACCESS } - { path: "%sylius.security.api_regex%/.*", role: ROLE_API_ACCESS } - { path: "%sylius.security.shop_regex%/account", role: ROLE_USER } + + - { path: "%sylius.security.new_api_admin_regex%/.*", role: ROLE_API_ACCESS } + - { path: "%sylius.security.new_api_shop_regex%/.*", role: IS_AUTHENTICATED_ANONYMOUSLY } diff --git a/tests/Application/config/routes/sylius_api.yaml b/tests/Application/config/routes/sylius_api.yaml new file mode 100644 index 000000000..ae01ffce8 --- /dev/null +++ b/tests/Application/config/routes/sylius_api.yaml @@ -0,0 +1,3 @@ +sylius_api: + resource: "@SyliusApiBundle/Resources/config/routing.yml" + prefix: "%sylius.security.new_api_route%"