2 require 'helpers/git_test_helper'
4 # NOTE: calling Commit.find_commit_range(nil, nil, 'rev')
5 # produces an error message "fatal: bad object 'rev'" on stderr if
6 # 'rev' does not exist in a given repository. Many of these tests
7 # report such errors; their presence does not represent a fatal
10 class CommitTest < ActiveSupport::TestCase
11 # See git_setup.rb for the commit log for test.git.tar
15 authorize_with :active
18 test 'find_commit_range does not bypass permissions' do
19 authorize_with :inactive
20 assert_raises ArgumentError do
21 c = Commit.find_commit_range 'foo', nil, 'master', []
26 'https://github.com/curoverse/arvados.git',
27 'http://github.com/curoverse/arvados.git',
28 'git://github.com/curoverse/arvados.git',
30 test "find_commit_range uses fetch_remote_repository to get #{url}" do
31 fake_gitdir = repositories(:foo).server_path
32 Commit.expects(:cache_dir_for).once.with(url).returns fake_gitdir
33 Commit.expects(:fetch_remote_repository).once.with(fake_gitdir, url).returns true
34 c = Commit.find_commit_range url, nil, 'master', []
43 'file:///not/allowed.git',
44 'git.curoverse.com/arvados.git',
45 'github.com/curoverse/arvados.git',
47 test "find_commit_range skips fetch_remote_repository for #{url}" do
48 Commit.expects(:fetch_remote_repository).never
49 assert_raises ArgumentError do
50 Commit.find_commit_range url, nil, 'master', []
55 test 'fetch_remote_repository does not leak commits across repositories' do
56 url = "http://localhost:1/fake/fake.git"
57 fetch_remote_from_local_repo url, :foo
58 c = Commit.find_commit_range url, nil, 'master', []
59 assert_equal ['077ba2ad3ea24a929091a9e6ce545c93199b8e57'], c
61 url = "http://localhost:2/fake/fake.git"
62 fetch_remote_from_local_repo url, 'file://' + File.expand_path('../../.git', Rails.root)
63 c = Commit.find_commit_range url, nil, '077ba2ad3ea24a929091a9e6ce545c93199b8e57', []
67 test 'tag_in_internal_repository creates and updates tags in internal.git' do
68 authorize_with :active
69 gitint = "git --git-dir #{Rails.configuration.git_internal_dir}"
70 IO.read("|#{gitint} tag -d testtag 2>/dev/null") # "no such tag", fine
71 assert_match /^fatal: /, IO.read("|#{gitint} show testtag 2>&1")
73 Commit.tag_in_internal_repository 'active/foo', '31ce37fe365b3dc204300a3e4c396ad333ed0556', 'testtag'
74 assert_match /^commit 31ce37f/, IO.read("|#{gitint} show testtag")
78 test "find_commit_range laundry list" do
79 authorize_with :active
82 a = Commit.find_commit_range('active/foo', nil, '31ce37fe365b3dc204300a3e4c396ad333ed0556', nil)
83 assert_equal ['31ce37fe365b3dc204300a3e4c396ad333ed0556'], a
85 #test "test_branch1" do
86 a = Commit.find_commit_range('active/foo', nil, 'master', nil)
87 assert_includes(a, '077ba2ad3ea24a929091a9e6ce545c93199b8e57')
89 #test "test_branch2" do
90 a = Commit.find_commit_range('active/foo', nil, 'b1', nil)
91 assert_equal ['1de84a854e2b440dc53bf42f8548afa4c17da332'], a
93 #test "test_branch3" do
94 a = Commit.find_commit_range('active/foo', nil, 'HEAD', nil)
95 assert_equal ['1de84a854e2b440dc53bf42f8548afa4c17da332'], a
97 #test "test_single_revision_repo" do
98 a = Commit.find_commit_range('active/foo', nil, '31ce37fe365b3dc204300a3e4c396ad333ed0556', nil)
99 assert_equal ['31ce37fe365b3dc204300a3e4c396ad333ed0556'], a
100 a = Commit.find_commit_range('arvados', nil, '31ce37fe365b3dc204300a3e4c396ad333ed0556', nil)
103 #test "test_multi_revision" do
104 # complains "fatal: bad object 077ba2ad3ea24a929091a9e6ce545c93199b8e57"
105 a = Commit.find_commit_range('active/foo', '31ce37fe365b3dc204300a3e4c396ad333ed0556', '077ba2ad3ea24a929091a9e6ce545c93199b8e57', nil)
106 assert_equal ['077ba2ad3ea24a929091a9e6ce545c93199b8e57', '4fe459abe02d9b365932b8f5dc419439ab4e2577', '31ce37fe365b3dc204300a3e4c396ad333ed0556'], a
109 # complains "fatal: ambiguous argument 'tag1': unknown revision or path
110 # not in the working tree."
111 a = Commit.find_commit_range('active/foo', 'tag1', 'master', nil)
112 assert_equal ['077ba2ad3ea24a929091a9e6ce545c93199b8e57', '4fe459abe02d9b365932b8f5dc419439ab4e2577'], a
114 #test "test_multi_revision_exclude" do
115 a = Commit.find_commit_range('active/foo', '31ce37fe365b3dc204300a3e4c396ad333ed0556', '077ba2ad3ea24a929091a9e6ce545c93199b8e57', ['4fe459abe02d9b365932b8f5dc419439ab4e2577'])
116 assert_equal ['077ba2ad3ea24a929091a9e6ce545c93199b8e57', '31ce37fe365b3dc204300a3e4c396ad333ed0556'], a
118 #test "test_multi_revision_tagged_exclude" do
119 # complains "fatal: bad object 077ba2ad3ea24a929091a9e6ce545c93199b8e57"
120 a = Commit.find_commit_range('active/foo', '31ce37fe365b3dc204300a3e4c396ad333ed0556', '077ba2ad3ea24a929091a9e6ce545c93199b8e57', ['tag1'])
121 assert_equal ['077ba2ad3ea24a929091a9e6ce545c93199b8e57', '31ce37fe365b3dc204300a3e4c396ad333ed0556'], a
123 Dir.mktmpdir do |touchdir|
124 # invalid input to maximum
125 a = Commit.find_commit_range('active/foo', nil, "31ce37fe365b3dc204300a3e4c396ad333ed0556 ; touch #{touchdir}/uh_oh", nil)
126 assert !File.exists?("#{touchdir}/uh_oh"), "#{touchdir}/uh_oh should not exist, 'maximum' parameter of find_commit_range is exploitable"
129 # invalid input to maximum
130 a = Commit.find_commit_range('active/foo', nil, "$(uname>#{touchdir}/uh_oh)", nil)
131 assert !File.exists?("#{touchdir}/uh_oh"), "#{touchdir}/uh_oh should not exist, 'maximum' parameter of find_commit_range is exploitable"
134 # invalid input to minimum
135 a = Commit.find_commit_range('active/foo', "31ce37fe365b3dc204300a3e4c396ad333ed0556 ; touch #{touchdir}/uh_oh", "31ce37fe365b3dc204300a3e4c396ad333ed0556", nil)
136 assert !File.exists?("#{touchdir}/uh_oh"), "#{touchdir}/uh_oh should not exist, 'minimum' parameter of find_commit_range is exploitable"
139 # invalid input to minimum
140 a = Commit.find_commit_range('active/foo', "$(uname>#{touchdir}/uh_oh)", "31ce37fe365b3dc204300a3e4c396ad333ed0556", nil)
141 assert !File.exists?("#{touchdir}/uh_oh"), "#{touchdir}/uh_oh should not exist, 'minimum' parameter of find_commit_range is exploitable"
144 # invalid input to 'excludes'
145 # complains "fatal: bad object 077ba2ad3ea24a929091a9e6ce545c93199b8e57"
146 a = Commit.find_commit_range('active/foo', "31ce37fe365b3dc204300a3e4c396ad333ed0556", "077ba2ad3ea24a929091a9e6ce545c93199b8e57", ["4fe459abe02d9b365932b8f5dc419439ab4e2577 ; touch #{touchdir}/uh_oh"])
147 assert !File.exists?("#{touchdir}/uh_oh"), "#{touchdir}/uh_oh should not exist, 'excludes' parameter of find_commit_range is exploitable"
150 # invalid input to 'excludes'
151 # complains "fatal: bad object 077ba2ad3ea24a929091a9e6ce545c93199b8e57"
152 a = Commit.find_commit_range('active/foo', "31ce37fe365b3dc204300a3e4c396ad333ed0556", "077ba2ad3ea24a929091a9e6ce545c93199b8e57", ["$(uname>#{touchdir}/uh_oh)"])
153 assert !File.exists?("#{touchdir}/uh_oh"), "#{touchdir}/uh_oh should not exist, 'excludes' parameter of find_commit_range is exploitable"