@@ -694,91 +694,115 @@ def test_push_error(self, repo):
694
694
695
695
@with_rw_repo ("HEAD" )
696
696
def test_set_unsafe_url (self , rw_repo ):
697
+ tmp_dir = Path (tempfile .mkdtemp ())
698
+ tmp_file = tmp_dir / "pwn"
697
699
remote = rw_repo .remote ("origin" )
698
700
urls = [
699
- "ext::sh -c touch% /tmp/pwn " ,
701
+ f "ext::sh -c touch% { tmp_file } " ,
700
702
"fd::17/foo" ,
701
703
]
702
704
for url in urls :
703
705
with self .assertRaises (UnsafeProtocolError ):
704
706
remote .set_url (url )
707
+ assert not tmp_file .exists ()
705
708
706
709
@with_rw_repo ("HEAD" )
707
710
def test_set_unsafe_url_allowed (self , rw_repo ):
711
+ tmp_dir = Path (tempfile .mkdtemp ())
712
+ tmp_file = tmp_dir / "pwn"
708
713
remote = rw_repo .remote ("origin" )
709
714
urls = [
710
- "ext::sh -c touch% /tmp/pwn " ,
715
+ f "ext::sh -c touch% { tmp_file } " ,
711
716
"fd::17/foo" ,
712
717
]
713
718
for url in urls :
714
719
remote .set_url (url , allow_unsafe_protocols = True )
715
720
assert list (remote .urls )[- 1 ] == url
721
+ assert not tmp_file .exists ()
716
722
717
723
@with_rw_repo ("HEAD" )
718
724
def test_add_unsafe_url (self , rw_repo ):
725
+ tmp_dir = Path (tempfile .mkdtemp ())
726
+ tmp_file = tmp_dir / "pwn"
719
727
remote = rw_repo .remote ("origin" )
720
728
urls = [
721
- "ext::sh -c touch% /tmp/pwn " ,
729
+ f "ext::sh -c touch% { tmp_file } " ,
722
730
"fd::17/foo" ,
723
731
]
724
732
for url in urls :
725
733
with self .assertRaises (UnsafeProtocolError ):
726
734
remote .add_url (url )
735
+ assert not tmp_file .exists ()
727
736
728
737
@with_rw_repo ("HEAD" )
729
738
def test_add_unsafe_url_allowed (self , rw_repo ):
739
+ tmp_dir = Path (tempfile .mkdtemp ())
740
+ tmp_file = tmp_dir / "pwn"
730
741
remote = rw_repo .remote ("origin" )
731
742
urls = [
732
- "ext::sh -c touch% /tmp/pwn " ,
743
+ f "ext::sh -c touch% { tmp_file } " ,
733
744
"fd::17/foo" ,
734
745
]
735
746
for url in urls :
736
747
remote .add_url (url , allow_unsafe_protocols = True )
737
748
assert list (remote .urls )[- 1 ] == url
749
+ assert not tmp_file .exists ()
738
750
739
751
@with_rw_repo ("HEAD" )
740
752
def test_create_remote_unsafe_url (self , rw_repo ):
753
+ tmp_dir = Path (tempfile .mkdtemp ())
754
+ tmp_file = tmp_dir / "pwn"
741
755
urls = [
742
- "ext::sh -c touch% /tmp/pwn " ,
756
+ f "ext::sh -c touch% { tmp_file } " ,
743
757
"fd::17/foo" ,
744
758
]
745
759
for url in urls :
746
760
with self .assertRaises (UnsafeProtocolError ):
747
761
Remote .create (rw_repo , "origin" , url )
762
+ assert not tmp_file .exists ()
748
763
749
764
@with_rw_repo ("HEAD" )
750
765
def test_create_remote_unsafe_url_allowed (self , rw_repo ):
766
+ tmp_dir = Path (tempfile .mkdtemp ())
767
+ tmp_file = tmp_dir / "pwn"
751
768
urls = [
752
- "ext::sh -c touch% /tmp/pwn " ,
769
+ f "ext::sh -c touch% { tmp_file } " ,
753
770
"fd::17/foo" ,
754
771
]
755
772
for i , url in enumerate (urls ):
756
773
remote = Remote .create (rw_repo , f"origin{ i } " , url , allow_unsafe_protocols = True )
757
774
assert remote .url == url
775
+ assert not tmp_file .exists ()
758
776
759
777
@with_rw_repo ("HEAD" )
760
778
def test_fetch_unsafe_url (self , rw_repo ):
779
+ tmp_dir = Path (tempfile .mkdtemp ())
780
+ tmp_file = tmp_dir / "pwn"
761
781
remote = rw_repo .remote ("origin" )
762
782
urls = [
763
- "ext::sh -c touch% /tmp/pwn " ,
783
+ f "ext::sh -c touch% { tmp_file } " ,
764
784
"fd::17/foo" ,
765
785
]
766
786
for url in urls :
767
787
with self .assertRaises (UnsafeProtocolError ):
768
788
remote .fetch (url )
789
+ assert not tmp_file .exists ()
769
790
770
791
@with_rw_repo ("HEAD" )
771
792
def test_fetch_unsafe_url_allowed (self , rw_repo ):
793
+ tmp_dir = Path (tempfile .mkdtemp ())
794
+ tmp_file = tmp_dir / "pwn"
772
795
remote = rw_repo .remote ("origin" )
773
796
urls = [
774
- "ext::sh -c touch% /tmp/pwn " ,
797
+ f "ext::sh -c touch% { tmp_file } " ,
775
798
"fd::17/foo" ,
776
799
]
777
800
for url in urls :
778
801
# The URL will be allowed into the command, but the command will
779
802
# fail since we don't have that protocol enabled in the Git config file.
780
803
with self .assertRaises (GitCommandError ):
781
804
remote .fetch (url , allow_unsafe_protocols = True )
805
+ assert not tmp_file .exists ()
782
806
783
807
@with_rw_repo ("HEAD" )
784
808
def test_fetch_unsafe_options (self , rw_repo ):
@@ -789,6 +813,7 @@ def test_fetch_unsafe_options(self, rw_repo):
789
813
for unsafe_option in unsafe_options :
790
814
with self .assertRaises (UnsafeOptionError ):
791
815
remote .fetch (** unsafe_option )
816
+ assert not tmp_file .exists ()
792
817
793
818
@with_rw_repo ("HEAD" )
794
819
def test_fetch_unsafe_options_allowed (self , rw_repo ):
@@ -798,32 +823,40 @@ def test_fetch_unsafe_options_allowed(self, rw_repo):
798
823
unsafe_options = [{"upload-pack" : f"touch { tmp_file } " }]
799
824
for unsafe_option in unsafe_options :
800
825
# The options will be allowed, but the command will fail.
826
+ assert not tmp_file .exists ()
801
827
with self .assertRaises (GitCommandError ):
802
828
remote .fetch (** unsafe_option , allow_unsafe_options = True )
829
+ assert tmp_file .exists ()
803
830
804
831
@with_rw_repo ("HEAD" )
805
832
def test_pull_unsafe_url (self , rw_repo ):
833
+ tmp_dir = Path (tempfile .mkdtemp ())
834
+ tmp_file = tmp_dir / "pwn"
806
835
remote = rw_repo .remote ("origin" )
807
836
urls = [
808
- "ext::sh -c touch% /tmp/pwn " ,
837
+ f "ext::sh -c touch% { tmp_file } " ,
809
838
"fd::17/foo" ,
810
839
]
811
840
for url in urls :
812
841
with self .assertRaises (UnsafeProtocolError ):
813
842
remote .pull (url )
843
+ assert not tmp_file .exists ()
814
844
815
845
@with_rw_repo ("HEAD" )
816
846
def test_pull_unsafe_url_allowed (self , rw_repo ):
847
+ tmp_dir = Path (tempfile .mkdtemp ())
848
+ tmp_file = tmp_dir / "pwn"
817
849
remote = rw_repo .remote ("origin" )
818
850
urls = [
819
- "ext::sh -c touch% /tmp/pwn " ,
851
+ f "ext::sh -c touch% { tmp_file } " ,
820
852
"fd::17/foo" ,
821
853
]
822
854
for url in urls :
823
855
# The URL will be allowed into the command, but the command will
824
856
# fail since we don't have that protocol enabled in the Git config file.
825
857
with self .assertRaises (GitCommandError ):
826
858
remote .pull (url , allow_unsafe_protocols = True )
859
+ assert not tmp_file .exists ()
827
860
828
861
@with_rw_repo ("HEAD" )
829
862
def test_pull_unsafe_options (self , rw_repo ):
@@ -834,6 +867,7 @@ def test_pull_unsafe_options(self, rw_repo):
834
867
for unsafe_option in unsafe_options :
835
868
with self .assertRaises (UnsafeOptionError ):
836
869
remote .pull (** unsafe_option )
870
+ assert not tmp_file .exists ()
837
871
838
872
@with_rw_repo ("HEAD" )
839
873
def test_pull_unsafe_options_allowed (self , rw_repo ):
@@ -843,32 +877,40 @@ def test_pull_unsafe_options_allowed(self, rw_repo):
843
877
unsafe_options = [{"upload-pack" : f"touch { tmp_file } " }]
844
878
for unsafe_option in unsafe_options :
845
879
# The options will be allowed, but the command will fail.
880
+ assert not tmp_file .exists ()
846
881
with self .assertRaises (GitCommandError ):
847
882
remote .pull (** unsafe_option , allow_unsafe_options = True )
883
+ assert tmp_file .exists ()
848
884
849
885
@with_rw_repo ("HEAD" )
850
886
def test_push_unsafe_url (self , rw_repo ):
887
+ tmp_dir = Path (tempfile .mkdtemp ())
888
+ tmp_file = tmp_dir / "pwn"
851
889
remote = rw_repo .remote ("origin" )
852
890
urls = [
853
- "ext::sh -c touch% /tmp/pwn " ,
891
+ f "ext::sh -c touch% { tmp_file } " ,
854
892
"fd::17/foo" ,
855
893
]
856
894
for url in urls :
857
895
with self .assertRaises (UnsafeProtocolError ):
858
896
remote .push (url )
897
+ assert not tmp_file .exists ()
859
898
860
899
@with_rw_repo ("HEAD" )
861
900
def test_push_unsafe_url_allowed (self , rw_repo ):
901
+ tmp_dir = Path (tempfile .mkdtemp ())
902
+ tmp_file = tmp_dir / "pwn"
862
903
remote = rw_repo .remote ("origin" )
863
904
urls = [
864
- "ext::sh -c touch% /tmp/pwn " ,
905
+ f "ext::sh -c touch% { tmp_file } " ,
865
906
"fd::17/foo" ,
866
907
]
867
908
for url in urls :
868
909
# The URL will be allowed into the command, but the command will
869
910
# fail since we don't have that protocol enabled in the Git config file.
870
911
with self .assertRaises (GitCommandError ):
871
912
remote .push (url , allow_unsafe_protocols = True )
913
+ assert not tmp_file .exists ()
872
914
873
915
@with_rw_repo ("HEAD" )
874
916
def test_push_unsafe_options (self , rw_repo ):
@@ -882,8 +924,10 @@ def test_push_unsafe_options(self, rw_repo):
882
924
}
883
925
]
884
926
for unsafe_option in unsafe_options :
927
+ assert not tmp_file .exists ()
885
928
with self .assertRaises (UnsafeOptionError ):
886
929
remote .push (** unsafe_option )
930
+ assert not tmp_file .exists ()
887
931
888
932
@with_rw_repo ("HEAD" )
889
933
def test_push_unsafe_options_allowed (self , rw_repo ):
@@ -898,8 +942,11 @@ def test_push_unsafe_options_allowed(self, rw_repo):
898
942
]
899
943
for unsafe_option in unsafe_options :
900
944
# The options will be allowed, but the command will fail.
945
+ assert not tmp_file .exists ()
901
946
with self .assertRaises (GitCommandError ):
902
947
remote .push (** unsafe_option , allow_unsafe_options = True )
948
+ assert tmp_file .exists ()
949
+ tmp_file .unlink ()
903
950
904
951
905
952
class TestTimeouts (TestBase ):
0 commit comments