Skip to content
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

Make failed key resources throw informative error #99

Merged
merged 4 commits into from
Jul 9, 2016
Merged

Make failed key resources throw informative error #99

merged 4 commits into from
Jul 9, 2016

Conversation

tdhsmith
Copy link
Contributor

@tdhsmith tdhsmith commented Jul 7, 2016

This is in response to an issue raised in tymondesigns/jwt-auth#763. A couple users were attempting to pass in file:// keys, but having a hard time diagnosing why they would fail. I suggest you utilize openssl_error_string() to communicate problems with potential key resources:

At the moment, when keys are passed in as invalid file strings (or potentially other non-resource objects), PublicKey fails with the unclear message:

Could not create token: openssl_pkey_get_details() expects parameter 1 to be resource, boolean given

It would be more helpful if failures to retrieve key resources were communicated directly to the user, so I have getKeyResource checking its result before submitting and throwing an exception if it couldn't successfully create a resource.

At the moment, when keys are passed in as invalid file strings (or potentially other non-resource objects), `PublicKey` fails with the unclear message:
```
Could not create token: openssl_pkey_get_details() expects parameter 1 to be resource, boolean given
```
It would be more helpful if failures to retrieve key resources were communicated directly to the user, so I suggest `getKeyResource` checks its result before submitting and throws an exception if it couldn't successfully get a resource.
@tdhsmith
Copy link
Contributor Author

tdhsmith commented Jul 7, 2016

Ok, I see a bad typo in there! I'll fix that and add some cases to KeyFormatTest.php later today...

@tdhsmith
Copy link
Contributor Author

tdhsmith commented Jul 8, 2016

Hrm. PHPUnit 4.8 doesn't have the same method signature for exception checks. And I guess HHVM actually throws an error when the file isn't found? I wonder if the openssl_ methods change slightly or if it's just differences in error bubbling...

@tdhsmith
Copy link
Contributor Author

tdhsmith commented Jul 8, 2016

Ok, passing all checks! Let me know if you need a squash or any style changes...

@odino
Copy link
Contributor

odino commented Jul 9, 2016

👍 great work @tdhsmith, thank for the help!

@odino odino merged commit 01e5caa into namshi:master Jul 9, 2016
@odino
Copy link
Contributor

odino commented Jul 9, 2016

in 7.2.0

@tdhsmith tdhsmith deleted the patch-1 branch July 11, 2016 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants