I am having issues using io.dropwizard.testing.junit.ResourceTestRule in tandem with @Auth decorations associated with io.dropwizard.auth.Auth.
I am using the @Auth decoration to fetch the Principal in my route handlers. I am able to get our Okta roles in this manner for access control. This all works fine when standing the AP and execute it as a jar. However, I’m having problems when I attempt to UnitTest my route handlers.
Logs include this information:
ERROR [2020-05-28 15:23:11,770] org.glassfish.jersey.internal.Errors: Following issues have been detected:
WARNING: No injection source found for a parameter of type public javax.ws.rs.core.Response com.helixeducation.ipa.admin.resources.InquiryResource.searchInquiries(com.helixeducation.components.auth.HelixUser,com.helixeducation.components.domain.InquirySearch) at index 0.
The parameter at index 0 is my Principal. Here is the method declaration:
@POST
@Timed
@Path("/search")
@Consumes(MediaType.APPLICATION_JSON)
@PermitAll
public Response searchInquiries(@Auth HelixUser user,
@Valid @NotNull InquirySearch inquirySearch) {
// check if user has an appropriate role or return 401.
// implementation Omitted.
}
Here’s the declaration of my TestRule:
@ClassRule
public static final ResourceTestRule resourceMock = ResourceTestRule.builder()
.addResource(new InquiryResource(mockDao, mockSearchDao, findApiConfiguration, mockInquiryCreateSvc))
.build();
How do I get the TestRule to inject a mocked Principal? I think if I can get past that issue, I can get unblocked.
Regards,
- jeremiah