|
23 | 23 | GitCommandError,
|
24 | 24 | )
|
25 | 25 | fromgit.cmdimportGit
|
| 26 | +frompathlibimportPath |
| 27 | +fromgit.excimportUnsafeOptionError,UnsafeProtocolError |
26 | 28 | fromtest.libimport (
|
27 | 29 | TestBase,
|
28 | 30 | with_rw_repo,
|
@@ -690,6 +692,215 @@ def test_push_error(self, repo):
|
690 | 692 | withself.assertRaisesRegex(GitCommandError,"src refspec __BAD_REF__ does not match any"):
|
691 | 693 | rem.push("__BAD_REF__")
|
692 | 694 |
|
| 695 | +@with_rw_repo("HEAD") |
| 696 | +deftest_set_unsafe_url(self,rw_repo): |
| 697 | +remote=rw_repo.remote("origin") |
| 698 | +urls= [ |
| 699 | +"ext::sh -c touch% /tmp/pwn", |
| 700 | +"fd::17/foo", |
| 701 | + ] |
| 702 | +forurlinurls: |
| 703 | +withself.assertRaises(UnsafeProtocolError): |
| 704 | +remote.set_url(url) |
| 705 | + |
| 706 | +@with_rw_repo("HEAD") |
| 707 | +deftest_set_unsafe_url_allowed(self,rw_repo): |
| 708 | +remote=rw_repo.remote("origin") |
| 709 | +urls= [ |
| 710 | +"ext::sh -c touch% /tmp/pwn", |
| 711 | +"fd::17/foo", |
| 712 | + ] |
| 713 | +forurlinurls: |
| 714 | +remote.set_url(url,allow_unsafe_protocols=True) |
| 715 | +assertlist(remote.urls)[-1]==url |
| 716 | + |
| 717 | +@with_rw_repo("HEAD") |
| 718 | +deftest_add_unsafe_url(self,rw_repo): |
| 719 | +remote=rw_repo.remote("origin") |
| 720 | +urls= [ |
| 721 | +"ext::sh -c touch% /tmp/pwn", |
| 722 | +"fd::17/foo", |
| 723 | + ] |
| 724 | +forurlinurls: |
| 725 | +withself.assertRaises(UnsafeProtocolError): |
| 726 | +remote.add_url(url) |
| 727 | + |
| 728 | +@with_rw_repo("HEAD") |
| 729 | +deftest_add_unsafe_url_allowed(self,rw_repo): |
| 730 | +remote=rw_repo.remote("origin") |
| 731 | +urls= [ |
| 732 | +"ext::sh -c touch% /tmp/pwn", |
| 733 | +"fd::17/foo", |
| 734 | + ] |
| 735 | +forurlinurls: |
| 736 | +remote.add_url(url,allow_unsafe_protocols=True) |
| 737 | +assertlist(remote.urls)[-1]==url |
| 738 | + |
| 739 | +@with_rw_repo("HEAD") |
| 740 | +deftest_create_remote_unsafe_url(self,rw_repo): |
| 741 | +urls= [ |
| 742 | +"ext::sh -c touch% /tmp/pwn", |
| 743 | +"fd::17/foo", |
| 744 | + ] |
| 745 | +forurlinurls: |
| 746 | +withself.assertRaises(UnsafeProtocolError): |
| 747 | +Remote.create(rw_repo,"origin",url) |
| 748 | + |
| 749 | +@with_rw_repo("HEAD") |
| 750 | +deftest_create_remote_unsafe_url_allowed(self,rw_repo): |
| 751 | +urls= [ |
| 752 | +"ext::sh -c touch% /tmp/pwn", |
| 753 | +"fd::17/foo", |
| 754 | + ] |
| 755 | +fori,urlinenumerate(urls): |
| 756 | +remote=Remote.create(rw_repo,f"origin{i}",url,allow_unsafe_protocols=True) |
| 757 | +assertremote.url==url |
| 758 | + |
| 759 | +@with_rw_repo("HEAD") |
| 760 | +deftest_fetch_unsafe_url(self,rw_repo): |
| 761 | +remote=rw_repo.remote("origin") |
| 762 | +urls= [ |
| 763 | +"ext::sh -c touch% /tmp/pwn", |
| 764 | +"fd::17/foo", |
| 765 | + ] |
| 766 | +forurlinurls: |
| 767 | +withself.assertRaises(UnsafeProtocolError): |
| 768 | +remote.fetch(url) |
| 769 | + |
| 770 | +@with_rw_repo("HEAD") |
| 771 | +deftest_fetch_unsafe_url_allowed(self,rw_repo): |
| 772 | +remote=rw_repo.remote("origin") |
| 773 | +urls= [ |
| 774 | +"ext::sh -c touch% /tmp/pwn", |
| 775 | +"fd::17/foo", |
| 776 | + ] |
| 777 | +forurlinurls: |
| 778 | +# The URL will be allowed into the command, but the command will |
| 779 | +# fail since we don't have that protocol enabled in the Git config file. |
| 780 | +withself.assertRaises(GitCommandError): |
| 781 | +remote.fetch(url,allow_unsafe_protocols=True) |
| 782 | + |
| 783 | +@with_rw_repo("HEAD") |
| 784 | +deftest_fetch_unsafe_options(self,rw_repo): |
| 785 | +remote=rw_repo.remote("origin") |
| 786 | +tmp_dir=Path(tempfile.mkdtemp()) |
| 787 | +tmp_file=tmp_dir/"pwn" |
| 788 | +unsafe_options= [{"upload-pack":f"touch{tmp_file}"}] |
| 789 | +forunsafe_optioninunsafe_options: |
| 790 | +withself.assertRaises(UnsafeOptionError): |
| 791 | +remote.fetch(**unsafe_option) |
| 792 | + |
| 793 | +@with_rw_repo("HEAD") |
| 794 | +deftest_fetch_unsafe_options_allowed(self,rw_repo): |
| 795 | +remote=rw_repo.remote("origin") |
| 796 | +tmp_dir=Path(tempfile.mkdtemp()) |
| 797 | +tmp_file=tmp_dir/"pwn" |
| 798 | +unsafe_options= [{"upload-pack":f"touch{tmp_file}"}] |
| 799 | +forunsafe_optioninunsafe_options: |
| 800 | +# The options will be allowed, but the command will fail. |
| 801 | +withself.assertRaises(GitCommandError): |
| 802 | +remote.fetch(**unsafe_option,allow_unsafe_options=True) |
| 803 | + |
| 804 | +@with_rw_repo("HEAD") |
| 805 | +deftest_pull_unsafe_url(self,rw_repo): |
| 806 | +remote=rw_repo.remote("origin") |
| 807 | +urls= [ |
| 808 | +"ext::sh -c touch% /tmp/pwn", |
| 809 | +"fd::17/foo", |
| 810 | + ] |
| 811 | +forurlinurls: |
| 812 | +withself.assertRaises(UnsafeProtocolError): |
| 813 | +remote.pull(url) |
| 814 | + |
| 815 | +@with_rw_repo("HEAD") |
| 816 | +deftest_pull_unsafe_url_allowed(self,rw_repo): |
| 817 | +remote=rw_repo.remote("origin") |
| 818 | +urls= [ |
| 819 | +"ext::sh -c touch% /tmp/pwn", |
| 820 | +"fd::17/foo", |
| 821 | + ] |
| 822 | +forurlinurls: |
| 823 | +# The URL will be allowed into the command, but the command will |
| 824 | +# fail since we don't have that protocol enabled in the Git config file. |
| 825 | +withself.assertRaises(GitCommandError): |
| 826 | +remote.pull(url,allow_unsafe_protocols=True) |
| 827 | + |
| 828 | +@with_rw_repo("HEAD") |
| 829 | +deftest_pull_unsafe_options(self,rw_repo): |
| 830 | +remote=rw_repo.remote("origin") |
| 831 | +tmp_dir=Path(tempfile.mkdtemp()) |
| 832 | +tmp_file=tmp_dir/"pwn" |
| 833 | +unsafe_options= [{"upload-pack":f"touch{tmp_file}"}] |
| 834 | +forunsafe_optioninunsafe_options: |
| 835 | +withself.assertRaises(UnsafeOptionError): |
| 836 | +remote.pull(**unsafe_option) |
| 837 | + |
| 838 | +@with_rw_repo("HEAD") |
| 839 | +deftest_pull_unsafe_options_allowed(self,rw_repo): |
| 840 | +remote=rw_repo.remote("origin") |
| 841 | +tmp_dir=Path(tempfile.mkdtemp()) |
| 842 | +tmp_file=tmp_dir/"pwn" |
| 843 | +unsafe_options= [{"upload-pack":f"touch{tmp_file}"}] |
| 844 | +forunsafe_optioninunsafe_options: |
| 845 | +# The options will be allowed, but the command will fail. |
| 846 | +withself.assertRaises(GitCommandError): |
| 847 | +remote.pull(**unsafe_option,allow_unsafe_options=True) |
| 848 | + |
| 849 | +@with_rw_repo("HEAD") |
| 850 | +deftest_push_unsafe_url(self,rw_repo): |
| 851 | +remote=rw_repo.remote("origin") |
| 852 | +urls= [ |
| 853 | +"ext::sh -c touch% /tmp/pwn", |
| 854 | +"fd::17/foo", |
| 855 | + ] |
| 856 | +forurlinurls: |
| 857 | +withself.assertRaises(UnsafeProtocolError): |
| 858 | +remote.push(url) |
| 859 | + |
| 860 | +@with_rw_repo("HEAD") |
| 861 | +deftest_push_unsafe_url_allowed(self,rw_repo): |
| 862 | +remote=rw_repo.remote("origin") |
| 863 | +urls= [ |
| 864 | +"ext::sh -c touch% /tmp/pwn", |
| 865 | +"fd::17/foo", |
| 866 | + ] |
| 867 | +forurlinurls: |
| 868 | +# The URL will be allowed into the command, but the command will |
| 869 | +# fail since we don't have that protocol enabled in the Git config file. |
| 870 | +withself.assertRaises(GitCommandError): |
| 871 | +remote.push(url,allow_unsafe_protocols=True) |
| 872 | + |
| 873 | +@with_rw_repo("HEAD") |
| 874 | +deftest_push_unsafe_options(self,rw_repo): |
| 875 | +remote=rw_repo.remote("origin") |
| 876 | +tmp_dir=Path(tempfile.mkdtemp()) |
| 877 | +tmp_file=tmp_dir/"pwn" |
| 878 | +unsafe_options= [ |
| 879 | + { |
| 880 | +"receive-pack":f"touch{tmp_file}", |
| 881 | +"exec":f"touch{tmp_file}", |
| 882 | + } |
| 883 | + ] |
| 884 | +forunsafe_optioninunsafe_options: |
| 885 | +withself.assertRaises(UnsafeOptionError): |
| 886 | +remote.push(**unsafe_option) |
| 887 | + |
| 888 | +@with_rw_repo("HEAD") |
| 889 | +deftest_push_unsafe_options_allowed(self,rw_repo): |
| 890 | +remote=rw_repo.remote("origin") |
| 891 | +tmp_dir=Path(tempfile.mkdtemp()) |
| 892 | +tmp_file=tmp_dir/"pwn" |
| 893 | +unsafe_options= [ |
| 894 | + { |
| 895 | +"receive-pack":f"touch{tmp_file}", |
| 896 | +"exec":f"touch{tmp_file}", |
| 897 | + } |
| 898 | + ] |
| 899 | +forunsafe_optioninunsafe_options: |
| 900 | +# The options will be allowed, but the command will fail. |
| 901 | +withself.assertRaises(GitCommandError): |
| 902 | +remote.push(**unsafe_option,allow_unsafe_options=True) |
| 903 | + |
693 | 904 |
|
694 | 905 | classTestTimeouts(TestBase):
|
695 | 906 | @with_rw_repo("HEAD",bare=False)
|
|