Description
Expected Behavior
Easy way to avoid the call to an OP /.well-known/openid-configuration
in a @SpringBootTest
of an application configured with oauth2Client
(or oauth2Login
).
Context
When working with mocked Authentication
instances (using MockMvc
request post processors, WebTestClient
mutators, or test annotations), no communication with the authorization server should be needed. However, in the case of a @SpringBootTest
for an application configured for OAuth2 with an OP issuer URI, the OpenID configuration is fetched eagerly during application context initialisation.
I found two options, but neither is as convenient as declaring a @MockitoBean
for a Spring Boot @ConditionalOnMissingBean
like we can do for the (Reactive)JwtDecoder
in an oauth2ResourceServer
:
- Testcontainers, but this is super slow and completely overkill to provide no more than OpenID configuration
- Wiremock, lighter and faster than Testcontainers, but still requires additional dependencies, adds some overhead, and requires more configuration than a
@MockitoBean
(declare astatic WireMockServer
, a@DynamicPropertySource
to bind the issuer URI to this server base URL, and@BeforeAll
/@AfterAll
to start & stop the mocked server)