2 require 'helpers/git_test_helper'
4 # NOTE: calling Commit.find_commit_range(user, nil, nil, 'rev') will produce
5 # an error message "fatal: bad object 'rev'" on stderr if 'rev' does not exist
6 # in a given repository. Many of these tests report such errors; their presence
7 # does not represent a fatal condition.
9 # TODO(twp): consider better error handling of these messages, or
10 # decide to abandon it.
12 class Arvados::V1::CommitsControllerTest < ActionController::TestCase
13 fixtures :repositories, :users
15 # See git_setup.rb for the commit log for test.git.tar
18 test "test_find_commit_range" do
19 authorize_with :active
22 a = Commit.find_commit_range(users(:active), nil, nil, '31ce37fe365b3dc204300a3e4c396ad333ed0556', nil)
23 assert_equal ['31ce37fe365b3dc204300a3e4c396ad333ed0556'], a
25 #test "test_branch1" do
26 # complains "fatal: bad object 077ba2ad3ea24a929091a9e6ce545c93199b8e57"
27 a = Commit.find_commit_range(users(:active), nil, nil, 'master', nil)
28 assert_equal ['f35f99b7d32bac257f5989df02b9f12ee1a9b0d6', '077ba2ad3ea24a929091a9e6ce545c93199b8e57'], a
30 #test "test_branch2" do
31 a = Commit.find_commit_range(users(:active), 'foo', nil, 'b1', nil)
32 assert_equal ['1de84a854e2b440dc53bf42f8548afa4c17da332'], a
34 #test "test_branch3" do
35 a = Commit.find_commit_range(users(:active), 'foo', nil, 'HEAD', nil)
36 assert_equal ['1de84a854e2b440dc53bf42f8548afa4c17da332'], a
38 #test "test_single_revision_repo" do
39 a = Commit.find_commit_range(users(:active), "foo", nil, '31ce37fe365b3dc204300a3e4c396ad333ed0556', nil)
40 assert_equal ['31ce37fe365b3dc204300a3e4c396ad333ed0556'], a
41 a = Commit.find_commit_range(users(:active), "bar", nil, '31ce37fe365b3dc204300a3e4c396ad333ed0556', nil)
44 #test "test_multi_revision" do
45 # complains "fatal: bad object 077ba2ad3ea24a929091a9e6ce545c93199b8e57"
46 a = Commit.find_commit_range(users(:active), nil, '31ce37fe365b3dc204300a3e4c396ad333ed0556', '077ba2ad3ea24a929091a9e6ce545c93199b8e57', nil)
47 assert_equal ['077ba2ad3ea24a929091a9e6ce545c93199b8e57', '4fe459abe02d9b365932b8f5dc419439ab4e2577', '31ce37fe365b3dc204300a3e4c396ad333ed0556'], a
50 # complains "fatal: ambiguous argument 'tag1': unknown revision or path
51 # not in the working tree."
52 a = Commit.find_commit_range(users(:active), nil, 'tag1', 'master', nil)
53 assert_equal ['077ba2ad3ea24a929091a9e6ce545c93199b8e57', '4fe459abe02d9b365932b8f5dc419439ab4e2577'], a
55 #test "test_multi_revision_exclude" do
56 a = Commit.find_commit_range(users(:active), nil, '31ce37fe365b3dc204300a3e4c396ad333ed0556', '077ba2ad3ea24a929091a9e6ce545c93199b8e57', ['4fe459abe02d9b365932b8f5dc419439ab4e2577'])
57 assert_equal ['077ba2ad3ea24a929091a9e6ce545c93199b8e57', '31ce37fe365b3dc204300a3e4c396ad333ed0556'], a
59 #test "test_multi_revision_tagged_exclude" do
60 # complains "fatal: bad object 077ba2ad3ea24a929091a9e6ce545c93199b8e57"
61 a = Commit.find_commit_range(users(:active), nil, '31ce37fe365b3dc204300a3e4c396ad333ed0556', '077ba2ad3ea24a929091a9e6ce545c93199b8e57', ['tag1'])
62 assert_equal ['077ba2ad3ea24a929091a9e6ce545c93199b8e57', '31ce37fe365b3dc204300a3e4c396ad333ed0556'], a
64 Dir.mktmpdir do |touchdir|
65 # invalid input to maximum
66 a = Commit.find_commit_range(users(:active), nil, nil, "31ce37fe365b3dc204300a3e4c396ad333ed0556 ; touch #{touchdir}/uh_oh", nil)
67 assert !File.exists?("#{touchdir}/uh_oh"), "#{touchdir}/uh_oh should not exist, 'maximum' parameter of find_commit_range is exploitable"
70 # invalid input to maximum
71 a = Commit.find_commit_range(users(:active), nil, nil, "$(uname>#{touchdir}/uh_oh)", nil)
72 assert !File.exists?("#{touchdir}/uh_oh"), "#{touchdir}/uh_oh should not exist, 'maximum' parameter of find_commit_range is exploitable"
75 # invalid input to minimum
76 a = Commit.find_commit_range(users(:active), nil, "31ce37fe365b3dc204300a3e4c396ad333ed0556 ; touch #{touchdir}/uh_oh", "31ce37fe365b3dc204300a3e4c396ad333ed0556", nil)
77 assert !File.exists?("#{touchdir}/uh_oh"), "#{touchdir}/uh_oh should not exist, 'minimum' parameter of find_commit_range is exploitable"
80 # invalid input to minimum
81 a = Commit.find_commit_range(users(:active), nil, "$(uname>#{touchdir}/uh_oh)", "31ce37fe365b3dc204300a3e4c396ad333ed0556", nil)
82 assert !File.exists?("#{touchdir}/uh_oh"), "#{touchdir}/uh_oh should not exist, 'minimum' parameter of find_commit_range is exploitable"
85 # invalid input to 'excludes'
86 # complains "fatal: bad object 077ba2ad3ea24a929091a9e6ce545c93199b8e57"
87 a = Commit.find_commit_range(users(:active), nil, "31ce37fe365b3dc204300a3e4c396ad333ed0556", "077ba2ad3ea24a929091a9e6ce545c93199b8e57", ["4fe459abe02d9b365932b8f5dc419439ab4e2577 ; touch #{touchdir}/uh_oh"])
88 assert !File.exists?("#{touchdir}/uh_oh"), "#{touchdir}/uh_oh should not exist, 'excludes' parameter of find_commit_range is exploitable"
91 # invalid input to 'excludes'
92 # complains "fatal: bad object 077ba2ad3ea24a929091a9e6ce545c93199b8e57"
93 a = Commit.find_commit_range(users(:active), nil, "31ce37fe365b3dc204300a3e4c396ad333ed0556", "077ba2ad3ea24a929091a9e6ce545c93199b8e57", ["$(uname>#{touchdir}/uh_oh)"])
94 assert !File.exists?("#{touchdir}/uh_oh"), "#{touchdir}/uh_oh should not exist, 'excludes' parameter of find_commit_range is exploitable"