Browse Source

Industrial strength mocking required for upload_file

Should at least catch cases where _process_file has been lethally altered
George S. Baugh 10 years ago
parent
commit
eb6e343c07
2 changed files with 26 additions and 12 deletions
  1. 20 3
      t/01-driver.t
  2. 6 9
      t/mock-recordings/01-driver-mock-linux.json

+ 20 - 3
t/01-driver.t

@@ -505,12 +505,29 @@ UPLOAD: {
     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('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' );
+
+    my $fake_driver;
+    if ($harness->record) {
+        $fake_driver = $driver;
+    } else {
+        #Going to have to use a custom UA to test this, since bogosity ensues
+        my $ftua = Test::LWP::UserAgent->new;
+        my $fake_header = bless( {'content-type' => 'application/json; charset=utf-8'}, 'HTTP::Headers' );
+        #Seems a bit heavy handed, but shouldn't be a problem.
+        $ftua->map_response(qr{.*}, HTTP::Response->new(200, 'OK', $fake_header, '{"sessionId":"89726c41-409f-421e-95a8-8b1fa482fa33","status":0,"state":"success","value":"/tmp/89726c41-409f-421e-95a8-8b1fa482fa33/upload1105744174029267337file/uploadTest","class":"org.openqa.selenium.remote.Response","hCode":516517658}'));
+        $fake_driver = Selenium::Remote::Driver->new(
+            ua => $ftua
+        );
+
+    }
+
+    #In the case this is not mocked, it tests a real issue (.. in paths), if not, it makes sure the zip/base64 bits at least don't make us explode.
+    like( $fake_driver->upload_file('t/uploadTest'),qr/uploadTest$/,'upload_file: zip/base64 branch' );
+    like( $fake_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
     like( exception { $driver->upload_file('@@@SomeFileThatDoesNotExist@@@')},qr/no such file/,"Passing missing file terminates program");
-  SKIP: {
+    SKIP: {
         skip 'purposefully excluding this test from the recording', 1
           if $harness->record;
         like( exception { $driver->upload_file(__FILE__) },qr/501/,"Passing this file rightly fails due to mock not being present");

File diff suppressed because it is too large
+ 6 - 9
t/mock-recordings/01-driver-mock-linux.json


Some files were not shown because too many files changed in this diff