3 class Arvados::V1::CollectionsControllerTest < ActionController::TestCase
5 test "should get index" do
8 assert_response :success
9 assert_not_nil assigns(:objects)
12 test "should create" do
13 authorize_with :active
16 . d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo.txt
17 . acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:bar.txt
18 . acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:bar.txt
19 ./baz acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:bar.txt
22 test_collection[:uuid] =
23 Digest::MD5.hexdigest(test_collection[:manifest_text]) +
25 test_collection[:manifest_text].length.to_s
27 collection: test_collection
29 assert_response :success
30 assert_nil assigns(:objects)
33 id: test_collection[:uuid]
35 assert_response :success
36 assert_not_nil assigns(:object)
37 resp = JSON.parse(@response.body)
38 assert_equal test_collection[:uuid], resp['uuid']
39 assert_equal test_collection[:manifest_text], resp['manifest_text']
40 assert_equal 9, resp['data_size']
41 assert_equal [['.', 'foo.txt', 0],
43 ['./baz', 'bar.txt', 3]], resp['files']
46 test "list of files is correct for empty manifest" do
47 authorize_with :active
50 uuid: "d41d8cd98f00b204e9800998ecf8427e+0"
53 collection: test_collection
55 assert_response :success
58 id: "d41d8cd98f00b204e9800998ecf8427e+0"
60 assert_response :success
61 resp = JSON.parse(@response.body)
62 assert_equal [], resp['files']
65 test "create with owner_uuid set to owned group" do
66 authorize_with :active
67 manifest_text = ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n"
70 owner_uuid: 'zzzzz-j7d0g-rew6elm53kancon',
71 manifest_text: manifest_text,
72 uuid: "d30fe8ae534397864cb96c544f4cf102"
75 assert_response :success
76 resp = JSON.parse(@response.body)
77 assert_equal 'zzzzz-tpzed-000000000000000', resp['owner_uuid']
80 test "create with owner_uuid set to group i can_manage" do
81 authorize_with :active
82 manifest_text = ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n"
85 owner_uuid: 'zzzzz-j7d0g-8ulrifv67tve5sx',
86 manifest_text: manifest_text,
87 uuid: "d30fe8ae534397864cb96c544f4cf102"
90 assert_response :success
91 resp = JSON.parse(@response.body)
92 assert_equal 'zzzzz-tpzed-000000000000000', resp['owner_uuid']
95 test "create with owner_uuid set to group with no can_manage permission" do
96 authorize_with :active
97 manifest_text = ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n"
100 owner_uuid: 'zzzzz-j7d0g-it30l961gq3t0oi',
101 manifest_text: manifest_text,
102 uuid: "d30fe8ae534397864cb96c544f4cf102"
108 test "admin create with owner_uuid set to group with no permission" do
109 authorize_with :admin
110 manifest_text = ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n"
113 owner_uuid: 'zzzzz-j7d0g-it30l961gq3t0oi',
114 manifest_text: manifest_text,
115 uuid: "d30fe8ae534397864cb96c544f4cf102"
118 assert_response :success
121 test "should create with collection passed as json" do
122 authorize_with :active
126 "manifest_text":". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n",\
127 "uuid":"d30fe8ae534397864cb96c544f4cf102"\
131 assert_response :success
134 test "should fail to create with checksum mismatch" do
135 authorize_with :active
139 "manifest_text":". d41d8cd98f00b204e9800998ecf8427e 0:0:bar.txt\n",\
140 "uuid":"d30fe8ae534397864cb96c544f4cf102"\
147 test "get full provenance for baz file" do
148 authorize_with :active
149 get :provenance, uuid: 'ea10d51bcf88862dbcc36eb292017dfd+45'
150 assert_response :success
151 resp = JSON.parse(@response.body)
152 assert_not_nil resp['ea10d51bcf88862dbcc36eb292017dfd+45'] # baz
153 assert_not_nil resp['fa7aeb5140e2848d39b416daeef4ffc5+45'] # bar
154 assert_not_nil resp['1f4b0bc7583c2a7f9102c395f4ffc5e3+45'] # foo
155 assert_not_nil resp['zzzzz-8i9sb-cjs4pklxxjykyuq'] # bar->baz
156 assert_not_nil resp['zzzzz-8i9sb-aceg2bnq7jt7kon'] # foo->bar
159 test "get no provenance for foo file" do
160 # spectator user cannot even see baz collection
161 authorize_with :spectator
162 get :provenance, uuid: '1f4b0bc7583c2a7f9102c395f4ffc5e3+45'
166 test "get partial provenance for baz file" do
167 # spectator user can see bar->baz job, but not foo->bar job
168 authorize_with :spectator
169 get :provenance, uuid: 'ea10d51bcf88862dbcc36eb292017dfd+45'
170 assert_response :success
171 resp = JSON.parse(@response.body)
172 assert_not_nil resp['ea10d51bcf88862dbcc36eb292017dfd+45'] # baz
173 assert_not_nil resp['fa7aeb5140e2848d39b416daeef4ffc5+45'] # bar
174 assert_not_nil resp['zzzzz-8i9sb-cjs4pklxxjykyuq'] # bar->baz
175 assert_nil resp['zzzzz-8i9sb-aceg2bnq7jt7kon'] # foo->bar
176 assert_nil resp['1f4b0bc7583c2a7f9102c395f4ffc5e3+45'] # foo