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