-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problems testing Passport with actingAsClient #2556
Conversation
While my experience with Passport is limited, the changes you are proposing here so far make sense. (Edit: except that, as parallels999 has said, the proposed checks are already in the code, elsewhere) Are you satisfied that these changes have resolved the testing problem you were encountering? |
@drbyte I reset the file to the current situation and run the tests, they failed. Than changed it with this change and they passed. I did wonder if for the sake of readability the if statement should become a method? |
laravel-permission/src/Guard.php Lines 91 to 93 in c66c0de
laravel-permission/src/Guard.php Line 95 in c66c0de
laravel-permission/src/Guard.php Lines 81 to 106 in c66c0de
|
It seems that this was expected, they added a dump bearer for testing laravel-permission/tests/TestCase.php Lines 275 to 277 in c66c0de
Also passport does the same on their tests, look their codelaravel/passport/CheckClientCredentialsTest.php#L44-L49 laravel/passport/search?q=Bearer%20token |
not always, depends on default guard, maybe you forget the guard Passport::actingAsClient($YOUR_CLIENT, [], 'guard_name_here'); Also add guard on middleware |
@parallels999 the way I handle // Some test
public function test()
{
$this->actingAsClient();
}
// Passport actingAsClient wrapper method
protected function actingAsClient( client = null, $permissions = null )
{
if( !$client )
{
$client = Client::factory()->create();
}
Passport::actingAsClient(
$client,
[ '*' ]
);
if( $permissions )
{
$this->assignRole(<some params>);
}
return $this;
} From what I understand is that |
That example doesn't help much. I can't see how you call the middlewares, I can't guess what code you used You could try to make a PR to Passport so that it adds the dummy bearer token automatically |
Dear contributor, because this pull request seems to be inactive for quite some time now, I've automatically closed it. If you feel this pull request deserves some attention from my human colleagues feel free to reopen it. |
While testing locally I noticed that I got an
403
error even though I was usingPassport::actingAsClient()
. That error occurs because there is no$user
and nobearerToken()
provided. But I did notice thatauth()?->client()
returned thePassport::actingAsClient()
Client
instance.So I'm hoping that with this change testing works as expected. It should now check for either the
bearerToken()
or the loggedin Client provided byPassport::actingAsClient()
.