فهرست منبع

Fix RemoteConnection mishandling redirects

Due to f72178f in #164, the request sub in RemoteConnection no longer
accepts a list of parameters. Instead, it wants a couple hashrefs, and
we forgot to update the invocation in the response handler during the
redirect case.
Daniel Gempesaw 11 سال پیش
والد
کامیت
2a0c9b31cc
2فایلهای تغییر یافته به همراه44 افزوده شده و 1 حذف شده
  1. 5 1
      lib/Selenium/Remote/RemoteConnection.pm
  2. 39 0
      t/Remote-Connection.t

+ 5 - 1
lib/Selenium/Remote/RemoteConnection.pm

@@ -116,7 +116,11 @@ sub _process_response {
     my $json = JSON->new;
 
     if ($response->is_redirect) {
-        return $self->request('GET', $response->header('location'));
+        my $redirect = {
+            method => 'GET',
+            url    => $response->header('location')
+        };
+        return $self->request($redirect);
     }
     else {
         my $decoded_json = undef;

+ 39 - 0
t/Remote-Connection.t

@@ -0,0 +1,39 @@
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+use Test::More;
+use Test::Exception;
+use Test::LWP::UserAgent;
+
+BEGIN: {
+    unless (use_ok('Selenium::Remote::RemoteConnection')) {
+        BAIL_OUT("Couldn't load Selenium::Remote::RemoteConnection");
+        exit;
+    }
+}
+
+REDIRECT: {
+    my $tua = Test::LWP::UserAgent->new(
+        max_redirect => 0
+    );
+
+    $tua->map_response(qr/redirect/, HTTP::Response->new(303, undef, ['Location' => 'http://localhost/elsewhere']));
+    $tua->map_response(qr/elsewhere/, HTTP::Response->new(200, 'OK', undef, ''));
+
+    my $conn = Selenium::Remote::RemoteConnection->new(
+        remote_server_addr => 'localhost',
+        port => '',
+        ua => $tua
+    );
+
+    my $redirect_endpoint = {
+        method => 'GET',
+        url => 'http://localhost/redirect'
+    };
+
+    lives_ok(sub { $conn->request($redirect_endpoint) }, '303 redirects no longer kill us');
+}
+
+
+done_testing;