diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..1ec120b --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,31 @@ +name: Test + +on: + push: + branches: + - main + + tags: + - v* + + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - uses: "shivammathur/setup-php@v2" + with: + php-version: "8.1" + - uses: "ramsey/composer-install@v2" + + - name: Run PHPCS + run: | + composer run-script lint + + - name: Run tests + run: | + composer run-script test diff --git a/README.md b/README.md index 7476e3e..fa9ccd8 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ - [Add new custom guard](#add-new-custom-guard) - [Usage example](#usage-example) - [Testing](#testing) + - [HTTP testing](#http-testing) ## Installation @@ -15,8 +16,8 @@ add env vars to your `.env`: ```env -`SUPAAPPS_GUARD_AUTH_SERVER_URL=http://example.com` -`SUPAAPPS_GUARD_AUTH_REALM_NAME=myapp` +SUPAAPPS_GUARD_AUTH_SERVER_URL=http://example.com +SUPAAPPS_GUARD_AUTH_REALM_NAME=myapp ``` ### Add new custom guard @@ -73,7 +74,7 @@ class CustomTest extends TestCase public function testThatIAmActingAsUser(): void { - $user = User::create(); + $user = User::factory()->create(); $this->withAccessTokenFor($user); @@ -82,3 +83,53 @@ class CustomTest extends TestCase } } ``` + +### HTTP testing + +`withAccessTokenFor` method is adding the `Bearer` token to `headers` which are sent by http tests. But you need to specify the server url somewhere on your tests. eg. `tests/CreatesApplication`: + +```php +setAuthServerUrl(); + return $app; + } +} +``` + +Next run your http tests, for example: + +```php +create(); + + $this->withAccessTokenFor($user); + + // assume you have /user endpoint that + // - uses auth:jwt middleware + // - and returns auth user + $response = $this->getJson('/user'); + + $response->assertOk() + ->assertJson($user->toArray()); + } +} +``` diff --git a/composer.json b/composer.json index d395448..f1a3f72 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,8 @@ }, "require-dev": { "orchestra/testbench": "^8.21", - "nunomaduro/collision": "^7.8" + "nunomaduro/collision": "^7.8", + "squizlabs/php_codesniffer": "^3.8" }, "autoload-dev": { "psr-4": { @@ -57,7 +58,7 @@ "@php vendor/bin/testbench serve" ], "lint": [ - "@php vendor/bin/phpstan analyse" + "@php vendor/bin/phpcs src tests config -v" ], "test": [ "@php vendor/bin/testbench package:test" diff --git a/composer.lock b/composer.lock index b0569cc..54d310f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6cf65b04a222c856ffd7fc017fc1a442", + "content-hash": "8d5ee21c6b2231832edc9b33954ec974", "packages": [ { "name": "brick/math", @@ -207,16 +207,16 @@ }, { "name": "doctrine/inflector", - "version": "2.0.9", + "version": "2.0.10", "source": { "type": "git", "url": "https://github.com/doctrine/inflector.git", - "reference": "2930cd5ef353871c821d5c43ed030d39ac8cfe65" + "reference": "5817d0659c5b50c9b950feb9af7b9668e2c436bc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/inflector/zipball/2930cd5ef353871c821d5c43ed030d39ac8cfe65", - "reference": "2930cd5ef353871c821d5c43ed030d39ac8cfe65", + "url": "https://api.github.com/repos/doctrine/inflector/zipball/5817d0659c5b50c9b950feb9af7b9668e2c436bc", + "reference": "5817d0659c5b50c9b950feb9af7b9668e2c436bc", "shasum": "" }, "require": { @@ -278,7 +278,7 @@ ], "support": { "issues": "https://github.com/doctrine/inflector/issues", - "source": "https://github.com/doctrine/inflector/tree/2.0.9" + "source": "https://github.com/doctrine/inflector/tree/2.0.10" }, "funding": [ { @@ -294,31 +294,31 @@ "type": "tidelift" } ], - "time": "2024-01-15T18:05:13+00:00" + "time": "2024-02-18T20:23:39+00:00" }, { "name": "doctrine/lexer", - "version": "3.0.0", + "version": "3.0.1", "source": { "type": "git", "url": "https://github.com/doctrine/lexer.git", - "reference": "84a527db05647743d50373e0ec53a152f2cde568" + "reference": "31ad66abc0fc9e1a1f2d9bc6a42668d2fbbcd6dd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/lexer/zipball/84a527db05647743d50373e0ec53a152f2cde568", - "reference": "84a527db05647743d50373e0ec53a152f2cde568", + "url": "https://api.github.com/repos/doctrine/lexer/zipball/31ad66abc0fc9e1a1f2d9bc6a42668d2fbbcd6dd", + "reference": "31ad66abc0fc9e1a1f2d9bc6a42668d2fbbcd6dd", "shasum": "" }, "require": { "php": "^8.1" }, "require-dev": { - "doctrine/coding-standard": "^10", - "phpstan/phpstan": "^1.9", - "phpunit/phpunit": "^9.5", + "doctrine/coding-standard": "^12", + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^10.5", "psalm/plugin-phpunit": "^0.18.3", - "vimeo/psalm": "^5.0" + "vimeo/psalm": "^5.21" }, "type": "library", "autoload": { @@ -355,7 +355,7 @@ ], "support": { "issues": "https://github.com/doctrine/lexer/issues", - "source": "https://github.com/doctrine/lexer/tree/3.0.0" + "source": "https://github.com/doctrine/lexer/tree/3.0.1" }, "funding": [ { @@ -371,7 +371,7 @@ "type": "tidelift" } ], - "time": "2022-12-15T16:57:16+00:00" + "time": "2024-02-05T11:56:58+00:00" }, { "name": "dragonmantank/cron-expression", @@ -785,16 +785,16 @@ }, { "name": "laravel/framework", - "version": "v10.43.0", + "version": "v10.45.0", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "4f7802dfc9993cb57cf69615491ce1a7eb2e9529" + "reference": "8b08d8cd79f8093eb51a8c59e21647bedfbf05f2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/4f7802dfc9993cb57cf69615491ce1a7eb2e9529", - "reference": "4f7802dfc9993cb57cf69615491ce1a7eb2e9529", + "url": "https://api.github.com/repos/laravel/framework/zipball/8b08d8cd79f8093eb51a8c59e21647bedfbf05f2", + "reference": "8b08d8cd79f8093eb51a8c59e21647bedfbf05f2", "shasum": "" }, "require": { @@ -842,6 +842,7 @@ "conflict": { "carbonphp/carbon-doctrine-types": ">=3.0", "doctrine/dbal": ">=4.0", + "phpunit/phpunit": ">=11.0.0", "tightenco/collect": "<5.5.33" }, "provide": { @@ -986,7 +987,7 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-01-30T16:25:02+00:00" + "time": "2024-02-20T15:32:48+00:00" }, { "name": "laravel/prompts", @@ -1295,16 +1296,16 @@ }, { "name": "league/flysystem", - "version": "3.23.1", + "version": "3.24.0", "source": { "type": "git", "url": "https://github.com/thephpleague/flysystem.git", - "reference": "199e1aebbe3e62bd39f4d4fc8c61ce0b3786197e" + "reference": "b25a361508c407563b34fac6f64a8a17a8819675" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/199e1aebbe3e62bd39f4d4fc8c61ce0b3786197e", - "reference": "199e1aebbe3e62bd39f4d4fc8c61ce0b3786197e", + "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/b25a361508c407563b34fac6f64a8a17a8819675", + "reference": "b25a361508c407563b34fac6f64a8a17a8819675", "shasum": "" }, "require": { @@ -1324,7 +1325,7 @@ "require-dev": { "async-aws/s3": "^1.5 || ^2.0", "async-aws/simple-s3": "^1.1 || ^2.0", - "aws/aws-sdk-php": "^3.220.0", + "aws/aws-sdk-php": "^3.295.10", "composer/semver": "^3.0", "ext-fileinfo": "*", "ext-ftp": "*", @@ -1335,7 +1336,7 @@ "phpseclib/phpseclib": "^3.0.34", "phpstan/phpstan": "^1.10", "phpunit/phpunit": "^9.5.11|^10.0", - "sabre/dav": "^4.3.1" + "sabre/dav": "^4.6.0" }, "type": "library", "autoload": { @@ -1369,7 +1370,7 @@ ], "support": { "issues": "https://github.com/thephpleague/flysystem/issues", - "source": "https://github.com/thephpleague/flysystem/tree/3.23.1" + "source": "https://github.com/thephpleague/flysystem/tree/3.24.0" }, "funding": [ { @@ -1381,7 +1382,7 @@ "type": "github" } ], - "time": "2024-01-26T18:42:03+00:00" + "time": "2024-02-04T12:10:17+00:00" }, { "name": "league/flysystem-local", @@ -3326,16 +3327,16 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.28.0", + "version": "v1.29.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb" + "reference": "ef4d7e442ca910c4764bce785146269b30cb5fc4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb", - "reference": "ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/ef4d7e442ca910c4764bce785146269b30cb5fc4", + "reference": "ef4d7e442ca910c4764bce785146269b30cb5fc4", "shasum": "" }, "require": { @@ -3349,9 +3350,6 @@ }, "type": "library", "extra": { - "branch-alias": { - "dev-main": "1.28-dev" - }, "thanks": { "name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill" @@ -3388,7 +3386,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.28.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.29.0" }, "funding": [ { @@ -3404,20 +3402,20 @@ "type": "tidelift" } ], - "time": "2023-01-26T09:26:14+00:00" + "time": "2024-01-29T20:11:03+00:00" }, { "name": "symfony/polyfill-intl-grapheme", - "version": "v1.28.0", + "version": "v1.29.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-grapheme.git", - "reference": "875e90aeea2777b6f135677f618529449334a612" + "reference": "32a9da87d7b3245e09ac426c83d334ae9f06f80f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/875e90aeea2777b6f135677f618529449334a612", - "reference": "875e90aeea2777b6f135677f618529449334a612", + "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/32a9da87d7b3245e09ac426c83d334ae9f06f80f", + "reference": "32a9da87d7b3245e09ac426c83d334ae9f06f80f", "shasum": "" }, "require": { @@ -3428,9 +3426,6 @@ }, "type": "library", "extra": { - "branch-alias": { - "dev-main": "1.28-dev" - }, "thanks": { "name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill" @@ -3469,7 +3464,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.28.0" + "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.29.0" }, "funding": [ { @@ -3485,20 +3480,20 @@ "type": "tidelift" } ], - "time": "2023-01-26T09:26:14+00:00" + "time": "2024-01-29T20:11:03+00:00" }, { "name": "symfony/polyfill-intl-idn", - "version": "v1.28.0", + "version": "v1.29.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-idn.git", - "reference": "ecaafce9f77234a6a449d29e49267ba10499116d" + "reference": "a287ed7475f85bf6f61890146edbc932c0fff919" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/ecaafce9f77234a6a449d29e49267ba10499116d", - "reference": "ecaafce9f77234a6a449d29e49267ba10499116d", + "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/a287ed7475f85bf6f61890146edbc932c0fff919", + "reference": "a287ed7475f85bf6f61890146edbc932c0fff919", "shasum": "" }, "require": { @@ -3511,9 +3506,6 @@ }, "type": "library", "extra": { - "branch-alias": { - "dev-main": "1.28-dev" - }, "thanks": { "name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill" @@ -3556,7 +3548,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-idn/tree/v1.28.0" + "source": "https://github.com/symfony/polyfill-intl-idn/tree/v1.29.0" }, "funding": [ { @@ -3572,20 +3564,20 @@ "type": "tidelift" } ], - "time": "2023-01-26T09:30:37+00:00" + "time": "2024-01-29T20:11:03+00:00" }, { "name": "symfony/polyfill-intl-normalizer", - "version": "v1.28.0", + "version": "v1.29.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-normalizer.git", - "reference": "8c4ad05dd0120b6a53c1ca374dca2ad0a1c4ed92" + "reference": "bc45c394692b948b4d383a08d7753968bed9a83d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/8c4ad05dd0120b6a53c1ca374dca2ad0a1c4ed92", - "reference": "8c4ad05dd0120b6a53c1ca374dca2ad0a1c4ed92", + "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/bc45c394692b948b4d383a08d7753968bed9a83d", + "reference": "bc45c394692b948b4d383a08d7753968bed9a83d", "shasum": "" }, "require": { @@ -3596,9 +3588,6 @@ }, "type": "library", "extra": { - "branch-alias": { - "dev-main": "1.28-dev" - }, "thanks": { "name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill" @@ -3640,7 +3629,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.28.0" + "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.29.0" }, "funding": [ { @@ -3656,20 +3645,20 @@ "type": "tidelift" } ], - "time": "2023-01-26T09:26:14+00:00" + "time": "2024-01-29T20:11:03+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.28.0", + "version": "v1.29.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "42292d99c55abe617799667f454222c54c60e229" + "reference": "9773676c8a1bb1f8d4340a62efe641cf76eda7ec" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/42292d99c55abe617799667f454222c54c60e229", - "reference": "42292d99c55abe617799667f454222c54c60e229", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/9773676c8a1bb1f8d4340a62efe641cf76eda7ec", + "reference": "9773676c8a1bb1f8d4340a62efe641cf76eda7ec", "shasum": "" }, "require": { @@ -3683,9 +3672,6 @@ }, "type": "library", "extra": { - "branch-alias": { - "dev-main": "1.28-dev" - }, "thanks": { "name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill" @@ -3723,7 +3709,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.28.0" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.29.0" }, "funding": [ { @@ -3739,20 +3725,20 @@ "type": "tidelift" } ], - "time": "2023-07-28T09:04:16+00:00" + "time": "2024-01-29T20:11:03+00:00" }, { "name": "symfony/polyfill-php72", - "version": "v1.28.0", + "version": "v1.29.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php72.git", - "reference": "70f4aebd92afca2f865444d30a4d2151c13c3179" + "reference": "861391a8da9a04cbad2d232ddd9e4893220d6e25" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/70f4aebd92afca2f865444d30a4d2151c13c3179", - "reference": "70f4aebd92afca2f865444d30a4d2151c13c3179", + "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/861391a8da9a04cbad2d232ddd9e4893220d6e25", + "reference": "861391a8da9a04cbad2d232ddd9e4893220d6e25", "shasum": "" }, "require": { @@ -3760,9 +3746,6 @@ }, "type": "library", "extra": { - "branch-alias": { - "dev-main": "1.28-dev" - }, "thanks": { "name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill" @@ -3799,7 +3782,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php72/tree/v1.28.0" + "source": "https://github.com/symfony/polyfill-php72/tree/v1.29.0" }, "funding": [ { @@ -3815,20 +3798,20 @@ "type": "tidelift" } ], - "time": "2023-01-26T09:26:14+00:00" + "time": "2024-01-29T20:11:03+00:00" }, { "name": "symfony/polyfill-php80", - "version": "v1.28.0", + "version": "v1.29.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "6caa57379c4aec19c0a12a38b59b26487dcfe4b5" + "reference": "87b68208d5c1188808dd7839ee1e6c8ec3b02f1b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/6caa57379c4aec19c0a12a38b59b26487dcfe4b5", - "reference": "6caa57379c4aec19c0a12a38b59b26487dcfe4b5", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/87b68208d5c1188808dd7839ee1e6c8ec3b02f1b", + "reference": "87b68208d5c1188808dd7839ee1e6c8ec3b02f1b", "shasum": "" }, "require": { @@ -3836,9 +3819,6 @@ }, "type": "library", "extra": { - "branch-alias": { - "dev-main": "1.28-dev" - }, "thanks": { "name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill" @@ -3882,7 +3862,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.28.0" + "source": "https://github.com/symfony/polyfill-php80/tree/v1.29.0" }, "funding": [ { @@ -3898,20 +3878,20 @@ "type": "tidelift" } ], - "time": "2023-01-26T09:26:14+00:00" + "time": "2024-01-29T20:11:03+00:00" }, { "name": "symfony/polyfill-php83", - "version": "v1.28.0", + "version": "v1.29.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php83.git", - "reference": "b0f46ebbeeeda3e9d2faebdfbf4b4eae9b59fa11" + "reference": "86fcae159633351e5fd145d1c47de6c528f8caff" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php83/zipball/b0f46ebbeeeda3e9d2faebdfbf4b4eae9b59fa11", - "reference": "b0f46ebbeeeda3e9d2faebdfbf4b4eae9b59fa11", + "url": "https://api.github.com/repos/symfony/polyfill-php83/zipball/86fcae159633351e5fd145d1c47de6c528f8caff", + "reference": "86fcae159633351e5fd145d1c47de6c528f8caff", "shasum": "" }, "require": { @@ -3920,9 +3900,6 @@ }, "type": "library", "extra": { - "branch-alias": { - "dev-main": "1.28-dev" - }, "thanks": { "name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill" @@ -3962,7 +3939,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php83/tree/v1.28.0" + "source": "https://github.com/symfony/polyfill-php83/tree/v1.29.0" }, "funding": [ { @@ -3978,20 +3955,20 @@ "type": "tidelift" } ], - "time": "2023-08-16T06:22:46+00:00" + "time": "2024-01-29T20:11:03+00:00" }, { "name": "symfony/polyfill-uuid", - "version": "v1.28.0", + "version": "v1.29.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-uuid.git", - "reference": "9c44518a5aff8da565c8a55dbe85d2769e6f630e" + "reference": "3abdd21b0ceaa3000ee950097bc3cf9efc137853" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-uuid/zipball/9c44518a5aff8da565c8a55dbe85d2769e6f630e", - "reference": "9c44518a5aff8da565c8a55dbe85d2769e6f630e", + "url": "https://api.github.com/repos/symfony/polyfill-uuid/zipball/3abdd21b0ceaa3000ee950097bc3cf9efc137853", + "reference": "3abdd21b0ceaa3000ee950097bc3cf9efc137853", "shasum": "" }, "require": { @@ -4005,9 +3982,6 @@ }, "type": "library", "extra": { - "branch-alias": { - "dev-main": "1.28-dev" - }, "thanks": { "name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill" @@ -4044,7 +4018,7 @@ "uuid" ], "support": { - "source": "https://github.com/symfony/polyfill-uuid/tree/v1.28.0" + "source": "https://github.com/symfony/polyfill-uuid/tree/v1.29.0" }, "funding": [ { @@ -4060,7 +4034,7 @@ "type": "tidelift" } ], - "time": "2023-01-26T09:26:14+00:00" + "time": "2024-01-29T20:11:03+00:00" }, { "name": "symfony/process", @@ -5723,16 +5697,16 @@ }, { "name": "orchestra/canvas", - "version": "v8.11.6", + "version": "v8.11.7", "source": { "type": "git", "url": "https://github.com/orchestral/canvas.git", - "reference": "6ab236c7a190f7f53ce2e9c65fd9ee781e5aeb6c" + "reference": "e4a0157f522222725f1559bde0da1091a91542fb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/orchestral/canvas/zipball/6ab236c7a190f7f53ce2e9c65fd9ee781e5aeb6c", - "reference": "6ab236c7a190f7f53ce2e9c65fd9ee781e5aeb6c", + "url": "https://api.github.com/repos/orchestral/canvas/zipball/e4a0157f522222725f1559bde0da1091a91542fb", + "reference": "e4a0157f522222725f1559bde0da1091a91542fb", "shasum": "" }, "require": { @@ -5792,9 +5766,9 @@ "description": "Code Generators for Laravel Applications and Packages", "support": { "issues": "https://github.com/orchestral/canvas/issues", - "source": "https://github.com/orchestral/canvas/tree/v8.11.6" + "source": "https://github.com/orchestral/canvas/tree/v8.11.7" }, - "time": "2023-12-28T15:08:19+00:00" + "time": "2024-02-07T10:29:23+00:00" }, { "name": "orchestra/canvas-core", @@ -6198,16 +6172,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.10.57", + "version": "1.10.59", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "1627b1d03446904aaa77593f370c5201d2ecc34e" + "reference": "e607609388d3a6d418a50a49f7940e8086798281" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/1627b1d03446904aaa77593f370c5201d2ecc34e", - "reference": "1627b1d03446904aaa77593f370c5201d2ecc34e", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/e607609388d3a6d418a50a49f7940e8086798281", + "reference": "e607609388d3a6d418a50a49f7940e8086798281", "shasum": "" }, "require": { @@ -6256,7 +6230,7 @@ "type": "tidelift" } ], - "time": "2024-01-24T11:51:34+00:00" + "time": "2024-02-20T13:59:13+00:00" }, { "name": "phpunit/php-code-coverage", @@ -6581,16 +6555,16 @@ }, { "name": "phpunit/phpunit", - "version": "10.5.9", + "version": "10.5.10", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "0bd663704f0165c9e76fe4f06ffa6a1ca727fdbe" + "reference": "50b8e314b6d0dd06521dc31d1abffa73f25f850c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/0bd663704f0165c9e76fe4f06ffa6a1ca727fdbe", - "reference": "0bd663704f0165c9e76fe4f06ffa6a1ca727fdbe", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/50b8e314b6d0dd06521dc31d1abffa73f25f850c", + "reference": "50b8e314b6d0dd06521dc31d1abffa73f25f850c", "shasum": "" }, "require": { @@ -6662,7 +6636,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/10.5.9" + "source": "https://github.com/sebastianbergmann/phpunit/tree/10.5.10" }, "funding": [ { @@ -6678,7 +6652,7 @@ "type": "tidelift" } ], - "time": "2024-01-22T14:35:40+00:00" + "time": "2024-02-04T09:07:51+00:00" }, { "name": "pimple/pimple", @@ -6966,21 +6940,21 @@ }, { "name": "rector/rector", - "version": "0.19.5", + "version": "1.0.1", "source": { "type": "git", "url": "https://github.com/rectorphp/rector.git", - "reference": "89c895d127b9d248d2af007068a824b5348ef81f" + "reference": "258b775511e62a7188f8ce114d44acaf244d9a7d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/rectorphp/rector/zipball/89c895d127b9d248d2af007068a824b5348ef81f", - "reference": "89c895d127b9d248d2af007068a824b5348ef81f", + "url": "https://api.github.com/repos/rectorphp/rector/zipball/258b775511e62a7188f8ce114d44acaf244d9a7d", + "reference": "258b775511e62a7188f8ce114d44acaf244d9a7d", "shasum": "" }, "require": { "php": "^7.2|^8.0", - "phpstan/phpstan": "^1.10.56" + "phpstan/phpstan": "^1.10.57" }, "conflict": { "rector/rector-doctrine": "*", @@ -7010,7 +6984,7 @@ ], "support": { "issues": "https://github.com/rectorphp/rector/issues", - "source": "https://github.com/rectorphp/rector/tree/0.19.5" + "source": "https://github.com/rectorphp/rector/tree/1.0.1" }, "funding": [ { @@ -7018,7 +6992,7 @@ "type": "github" } ], - "time": "2024-01-29T23:53:47+00:00" + "time": "2024-02-16T07:53:23+00:00" }, { "name": "sebastian/cli-parser", @@ -7999,26 +7973,26 @@ }, { "name": "spatie/laravel-ray", - "version": "1.34.0", + "version": "1.35.1", "source": { "type": "git", "url": "https://github.com/spatie/laravel-ray.git", - "reference": "449c164c0ad0cf42a5abb52955d329199138604b" + "reference": "f504d3787d88c7e5de7a4290658f7ad9b1352f22" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/spatie/laravel-ray/zipball/449c164c0ad0cf42a5abb52955d329199138604b", - "reference": "449c164c0ad0cf42a5abb52955d329199138604b", + "url": "https://api.github.com/repos/spatie/laravel-ray/zipball/f504d3787d88c7e5de7a4290658f7ad9b1352f22", + "reference": "f504d3787d88c7e5de7a4290658f7ad9b1352f22", "shasum": "" }, "require": { "ext-json": "*", - "illuminate/contracts": "^7.20|^8.19|^9.0|^10.0", - "illuminate/database": "^7.20|^8.19|^9.0|^10.0", - "illuminate/queue": "^7.20|^8.19|^9.0|^10.0", - "illuminate/support": "^7.20|^8.19|^9.0|^10.0", + "illuminate/contracts": "^7.20|^8.19|^9.0|^10.0|^11.0", + "illuminate/database": "^7.20|^8.19|^9.0|^10.0|^11.0", + "illuminate/queue": "^7.20|^8.19|^9.0|^10.0|^11.0", + "illuminate/support": "^7.20|^8.19|^9.0|^10.0|^11.0", "php": "^7.4|^8.0", - "rector/rector": "^0.19.2", + "rector/rector": "^0.19.2|^1.0", "spatie/backtrace": "^1.0", "spatie/ray": "^1.41.1", "symfony/stopwatch": "4.2|^5.1|^6.0|^7.0", @@ -8026,12 +8000,13 @@ }, "require-dev": { "guzzlehttp/guzzle": "^7.3", - "laravel/framework": "^7.20|^8.19|^9.0|^10.0", - "orchestra/testbench-core": "^5.0|^6.0|^7.0|^8.0", - "pestphp/pest": "^1.22", + "laravel/framework": "^7.20|^8.19|^9.0|^10.0|^11.0", + "orchestra/testbench-core": "^5.0|^6.0|^7.0|^8.0|^9.0", + "pestphp/pest": "^1.22|^2.0", "phpstan/phpstan": "^1.10.57", - "phpunit/phpunit": "^9.3", - "spatie/pest-plugin-snapshots": "^1.1" + "phpunit/phpunit": "^9.3|^10.1", + "spatie/pest-plugin-snapshots": "^1.1|^2.0", + "symfony/var-dumper": "^4.2|^5.1|^6.0|^7.0.3" }, "type": "library", "extra": { @@ -8069,7 +8044,7 @@ ], "support": { "issues": "https://github.com/spatie/laravel-ray/issues", - "source": "https://github.com/spatie/laravel-ray/tree/1.34.0" + "source": "https://github.com/spatie/laravel-ray/tree/1.35.1" }, "funding": [ { @@ -8081,7 +8056,7 @@ "type": "other" } ], - "time": "2024-01-25T10:39:25+00:00" + "time": "2024-02-13T14:19:41+00:00" }, { "name": "spatie/macroable", @@ -8213,18 +8188,98 @@ ], "time": "2024-01-25T10:15:50+00:00" }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.9.0", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", + "reference": "d63cee4890a8afaf86a22e51ad4d97c91dd4579b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/d63cee4890a8afaf86a22e51ad4d97c91dd4579b", + "reference": "d63cee4890a8afaf86a22e51ad4d97c91dd4579b", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" + }, + "bin": [ + "bin/phpcbf", + "bin/phpcs" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "Former lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "Current lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/PHP_CodeSniffer/issues", + "security": "https://github.com/PHPCSStandards/PHP_CodeSniffer/security/policy", + "source": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "wiki": "https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki" + }, + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + } + ], + "time": "2024-02-16T15:06:51+00:00" + }, { "name": "symfony/polyfill-iconv", - "version": "v1.28.0", + "version": "v1.29.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-iconv.git", - "reference": "6de50471469b8c9afc38164452ab2b6170ee71c1" + "reference": "cd4226d140ecd3d0f13d32ed0a4a095ffe871d2f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-iconv/zipball/6de50471469b8c9afc38164452ab2b6170ee71c1", - "reference": "6de50471469b8c9afc38164452ab2b6170ee71c1", + "url": "https://api.github.com/repos/symfony/polyfill-iconv/zipball/cd4226d140ecd3d0f13d32ed0a4a095ffe871d2f", + "reference": "cd4226d140ecd3d0f13d32ed0a4a095ffe871d2f", "shasum": "" }, "require": { @@ -8238,9 +8293,6 @@ }, "type": "library", "extra": { - "branch-alias": { - "dev-main": "1.28-dev" - }, "thanks": { "name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill" @@ -8278,7 +8330,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-iconv/tree/v1.28.0" + "source": "https://github.com/symfony/polyfill-iconv/tree/v1.29.0" }, "funding": [ { @@ -8294,7 +8346,7 @@ "type": "tidelift" } ], - "time": "2023-01-26T09:26:14+00:00" + "time": "2024-01-29T20:11:03+00:00" }, { "name": "symfony/stopwatch", diff --git a/config/sguard.php b/config/sguard.php index b535da2..e62d499 100644 --- a/config/sguard.php +++ b/config/sguard.php @@ -1,4 +1,5 @@ fetchAlgo(); }); $this->jwtPayload = JWT::decode($bearerToken, new Key(trim($publicKey), trim($algorithm))); - if ( config('sguard.realm_name') !== $this->jwtPayload->aud) { + if (config('sguard.realm_name') !== $this->jwtPayload->aud) { throw new AuthenticationException('Auth error - realm mismatch'); } $revokedIds = Cache::remember('supaapps_jwt/revoked_ids', 15, function () { @@ -172,19 +169,24 @@ public function validate(array $credentials = []): bool $this->email = $this->jwtPayload->email; $this->scopesArray = explode(' ', $this->jwtPayload->scopes); $this->scopes = $this->jwtPayload->scopes; - if (strpos($this->scopes, '/' . config('sguard.realm_name') .'/*') !== false) { + if (strpos($this->scopes, '/' . config('sguard.realm_name') . '/*') !== false) { $this->admin = true; } else { $this->admin = false; } - } catch (Throwable $ex) { throw new AuthenticationException('Auth error - ' . $ex->getMessage()); } - + return true; } + public function setRequest(Request $request) + { + $this->request = $request; + + return $this; + } /** * @return string diff --git a/src/GuardServiceProvider.php b/src/GuardServiceProvider.php index e03ea5a..2da1a37 100644 --- a/src/GuardServiceProvider.php +++ b/src/GuardServiceProvider.php @@ -19,6 +19,8 @@ public function boot(): void $this->publishes([ __DIR__ . '/../config/sguard.php' => config_path('sguard.php'), + __DIR__ . '/../database/migrations' + => database_path('migrations') ]); } @@ -36,6 +38,4 @@ public function register(): void { $this->mergeConfigFrom(__DIR__ . '/../config/sguard.php', 'sguard'); } - - } diff --git a/src/Tests/Concerns/GenerateJwtToken.php b/src/Tests/Concerns/GenerateJwtToken.php index 13c9df3..08dee9e 100644 --- a/src/Tests/Concerns/GenerateJwtToken.php +++ b/src/Tests/Concerns/GenerateJwtToken.php @@ -4,10 +4,14 @@ use Firebase\JWT\JWT; use Illuminate\Contracts\Auth\Authenticatable; +use Illuminate\Foundation\Testing\Concerns\MakesHttpRequests; +use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\File; trait GenerateJwtToken { + use MakesHttpRequests; + public function withAccessTokenFor(Authenticatable $user, array $payload = []): string { $accessToken = $this->generateTestingJwtToken($payload + [ @@ -18,6 +22,14 @@ public function withAccessTokenFor(Authenticatable $user, array $payload = []): 'Authorization' => "Bearer {$accessToken}" ]); + auth('jwt')->setRequest( + $this->app->refresh('request', auth('jwt'), 'setRequest') + ); + + auth('jwt')->setUser($user); + + $this->withToken($accessToken); + return $accessToken; } @@ -42,4 +54,9 @@ public function generateTestingJwtToken(array $payload = []): string File::get(__DIR__ . '/../../../tests/public/algo') ); } + + public function setAuthServerUrl() + { + Config::set('sguard.auth_server_url', __DIR__ . '/../../../tests'); + } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 7415553..f17a378 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -11,7 +11,8 @@ class TestCase extends BaseTestCase { - use RefreshDatabase, GenerateJwtToken; + use RefreshDatabase; + use GenerateJwtToken; protected function getPackageProviders($app) { @@ -27,7 +28,8 @@ protected function getEnvironmentSetUp($app) 'driver' => 'supaapps-guard', 'provider' => 'users', ]); - $app['config']->set('sguard.auth_server_url', __DIR__); + + $this->setAuthServerUrl(); $app->afterResolving('migrator', static function ($migrator) { $migrator->path(laravel_migration_path());