Skip to content

Commit

Permalink
Fix RemoteConnection mishandling redirects
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gempesaw committed Nov 13, 2014
1 parent 0a84d26 commit 2a0c9b3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/Selenium/Remote/RemoteConnection.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
39 changes: 39 additions & 0 deletions t/Remote-Connection.t
Original file line number Diff line number Diff line change
@@ -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;

1 comment on commit 2a0c9b3

@gempesaw
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.