3 class Arvados::V1::LinksControllerTest < ActionController::TestCase
5 test "no symbol keys in serialized hash" do
7 properties: {username: 'testusername'},
10 tail_uuid: users(:admin).uuid,
11 head_uuid: virtual_machines(:testvm).uuid
14 [link, link.to_json].each do |formatted_link|
15 post :create, link: formatted_link
16 assert_response :success
17 assert_not_nil assigns(:object)
18 assert_equal 'testusername', assigns(:object).properties['username']
19 assert_equal false, assigns(:object).properties.has_key?(:username)
23 test "head must exist" do
27 tail_uuid: users(:active).uuid,
28 head_uuid: 'zzzzz-tpzed-xyzxyzxerrrorxx'
31 post :create, link: link
35 test "tail must exist" do
39 head_uuid: users(:active).uuid,
40 tail_uuid: 'zzzzz-tpzed-xyzxyzxerrrorxx'
43 post :create, link: link
47 test "head and tail exist, head_kind and tail_kind are returned" do
51 head_uuid: users(:active).uuid,
52 tail_uuid: users(:spectator).uuid,
55 post :create, link: link
56 assert_response :success
57 l = JSON.parse(@response.body)
58 assert 'arvados#user', l['head_kind']
59 assert 'arvados#user', l['tail_kind']
62 test "can supply head_kind and tail_kind without error" do
66 head_uuid: users(:active).uuid,
67 tail_uuid: users(:spectator).uuid,
68 head_kind: "arvados#user",
69 tail_kind: "arvados#user",
72 post :create, link: link
73 assert_response :success
74 l = JSON.parse(@response.body)
75 assert 'arvados#user', l['head_kind']
76 assert 'arvados#user', l['tail_kind']
79 test "tail must be visible by user" do
83 head_uuid: users(:active).uuid,
84 tail_uuid: virtual_machines(:testvm).uuid
86 authorize_with :active
87 post :create, link: link
91 test "filter links with 'is_a' operator" do
94 filters: [ ['tail_uuid', 'is_a', 'arvados#user'] ]
96 assert_response :success
97 found = assigns(:objects)
98 assert_not_equal 0, found.count
99 assert_equal found.count, (found.select { |f| f.tail_uuid.match /[a-z0-9]{5}-tpzed-[a-z0-9]{15}/}).count
102 test "filter links with 'is_a' operator with more than one" do
103 authorize_with :admin
105 filters: [ ['tail_uuid', 'is_a', ['arvados#user', 'arvados#group'] ] ],
107 assert_response :success
108 found = assigns(:objects)
109 assert_not_equal 0, found.count
110 assert_equal found.count, (found.select { |f| f.tail_uuid.match /[a-z0-9]{5}-(tpzed|j7d0g)-[a-z0-9]{15}/}).count
113 test "filter links with 'is_a' operator with bogus type" do
114 authorize_with :admin
116 filters: [ ['tail_uuid', 'is_a', ['arvados#bogus'] ] ],
118 assert_response :success
119 found = assigns(:objects)
120 assert_equal 0, found.count
123 test "filter links with 'is_a' operator with collection" do
124 authorize_with :admin
126 filters: [ ['head_uuid', 'is_a', ['arvados#collection'] ] ],
128 assert_response :success
129 found = assigns(:objects)
130 assert_not_equal 0, found.count
131 assert_equal found.count, (found.select { |f| f.head_uuid.match /[a-f0-9]{32}\+\d+/}).count
134 test "test can still use where tail_kind" do
135 authorize_with :admin
137 where: { tail_kind: 'arvados#user' }
139 assert_response :success
140 found = assigns(:objects)
141 assert_not_equal 0, found.count
142 assert_equal found.count, (found.select { |f| f.tail_uuid.match /[a-z0-9]{5}-tpzed-[a-z0-9]{15}/}).count
145 test "test can still use where head_kind" do
146 authorize_with :admin
148 where: { head_kind: 'arvados#user' }
150 assert_response :success
151 found = assigns(:objects)
152 assert_not_equal 0, found.count
153 assert_equal found.count, (found.select { |f| f.head_uuid.match /[a-z0-9]{5}-tpzed-[a-z0-9]{15}/}).count
156 test "test can still use filter tail_kind" do
157 authorize_with :admin
159 filters: [ ['tail_kind', '=', 'arvados#user'] ]
161 assert_response :success
162 found = assigns(:objects)
163 assert_not_equal 0, found.count
164 assert_equal found.count, (found.select { |f| f.tail_uuid.match /[a-z0-9]{5}-tpzed-[a-z0-9]{15}/}).count
167 test "test can still use filter head_kind" do
168 authorize_with :admin
170 filters: [ ['head_kind', '=', 'arvados#user'] ]
172 assert_response :success
173 found = assigns(:objects)
174 assert_not_equal 0, found.count
175 assert_equal found.count, (found.select { |f| f.head_uuid.match /[a-z0-9]{5}-tpzed-[a-z0-9]{15}/}).count
178 test "head_kind matches head_uuid" do
182 head_uuid: groups(:public).uuid,
183 head_kind: "arvados#user",
184 tail_uuid: users(:spectator).uuid,
185 tail_kind: "arvados#user",
187 authorize_with :admin
188 post :create, link: link
192 test "tail_kind matches tail_uuid" do
196 head_uuid: users(:active).uuid,
197 head_kind: "arvados#user",
198 tail_uuid: groups(:public).uuid,
199 tail_kind: "arvados#user",
201 authorize_with :admin
202 post :create, link: link
206 test "test with virtual_machine" do
208 tail_kind: "arvados#user",
209 tail_uuid: users(:active).uuid,
210 head_kind: "arvados#virtual_machine",
211 head_uuid: virtual_machines(:testvm).uuid,
212 link_class: "permission",
214 properties: {username: "repo_and_user_name"}
216 authorize_with :admin
217 post :create, link: link
221 test "test with virtualMachine" do
223 tail_kind: "arvados#user",
224 tail_uuid: users(:active).uuid,
225 head_kind: "arvados#virtualMachine",
226 head_uuid: virtual_machines(:testvm).uuid,
227 link_class: "permission",
229 properties: {username: "repo_and_user_name"}
231 authorize_with :admin
232 post :create, link: link
233 assert_response :success