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_includes(a, 'f35f99b7d32bac257f5989df02b9f12ee1a9b0d6')
29 assert_includes(a, '077ba2ad3ea24a929091a9e6ce545c93199b8e57')
31 #test "test_branch2" do
32 a = Commit.find_commit_range(users(:active), 'foo', nil, 'b1', nil)
33 assert_equal ['1de84a854e2b440dc53bf42f8548afa4c17da332'], a
35 #test "test_branch3" do
36 a = Commit.find_commit_range(users(:active), 'foo', nil, 'HEAD', nil)
37 assert_equal ['1de84a854e2b440dc53bf42f8548afa4c17da332'], a
39 #test "test_single_revision_repo" do
40 a = Commit.find_commit_range(users(:active), "foo", nil, '31ce37fe365b3dc204300a3e4c396ad333ed0556', nil)
41 assert_equal ['31ce37fe365b3dc204300a3e4c396ad333ed0556'], a
42 a = Commit.find_commit_range(users(:active), "bar", nil, '31ce37fe365b3dc204300a3e4c396ad333ed0556', nil)
45 #test "test_multi_revision" do
46 # complains "fatal: bad object 077ba2ad3ea24a929091a9e6ce545c93199b8e57"
47 a = Commit.find_commit_range(users(:active), nil, '31ce37fe365b3dc204300a3e4c396ad333ed0556', '077ba2ad3ea24a929091a9e6ce545c93199b8e57', nil)
48 assert_equal ['077ba2ad3ea24a929091a9e6ce545c93199b8e57', '4fe459abe02d9b365932b8f5dc419439ab4e2577', '31ce37fe365b3dc204300a3e4c396ad333ed0556'], a
51 # complains "fatal: ambiguous argument 'tag1': unknown revision or path
52 # not in the working tree."
53 a = Commit.find_commit_range(users(:active), nil, 'tag1', 'master', nil)
54 assert_equal ['077ba2ad3ea24a929091a9e6ce545c93199b8e57', '4fe459abe02d9b365932b8f5dc419439ab4e2577'], a
56 #test "test_multi_revision_exclude" do
57 a = Commit.find_commit_range(users(:active), nil, '31ce37fe365b3dc204300a3e4c396ad333ed0556', '077ba2ad3ea24a929091a9e6ce545c93199b8e57', ['4fe459abe02d9b365932b8f5dc419439ab4e2577'])
58 assert_equal ['077ba2ad3ea24a929091a9e6ce545c93199b8e57', '31ce37fe365b3dc204300a3e4c396ad333ed0556'], a
60 #test "test_multi_revision_tagged_exclude" do
61 # complains "fatal: bad object 077ba2ad3ea24a929091a9e6ce545c93199b8e57"
62 a = Commit.find_commit_range(users(:active), nil, '31ce37fe365b3dc204300a3e4c396ad333ed0556', '077ba2ad3ea24a929091a9e6ce545c93199b8e57', ['tag1'])
63 assert_equal ['077ba2ad3ea24a929091a9e6ce545c93199b8e57', '31ce37fe365b3dc204300a3e4c396ad333ed0556'], a
65 Dir.mktmpdir do |touchdir|
66 # invalid input to maximum
67 a = Commit.find_commit_range(users(:active), nil, nil, "31ce37fe365b3dc204300a3e4c396ad333ed0556 ; touch #{touchdir}/uh_oh", nil)
68 assert !File.exists?("#{touchdir}/uh_oh"), "#{touchdir}/uh_oh should not exist, 'maximum' parameter of find_commit_range is exploitable"
71 # invalid input to maximum
72 a = Commit.find_commit_range(users(:active), nil, nil, "$(uname>#{touchdir}/uh_oh)", nil)
73 assert !File.exists?("#{touchdir}/uh_oh"), "#{touchdir}/uh_oh should not exist, 'maximum' parameter of find_commit_range is exploitable"
76 # invalid input to minimum
77 a = Commit.find_commit_range(users(:active), nil, "31ce37fe365b3dc204300a3e4c396ad333ed0556 ; touch #{touchdir}/uh_oh", "31ce37fe365b3dc204300a3e4c396ad333ed0556", nil)
78 assert !File.exists?("#{touchdir}/uh_oh"), "#{touchdir}/uh_oh should not exist, 'minimum' parameter of find_commit_range is exploitable"
81 # invalid input to minimum
82 a = Commit.find_commit_range(users(:active), nil, "$(uname>#{touchdir}/uh_oh)", "31ce37fe365b3dc204300a3e4c396ad333ed0556", nil)
83 assert !File.exists?("#{touchdir}/uh_oh"), "#{touchdir}/uh_oh should not exist, 'minimum' parameter of find_commit_range is exploitable"
86 # invalid input to 'excludes'
87 # complains "fatal: bad object 077ba2ad3ea24a929091a9e6ce545c93199b8e57"
88 a = Commit.find_commit_range(users(:active), nil, "31ce37fe365b3dc204300a3e4c396ad333ed0556", "077ba2ad3ea24a929091a9e6ce545c93199b8e57", ["4fe459abe02d9b365932b8f5dc419439ab4e2577 ; touch #{touchdir}/uh_oh"])
89 assert !File.exists?("#{touchdir}/uh_oh"), "#{touchdir}/uh_oh should not exist, 'excludes' parameter of find_commit_range is exploitable"
92 # invalid input to 'excludes'
93 # complains "fatal: bad object 077ba2ad3ea24a929091a9e6ce545c93199b8e57"
94 a = Commit.find_commit_range(users(:active), nil, "31ce37fe365b3dc204300a3e4c396ad333ed0556", "077ba2ad3ea24a929091a9e6ce545c93199b8e57", ["$(uname>#{touchdir}/uh_oh)"])
95 assert !File.exists?("#{touchdir}/uh_oh"), "#{touchdir}/uh_oh should not exist, 'excludes' parameter of find_commit_range is exploitable"