Add 'apps/arv-web/' from commit 'f9732ad8460d013c2f28363655d0d1b91894dca5'
[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_includes(a, 'f35f99b7d32bac257f5989df02b9f12ee1a9b0d6')
29     assert_includes(a, '077ba2ad3ea24a929091a9e6ce545c93199b8e57')
30
31   #test "test_branch2" do
32     a = Commit.find_commit_range(users(:active), 'foo', nil, 'b1', nil)
33     assert_equal ['1de84a854e2b440dc53bf42f8548afa4c17da332'], a
34
35   #test "test_branch3" do
36     a = Commit.find_commit_range(users(:active), 'foo', nil, 'HEAD', nil)
37     assert_equal ['1de84a854e2b440dc53bf42f8548afa4c17da332'], a
38
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)
43     assert_equal nil, a
44
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
49
50   #test "test_tag" do
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
55
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
59
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
64
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"
69       assert_equal nil, a
70
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"
74       assert_equal nil, a
75
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"
79       assert_equal nil, a
80
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"
84       assert_equal nil, a
85
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"
90       assert_equal nil, a
91
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"
96       assert_equal nil, a
97
98     end
99
100   end
101
102 end