2 require 'helpers/git_test_helper'
4 # NOTE: calling Commit.find_commit_range(user, 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
14 test 'find_commit_range does not bypass permissions' do
15 assert_raises ArgumentError do
16 c = Commit.find_commit_range users(:inactive), 'foo', nil, 'master', []
21 'https://github.com/curoverse/arvados.git',
22 'http://github.com/curoverse/arvados.git',
23 'git://github.com/curoverse/arvados.git',
25 test "find_commit_range uses fetch_remote_repository to get #{url}" do
26 fake_gitdir = repositories(:foo).server_path
27 Commit.expects(:fetch_remote_repository).
28 once.with(Commit.cache_dir_for(url), url).returns fake_gitdir
29 c = Commit.find_commit_range users(:active), url, nil, 'master', []
38 'file:///not/allowed.git',
39 'git.curoverse.com/arvados.git',
40 'github.com/curoverse/arvados.git',
42 test "find_commit_range skips fetch_remote_repository for #{url}" do
43 Commit.expects(:fetch_remote_repository).never
44 assert_raises ArgumentError do
45 Commit.find_commit_range users(:active), url, nil, 'master', []
50 test 'fetch_remote_repository does not leak commits across repositories' do
51 url = "http://localhost:1/fake/fake.git"
52 fetch_remote_from_local_repo url, :foo
53 c = Commit.find_commit_range users(:active), url, nil, 'master', []
54 assert_equal ['077ba2ad3ea24a929091a9e6ce545c93199b8e57'], c
56 url = "http://localhost:2/fake/fake.git"
57 fetch_remote_from_local_repo url, 'file://' + File.expand_path('../../.git', Rails.root)
58 c = Commit.find_commit_range users(:active), url, nil, '077ba2ad3ea24a929091a9e6ce545c93199b8e57', []
62 test 'fetch_remote_repository finds versions' do
63 skip 'not written yet'
66 test 'tag_in_internal_repository creates and updates tags in internal.git' do
67 authorize_with :active
68 gitint = "git --git-dir #{Rails.configuration.git_internal_dir}"
69 IO.read("|#{gitint} tag -d testtag 2>/dev/null") # "no such tag", fine
70 assert_match /^fatal: /, IO.read("|#{gitint} show testtag 2>&1")
72 Commit.tag_in_internal_repository 'active/foo', '31ce37fe365b3dc204300a3e4c396ad333ed0556', 'testtag'
73 assert_match /^commit 31ce37f/, IO.read("|#{gitint} show testtag")
77 test "find_commit_range laundry list" do
78 authorize_with :active
81 a = Commit.find_commit_range(users(:active), 'active/foo', nil, '31ce37fe365b3dc204300a3e4c396ad333ed0556', nil)
82 assert_equal ['31ce37fe365b3dc204300a3e4c396ad333ed0556'], a
84 #test "test_branch1" do
85 a = Commit.find_commit_range(users(:active), 'active/foo', nil, 'master', nil)
86 assert_includes(a, '077ba2ad3ea24a929091a9e6ce545c93199b8e57')
88 #test "test_branch2" do
89 a = Commit.find_commit_range(users(:active), 'active/foo', nil, 'b1', nil)
90 assert_equal ['1de84a854e2b440dc53bf42f8548afa4c17da332'], a
92 #test "test_branch3" do
93 a = Commit.find_commit_range(users(:active), 'active/foo', nil, 'HEAD', nil)
94 assert_equal ['1de84a854e2b440dc53bf42f8548afa4c17da332'], a
96 #test "test_single_revision_repo" do
97 a = Commit.find_commit_range(users(:active), 'active/foo', nil, '31ce37fe365b3dc204300a3e4c396ad333ed0556', nil)
98 assert_equal ['31ce37fe365b3dc204300a3e4c396ad333ed0556'], a
99 a = Commit.find_commit_range(users(:active), 'arvados', nil, '31ce37fe365b3dc204300a3e4c396ad333ed0556', nil)
102 #test "test_multi_revision" do
103 # complains "fatal: bad object 077ba2ad3ea24a929091a9e6ce545c93199b8e57"
104 a = Commit.find_commit_range(users(:active), 'active/foo', '31ce37fe365b3dc204300a3e4c396ad333ed0556', '077ba2ad3ea24a929091a9e6ce545c93199b8e57', nil)
105 assert_equal ['077ba2ad3ea24a929091a9e6ce545c93199b8e57', '4fe459abe02d9b365932b8f5dc419439ab4e2577', '31ce37fe365b3dc204300a3e4c396ad333ed0556'], a
108 # complains "fatal: ambiguous argument 'tag1': unknown revision or path
109 # not in the working tree."
110 a = Commit.find_commit_range(users(:active), 'active/foo', 'tag1', 'master', nil)
111 assert_equal ['077ba2ad3ea24a929091a9e6ce545c93199b8e57', '4fe459abe02d9b365932b8f5dc419439ab4e2577'], a
113 #test "test_multi_revision_exclude" do
114 a = Commit.find_commit_range(users(:active), 'active/foo', '31ce37fe365b3dc204300a3e4c396ad333ed0556', '077ba2ad3ea24a929091a9e6ce545c93199b8e57', ['4fe459abe02d9b365932b8f5dc419439ab4e2577'])
115 assert_equal ['077ba2ad3ea24a929091a9e6ce545c93199b8e57', '31ce37fe365b3dc204300a3e4c396ad333ed0556'], a
117 #test "test_multi_revision_tagged_exclude" do
118 # complains "fatal: bad object 077ba2ad3ea24a929091a9e6ce545c93199b8e57"
119 a = Commit.find_commit_range(users(:active), 'active/foo', '31ce37fe365b3dc204300a3e4c396ad333ed0556', '077ba2ad3ea24a929091a9e6ce545c93199b8e57', ['tag1'])
120 assert_equal ['077ba2ad3ea24a929091a9e6ce545c93199b8e57', '31ce37fe365b3dc204300a3e4c396ad333ed0556'], a
122 Dir.mktmpdir do |touchdir|
123 # invalid input to maximum
124 a = Commit.find_commit_range(users(:active), 'active/foo', nil, "31ce37fe365b3dc204300a3e4c396ad333ed0556 ; touch #{touchdir}/uh_oh", nil)
125 assert !File.exists?("#{touchdir}/uh_oh"), "#{touchdir}/uh_oh should not exist, 'maximum' parameter of find_commit_range is exploitable"
128 # invalid input to maximum
129 a = Commit.find_commit_range(users(:active), 'active/foo', nil, "$(uname>#{touchdir}/uh_oh)", nil)
130 assert !File.exists?("#{touchdir}/uh_oh"), "#{touchdir}/uh_oh should not exist, 'maximum' parameter of find_commit_range is exploitable"
133 # invalid input to minimum
134 a = Commit.find_commit_range(users(:active), 'active/foo', "31ce37fe365b3dc204300a3e4c396ad333ed0556 ; touch #{touchdir}/uh_oh", "31ce37fe365b3dc204300a3e4c396ad333ed0556", nil)
135 assert !File.exists?("#{touchdir}/uh_oh"), "#{touchdir}/uh_oh should not exist, 'minimum' parameter of find_commit_range is exploitable"
138 # invalid input to minimum
139 a = Commit.find_commit_range(users(:active), 'active/foo', "$(uname>#{touchdir}/uh_oh)", "31ce37fe365b3dc204300a3e4c396ad333ed0556", nil)
140 assert !File.exists?("#{touchdir}/uh_oh"), "#{touchdir}/uh_oh should not exist, 'minimum' parameter of find_commit_range is exploitable"
143 # invalid input to 'excludes'
144 # complains "fatal: bad object 077ba2ad3ea24a929091a9e6ce545c93199b8e57"
145 a = Commit.find_commit_range(users(:active), 'active/foo', "31ce37fe365b3dc204300a3e4c396ad333ed0556", "077ba2ad3ea24a929091a9e6ce545c93199b8e57", ["4fe459abe02d9b365932b8f5dc419439ab4e2577 ; touch #{touchdir}/uh_oh"])
146 assert !File.exists?("#{touchdir}/uh_oh"), "#{touchdir}/uh_oh should not exist, 'excludes' parameter of find_commit_range is exploitable"
149 # invalid input to 'excludes'
150 # complains "fatal: bad object 077ba2ad3ea24a929091a9e6ce545c93199b8e57"
151 a = Commit.find_commit_range(users(:active), 'active/foo', "31ce37fe365b3dc204300a3e4c396ad333ed0556", "077ba2ad3ea24a929091a9e6ce545c93199b8e57", ["$(uname>#{touchdir}/uh_oh)"])
152 assert !File.exists?("#{touchdir}/uh_oh"), "#{touchdir}/uh_oh should not exist, 'excludes' parameter of find_commit_range is exploitable"