specials = [system_user_uuid, 'd41d8cd98f00b204e9800998ecf8427e+0']
foreign_key_attributes.each do |attr|
+ next if attr == "modified_by_client_uuid"
begin
attr_value = send attr
r = ArvadosModel::resource_class_for_uuid attr_value if attr_value
- if r and r.where(uuid: attr_value).count == 0 and not specials.include? attr_value
+ if r and r.readable_by(current_user).where(uuid: attr_value).count == 0 and not specials.include? attr_value
errors.add(attr, "'#{attr_value}' not found")
end
rescue Exception => e
tail_uuid: users(:active).uuid,
head_uuid: 'zzzzz-tpzed-xyzxyzxerrrorxx'
}
- authorize_with :active
+ authorize_with :admin
post :create, link: link
assert_response 422
end
head_uuid: users(:active).uuid,
tail_uuid: 'zzzzz-tpzed-xyzxyzxerrrorxx'
}
- authorize_with :active
+ authorize_with :admin
post :create, link: link
assert_response 422
end
- test "tail must exist on update" do
+ test "tail must be visible by user" do
link = {
link_class: 'test',
name: 'stuff',
}
authorize_with :active
post :create, link: link
- u = (ActiveSupport::JSON.decode @response.body)['uuid']
- assert_response :success
-
- link = {
- tail_uuid: virtual_machines(:testvm2).uuid
- }
- put :update, {id: u, link: link}
- assert_equal virtual_machines(:testvm2).uuid, (ActiveSupport::JSON.decode @response.body)['tail_uuid']
- assert_response :success
-
- link = {
- tail_uuid: 'zzzzz-tpzed-xyzxyzxerrrorxx'
- }
- put :update, {id: u, link: link}
assert_response 422
end
--- /dev/null
+require 'test_helper'
+
+class ValidLinksTest < ActionDispatch::IntegrationTest
+ fixtures :all
+
+ test "tail must exist on update" do
+ admin_auth = {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:admin).api_token}"}
+
+ post "/arvados/v1/links", {
+ :format => :json,
+ :link => {
+ link_class: 'test',
+ name: 'stuff',
+ head_uuid: users(:active).uuid,
+ tail_uuid: virtual_machines(:testvm).uuid
+ }
+ }, admin_auth
+ assert_response :success
+ u = jresponse['uuid']
+
+ put "/arvados/v1/links/#{u}", {
+ :format => :json,
+ :link => {
+ tail_uuid: virtual_machines(:testvm2).uuid
+ }
+ }, admin_auth
+ assert_response :success
+ #puts @response.body
+ #puts jresponse['tail_uuid']
+ #puts virtual_machines(:testvm2)
+ assert_equal virtual_machines(:testvm2).uuid, (ActiveSupport::JSON.decode @response.body)['tail_uuid']
+
+ put "/arvados/v1/links/#{u}", {
+ :format => :json,
+ :link => {
+ tail_uuid: 'zzzzz-tpzed-xyzxyzxerrrorxx'
+ }
+ }, admin_auth
+ assert_response 422
+ end
+
+end