@@ -694,91 +694,115 @@ def test_push_error(self, repo):
694694
695695 @with_rw_repo ("HEAD" )
696696 def test_set_unsafe_url (self , rw_repo ):
697+ tmp_dir = Path (tempfile .mkdtemp ())
698+ tmp_file = tmp_dir / "pwn"
697699 remote = rw_repo .remote ("origin" )
698700 urls = [
699- "ext::sh -c touch% /tmp/pwn " ,
701+ f "ext::sh -c touch% { tmp_file } " ,
700702 "fd::17/foo" ,
701703 ]
702704 for url in urls :
703705 with self .assertRaises (UnsafeProtocolError ):
704706 remote .set_url (url )
707+ assert not tmp_file .exists ()
705708
706709 @with_rw_repo ("HEAD" )
707710 def test_set_unsafe_url_allowed (self , rw_repo ):
711+ tmp_dir = Path (tempfile .mkdtemp ())
712+ tmp_file = tmp_dir / "pwn"
708713 remote = rw_repo .remote ("origin" )
709714 urls = [
710- "ext::sh -c touch% /tmp/pwn " ,
715+ f "ext::sh -c touch% { tmp_file } " ,
711716 "fd::17/foo" ,
712717 ]
713718 for url in urls :
714719 remote .set_url (url , allow_unsafe_protocols = True )
715720 assert list (remote .urls )[- 1 ] == url
721+ assert not tmp_file .exists ()
716722
717723 @with_rw_repo ("HEAD" )
718724 def test_add_unsafe_url (self , rw_repo ):
725+ tmp_dir = Path (tempfile .mkdtemp ())
726+ tmp_file = tmp_dir / "pwn"
719727 remote = rw_repo .remote ("origin" )
720728 urls = [
721- "ext::sh -c touch% /tmp/pwn " ,
729+ f "ext::sh -c touch% { tmp_file } " ,
722730 "fd::17/foo" ,
723731 ]
724732 for url in urls :
725733 with self .assertRaises (UnsafeProtocolError ):
726734 remote .add_url (url )
735+ assert not tmp_file .exists ()
727736
728737 @with_rw_repo ("HEAD" )
729738 def test_add_unsafe_url_allowed (self , rw_repo ):
739+ tmp_dir = Path (tempfile .mkdtemp ())
740+ tmp_file = tmp_dir / "pwn"
730741 remote = rw_repo .remote ("origin" )
731742 urls = [
732- "ext::sh -c touch% /tmp/pwn " ,
743+ f "ext::sh -c touch% { tmp_file } " ,
733744 "fd::17/foo" ,
734745 ]
735746 for url in urls :
736747 remote .add_url (url , allow_unsafe_protocols = True )
737748 assert list (remote .urls )[- 1 ] == url
749+ assert not tmp_file .exists ()
738750
739751 @with_rw_repo ("HEAD" )
740752 def test_create_remote_unsafe_url (self , rw_repo ):
753+ tmp_dir = Path (tempfile .mkdtemp ())
754+ tmp_file = tmp_dir / "pwn"
741755 urls = [
742- "ext::sh -c touch% /tmp/pwn " ,
756+ f "ext::sh -c touch% { tmp_file } " ,
743757 "fd::17/foo" ,
744758 ]
745759 for url in urls :
746760 with self .assertRaises (UnsafeProtocolError ):
747761 Remote .create (rw_repo , "origin" , url )
762+ assert not tmp_file .exists ()
748763
749764 @with_rw_repo ("HEAD" )
750765 def test_create_remote_unsafe_url_allowed (self , rw_repo ):
766+ tmp_dir = Path (tempfile .mkdtemp ())
767+ tmp_file = tmp_dir / "pwn"
751768 urls = [
752- "ext::sh -c touch% /tmp/pwn " ,
769+ f "ext::sh -c touch% { tmp_file } " ,
753770 "fd::17/foo" ,
754771 ]
755772 for i , url in enumerate (urls ):
756773 remote = Remote .create (rw_repo , f"origin{ i } " , url , allow_unsafe_protocols = True )
757774 assert remote .url == url
775+ assert not tmp_file .exists ()
758776
759777 @with_rw_repo ("HEAD" )
760778 def test_fetch_unsafe_url (self , rw_repo ):
779+ tmp_dir = Path (tempfile .mkdtemp ())
780+ tmp_file = tmp_dir / "pwn"
761781 remote = rw_repo .remote ("origin" )
762782 urls = [
763- "ext::sh -c touch% /tmp/pwn " ,
783+ f "ext::sh -c touch% { tmp_file } " ,
764784 "fd::17/foo" ,
765785 ]
766786 for url in urls :
767787 with self .assertRaises (UnsafeProtocolError ):
768788 remote .fetch (url )
789+ assert not tmp_file .exists ()
769790
770791 @with_rw_repo ("HEAD" )
771792 def test_fetch_unsafe_url_allowed (self , rw_repo ):
793+ tmp_dir = Path (tempfile .mkdtemp ())
794+ tmp_file = tmp_dir / "pwn"
772795 remote = rw_repo .remote ("origin" )
773796 urls = [
774- "ext::sh -c touch% /tmp/pwn " ,
797+ f "ext::sh -c touch% { tmp_file } " ,
775798 "fd::17/foo" ,
776799 ]
777800 for url in urls :
778801 # The URL will be allowed into the command, but the command will
779802 # fail since we don't have that protocol enabled in the Git config file.
780803 with self .assertRaises (GitCommandError ):
781804 remote .fetch (url , allow_unsafe_protocols = True )
805+ assert not tmp_file .exists ()
782806
783807 @with_rw_repo ("HEAD" )
784808 def test_fetch_unsafe_options (self , rw_repo ):
@@ -789,6 +813,7 @@ def test_fetch_unsafe_options(self, rw_repo):
789813 for unsafe_option in unsafe_options :
790814 with self .assertRaises (UnsafeOptionError ):
791815 remote .fetch (** unsafe_option )
816+ assert not tmp_file .exists ()
792817
793818 @with_rw_repo ("HEAD" )
794819 def test_fetch_unsafe_options_allowed (self , rw_repo ):
@@ -798,32 +823,40 @@ def test_fetch_unsafe_options_allowed(self, rw_repo):
798823 unsafe_options = [{"upload-pack" : f"touch { tmp_file } " }]
799824 for unsafe_option in unsafe_options :
800825 # The options will be allowed, but the command will fail.
826+ assert not tmp_file .exists ()
801827 with self .assertRaises (GitCommandError ):
802828 remote .fetch (** unsafe_option , allow_unsafe_options = True )
829+ assert tmp_file .exists ()
803830
804831 @with_rw_repo ("HEAD" )
805832 def test_pull_unsafe_url (self , rw_repo ):
833+ tmp_dir = Path (tempfile .mkdtemp ())
834+ tmp_file = tmp_dir / "pwn"
806835 remote = rw_repo .remote ("origin" )
807836 urls = [
808- "ext::sh -c touch% /tmp/pwn " ,
837+ f "ext::sh -c touch% { tmp_file } " ,
809838 "fd::17/foo" ,
810839 ]
811840 for url in urls :
812841 with self .assertRaises (UnsafeProtocolError ):
813842 remote .pull (url )
843+ assert not tmp_file .exists ()
814844
815845 @with_rw_repo ("HEAD" )
816846 def test_pull_unsafe_url_allowed (self , rw_repo ):
847+ tmp_dir = Path (tempfile .mkdtemp ())
848+ tmp_file = tmp_dir / "pwn"
817849 remote = rw_repo .remote ("origin" )
818850 urls = [
819- "ext::sh -c touch% /tmp/pwn " ,
851+ f "ext::sh -c touch% { tmp_file } " ,
820852 "fd::17/foo" ,
821853 ]
822854 for url in urls :
823855 # The URL will be allowed into the command, but the command will
824856 # fail since we don't have that protocol enabled in the Git config file.
825857 with self .assertRaises (GitCommandError ):
826858 remote .pull (url , allow_unsafe_protocols = True )
859+ assert not tmp_file .exists ()
827860
828861 @with_rw_repo ("HEAD" )
829862 def test_pull_unsafe_options (self , rw_repo ):
@@ -834,6 +867,7 @@ def test_pull_unsafe_options(self, rw_repo):
834867 for unsafe_option in unsafe_options :
835868 with self .assertRaises (UnsafeOptionError ):
836869 remote .pull (** unsafe_option )
870+ assert not tmp_file .exists ()
837871
838872 @with_rw_repo ("HEAD" )
839873 def test_pull_unsafe_options_allowed (self , rw_repo ):
@@ -843,32 +877,40 @@ def test_pull_unsafe_options_allowed(self, rw_repo):
843877 unsafe_options = [{"upload-pack" : f"touch { tmp_file } " }]
844878 for unsafe_option in unsafe_options :
845879 # The options will be allowed, but the command will fail.
880+ assert not tmp_file .exists ()
846881 with self .assertRaises (GitCommandError ):
847882 remote .pull (** unsafe_option , allow_unsafe_options = True )
883+ assert tmp_file .exists ()
848884
849885 @with_rw_repo ("HEAD" )
850886 def test_push_unsafe_url (self , rw_repo ):
887+ tmp_dir = Path (tempfile .mkdtemp ())
888+ tmp_file = tmp_dir / "pwn"
851889 remote = rw_repo .remote ("origin" )
852890 urls = [
853- "ext::sh -c touch% /tmp/pwn " ,
891+ f "ext::sh -c touch% { tmp_file } " ,
854892 "fd::17/foo" ,
855893 ]
856894 for url in urls :
857895 with self .assertRaises (UnsafeProtocolError ):
858896 remote .push (url )
897+ assert not tmp_file .exists ()
859898
860899 @with_rw_repo ("HEAD" )
861900 def test_push_unsafe_url_allowed (self , rw_repo ):
901+ tmp_dir = Path (tempfile .mkdtemp ())
902+ tmp_file = tmp_dir / "pwn"
862903 remote = rw_repo .remote ("origin" )
863904 urls = [
864- "ext::sh -c touch% /tmp/pwn " ,
905+ f "ext::sh -c touch% { tmp_file } " ,
865906 "fd::17/foo" ,
866907 ]
867908 for url in urls :
868909 # The URL will be allowed into the command, but the command will
869910 # fail since we don't have that protocol enabled in the Git config file.
870911 with self .assertRaises (GitCommandError ):
871912 remote .push (url , allow_unsafe_protocols = True )
913+ assert not tmp_file .exists ()
872914
873915 @with_rw_repo ("HEAD" )
874916 def test_push_unsafe_options (self , rw_repo ):
@@ -882,8 +924,10 @@ def test_push_unsafe_options(self, rw_repo):
882924 }
883925 ]
884926 for unsafe_option in unsafe_options :
927+ assert not tmp_file .exists ()
885928 with self .assertRaises (UnsafeOptionError ):
886929 remote .push (** unsafe_option )
930+ assert not tmp_file .exists ()
887931
888932 @with_rw_repo ("HEAD" )
889933 def test_push_unsafe_options_allowed (self , rw_repo ):
@@ -898,8 +942,11 @@ def test_push_unsafe_options_allowed(self, rw_repo):
898942 ]
899943 for unsafe_option in unsafe_options :
900944 # The options will be allowed, but the command will fail.
945+ assert not tmp_file .exists ()
901946 with self .assertRaises (GitCommandError ):
902947 remote .push (** unsafe_option , allow_unsafe_options = True )
948+ assert tmp_file .exists ()
949+ tmp_file .unlink ()
903950
904951
905952class TestTimeouts (TestBase ):
0 commit comments