47
47
@ TestConstructor (autowireMode = TestConstructor .AutowireMode .ALL )
48
48
public class WithingsControllerTests extends BaseIntegrationTest {
49
49
50
- // RefreshTokenOAuth2AuthorizedClientProvider
51
-
52
50
private final MockMvc mockMvc ;
53
51
private final TestAuthorizedClientRepository authorizedClientRepository ;
54
52
private final WeightRepository weightRepository ;
@@ -109,7 +107,7 @@ public void returns_not_authorized_if_authorized_client_is_not_found() throws Ex
109
107
110
108
assertThat (response .getStatus ()).isEqualTo (401 );
111
109
assertThat (JsonPath .parse (response .getContentAsString ()).read ("$._links.oauth2Login.href" , String .class ))
112
- .isEqualTo ("http://localhost/oauth2/authorization/ withings-client " );
110
+ .isEqualTo ("http://localhost/withings/authorize " );
113
111
}
114
112
115
113
@ Test
@@ -128,7 +126,7 @@ public void returns_forbidden_if_user_has_no_user_role() throws Exception {
128
126
public void redirects_to_withings_request_authorization_page () throws Exception {
129
127
MockHttpServletResponse response = mockMvc
130
128
.perform (
131
- get ("/oauth2/authorization/ withings-client" ))
129
+ get ("/withings/authorize" ). headers ( getAuthHeaders ( "user" ) ))
132
130
.andReturn ().getResponse ();
133
131
134
132
assertThat (response .getStatus ()).isEqualTo (302 );
@@ -141,7 +139,7 @@ public void redirects_to_withings_request_authorization_page() throws Exception
141
139
assertThat (redirectUrl ).hasParameter (OAuth2ParameterNames .SCOPE , "user.metrics" );
142
140
assertThat (redirectUrl ).hasParameter (OAuth2ParameterNames .STATE );
143
141
assertThat (redirectUrl ).hasParameter (OAuth2ParameterNames .REDIRECT_URI ,
144
- "http://localhost/authorize/oauth2/code/ withings-client " );
142
+ "http://localhost/withings/authorize " );
145
143
}
146
144
147
145
@ Test
@@ -153,24 +151,24 @@ public void requests_access_token_after_consent_is_granted() throws Exception {
153
151
154
152
MockHttpSession mockHttpSession = new MockHttpSession ();
155
153
MockHttpServletResponse response1 = mockMvc .perform (
156
- get ("/oauth2/authorization/withings-client" )
157
- .headers (getAuthHeaders ("user" ))
154
+ get ("/withings/authorize" ).headers (getAuthHeaders ("user" ))
158
155
.session (mockHttpSession ))
159
156
.andReturn ().getResponse ();
160
157
UriComponents components = UriComponentsBuilder .fromUriString (response1 .getRedirectedUrl ()).build ();
161
158
String state = URLDecoder .decode (
162
159
components .getQueryParams ().getFirst (OAuth2ParameterNames .STATE ),
163
160
StandardCharsets .UTF_8 );
164
161
165
- MockHttpServletResponse response2 = mockMvc .perform (get ("/authorize/oauth2/code/withings-client" )
166
- .headers (getAuthHeaders ("user" ))
167
- .queryParam (OAuth2ParameterNames .STATE , state )
168
- .queryParam (OAuth2ParameterNames .CODE , "test-authorization-code" )
169
- .session (mockHttpSession ))
162
+ MockHttpServletResponse response2 = mockMvc
163
+ .perform (get (components .getQueryParams ().getFirst (OAuth2ParameterNames .REDIRECT_URI ))
164
+ .headers (getAuthHeaders ("user" ))
165
+ .queryParam (OAuth2ParameterNames .STATE , state )
166
+ .queryParam (OAuth2ParameterNames .CODE , "test-authorization-code" )
167
+ .session (mockHttpSession ))
170
168
.andReturn ().getResponse ();
171
169
172
170
assertThat (response2 .getStatus ()).isEqualTo (302 );
173
- assertThat (response2 .getRedirectedUrl ()).isEqualTo ("http://localhost/" );
171
+ assertThat (response2 .getRedirectedUrl ()).isEqualTo ("http://localhost/withings/authorize " );
174
172
175
173
List <LoggedRequest > requests = mockWithingsServer
176
174
.findAll (WireMock .postRequestedFor (WireMock .urlEqualTo ("/v2/oauth2" )));
0 commit comments