Merge branch '3627-selectable-projects' closes #3627
[arvados.git] / services / api / test / functional / arvados / v1 / commits_controller_test.rb
1 require 'test_helper'
2 require 'helpers/git_test_helper'
3
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.
8 #
9 # TODO(twp): consider better error handling of these messages, or
10 # decide to abandon it.
11
12 class Arvados::V1::CommitsControllerTest < ActionController::TestCase
13   fixtures :repositories, :users
14
15   # See git_setup.rb for the commit log for test.git.tar
16   include GitTestHelper
17
18   test "test_find_commit_range" do
19     authorize_with :active
20
21   # single
22     a = Commit.find_commit_range(users(:active), nil, nil, '31ce37fe365b3dc204300a3e4c396ad333ed0556', nil)
23     assert_equal ['31ce37fe365b3dc204300a3e4c396ad333ed0556'], a
24
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
29
30   #test "test_branch2" do
31     a = Commit.find_commit_range(users(:active), 'foo', nil, 'b1', nil)
32     assert_equal ['1de84a854e2b440dc53bf42f8548afa4c17da332'], a
33
34   #test "test_branch3" do
35     a = Commit.find_commit_range(users(:active), 'foo', nil, 'HEAD', nil)
36     assert_equal ['1de84a854e2b440dc53bf42f8548afa4c17da332'], a
37
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)
42     assert_equal nil, a
43
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
48
49   #test "test_tag" do
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
54
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
58
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
63
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"
68       assert_equal nil, a
69
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"
73       assert_equal nil, a
74
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"
78       assert_equal nil, a
79
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"
83       assert_equal nil, a
84
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"
89       assert_equal nil, a
90
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"
95       assert_equal nil, a
96
97     end
98
99   end
100
101 end