@Before public void setUp() { this.idTokenDecoderFactory = new ReactiveOidcIdTokenDecoderFactory(); }
@Test public void createDecoderWhenCustomJwtValidatorFactorySetThenApplied() { Function<ClientRegistration, OAuth2TokenValidator<Jwt>> customJwtValidatorFactory = mock(Function.class); this.idTokenDecoderFactory.setJwtValidatorFactory(customJwtValidatorFactory); when(customJwtValidatorFactory.apply(any(ClientRegistration.class))) .thenReturn(this.defaultJwtValidatorFactory.apply(this.registration.build())); this.idTokenDecoderFactory.createDecoder(this.registration.build()); verify(customJwtValidatorFactory).apply(any(ClientRegistration.class)); } }
@Test public void createDecoderWhenClientRegistrationNullThenThrowIllegalArgumentException() { assertThatThrownBy(() -> this.idTokenDecoderFactory.createDecoder(null)) .isInstanceOf(IllegalArgumentException.class); }
@Test public void setJwtValidatorFactoryWhenNullThenThrowIllegalArgumentException() { assertThatThrownBy(() -> this.idTokenDecoderFactory.setJwtValidatorFactory(null)) .isInstanceOf(IllegalArgumentException.class); }
@Test public void createDecoderWhenClientRegistrationValidThenReturnDecoder() { assertThat(this.idTokenDecoderFactory.createDecoder(this.registration.build())) .isNotNull(); }
@Test public void createDecoderWhenJwkSetUriEmptyThenThrowOAuth2AuthenticationException() { assertThatThrownBy(() -> this.idTokenDecoderFactory.createDecoder(this.registration.jwkSetUri(null).build())) .isInstanceOf(OAuth2AuthenticationException.class); }