toleador
toleador

Reputation: 1

jakarta.ws.rs.core.SecurityContext throws exception when testing in Quarkus

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?

Upvotes: 0

Views: 169

Answers (1)

Serkan
Serkan

Reputation: 1235

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

Upvotes: 0

Related Questions