Merge branch 'master' into 1971-show-image-thumbnails
[arvados.git] / services / api / test / functional / arvados / v1 / commits_controller_test.rb
1 require 'test_helper'
2 load 'test/functional/arvados/v1/git_setup.rb'
3
4 class Arvados::V1::CommitsControllerTest < ActionController::TestCase
5   fixtures :repositories, :users
6
7   # See git_setup.rb for the commit log for test.git.tar
8   include GitSetup
9
10   test "test_find_commit_range" do
11     authorize_with :active
12
13   # single
14     a = Commit.find_commit_range(users(:active), nil, nil, '31ce37fe365b3dc204300a3e4c396ad333ed0556', nil)
15     assert_equal ['31ce37fe365b3dc204300a3e4c396ad333ed0556'], a
16
17   #test "test_branch1" do
18     a = Commit.find_commit_range(users(:active), nil, nil, 'master', nil)
19     assert_equal ['077ba2ad3ea24a929091a9e6ce545c93199b8e57'], a
20
21   #test "test_branch2" do
22     a = Commit.find_commit_range(users(:active), 'foo', nil, 'b1', nil)
23     assert_equal ['1de84a854e2b440dc53bf42f8548afa4c17da332'], a
24
25   #test "test_branch3" do
26     a = Commit.find_commit_range(users(:active), 'foo', nil, 'HEAD', nil)
27     assert_equal ['1de84a854e2b440dc53bf42f8548afa4c17da332'], a
28
29   #test "test_single_revision_repo" do
30     a = Commit.find_commit_range(users(:active), "foo", nil, '31ce37fe365b3dc204300a3e4c396ad333ed0556', nil)
31     assert_equal ['31ce37fe365b3dc204300a3e4c396ad333ed0556'], a
32     a = Commit.find_commit_range(users(:active), "bar", nil, '31ce37fe365b3dc204300a3e4c396ad333ed0556', nil)
33     assert_equal nil, a
34
35   #test "test_multi_revision" do
36     a = Commit.find_commit_range(users(:active), nil, '31ce37fe365b3dc204300a3e4c396ad333ed0556', '077ba2ad3ea24a929091a9e6ce545c93199b8e57', nil)
37     assert_equal ['077ba2ad3ea24a929091a9e6ce545c93199b8e57', '4fe459abe02d9b365932b8f5dc419439ab4e2577', '31ce37fe365b3dc204300a3e4c396ad333ed0556'], a
38
39   #test "test_tag" do
40     a = Commit.find_commit_range(users(:active), nil, 'tag1', 'master', nil)
41     assert_equal ['077ba2ad3ea24a929091a9e6ce545c93199b8e57', '4fe459abe02d9b365932b8f5dc419439ab4e2577'], a
42
43   #test "test_multi_revision_exclude" do
44     a = Commit.find_commit_range(users(:active), nil, '31ce37fe365b3dc204300a3e4c396ad333ed0556', '077ba2ad3ea24a929091a9e6ce545c93199b8e57', ['4fe459abe02d9b365932b8f5dc419439ab4e2577'])
45     assert_equal ['077ba2ad3ea24a929091a9e6ce545c93199b8e57', '31ce37fe365b3dc204300a3e4c396ad333ed0556'], a
46
47   #test "test_multi_revision_tagged_exclude" do
48     a = Commit.find_commit_range(users(:active), nil, '31ce37fe365b3dc204300a3e4c396ad333ed0556', '077ba2ad3ea24a929091a9e6ce545c93199b8e57', ['tag1'])
49     assert_equal ['077ba2ad3ea24a929091a9e6ce545c93199b8e57', '31ce37fe365b3dc204300a3e4c396ad333ed0556'], a
50
51     Dir.mktmpdir do |touchdir|
52       # invalid input to maximum
53       a = Commit.find_commit_range(users(:active), nil, nil, "31ce37fe365b3dc204300a3e4c396ad333ed0556 ; touch #{touchdir}/uh_oh", nil)
54       assert !File.exists?("#{touchdir}/uh_oh"), "#{touchdir}/uh_oh should not exist, 'maximum' parameter of find_commit_range is exploitable"
55       assert_equal nil, a
56
57       # invalid input to maximum
58       a = Commit.find_commit_range(users(:active), nil, nil, "$(uname>#{touchdir}/uh_oh)", nil)
59       assert !File.exists?("#{touchdir}/uh_oh"), "#{touchdir}/uh_oh should not exist, 'maximum' parameter of find_commit_range is exploitable"
60       assert_equal nil, a
61
62       # invalid input to minimum
63       a = Commit.find_commit_range(users(:active), nil, "31ce37fe365b3dc204300a3e4c396ad333ed0556 ; touch #{touchdir}/uh_oh", "31ce37fe365b3dc204300a3e4c396ad333ed0556", nil)
64       assert !File.exists?("#{touchdir}/uh_oh"), "#{touchdir}/uh_oh should not exist, 'minimum' parameter of find_commit_range is exploitable"
65       assert_equal nil, a
66
67       # invalid input to minimum
68       a = Commit.find_commit_range(users(:active), nil, "$(uname>#{touchdir}/uh_oh)", "31ce37fe365b3dc204300a3e4c396ad333ed0556", nil)
69       assert !File.exists?("#{touchdir}/uh_oh"), "#{touchdir}/uh_oh should not exist, 'minimum' parameter of find_commit_range is exploitable"
70       assert_equal nil, a
71
72       # invalid input to 'excludes'
73       a = Commit.find_commit_range(users(:active), nil, "31ce37fe365b3dc204300a3e4c396ad333ed0556", "077ba2ad3ea24a929091a9e6ce545c93199b8e57", ["4fe459abe02d9b365932b8f5dc419439ab4e2577 ; touch #{touchdir}/uh_oh"])
74       assert !File.exists?("#{touchdir}/uh_oh"), "#{touchdir}/uh_oh should not exist, 'excludes' parameter of find_commit_range is exploitable"
75       assert_equal nil, a
76
77       # invalid input to 'excludes'
78       a = Commit.find_commit_range(users(:active), nil, "31ce37fe365b3dc204300a3e4c396ad333ed0556", "077ba2ad3ea24a929091a9e6ce545c93199b8e57", ["$(uname>#{touchdir}/uh_oh)"])
79       assert !File.exists?("#{touchdir}/uh_oh"), "#{touchdir}/uh_oh should not exist, 'excludes' parameter of find_commit_range is exploitable"
80       assert_equal nil, a
81
82     end
83
84   end
85
86 end