@@ -571,6 +571,44 @@ void testHandle3XXResponseWithoutLocationHeader() throws Exception {
571571 assertNull (nativeResponse );
572572 }
573573
574+ @ Test
575+ void handle3XXResponseWithLocationHeader () throws Exception {
576+ final var authenticationProviderMock = mock (AuthenticationProvider .class );
577+ authenticationProviderMock .authenticateRequest (
578+ any (RequestInformation .class ), any (Map .class ));
579+ final var client =
580+ getMockClient (
581+ new Response .Builder ()
582+ .code (301 )
583+ .message ("Moved Permanently" )
584+ .protocol (Protocol .HTTP_1_1 )
585+ .request (new Request .Builder ().url ("http://localhost" ).build ())
586+ .header ("Location" , "https://newlocation" )
587+ .body (
588+ ResponseBody .create (
589+ "test" .getBytes ("UTF-8" ),
590+ MediaType .parse ("application/json" )))
591+ .build ());
592+ final var requestInformation =
593+ new RequestInformation () {
594+ {
595+ setUri (new URI ("https://localhost" ));
596+ httpMethod = HttpMethod .GET ;
597+ }
598+ };
599+ final var mockEntity = creatMockEntity ();
600+ final var mockParseNode = creatMockParseNode (mockEntity );
601+ final var mockFactory = creatMockParseNodeFactory (mockParseNode , "application/json" );
602+
603+ final var requestAdapter =
604+ new OkHttpRequestAdapter (authenticationProviderMock , mockFactory , null , client );
605+ var nativeResponseHandler = new NativeResponseHandler ();
606+ requestAdapter .send (requestInformation , null , node -> mockEntity );
607+ // Should throw an exception
608+ var nativeResponse = (Response ) nativeResponseHandler .getValue ();
609+ assertNull (nativeResponse );
610+ }
611+
574612 public static OkHttpClient getMockClient (final Response response ) throws IOException {
575613 final OkHttpClient mockClient = mock (OkHttpClient .class );
576614 final Call remoteCall = mock (Call .class );
0 commit comments