Skip to content
This repository was archived by the owner on Jul 15, 2021. It is now read-only.
This repository was archived by the owner on Jul 15, 2021. It is now read-only.

Mocking JWT/JKU service in tests is tedious #250

@marijnhurkens

Description

@marijnhurkens

Withing my Symfony project I use an external authentication service which uses the OpenId connect standard. This involves decoding and verifying JWT tokens which a user sends with a request and using external public keys (JKU) to verify the signature.

I am using PHPunit for tests and I want to test the decoding and verification code I wrote for the tokens. The class which does the decoding and verifying uses a Guzzle client which I have setup using this bundle. I have looked at the options for mocking responses, and as far as I can see the only option is to use the Mock middleware and record / replay the responses.

The problem is that I don't have access to the private key of the service I use, so I can't generate a test JWT with test claims myself which would match the response from the JKU public key. So now I have to record the JKU response, go in the recorded file and change the response to match my own generated public JKU. Then I have to be careful to not change back the mock middleware back to record which would overwrite the JKU response.

My ideal solution would be to override the handler settings of the Guzzle client in the test configuration of the CsaGuzzleBundle, but I have no idea if this is possible? This way I could use the MockHandler to have full control over the responses. Is that possible?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions