Merge branch '1977-provenance-report'
[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 "create with owner_uuid set to owned group" do
25     authorize_with :active
26     manifest_text = ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n"
27     post :create, {
28       collection: {
29         owner_uuid: 'zzzzz-j7d0g-rew6elm53kancon',
30         manifest_text: manifest_text,
31         uuid: "d30fe8ae534397864cb96c544f4cf102"
32       }
33     }
34     assert_response :success
35     resp = JSON.parse(@response.body)
36     assert_equal 'zzzzz-tpzed-000000000000000', resp['owner_uuid']
37   end
38
39   test "create with owner_uuid set to group i can_manage" do
40     authorize_with :active
41     manifest_text = ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n"
42     post :create, {
43       collection: {
44         owner_uuid: 'zzzzz-j7d0g-8ulrifv67tve5sx',
45         manifest_text: manifest_text,
46         uuid: "d30fe8ae534397864cb96c544f4cf102"
47       }
48     }
49     assert_response :success
50     resp = JSON.parse(@response.body)
51     assert_equal 'zzzzz-tpzed-000000000000000', resp['owner_uuid']
52   end
53
54   test "create with owner_uuid set to group with no can_manage permission" do
55     authorize_with :active
56     manifest_text = ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n"
57     post :create, {
58       collection: {
59         owner_uuid: 'zzzzz-j7d0g-it30l961gq3t0oi',
60         manifest_text: manifest_text,
61         uuid: "d30fe8ae534397864cb96c544f4cf102"
62       }
63     }
64     assert_response 403
65   end
66
67   test "admin create with owner_uuid set to group with no permission" do
68     authorize_with :admin
69     manifest_text = ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n"
70     post :create, {
71       collection: {
72         owner_uuid: 'zzzzz-j7d0g-it30l961gq3t0oi',
73         manifest_text: manifest_text,
74         uuid: "d30fe8ae534397864cb96c544f4cf102"
75       }
76     }
77     assert_response :success
78   end
79
80   test "should create with collection passed as json" do
81     authorize_with :active
82     post :create, {
83       collection: <<-EOS
84       {
85         "manifest_text":". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n",\
86         "uuid":"d30fe8ae534397864cb96c544f4cf102"\
87       }
88       EOS
89     }
90     assert_response :success
91   end
92
93   test "should fail to create with checksum mismatch" do
94     authorize_with :active
95     post :create, {
96       collection: <<-EOS
97       {
98         "manifest_text":". d41d8cd98f00b204e9800998ecf8427e 0:0:bar.txt\n",\
99         "uuid":"d30fe8ae534397864cb96c544f4cf102"\
100       }
101       EOS
102     }
103     assert_response 422
104   end
105
106   test "get full provenance for baz file" do
107     authorize_with :active
108     get :provenance, uuid: 'ea10d51bcf88862dbcc36eb292017dfd+45'
109     assert_response :success
110     resp = JSON.parse(@response.body)
111     assert_not_nil resp['ea10d51bcf88862dbcc36eb292017dfd+45'] # baz
112     assert_not_nil resp['fa7aeb5140e2848d39b416daeef4ffc5+45'] # bar
113     assert_not_nil resp['1f4b0bc7583c2a7f9102c395f4ffc5e3+45'] # foo
114     assert_not_nil resp['zzzzz-8i9sb-cjs4pklxxjykyuq'] # bar->baz
115     assert_not_nil resp['zzzzz-8i9sb-aceg2bnq7jt7kon'] # foo->bar
116   end
117
118   test "get no provenance for foo file" do
119     # spectator user cannot even see baz collection
120     authorize_with :spectator
121     get :provenance, uuid: '1f4b0bc7583c2a7f9102c395f4ffc5e3+45'
122     assert_response 404
123   end
124
125   test "get partial provenance for baz file" do
126     # spectator user can see bar->baz job, but not foo->bar job
127     authorize_with :spectator
128     get :provenance, uuid: 'ea10d51bcf88862dbcc36eb292017dfd+45'
129     assert_response :success
130     resp = JSON.parse(@response.body)
131     assert_not_nil resp['ea10d51bcf88862dbcc36eb292017dfd+45'] # baz
132     assert_not_nil resp['fa7aeb5140e2848d39b416daeef4ffc5+45'] # bar
133     assert_not_nil resp['zzzzz-8i9sb-cjs4pklxxjykyuq']     # bar->baz
134     assert_nil resp['zzzzz-8i9sb-aceg2bnq7jt7kon']         # foo->bar
135     assert_nil resp['1f4b0bc7583c2a7f9102c395f4ffc5e3+45'] # foo
136   end
137
138 end