Skip to content

Commit b073dce

Browse files
authored
chore: PHP-JWT upgraded to v6.1.0 (#633)
* chore: PHP-JWT upgraded to v6.1.0, Unit tests updated to work with WPGraphQL Testcase v2.3 * chore: PHP7.2 removed from testing workflow matrix.
1 parent adf9c42 commit b073dce

File tree

14 files changed

+53
-45
lines changed

14 files changed

+53
-45
lines changed

.github/workflows/continous-integration.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ jobs:
2222
runs-on: ubuntu-latest
2323
strategy:
2424
matrix:
25-
php: ['8.0', '7.4', '7.3', '7.2']
26-
wordpress: ['5.9', '5.6', '5.3']
25+
php: ['8.0', '7.4', '7.3']
26+
wordpress: ['6.0', '5.9', '5.6']
2727
composer_version: ['v2']
2828
include:
2929
- php: '7.4'

Dockerfile

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,18 @@ RUN curl -sS https://getcomposer.org/installer | php -- \
3535
# Add composer global binaries to PATH
3636
ENV PATH "$PATH:~/.composer/vendor/bin"
3737

38-
# Set PHPUnit version.
39-
ARG PHPUNIT_VERSION="<=8.1"
4038
# Install wp-browser globally
4139
RUN composer global require --optimize-autoloader \
4240
wp-cli/wp-cli-bundle:* \
4341
lucatume/wp-browser \
44-
codeception/module-asserts:^1.0 \
45-
codeception/module-cli:^1.0 \
46-
codeception/module-db:^1.0 \
47-
codeception/module-filesystem:^1.0 \
48-
codeception/module-phpbrowser:^1.0 \
49-
codeception/module-rest:^1.0 \
50-
codeception/module-webdriver:^1.0 \
51-
codeception/util-universalframework:^1.0 \
42+
codeception/module-asserts:* \
43+
codeception/module-cli:* \
44+
codeception/module-db:* \
45+
codeception/module-filesystem:* \
46+
codeception/module-phpbrowser:* \
47+
codeception/module-rest:* \
48+
codeception/module-webdriver:* \
49+
codeception/util-universalframework:* \
5250
league/factory-muffin \
5351
league/factory-muffin-faker \
5452
stripe/stripe-php \

bin/_env.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ fi
1414
DB_HOST=${DB_HOST-localhost}
1515
DB_PASS=${DB_PASSWORD-""}
1616
WP_VERSION=${WP_VERSION-5}
17-
PHPUNIT_VERSION=${PHPUNIT_VERSION-"<=8.1"}
1817
PROJECT_ROOT_DIR=$(pwd)
1918
WP_CORE_DIR=${WP_CORE_DIR:-local/public}
2019
PLUGINS_DIR=${PLUGINS_DIR:-"$WP_CORE_DIR/wp-content/plugins"}

bin/entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fi
7373

7474
if ! wp config has GRAPHQL_WOOCOMMERCE_SECRET_KEY --allow-root; then
7575
echo "Adding WooGraphQL JWT Session Handler salt..."
76-
wp config set GRAPHQL_WOOCOMMERCE_SECRET_KEY 'test' --allow-root
76+
wp config set GRAPHQL_WOOCOMMERCE_SECRET_KEY 'testestestestest' --allow-root
7777
fi
7878

7979
if wp config has GRAPHQL_DEBUG --allow-root; then

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
],
2929
"require": {
3030
"php": ">=7.1.0",
31-
"firebase/php-jwt": "^5.0"
31+
"firebase/php-jwt": "^6.1.0"
3232
},
3333
"require-dev": {
3434
"squizlabs/php_codesniffer": "^3.5",

composer.lock

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/content/contributing/1-testing-quick-start.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ Until the documentation is in full effect, it's recommended that a [GraphiQL](ht
4545
GRAPHQL_JWT_AUTH_SECRET_KEY=testingtesting123
4646
STRIPE_API_PUBLISHABLE_KEY=""
4747
STRIPE_API_SECRET_KEY=""
48-
PHPUNIT_VERSION=":<=9.4.4"
4948
```
5049
- Typical you should only have to change the **WordPress database configurations** to use local testing.
5150
3. Once you have finished modifying the `.env` file. Run `composer install-test-env` from the project directory. This will install WordPress + Codeception w/ WPBrowser, as well as setup the database if needed.

includes/utils/class-ql-session-handler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace WPGraphQL\WooCommerce\Utils;
1010

1111
use Firebase\JWT\JWT;
12+
use Firebase\JWT\Key;
1213
use GraphQL\Error\UserError;
1314
use WC_Session_Handler;
1415

@@ -191,7 +192,8 @@ public function get_session_token() {
191192
JWT::$leeway = 60;
192193

193194
$secret = $this->get_secret_key();
194-
$token = ! empty( $token ) ? JWT::decode( $token, $secret, array( 'HS256' ) ) : null;
195+
$key = new Key( $secret, 'HS256' );
196+
$token = ! empty( $token ) ? JWT::decode( $token, $key ) : null;
195197

196198
// Check if token was successful decoded.
197199
if ( ! $token ) {

tests/_support/TestCase/WooGraphQLTestCase.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
*/
1010
namespace Tests\WPGraphQL\WooCommerce\TestCase;
1111

12+
use Automattic\WooCommerce\Internal\ProductDownloads\ApprovedDirectories\Register as Download_Directories;
13+
1214
class WooGraphQLTestCase extends \Tests\WPGraphQL\TestCase\WPGraphQLTestCase {
1315
/**
1416
* Holds the User ID of an user with the "shop_manager" role.
@@ -57,6 +59,10 @@ public function setUp(): void {
5759
$this->shop_manager = $this->factory->user->create( array( 'role' => 'shop_manager' ) );
5860
$this->customer = $this->factory->customer->create();
5961

62+
// For these tests, we are not concerned with Approved Download Directory functionality.
63+
wc_get_container()->get( Download_Directories::class )->set_mode( Download_Directories::MODE_DISABLED );
64+
65+
// Clear cached schema.
6066
$this->clearSchema();
6167
}
6268

tests/functional/QLSessionHandlerCest.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use Firebase\JWT\JWT;
4+
use Firebase\JWT\Key;
45
class QLSessionHandlerCest {
56
private $product_catalog;
67

@@ -9,7 +10,7 @@ public function _before( FunctionalTester $I ) {
910
$this->product_catalog = $I->getCatalog();
1011

1112
if ( ! defined( 'GRAPHQL_WOOCOMMERCE_SECRET_KEY' ) ) {
12-
define( 'GRAPHQL_WOOCOMMERCE_SECRET_KEY', 'test' );
13+
define( 'GRAPHQL_WOOCOMMERCE_SECRET_KEY', 'testestestestest' );
1314
}
1415
}
1516

@@ -42,7 +43,7 @@ public function testCartMutationsWithValidCartSessionToken( FunctionalTester $I
4243
// Decode token
4344
JWT::$leeway = 60;
4445
$token_data = ! empty( $session_token )
45-
? JWT::decode( $session_token, GRAPHQL_WOOCOMMERCE_SECRET_KEY, array( 'HS256' ) )
46+
? JWT::decode( $session_token, new Key( GRAPHQL_WOOCOMMERCE_SECRET_KEY, 'HS256' ) )
4647
: null;
4748

4849
$I->assertNotEmpty( $token_data );
@@ -213,7 +214,7 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $
213214

214215
// Decode token
215216
$token_data = ! empty( $valid_token )
216-
? JWT::decode( $valid_token, GRAPHQL_WOOCOMMERCE_SECRET_KEY, array( 'HS256' ) )
217+
? JWT::decode( $valid_token, new Key( GRAPHQL_WOOCOMMERCE_SECRET_KEY, 'HS256' ) )
217218
: null;
218219

219220
/**
@@ -222,7 +223,7 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $
222223
*/
223224
$invalid_token = $token_data;
224225
$invalid_token->data->customer_id = '';
225-
$invalid_token = JWT::encode( $invalid_token, GRAPHQL_WOOCOMMERCE_SECRET_KEY );
226+
$invalid_token = JWT::encode( (array) $invalid_token, GRAPHQL_WOOCOMMERCE_SECRET_KEY, 'HS256' );
226227

227228
$failed = $I->addToCart(
228229
array(
@@ -241,7 +242,7 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $
241242
*/
242243
$invalid_token = $token_data;
243244
$invalid_token->iss = '';
244-
$invalid_token = JWT::encode( $invalid_token, GRAPHQL_WOOCOMMERCE_SECRET_KEY );
245+
$invalid_token = JWT::encode( (array) $invalid_token, GRAPHQL_WOOCOMMERCE_SECRET_KEY, 'HS256' );
245246

246247
$failed = $I->removeItemsFromCart(
247248
array(
@@ -417,7 +418,7 @@ public function testCartSessionDataMutations( FunctionalTester $I ) {
417418
// Decode token
418419
JWT::$leeway = 60;
419420
$token_data = ! empty( $session_token )
420-
? JWT::decode( $session_token, GRAPHQL_WOOCOMMERCE_SECRET_KEY, array( 'HS256' ) )
421+
? JWT::decode( $session_token, new Key( GRAPHQL_WOOCOMMERCE_SECRET_KEY, 'HS256' ) )
421422
: null;
422423

423424
$I->assertNotEmpty( $token_data );

0 commit comments

Comments
 (0)