Эх сурвалжийг харах

Fix issues with paths containing .. in upload path (see PR 194 for discussion)

George S. Baugh 10 жил өмнө
parent
commit
26888844e8

+ 3 - 0
.gitignore

@@ -10,3 +10,6 @@ cover_db
 Selenium-Remote-Driver-*
 Selenium-Remote-Driver-*
 .prove
 .prove
 _prove
 _prove
+#vim swapfiles
+*.swo
+*.swp

+ 9 - 2
lib/Selenium/Remote/Driver.pm

@@ -23,6 +23,8 @@ use Selenium::Remote::WebElement;
 use File::Spec::Functions ();
 use File::Spec::Functions ();
 use File::Basename ();
 use File::Basename ();
 use Sub::Install ();
 use Sub::Install ();
+use Cwd ();
+use MIME::Base64 ();
 
 
 use constant FINDERS => {
 use constant FINDERS => {
     class             => 'class name',
     class             => 'class name',
@@ -1417,7 +1419,6 @@ sub capture_screenshot {
     my ( $self, $filename ) = @_;
     my ( $self, $filename ) = @_;
     croak '$filename is required' unless $filename;
     croak '$filename is required' unless $filename;
 
 
-    require MIME::Base64;
     open( my $fh, '>', $filename );
     open( my $fh, '>', $filename );
     binmode $fh;
     binmode $fh;
     print $fh MIME::Base64::decode_base64( $self->screenshot() );
     print $fh MIME::Base64::decode_base64( $self->screenshot() );
@@ -2437,6 +2438,10 @@ sub button_up {
     Passing raw data as an argument past the filename will upload
     Passing raw data as an argument past the filename will upload
     that rather than the file's contents.
     that rather than the file's contents.
 
 
+    When passing raw data, be advised that it expects a zipped
+    and then base64 encoded version of a single file.
+    Multiple files are not supported by the remote server.
+
  Usage:
  Usage:
     my $remote_fname = $driver->upload_file( $fname );
     my $remote_fname = $driver->upload_file( $fname );
     my $element = $driver->find_element( '//input[@id="file"]' );
     my $element = $driver->find_element( '//input[@id="file"]' );
@@ -2455,6 +2460,9 @@ sub upload_file {
         file => $raw_content
         file => $raw_content
     };
     };
 
 
+    #Apparently zip chokes on non-canonical paths, creating double submissions sometimes
+    $filename = Cwd::abs_path($filename);
+
     #Otherwise, zip/base64 it.
     #Otherwise, zip/base64 it.
     $params = $self->_prepare_file($filename) if !defined($raw_content);
     $params = $self->_prepare_file($filename) if !defined($raw_content);
 
 
@@ -2476,7 +2484,6 @@ sub _prepare_file {
     my $string = "";    # buffer
     my $string = "";    # buffer
     zip $filename => \$string
     zip $filename => \$string
       or die "zip failed: $ZipError\n";    # compress the file into string
       or die "zip failed: $ZipError\n";    # compress the file into string
-    require MIME::Base64;
 
 
     return {
     return {
         file => MIME::Base64::encode_base64($string)          # base64-encoded string
         file => MIME::Base64::encode_base64($string)          # base64-encoded string

+ 2 - 0
t/01-driver.t

@@ -505,6 +505,8 @@ UPLOAD: {
     my $otherTestFile = "UEsDBBQACAAIAFtuNEYAAAAAAAAAAAAAAAAMABUAdC91cGxvYWRUZXN0VVQJAAOesb5UnrG+VFV4\nBADoA+gDK0ktLgEAUEsHCAx+f9gGAAAABAAAAFBLAQIUAxQACAAIAFtuNEYMfn/YBgAAAAQAAAAM\nAA0AAAAAAAAAAACkgQAAAAB0L3VwbG9hZFRlc3RVVAUAAZ6xvlRVeAAAUEsFBgAAAAABAAEARwAA\nAFUAAAAAAA==\n";
     my $otherTestFile = "UEsDBBQACAAIAFtuNEYAAAAAAAAAAAAAAAAMABUAdC91cGxvYWRUZXN0VVQJAAOesb5UnrG+VFV4\nBADoA+gDK0ktLgEAUEsHCAx+f9gGAAAABAAAAFBLAQIUAxQACAAIAFtuNEYMfn/YBgAAAAQAAAAM\nAA0AAAAAAAAAAACkgQAAAAB0L3VwbG9hZFRlc3RVVAUAAZ6xvlRVeAAAUEsFBgAAAAABAAEARwAA\nAFUAAAAAAA==\n";
     like( $driver->upload_file('uploadTest',$testFile),qr/uploadTest$/,'upload_file returns FULL path to the file: cwd');
     like( $driver->upload_file('uploadTest',$testFile),qr/uploadTest$/,'upload_file returns FULL path to the file: cwd');
     like( $driver->upload_file('t/uploadTest',$otherTestFile),qr/uploadTest$/,'upload_file returns FULL path to the file: subdir');
     like( $driver->upload_file('t/uploadTest',$otherTestFile),qr/uploadTest$/,'upload_file returns FULL path to the file: subdir');
+    like( $driver->upload_file('t/uploadTest'),qr/uploadTest$/,'upload_file: zip/base64 branch' );
+    like( $driver->upload_file('t/../t/uploadTest'),qr/uploadTest$/,'upload_file: zip/base64 branch with .. in path' );
 
 
     #Negative tests to verify that our expected behavior codepath is travelled by tests
     #Negative tests to verify that our expected behavior codepath is travelled by tests
     like( exception { $driver->upload_file('@@@SomeFileThatDoesNotExist@@@')},qr/no such file/,"Passing missing file terminates program");
     like( exception { $driver->upload_file('@@@SomeFileThatDoesNotExist@@@')},qr/no such file/,"Passing missing file terminates program");

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 7 - 6
t/mock-recordings/01-driver-mock-linux.json


+ 0 - 0
t/uploadTest


Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно