0

Custom class that has jakarta core @Context SecurityContext throws following exception:

Method threw 'java.lang.IllegalStateException' exception. Cannot evaluate jakarta.ws.rs.core.ContextProducers_ProducerMethod_securityContext_4dee4dfc4a691eaefdabc3490f54879a07ccb609_ClientProxy.toString()

This happens when I do testing and invoking service method to test, which has this custom class injected. We utilize SecurityContext to retrieve some information and do some checks later in code.

Custom class is @RequestScoped.

We tried some different approaches from Quarkus documentation but without success. Is there a way to mock or initialize SecurityContext when doing unit tests or to have it in some test scope? How do you do unit test when having @Context SecurityContext usage?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555

1 Answers1

0

Add this dependency:

 <dependency>
  <groupId>io.quarkus</groupId>
  <artifactId>quarkus-test-security</artifactId>
  <scope>test</scope>
</dependency>

And use it like this:

@Test
@TestSecurity(user=“user”, roles=“admin”)

For more info check this link

Serkan
  • 639
  • 5
  • 14