Skip to content

How to emulate TestSecurity functionality when invoking secured methods directly, not going through HTTP calls? #44819

Answered by okarmazin
okarmazin asked this question in Q&A
Discussion options

You must be logged in to vote

Found an answer - I can inject CurrentIdentityAssociation into the test and set a manually constructed SecurityIdentity. This can further be combined with the TestSecurity and OidcSecurity annotations on the very same test method.

The manually constructed identity will be used for any direct invocations on injected secured beans, and if I perform a HTTP call with RestAssured, the identity will be constructed from the annotations.

This can be mixed and matched, so I can "direct-init" using an injected service instance (like inserting database rows through it), and then have that data returned and inspected using RestAssured.

@QuarkusTest
class SecuredResourceTest {

@Inject
lateinit var se…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by okarmazin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
1 participant