0

I have a microservice that use JWT for authentication/authorization, and it just need a verify an jwt token is correct or incorrect, so in the code, i only implement the decoder for JWT.

    Lcobucci\JWT\Configuration:
        factory: [ 'App\Security\JWT\JWTConfigurationFactory', 'createJWTReader' ]
        arguments:
            - '%env(JWT_PUBLIC_KEY)%'

this configuration will be injected to JWTManager. but as you see, i just implement the read part.

but in functional test, i need to generate some token to pass some functional test (call to authenticated endpoint.. eg) that need a encoder part.

my strategy is create a new file service-test.yaml and write a createAsymmetricSigner in factory to work both with read/write JWT.

    Lcobucci\JWT\Configuration:
        factory: [ '@CCT\Monolith\Shared\Symfony\Security\JWT\JWTConfigurationFactory', 'createAsymmetricSigner' ]
        arguments:
            - '%env(JWT_PRIVATE_KEY)%'
            - '%env(JWT_PUBLIC_KEY)%'
            - '%env(JWT_PASSWORD)%'

and the problem is, how can i overide the symfony start up endpoint to make it take service-test.yaml instead of service.yaml for DI configuration file.

2
  • 2
    you can use when@test in your existing services file for that. See docs Commented Nov 22, 2022 at 12:38
  • @craigh is correct and this is the recommended way. You can also put your services in config/services_test.yaml as said in the doc Commented Nov 23, 2022 at 6:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.