|
21 | 21 | public class RedirectHandlerTest { |
22 | 22 |
|
23 | 23 | String testmeurl = "https://graph.microsoft.com/v1.0/me/"; |
24 | | - String testurl = "https://graph.microsoft.com/v1.0/"; |
| 24 | + String testurl = "https://graph.microsoft.com/v1.0"; |
25 | 25 | String differenthosturl = "https://graph.abc.com/v1.0/"; |
26 | 26 |
|
27 | 27 | @Test |
@@ -228,5 +228,39 @@ public void testGetRedirectForPostMethodWithStatusCodeSeeOther() { |
228 | 228 | fail("Redirect handler testGetRedirectForPostMethod1 failure"); |
229 | 229 | } |
230 | 230 | } |
| 231 | + |
| 232 | + @Test |
| 233 | + public void testGetRedirectForRelativeURL() throws ProtocolException { |
| 234 | + RedirectHandler redirectHandler = new RedirectHandler(); |
| 235 | + Request httppost = new Request.Builder().url(testurl).build(); |
| 236 | + |
| 237 | + Response response = new Response.Builder() |
| 238 | + .protocol(Protocol.HTTP_1_1) |
| 239 | + .code(HttpURLConnection.HTTP_SEE_OTHER) |
| 240 | + .message("See Other") |
| 241 | + .addHeader("location", "/testrelativeurl") |
| 242 | + .request(httppost) |
| 243 | + .build(); |
| 244 | + |
| 245 | + Request request = redirectHandler.getRedirect(httppost, response); |
| 246 | + assertTrue(request.url().toString().compareTo(testurl+"/testrelativeurl") == 0); |
| 247 | + } |
| 248 | + |
| 249 | + @Test |
| 250 | + public void testGetRedirectRelativeLocationRequestURLwithSlash() throws ProtocolException { |
| 251 | + RedirectHandler redirectHandler = new RedirectHandler(); |
| 252 | + Request httppost = new Request.Builder().url(testmeurl).build(); |
| 253 | + |
| 254 | + Response response = new Response.Builder() |
| 255 | + .protocol(Protocol.HTTP_1_1) |
| 256 | + .code(HttpURLConnection.HTTP_SEE_OTHER) |
| 257 | + .message("See Other") |
| 258 | + .addHeader("location", "/testrelativeurl") |
| 259 | + .request(httppost) |
| 260 | + .build(); |
| 261 | + Request request = redirectHandler.getRedirect(httppost, response); |
| 262 | + String expected = "https://graph.microsoft.com/v1.0/me/testrelativeurl"; |
| 263 | + assertTrue(request.url().toString().compareTo(expected) == 0); |
| 264 | + } |
231 | 265 |
|
232 | 266 | } |
0 commit comments