Skip to content

Add unit tests#186

Merged
hajekj merged 12 commits into
TheNetworg:masterfrom
BertVM52:unit_tests
Jun 7, 2023
Merged

Add unit tests#186
hajekj merged 12 commits into
TheNetworg:masterfrom
BertVM52:unit_tests

Conversation

@BertVM52

Copy link
Copy Markdown
Contributor

Hi,

I've taken the time to add some unit tests. Since I use this package for B2C authentication, most tests that were written test this functionality. I believe it's a good starting point for people to add more tests.

The tests use a MockHandler that returns fake openIdConfig, keys, and tokens. This lets us test the package's code without having to worry about external connections. (See Fakers/ and Helper/)

Overview:

  • AccessTokenTest: correctly create and serialize AccessToken
  • AzureResourceOwnerTest: correctly create resource owner
  • AzureTest:
    • test openIdConfig handling

    • throw RuntimeException when client id is invalid

    • throw RuntimeException when token is expired

    • throw RuntimeException when token is from future

    • throw RuntimeException when issuer is invalid

    • test getBaseAuthorizationUrl

    • test getLogoutUrl

    • test validateAccessToken: ISSUE -> validateAccessToken causes UnexpectedValueException : "kid" invalid, unable to lookup correct key in JWT.php:448. Not sure if this is a bug. This function doesn't seem to be used anywhere else. The same error is thrown when I call validateAccessToken in my personal project.

    • throw exception for invalid keys: ISSUE -> code only catches JWT_Exception but this class does not exist and also does not catch other exceptions

    • throw exception for invalid token

    • test getGrant

@hajekj

hajekj commented Jun 7, 2023

Copy link
Copy Markdown
Member

Awesome! Thanks so much for this!

@hajekj
hajekj merged commit 7c0f784 into TheNetworg:master Jun 7, 2023
@BertVM52

BertVM52 commented Jun 7, 2023

Copy link
Copy Markdown
Contributor Author

Thanks for the merge! Any idea when the next package release might be?
(would mostly be for #184, for which i'm using a patch now)

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