Don't Mock OAuth2AuthorizedClientRepository
Issue gh-13542 Issue gh-13546
This commit is contained in:
parent
b0022a0ae8
commit
b3ad2b0dc5
|
@ -24,6 +24,9 @@ import org.junit.jupiter.api.extension.ExtendWith;
|
|||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.mock.web.MockHttpSession;
|
||||
import org.springframework.security.config.oauth2.client.CommonOAuth2Provider;
|
||||
import org.springframework.security.config.test.SpringTestContext;
|
||||
import org.springframework.security.config.test.SpringTestContextExtension;
|
||||
|
@ -219,8 +222,11 @@ public class OAuth2ClientBeanDefinitionParserTests {
|
|||
ClientRegistration clientRegistration = this.clientRegistrationRepository.findByRegistrationId("google");
|
||||
OAuth2AuthorizedClient authorizedClient = new OAuth2AuthorizedClient(clientRegistration, "user",
|
||||
TestOAuth2AccessTokens.noScopes());
|
||||
given(this.authorizedClientRepository.loadAuthorizedClient(any(), any(), any())).willReturn(authorizedClient);
|
||||
this.mvc.perform(get("/authorized-client")).andExpect(status().isOk()).andExpect(content().string("resolved"));
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
this.authorizedClientRepository.saveAuthorizedClient(authorizedClient, null, request, response);
|
||||
this.mvc.perform(get("/authorized-client").session((MockHttpSession) request.getSession()))
|
||||
.andExpect(status().isOk()).andExpect(content().string("resolved"));
|
||||
}
|
||||
|
||||
private static OAuth2AuthorizationRequest createAuthorizationRequest(ClientRegistration clientRegistration) {
|
||||
|
|
|
@ -27,6 +27,9 @@ import org.mockito.ArgumentCaptor;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.mock.web.MockHttpSession;
|
||||
import org.springframework.security.authentication.event.AuthenticationSuccessEvent;
|
||||
import org.springframework.security.config.test.SpringTestContext;
|
||||
import org.springframework.security.config.test.SpringTestContextExtension;
|
||||
|
@ -522,9 +525,11 @@ public class OAuth2LoginBeanDefinitionParserTests {
|
|||
ClientRegistration clientRegistration = this.clientRegistrationRepository.findByRegistrationId("google-login");
|
||||
OAuth2AuthorizedClient authorizedClient = new OAuth2AuthorizedClient(clientRegistration, "user",
|
||||
TestOAuth2AccessTokens.noScopes());
|
||||
given(this.authorizedClientRepository.loadAuthorizedClient(any(), any(), any())).willReturn(authorizedClient);
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
this.authorizedClientRepository.saveAuthorizedClient(authorizedClient, null, request, response);
|
||||
// @formatter:off
|
||||
this.mvc.perform(get("/authorized-client"))
|
||||
this.mvc.perform(get("/authorized-client").session((MockHttpSession) request.getSession()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string("resolved"));
|
||||
// @formatter:on
|
||||
|
@ -539,7 +544,7 @@ public class OAuth2LoginBeanDefinitionParserTests {
|
|||
|
||||
@GetMapping("/authorized-client")
|
||||
String authorizedClient(Model model,
|
||||
@RegisteredOAuth2AuthorizedClient("google") OAuth2AuthorizedClient authorizedClient) {
|
||||
@RegisteredOAuth2AuthorizedClient("google-login") OAuth2AuthorizedClient authorizedClient) {
|
||||
return (authorizedClient != null) ? "resolved" : "not-resolved";
|
||||
}
|
||||
|
||||
|
|
|
@ -43,9 +43,7 @@
|
|||
provider-id="google"/>
|
||||
</client-registrations>
|
||||
|
||||
<b:bean id="authorizedClientRepository" class="org.mockito.Mockito" factory-method="mock">
|
||||
<b:constructor-arg value="org.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository" type="java.lang.Class"/>
|
||||
</b:bean>
|
||||
<b:bean id="authorizedClientRepository" class="org.springframework.security.oauth2.client.web.HttpSessionOAuth2AuthorizedClientRepository"/>
|
||||
|
||||
<b:bean name="authorizedClientController" class="org.springframework.security.config.http.OAuth2ClientBeanDefinitionParserTests.AuthorizedClientController" />
|
||||
|
||||
|
|
|
@ -34,9 +34,7 @@
|
|||
|
||||
<mvc:annotation-driven />
|
||||
|
||||
<b:bean id="authorizedClientRepository" class="org.mockito.Mockito" factory-method="mock">
|
||||
<b:constructor-arg value="org.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository" type="java.lang.Class"/>
|
||||
</b:bean>
|
||||
<b:bean id="authorizedClientRepository" class="org.springframework.security.oauth2.client.web.HttpSessionOAuth2AuthorizedClientRepository"/>
|
||||
|
||||
<b:bean name="authorizedClientController" class="org.springframework.security.config.http.OAuth2LoginBeanDefinitionParserTests.AuthorizedClientController" />
|
||||
|
||||
|
|
Loading…
Reference in New Issue