@@ -741,6 +741,69 @@ def test_staging_ingestion_put_fails_if_localFile_not_in_uploads_base_path(self)
741
741
query = f"PUT '{ temp_path } ' INTO 'stage://tmp/{ self .staging_ingestion_user } /tmp/11/15/file1.csv' OVERWRITE"
742
742
cursor .execute (query )
743
743
744
+ def test_staging_ingestion_put_fails_if_file_exists_and_overwrite_not_set (self ):
745
+ """PUT a file into the staging location twice. First command should succeed. Second should fail.
746
+ """
747
+
748
+ fh , temp_path = tempfile .mkstemp ()
749
+
750
+ original_text = "hello world!" .encode ("utf-8" )
751
+
752
+ with open (fh , "wb" ) as fp :
753
+ fp .write (original_text )
754
+
755
+ def perform_put ():
756
+ with self .connection (extra_params = {"uploads_base_path" : temp_path }) as conn :
757
+ cursor = conn .cursor ()
758
+ query = f"PUT '{ temp_path } ' INTO 'stage://tmp/{ self .staging_ingestion_user } /tmp/12/15/file1.csv'"
759
+ cursor .execute (query )
760
+
761
+ def perform_remove ():
762
+ remove_query = (
763
+ f"REMOVE 'stage://tmp/{ self .staging_ingestion_user } /tmp/12/15/file1.csv'"
764
+ )
765
+
766
+ with self .connection (extra_params = {"uploads_base_path" : "/" }) as conn :
767
+ cursor = conn .cursor ()
768
+ cursor .execute (remove_query )
769
+
770
+
771
+ # Make sure file does not exist
772
+ perform_remove ()
773
+
774
+ # Put the file
775
+ perform_put ()
776
+
777
+ # Try to put it again
778
+ with pytest .raises (sql .exc .ServerOperationError , match = "FILE_IN_STAGING_PATH_ALREADY_EXISTS" ):
779
+ perform_put ()
780
+
781
+ # Clean up after ourselves
782
+ perform_remove ()
783
+
784
+ def test_staging_ingestion_fails_to_modify_another_staging_user (self ):
785
+ """The server should only allow modification of the staging_ingestion_user's files
786
+ """
787
+
788
+ some_other_user = "[email protected] "
789
+
790
+ fh , temp_path = tempfile .mkstemp ()
791
+
792
+ original_text = "hello world!" .encode ("utf-8" )
793
+
794
+ with open (fh , "wb" ) as fp :
795
+ fp .write (original_text )
796
+
797
+ def perform_put ():
798
+ with self .connection (extra_params = {"uploads_base_path" : temp_path }) as conn :
799
+ cursor = conn .cursor ()
800
+ query = f"PUT '{ temp_path } ' INTO 'stage://tmp/{ some_other_user } /tmp/12/15/file1.csv' OVERWRITE"
801
+ cursor .execute (query )
802
+
803
+ # Put should fail with permissions error
804
+ with pytest .raises (sql .exc .ServerOperationError , match = "PERMISSION_DENIED" ):
805
+ perform_put ()
806
+
744
807
def test_staging_ingestion_put_fails_if_absolute_localFile_not_in_uploads_base_path (self ):
745
808
"""
746
809
This test confirms that uploads_base_path and target_file are resolved into absolute paths.
0 commit comments