robsontenorio / laravel-keycloak-guard

🔑 Simple Keycloak Guard for Laravel
MIT License
434 stars 141 forks source link

Implement: 'scopes', 'hasScope' and 'hasAnyScopes' method #107

Closed vlauciani closed 8 months ago

vlauciani commented 8 months ago

Solve Issue: #106

robsontenorio commented 8 months ago

Thanks @vlauciani !

Could you please add tests?

vlauciani commented 8 months ago

Hi @robsontenorio

Tests added! Could you check If all is ok?

codecov[bot] commented 8 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 100.00%. Comparing base (042483a) to head (5db4c8a).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #107 +/- ## =========================================== Coverage 100.00% 100.00% - Complexity 37 43 +6 =========================================== Files 4 4 Lines 97 112 +15 =========================================== + Hits 97 112 +15 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

robsontenorio commented 8 months ago

There is a missing test case for empty returning. Check the report above.

vlauciani commented 8 months ago

The command composer test:coverage to test "coverage" doesn't work; the file .coverage/clover.xml is missing. It returns an error:

bash-5.1#
bash-5.1# composer test:coverage
> php -d pcov.enabled=1 ./vendor/bin/pest --coverage --coverage-clover=.coverage/clover.xml --coverage-html=.coverage

   PASS  KeycloakGuard\Tests\AuthenticateTest
  ✓ authenticates the user when requesting a private endpoint with token
  ✓ authenticates the user when requesting an public endpoint with token
  ✓ forbiden when request a protected endpoint without token
  ✓ laravel default interface for authenticated users
  ✓ laravel default interface for unathenticated users
  ✓ throws a exception when user is not found
  ✓ appends token to the user
  ✓ does not appends token to the user
  ✓ does not load user from database
  ✓ does not load user from database but appends decoded token
  ✓ throws a exception when resource access is not allowed by api
  ✓ ignores resources validation
  ✓ check user has role in resource
  ✓ check user no has role in resource
  ✓ prevent cross roles resources
  ✓ check user has any role in resource
  ✓ check user no has any role in resource
  ✓ prevent cross roles resources with any role
  ✓ check user has scope
  ✓ check user no has scope
  ✓ check user has any scope
  ✓ check user no has any scope
  ✓ custom user retrieve method
  ✓ throws a exception with invalid iat
  ✓ works with leeway
  ✓ authenticates with custom input key
  ✓ authentication prefers bearer token over with custom input key

  Tests:  27 passed
  Time:   0.95s

   ERROR  No code coverage driver is available.
Script php -d pcov.enabled=1 ./vendor/bin/pest --coverage --coverage-clover=.coverage/clover.xml --coverage-html=.coverage handling the test:coverage event returned with error code 1
bash-5.1#
bash-5.1#
robsontenorio commented 8 months ago

Thanks !