Skip to content

Commit f4f2658

Browse files
committed
Updates from review
1 parent 9dc4392 commit f4f2658

File tree

4 files changed

+110
-17
lines changed

4 files changed

+110
-17
lines changed

Diff for: AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,5 @@ Contributors are:
5050
-Patrick Gerard
5151
-Luke Twist <[email protected]>
5252
-Joseph Hale <me _at_ jhale.dev>
53+
-Santos Gallegos <stsewd _at_ proton.me>
5354
Portions derived from other open source works and are clearly marked.

Diff for: test/test_remote.py

+59-12
Original file line numberDiff line numberDiff line change
@@ -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

905952
class TestTimeouts(TestBase):

Diff for: test/test_repo.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ def test_clone_unsafe_options(self, rw_repo):
279279
for unsafe_option in unsafe_options:
280280
with self.assertRaises(UnsafeOptionError):
281281
rw_repo.clone(tmp_dir, multi_options=[unsafe_option])
282+
assert not tmp_file.exists()
282283

283284
@with_rw_repo("HEAD")
284285
def test_clone_unsafe_options_allowed(self, rw_repo):
@@ -290,9 +291,12 @@ def test_clone_unsafe_options_allowed(self, rw_repo):
290291
]
291292
for i, unsafe_option in enumerate(unsafe_options):
292293
destination = tmp_dir / str(i)
294+
assert not tmp_file.exists()
293295
# The options will be allowed, but the command will fail.
294296
with self.assertRaises(GitCommandError):
295297
rw_repo.clone(destination, multi_options=[unsafe_option], allow_unsafe_options=True)
298+
assert tmp_file.exists()
299+
tmp_file.unlink()
296300

297301
unsafe_options = [
298302
"--config=protocol.ext.allow=always",
@@ -331,6 +335,7 @@ def test_clone_from_unsafe_options(self, rw_repo):
331335
for unsafe_option in unsafe_options:
332336
with self.assertRaises(UnsafeOptionError):
333337
Repo.clone_from(rw_repo.working_dir, tmp_dir, multi_options=[unsafe_option])
338+
assert not tmp_file.exists()
334339

335340
@with_rw_repo("HEAD")
336341
def test_clone_from_unsafe_options_allowed(self, rw_repo):
@@ -342,11 +347,14 @@ def test_clone_from_unsafe_options_allowed(self, rw_repo):
342347
]
343348
for i, unsafe_option in enumerate(unsafe_options):
344349
destination = tmp_dir / str(i)
350+
assert not tmp_file.exists()
345351
# The options will be allowed, but the command will fail.
346352
with self.assertRaises(GitCommandError):
347353
Repo.clone_from(
348354
rw_repo.working_dir, destination, multi_options=[unsafe_option], allow_unsafe_options=True
349355
)
356+
assert tmp_file.exists()
357+
tmp_file.unlink()
350358

351359
unsafe_options = [
352360
"--config=protocol.ext.allow=always",
@@ -374,16 +382,19 @@ def test_clone_from_safe_options(self, rw_repo):
374382

375383
def test_clone_from_unsafe_procol(self):
376384
tmp_dir = pathlib.Path(tempfile.mkdtemp())
385+
tmp_file = tmp_dir / "pwn"
377386
urls = [
378-
"ext::sh -c touch% /tmp/pwn",
387+
f"ext::sh -c touch% {tmp_file}",
379388
"fd::17/foo",
380389
]
381390
for url in urls:
382391
with self.assertRaises(UnsafeProtocolError):
383392
Repo.clone_from(url, tmp_dir)
393+
assert not tmp_file.exists()
384394

385395
def test_clone_from_unsafe_procol_allowed(self):
386396
tmp_dir = pathlib.Path(tempfile.mkdtemp())
397+
tmp_file = tmp_dir / "pwn"
387398
urls = [
388399
"ext::sh -c touch% /tmp/pwn",
389400
"fd::/foo",
@@ -393,6 +404,7 @@ def test_clone_from_unsafe_procol_allowed(self):
393404
# fail since we don't have that protocol enabled in the Git config file.
394405
with self.assertRaises(GitCommandError):
395406
Repo.clone_from(url, tmp_dir, allow_unsafe_protocols=True)
407+
assert not tmp_file.exists()
396408

397409
@with_rw_repo("HEAD")
398410
def test_max_chunk_size(self, repo):

0 commit comments

Comments
 (0)