Add tests for permissions enforcement in collections.provenance.
[arvados.git] / services / api / test / functional / arvados / v1 / collections_controller_test.rb
1 require 'test_helper'
2
3 class Arvados::V1::CollectionsControllerTest < ActionController::TestCase
4
5   test "should get index" do
6     authorize_with :active
7     get :index
8     assert_response :success
9     assert_not_nil assigns(:objects)
10   end
11
12   test "should create" do
13     authorize_with :active
14     post :create, {
15       collection: {
16         manifest_text: ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n",
17         uuid: "d30fe8ae534397864cb96c544f4cf102"
18       }
19     }
20     assert_response :success
21     assert_nil assigns(:objects)
22   end
23
24   test "should create with collection passed as json" do
25     authorize_with :active
26     post :create, {
27       collection: <<-EOS
28       {
29         "manifest_text":". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n",\
30         "uuid":"d30fe8ae534397864cb96c544f4cf102"\
31       }
32       EOS
33     }
34     assert_response :success
35   end
36
37   test "should fail to create with checksum mismatch" do
38     authorize_with :active
39     post :create, {
40       collection: <<-EOS
41       {
42         "manifest_text":". d41d8cd98f00b204e9800998ecf8427e 0:0:bar.txt\n",\
43         "uuid":"d30fe8ae534397864cb96c544f4cf102"\
44       }
45       EOS
46     }
47     assert_response 422
48   end
49
50   test "get full provenance for baz file" do
51     authorize_with :active
52     get :provenance, uuid: 'ea10d51bcf88862dbcc36eb292017dfd+45'
53     assert_response :success
54     resp = JSON.parse(@response.body)
55     assert_not_nil resp['ea10d51bcf88862dbcc36eb292017dfd+45'] # baz
56     assert_not_nil resp['fa7aeb5140e2848d39b416daeef4ffc5+45'] # bar
57     assert_not_nil resp['1f4b0bc7583c2a7f9102c395f4ffc5e3+45'] # foo
58     assert_not_nil resp['zzzzz-8i9sb-cjs4pklxxjykyuq'] # bar->baz
59     assert_not_nil resp['zzzzz-8i9sb-aceg2bnq7jt7kon'] # foo->bar
60   end
61
62   test "get no provenance for foo file" do
63     # spectator user cannot even see baz collection
64     authorize_with :spectator
65     get :provenance, uuid: '1f4b0bc7583c2a7f9102c395f4ffc5e3+45'
66     assert_response 404
67   end
68
69   test "get partial provenance for baz file" do
70     # spectator user can see bar->baz job, but not foo->bar job
71     authorize_with :spectator
72     get :provenance, uuid: 'ea10d51bcf88862dbcc36eb292017dfd+45'
73     assert_response :success
74     resp = JSON.parse(@response.body)
75     assert_not_nil resp['ea10d51bcf88862dbcc36eb292017dfd+45'] # baz
76     assert_not_nil resp['fa7aeb5140e2848d39b416daeef4ffc5+45'] # bar
77     assert_not_nil resp['zzzzz-8i9sb-cjs4pklxxjykyuq']     # bar->baz
78     assert_nil resp['zzzzz-8i9sb-aceg2bnq7jt7kon']         # foo->bar
79     assert_nil resp['1f4b0bc7583c2a7f9102c395f4ffc5e3+45'] # foo
80   end
81
82 end