3 class PermissionsTest < ActionDispatch::IntegrationTest
4 fixtures :users, :groups, :api_client_authorizations, :collections
6 test "adding and removing direct can_read links" do
7 auth = {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:spectator).api_token}"}
8 admin_auth = {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:admin).api_token}"}
10 # try to read collection as spectator
11 get "/arvados/v1/collections/#{collections(:foo_file).uuid}", {:format => :json}, auth
14 # try to add permission as spectator
15 post "/arvados/v1/links", {
18 tail_kind: 'arvados#user',
19 tail_uuid: users(:spectator).uuid,
20 link_class: 'permission',
22 head_kind: 'arvados#collection',
23 head_uuid: collections(:foo_file).uuid,
29 # add permission as admin
30 post "/arvados/v1/links", {
33 tail_kind: 'arvados#user',
34 tail_uuid: users(:spectator).uuid,
35 link_class: 'permission',
37 head_kind: 'arvados#collection',
38 head_uuid: collections(:foo_file).uuid,
43 assert_response :success
45 # read collection as spectator
46 get "/arvados/v1/collections/#{collections(:foo_file).uuid}", {:format => :json}, auth
47 assert_response :success
49 # try to delete permission as spectator
50 delete "/arvados/v1/links/#{u}", {:format => :json}, auth
53 # delete permission as admin
54 delete "/arvados/v1/links/#{u}", {:format => :json}, admin_auth
55 assert_response :success
57 # try to read collection as spectator
58 get "/arvados/v1/collections/#{collections(:foo_file).uuid}", {:format => :json}, auth
63 test "adding can_read links from user to group, group to collection" do
64 auth = {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:spectator).api_token}"}
65 admin_auth = {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:admin).api_token}"}
67 # try to read collection as spectator
68 get "/arvados/v1/collections/#{collections(:foo_file).uuid}", {:format => :json}, auth
71 # add permission for spectator to read group
72 post "/arvados/v1/links", {
75 tail_kind: 'arvados#user',
76 tail_uuid: users(:spectator).uuid,
77 link_class: 'permission',
79 head_kind: 'arvados#group',
80 head_uuid: groups(:private).uuid,
84 assert_response :success
86 # try to read collection as spectator
87 get "/arvados/v1/collections/#{collections(:foo_file).uuid}", {:format => :json}, auth
90 # add permission for group to read collection
91 post "/arvados/v1/links", {
94 tail_kind: 'arvados#group',
95 tail_uuid: groups(:private).uuid,
96 link_class: 'permission',
98 head_kind: 'arvados#collection',
99 head_uuid: collections(:foo_file).uuid,
103 u = jresponse['uuid']
104 assert_response :success
106 # try to read collection as spectator
107 get "/arvados/v1/collections/#{collections(:foo_file).uuid}", {:format => :json}, auth
108 assert_response :success
110 # delete permission for group to read collection
111 delete "/arvados/v1/links/#{u}", {:format => :json}, admin_auth
112 assert_response :success
114 # try to read collection as spectator
115 get "/arvados/v1/collections/#{collections(:foo_file).uuid}", {:format => :json}, auth
121 test "adding can_read links from group to collection, user to group" do
122 auth = {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:spectator).api_token}"}
123 admin_auth = {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:admin).api_token}"}
125 # try to read collection as spectator
126 get "/arvados/v1/collections/#{collections(:foo_file).uuid}", {:format => :json}, auth
129 # add permission for group to read collection
130 post "/arvados/v1/links", {
133 tail_kind: 'arvados#group',
134 tail_uuid: groups(:private).uuid,
135 link_class: 'permission',
137 head_kind: 'arvados#collection',
138 head_uuid: collections(:foo_file).uuid,
142 assert_response :success
144 # try to read collection as spectator
145 get "/arvados/v1/collections/#{collections(:foo_file).uuid}", {:format => :json}, auth
148 # add permission for spectator to read group
149 post "/arvados/v1/links", {
152 tail_kind: 'arvados#user',
153 tail_uuid: users(:spectator).uuid,
154 link_class: 'permission',
156 head_kind: 'arvados#group',
157 head_uuid: groups(:private).uuid,
161 u = jresponse['uuid']
162 assert_response :success
164 # try to read collection as spectator
165 get "/arvados/v1/collections/#{collections(:foo_file).uuid}", {:format => :json}, auth
166 assert_response :success
168 # delete permission for spectator to read group
169 delete "/arvados/v1/links/#{u}", {:format => :json}, admin_auth
170 assert_response :success
172 # try to read collection as spectator
173 get "/arvados/v1/collections/#{collections(:foo_file).uuid}", {:format => :json}, auth
178 test "adding can_read links from user to group, group to group, group to collection" do
179 auth = {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:spectator).api_token}"}
180 admin_auth = {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:admin).api_token}"}
182 # try to read collection as spectator
183 get "/arvados/v1/collections/#{collections(:foo_file).uuid}", {:format => :json}, auth
186 # add permission for user to read group
187 post "/arvados/v1/links", {
190 tail_kind: 'arvados#user',
191 tail_uuid: users(:spectator).uuid,
192 link_class: 'permission',
194 head_kind: 'arvados#group',
195 head_uuid: groups(:private).uuid,
199 assert_response :success
201 # add permission for group to read group
202 post "/arvados/v1/links", {
205 tail_kind: 'arvados#group',
206 tail_uuid: groups(:private).uuid,
207 link_class: 'permission',
209 head_kind: 'arvados#group',
210 head_uuid: groups(:empty_lonely_group).uuid,
214 assert_response :success
216 # add permission for group to read collection
217 post "/arvados/v1/links", {
220 tail_kind: 'arvados#group',
221 tail_uuid: groups(:empty_lonely_group).uuid,
222 link_class: 'permission',
224 head_kind: 'arvados#collection',
225 head_uuid: collections(:foo_file).uuid,
229 u = jresponse['uuid']
230 assert_response :success
232 # try to read collection as spectator
233 get "/arvados/v1/collections/#{collections(:foo_file).uuid}", {:format => :json}, auth
234 assert_response :success
236 # delete permission for group to read collection
237 delete "/arvados/v1/links/#{u}", {:format => :json}, admin_auth
238 assert_response :success
240 # try to read collection as spectator
241 get "/arvados/v1/collections/#{collections(:foo_file).uuid}", {:format => :json}, auth