Annotation Interface WithJwt
@Target({METHOD,TYPE})
@Retention(RUNTIME)
@Inherited
@Documented
@WithSecurityContext(factory=AuthenticationFactory.class)
public @interface WithJwt
Annotation to setup test
SecurityContext with an Authentication instantiated by the (Reactive)JwtAuthenticaionConverter in the security conf.
Usage on tests decorated with @AutoConfigureAddonsSecurity or @AutoConfigureAddonsWebSecurity::
@Test
@WithJwt("ch4mp_auth0.json")
public void test() {
...
}
For usage with @ParameterizedTest, you'll need a @MethodSource in a test running with @TestInstance(Lifecycle.PER_CLASS).
Authentication instance should be injected in the test with @ParameterizedAuthentication.
@Autowired
WithJwt.AuthenticationFactory authFactory;
@ParameterizedTest
@MethodSource("authSource")
void givenUserIsPersona_whenGetGreet_thenReturnsGreeting(@ParameterizedAuthentication Authentication auth) {
...
}
Stream<AbstractAuthenticationToken> authSource() {
return authFactory.authenticationsFrom("ch4mp.json", "tonton-pirate.json");
}
If using spring-addons-oauth2-test without spring-addons-starter-oidc-test, you should explicitly import @Import(AuthenticationFactoriesTestConf.class)
(otherwise, the @Addons...Test will pull this configuration for you)- Author:
- Jérôme Wacongne <ch4mp@c4-soft.com>
-
Nested Class Summary
Nested Classes -
Optional Element Summary
Optional Elements