API server tests pass, workbench tests are failing
authorPeter Amstutz <peter.amstutz@curoverse.com>
Fri, 11 Apr 2014 19:45:08 +0000 (15:45 -0400)
committerPeter Amstutz <peter.amstutz@curoverse.com>
Fri, 11 Apr 2014 19:45:08 +0000 (15:45 -0400)
16 files changed:
services/api/Gemfile
services/api/Gemfile.lock
services/api/app/controllers/application_controller.rb
services/api/app/controllers/arvados/v1/links_controller.rb
services/api/app/controllers/arvados/v1/users_controller.rb
services/api/app/models/arvados_model.rb
services/api/app/models/link.rb
services/api/app/models/user.rb
services/api/db/migrate/20140325175653_remove_kind_columns.rb
services/api/db/schema.rb
services/api/lib/kind_and_etag.rb
services/api/test/fixtures/groups.yml
services/api/test/fixtures/links.yml
services/api/test/functional/arvados/v1/links_controller_test.rb
services/api/test/functional/arvados/v1/users_controller_test.rb
services/api/test/unit/user_test.rb

index 5932778657ff2b6f2917e237e675aa15e7e1ff64..25b2c2447ff632b094f3ba209473bfb7ebf80c4d 100644 (file)
@@ -63,4 +63,4 @@ gem 'test_after_commit', :group => :test
 gem 'google-api-client', '~> 0.6.3'
 gem 'trollop'
 
-gem 'arvados-cli', '>= 0.1.20140328152103'
+#gem 'arvados-cli', '>= 0.1.20140328152103'
index 39718bda445f29624ccd9d118c2a5b88e299656d..95f37df7d449f48cd6585f19a612b639fba3db49 100644 (file)
@@ -35,20 +35,6 @@ GEM
     addressable (2.3.5)
     andand (1.3.3)
     arel (3.0.2)
-    arvados (0.1.20140328152103)
-      activesupport (>= 3.2.13)
-      andand
-      google-api-client (~> 0.6.3)
-      json (>= 1.7.7)
-    arvados-cli (0.1.20140328152103)
-      activesupport (~> 3.2, >= 3.2.13)
-      andand (~> 1.3, >= 1.3.3)
-      arvados (~> 0.1.0)
-      curb (~> 0.8)
-      google-api-client (~> 0.6.3)
-      json (~> 1.7, >= 1.7.7)
-      oj (~> 2.0, >= 2.0.3)
-      trollop (~> 2.0)
     autoparse (0.3.3)
       addressable (>= 2.3.1)
       extlib (>= 0.9.15)
@@ -67,7 +53,6 @@ GEM
       coffee-script-source
       execjs
     coffee-script-source (1.6.3)
-    curb (0.8.5)
     daemon_controller (1.1.7)
     erubis (2.7.0)
     execjs (2.0.2)
@@ -198,7 +183,6 @@ PLATFORMS
 DEPENDENCIES
   acts_as_api
   andand
-  arvados-cli (>= 0.1.20140328152103)
   coffee-rails (~> 3.2.0)
   google-api-client (~> 0.6.3)
   jquery-rails
index 94ef19c87948fbf4225ec065d5b4c2072ddb6e22..9aad19507583c2e426a9a8070bbacbd3fbdc6c15 100644 (file)
@@ -251,7 +251,7 @@ class ApplicationController < ActionController::Base
       end
     else
       @offset = 0
-    end      
+    end
 
     orders = []
     if params[:order]
@@ -465,7 +465,7 @@ class ApplicationController < ActionController::Base
       order: { type: 'string', required: false }
     }
   end
-  
+
   def client_accepts_plain_text_stream
     (request.headers['Accept'].split(' ') &
      ['text/plain', '*/*']).count > 0
index deeda2869b3e494f20f02a1d25a324b9ef5531aa..1b79295af73524c607149d3aa849b9d2be4e9622 100644 (file)
@@ -1,10 +1,33 @@
 class Arvados::V1::LinksController < ApplicationController
-  def index
+
+  prepend_before_filter :load_kind_params, :only => :index
+
+  def create
+    resource_attrs.delete :head_kind
+    resource_attrs.delete :tail_kind
+    super
+  end
+
+  def load_kind_params
     if params[:tail_uuid]
       params[:where] = Oj.load(params[:where]) if params[:where].is_a?(String)
-      params[:where] ||= {}
-      params[:where][:tail_uuid] = params[:tail_uuid]
+      @where ||= {}
+      @where[:tail_uuid] = params[:tail_uuid]
     end
-    super
+
+    if params[:where] and params[:where].is_a? Hash
+      if params[:where][:head_kind]
+        params[:filters] ||= []
+        params[:filters] << ['head_uuid', 'is_a', params[:where][:head_kind]]
+        params[:where].delete :head_kind
+      end
+      if params[:where][:tail_kind]
+        params[:filters] ||= []
+        params[:filters] << ['tail_uuid', 'is_a', params[:where][:tail_kind]]
+        params[:where].delete :tail_kind
+      end
+    end
+
   end
+
 end
index 0934642261bb314fdfbf76175251a2d702fb3a6b..de067ce015136f7a3ea6a0f7fbf400021b4d7ba1 100644 (file)
@@ -59,7 +59,7 @@ class Arvados::V1::UsersController < ApplicationController
           "but is not invited"
         raise ArgumentError.new "Cannot activate without being invited."
       end
-      act_as_system_user do       
+      act_as_system_user do
         required_uuids = Link.where("owner_uuid = ? and link_class = ? and name = ? and tail_uuid = ? and head_uuid like ?",
                                     system_user_uuid,
                                     'signature',
@@ -130,7 +130,7 @@ class Arvados::V1::UsersController < ApplicationController
                     params[:repo_name], params[:vm_uuid]
     end
 
-    render json: { kind: "arvados#HashList", items: @response }
+    render json: { kind: "arvados#HashList", items: @response.as_api_response(nil) }
   end
 
   # delete user agreements, vm, repository, login links; set state to inactive
index 493cf828d165abaf6f6163daae6d714d0e8b8c8f..0cc26c5efc46bf849012b8296bdedc0132e5b617 100644 (file)
@@ -229,6 +229,24 @@ class ArvadosModel < ActiveRecord::Base
     end
   end
 
+  class Email
+    def self.kind
+      "email"
+    end
+
+    def kind
+      self.class.kind
+    end
+
+    def self.readable_by (u)
+      self
+    end
+
+    def self.where (u)
+      [{:uuid => u[:uuid]}]
+    end
+  end
+
   def self.resource_class_for_uuid(uuid)
     if uuid.is_a? ArvadosModel
       return uuid.class
@@ -245,6 +263,11 @@ class ArvadosModel < ActiveRecord::Base
     uuid.match @@UUID_REGEX do |re|
       return uuid_prefixes[re[1]] if uuid_prefixes[re[1]]
     end
+
+    if uuid.match /.+@.+/
+      return Email
+    end
+
     nil
   end
 
index 8e17ce697e52c16e1553b6a505297c1aa51ade6a..cf4ffce8ed8b1e0a7894742a7c9993955a46ebce 100644 (file)
@@ -9,16 +9,13 @@ class Link < ArvadosModel
   after_create :maybe_invalidate_permissions_cache
   after_destroy :maybe_invalidate_permissions_cache
 
-  attr_accessor :head
-  attr_accessor :tail
-
   api_accessible :user, extend: :common do |t|
     t.add :tail_uuid
     t.add :link_class
     t.add :name
     t.add :head_uuid
-    t.add :head, :if => :head
-    t.add :tail, :if => :tail
+    t.add :head_kind
+    t.add :tail_kind
     t.add :properties
   end
 
@@ -27,6 +24,18 @@ class Link < ArvadosModel
     super
   end
 
+  def head_kind
+    if k = ArvadosModel::resource_class_for_uuid(head_uuid)
+      k.kind
+    end
+  end
+
+  def tail_kind
+    if k = ArvadosModel::resource_class_for_uuid(tail_uuid)
+      k.kind
+    end
+  end
+
   protected
 
   def permission_to_attach_to_objects
index 41858e8b3adb3cb2394c0eb55d5a3cfc24a1d42e..50dc668448a9eee7a81a0924cd1c0b27b7b8b18b 100644 (file)
@@ -129,7 +129,6 @@ class User < ArvadosModel
   def unsetup
     # delete oid_login_perms for this user
     oid_login_perms = Link.where(tail_uuid: self.email,
-                                 head_kind: 'arvados#user',
                                  link_class: 'permission',
                                  name: 'can_login')
     oid_login_perms.each do |perm|
@@ -138,7 +137,6 @@ class User < ArvadosModel
 
     # delete repo_perms for this user
     repo_perms = Link.where(tail_uuid: self.uuid,
-                            head_kind: 'arvados#repository',
                             link_class: 'permission',
                             name: 'can_write')
     repo_perms.each do |perm|
@@ -147,7 +145,6 @@ class User < ArvadosModel
 
     # delete vm_login_perms for this user
     vm_login_perms = Link.where(tail_uuid: self.uuid,
-                                head_kind: 'arvados#virtualMachine',
                                 link_class: 'permission',
                                 name: 'can_login')
     vm_login_perms.each do |perm|
@@ -160,7 +157,6 @@ class User < ArvadosModel
     end.first
     group_perms = Link.where(tail_uuid: self.uuid,
                              head_uuid: group[:uuid],
-                             head_kind: 'arvados#group',
                              link_class: 'permission',
                              name: 'can_read')
     group_perms.each do |perm|
@@ -169,7 +165,6 @@ class User < ArvadosModel
 
     # delete any signatures by this user
     signed_uuids = Link.where(link_class: 'signature',
-                              tail_kind: 'arvados#user',
                               tail_uuid: self.uuid)
     signed_uuids.each do |sign|
       Link.delete sign
@@ -254,17 +249,14 @@ class User < ArvadosModel
 
     # Check oid_login_perm
     oid_login_perms = Link.where(tail_uuid: self.email,
-                                   head_kind: 'arvados#user',
                                    link_class: 'permission',
-                                   name: 'can_login')
+                                   name: 'can_login').where("head_uuid like ?", User.uuid_like_pattern)
 
     if !oid_login_perms.any?
       # create openid login permission
       oid_login_perm = Link.create(link_class: 'permission',
                                    name: 'can_login',
-                                   tail_kind: 'email',
                                    tail_uuid: self.email,
-                                   head_kind: 'arvados#user',
                                    head_uuid: self.uuid,
                                    properties: login_perm_props
                                   )
@@ -291,7 +283,6 @@ class User < ArvadosModel
 
       # Look for existing repository access for this repo
       repo_perms = Link.where(tail_uuid: self.uuid,
-                              head_kind: 'arvados#repository',
                               head_uuid: repo[:uuid],
                               link_class: 'permission',
                               name: 'can_write')
@@ -306,9 +297,7 @@ class User < ArvadosModel
     repo ||= Repository.create(name: repo_name)
     logger.info { "repo uuid: " + repo[:uuid] }
 
-    repo_perm = Link.create(tail_kind: 'arvados#user',
-                            tail_uuid: self.uuid,
-                            head_kind: 'arvados#repository',
+    repo_perm = Link.create(tail_uuid: self.uuid,
                             head_uuid: repo[:uuid],
                             link_class: 'permission',
                             name: 'can_write')
@@ -336,7 +325,6 @@ class User < ArvadosModel
 
       login_perms = Link.where(tail_uuid: self.uuid,
                               head_uuid: vm[:uuid],
-                              head_kind: 'arvados#virtualMachine',
                               link_class: 'permission',
                               name: 'can_login')
 
@@ -349,9 +337,7 @@ class User < ArvadosModel
       end
 
       if !perm_exists
-        login_perm = Link.create(tail_kind: 'arvados#user',
-                                 tail_uuid: self.uuid,
-                                 head_kind: 'arvados#virtualMachine',
+        login_perm = Link.create(tail_uuid: self.uuid,
                                  head_uuid: vm[:uuid],
                                  link_class: 'permission',
                                  name: 'can_login',
@@ -380,14 +366,11 @@ class User < ArvadosModel
 
       group_perms = Link.where(tail_uuid: self.uuid,
                               head_uuid: group[:uuid],
-                              head_kind: 'arvados#group',
                               link_class: 'permission',
                               name: 'can_read')
 
       if !group_perms.any?
-        group_perm = Link.create(tail_kind: 'arvados#user',
-                                 tail_uuid: self.uuid,
-                                 head_kind: 'arvados#group',
+        group_perm = Link.create(tail_uuid: self.uuid,
                                  head_uuid: group[:uuid],
                                  link_class: 'permission',
                                  name: 'can_read')
@@ -407,9 +390,7 @@ class User < ArvadosModel
     act_as_system_user do
       Link.create(link_class: 'permission',
                   name: 'can_manage',
-                  tail_kind: 'arvados#group',
                   tail_uuid: system_group_uuid,
-                  head_kind: 'arvados#user',
                   head_uuid: self.uuid)
     end
   end
index 115048d091312f22bf1c05098a08134162f5a4ad..1ecd5d527c5d424ba2f30c0967d9bf33e8040964 100644 (file)
@@ -1,13 +1,21 @@
 class RemoveKindColumns < ActiveRecord::Migration
+  include CurrentApiClient
+
   def up
     remove_column :links, :head_kind
     remove_column :links, :tail_kind
-    remove_column :logs, :object_kind
   end
 
   def down
     add_column :links, :head_kind, :string
     add_column :links, :tail_kind, :string
-    add_column :logs, :object_kind, :string
+
+    act_as_system_user do
+      Link.all.each do |l|
+        l.head_kind = ArvadosModel::resource_class_for_uuid(l.head_uuid).kind if l.head_uuid
+        l.tail_kind = ArvadosModel::resource_class_for_uuid(l.tail_uuid).kind if l.tail_uuid
+        l.save
+      end
+    end
   end
 end
index a63fdf4fe7a75cf2dad81bfa256ca68ae29b470a..a2b89e39116d58146c2144f4cea8d43636c1e190 100644 (file)
@@ -182,8 +182,8 @@ ActiveRecord::Schema.define(:version => 20140402001908) do
     t.boolean  "running"
     t.boolean  "success"
     t.string   "output"
-    t.datetime "created_at",                                  :null => false
-    t.datetime "updated_at",                                  :null => false
+    t.datetime "created_at"
+    t.datetime "updated_at"
     t.string   "priority"
     t.string   "is_locked_by_uuid"
     t.string   "log"
@@ -245,6 +245,8 @@ ActiveRecord::Schema.define(:version => 20140402001908) do
     t.string   "head_uuid"
     t.text     "properties"
     t.datetime "updated_at"
+    t.string   "head_kind"
+    t.string   "tail_kind"
   end
 
   add_index "links", ["created_at"], :name => "index_links_on_created_at"
index 9df128983950b17cc744f86731b387f7c55e8dc8..89c01ef3a2e086fdd38f2de2923dc00f7324c4a3 100644 (file)
@@ -5,10 +5,13 @@ module KindAndEtag
   end
 
   module ClassMethods
+    def kind
+      'arvados#' + self.to_s.camelcase(:lower)
+    end
   end
 
   def kind
-    'arvados#' + self.class.to_s.camelcase(:lower)
+    self.class.kind
   end
 
   def etag
index 958aab9c2f81db1923f08a996cff02a6bff384e9..c2f2dde5520ca050a98995aeb11c3dec3b1a14f8 100644 (file)
@@ -22,6 +22,12 @@ system_owned_group:
   name: System Private
   description: System-owned Group
 
+system_group:
+  uuid: zzzzz-j7d0g-000000000000000
+  owner_uuid: zzzzz-tpzed-000000000000000
+  name: System Private
+  description: System-owned Group
+
 empty_lonely_group:
   uuid: zzzzz-j7d0g-jtp06ulmvsezgyu
   owner_uuid: zzzzz-tpzed-000000000000000
index 47de7e5abc7963333c5a7d42c63dbb9bab19edfd..e3f6e2bcfbec47578d33601b83c775bc3e74de8b 100644 (file)
@@ -146,11 +146,9 @@ foo_file_readable_by_active_duplicate_permission:
   modified_by_user_uuid: zzzzz-tpzed-000000000000000
   modified_at: 2014-01-24 20:42:26 -0800
   updated_at: 2014-01-24 20:42:26 -0800
-  tail_kind: arvados#user
   tail_uuid: zzzzz-tpzed-xurymjxw79nv3jz
   link_class: permission
   name: can_read
-  head_kind: arvados#collection
   head_uuid: 1f4b0bc7583c2a7f9102c395f4ffc5e3+45
   properties: {}
 
@@ -162,11 +160,9 @@ foo_file_readable_by_active_redundant_permission_via_private_group:
   modified_by_user_uuid: zzzzz-tpzed-000000000000000
   modified_at: 2014-01-24 20:42:26 -0800
   updated_at: 2014-01-24 20:42:26 -0800
-  tail_kind: arvados#group
   tail_uuid: zzzzz-j7d0g-22xp1wpjul508rk
   link_class: permission
   name: can_read
-  head_kind: arvados#collection
   head_uuid: 1f4b0bc7583c2a7f9102c395f4ffc5e3+45
   properties: {}
 
@@ -234,11 +230,9 @@ foo_repository_readable_by_spectator:
   modified_by_user_uuid: zzzzz-tpzed-000000000000000
   modified_at: 2014-01-24 20:42:26 -0800
   updated_at: 2014-01-24 20:42:26 -0800
-  tail_kind: arvados#user
   tail_uuid: zzzzz-tpzed-l1s2piq4t4mps8r
   link_class: permission
   name: can_read
-  head_kind: arvados#repository
   head_uuid: zzzzz-2x53u-382brsig8rp3666
   properties: {}
 
@@ -250,11 +244,9 @@ miniadmin_user_is_a_testusergroup_admin:
   modified_by_user_uuid: zzzzz-tpzed-000000000000000
   modified_at: 2014-04-01 13:53:33 -0400
   updated_at: 2014-04-01 13:53:33 -0400
-  tail_kind: arvados#user
   tail_uuid: zzzzz-tpzed-2bg9x0oeydcw5hm
   link_class: permission
   name: can_manage
-  head_kind: arvados#group
   head_uuid: zzzzz-j7d0g-48foin4vonvc2at
   properties: {}
 
@@ -266,11 +258,9 @@ rominiadmin_user_is_a_testusergroup_admin:
   modified_by_user_uuid: zzzzz-tpzed-000000000000000
   modified_at: 2014-04-01 13:53:33 -0400
   updated_at: 2014-04-01 13:53:33 -0400
-  tail_kind: arvados#user
   tail_uuid: zzzzz-tpzed-4hvxm4n25emegis
   link_class: permission
   name: can_read
-  head_kind: arvados#group
   head_uuid: zzzzz-j7d0g-48foin4vonvc2at
   properties: {}
 
@@ -282,10 +272,8 @@ testusergroup_can_manage_active_user:
   modified_by_user_uuid: zzzzz-tpzed-000000000000000
   modified_at: 2014-04-01 13:56:10 -0400
   updated_at: 2014-04-01 13:56:10 -0400
-  tail_kind: arvados#group
   tail_uuid: zzzzz-j7d0g-48foin4vonvc2at
   link_class: permission
   name: can_manage
-  head_kind: arvados#user
   head_uuid: zzzzz-tpzed-xurymjxw79nv3jz
   properties: {}
index d2863f37ecd9ddb390a0cc72f5805386e74da9a5..4c0c8dc825fc41907d3e31fccb0952777a98c56c 100644 (file)
@@ -19,7 +19,7 @@ class Arvados::V1::LinksControllerTest < ActionController::TestCase
       assert_equal false, assigns(:object).properties.has_key?(:username)
     end
   end
-  
+
   test "head must exist" do
     link = {
       link_class: 'test',
@@ -44,6 +44,38 @@ class Arvados::V1::LinksControllerTest < ActionController::TestCase
     assert_response 422
   end
 
+  test "head and tail exist" do
+    link = {
+      link_class: 'test',
+      name: 'stuff',
+      head_uuid: users(:active).uuid,
+      tail_uuid: users(:spectator).uuid,
+    }
+    authorize_with :admin
+    post :create, link: link
+    assert_response :success
+    l = JSON.parse(@response.body)
+    assert 'arvados#user', l['head_kind']
+    assert 'arvados#user', l['tail_kind']
+  end
+
+  test "can supply head_kind and tail_kind without error" do
+    link = {
+      link_class: 'test',
+      name: 'stuff',
+      head_uuid: users(:active).uuid,
+      tail_uuid: users(:spectator).uuid,
+      head_kind: "arvados#user",
+      tail_kind: "arvados#user",
+    }
+    authorize_with :admin
+    post :create, link: link
+    assert_response :success
+    l = JSON.parse(@response.body)
+    assert 'arvados#user', l['head_kind']
+    assert 'arvados#user', l['tail_kind']
+  end
+
   test "tail must be visible by user" do
     link = {
       link_class: 'test',
@@ -95,10 +127,30 @@ class Arvados::V1::LinksControllerTest < ActionController::TestCase
     }
     assert_response :success
     found = assigns(:objects)
+    assert_not_equal 0, found.count
+    assert_equal found.count, (found.select { |f| f.head_uuid.match /[a-f0-9]{32}\+\d+/}).count
+  end
+
+  test "test can still use where tail_kind" do
+    authorize_with :admin
+    get :index, {
+      where: { tail_kind: 'arvados#user' }
+    }
     assert_response :success
     found = assigns(:objects)
     assert_not_equal 0, found.count
-    assert_equal found.count, (found.select { |f| f.head_uuid.match /[a-f0-9]{32}\+\d+/}).count
+    assert_equal found.count, (found.select { |f| f.tail_uuid.match /[a-z0-9]{5}-tpzed-[a-z0-9]{15}/}).count
+  end
+
+  test "test can still use where head_kind" do
+    authorize_with :admin
+    get :index, {
+      where: { head_kind: 'arvados#user' }
+    }
+    assert_response :success
+    found = assigns(:objects)
+    assert_not_equal 0, found.count
+    assert_equal found.count, (found.select { |f| f.head_uuid.match /[a-z0-9]{5}-tpzed-[a-z0-9]{15}/}).count
   end
 
 
index e62eff892585ae7e50d0734dfdfe6601ce3cb45c..5f1a3f0225d37b887d5c364ee965937b6ace66fa 100644 (file)
@@ -67,7 +67,7 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
       repo_name: repo_name,
       openid_prefix: 'https://www.google.com/accounts/o8/id',
       user: {
-        uuid: "this_is_agreeable",
+        uuid: 'zzzzz-tpzed-abcdefghijklmno',
         first_name: "in_create_test_first_name",
         last_name: "test_last_name",
         email: "foo@example.com"
@@ -77,9 +77,10 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
     response_items = JSON.parse(@response.body)['items']
 
     created = find_obj_in_resp response_items, 'User', nil
+
     assert_equal 'in_create_test_first_name', created['first_name']
     assert_not_nil created['uuid'], 'expected non-null uuid for the new user'
-    assert_equal 'this_is_agreeable', created['uuid']
+    assert_equal 'zzzzz-tpzed-abcdefghijklmno', created['uuid']
     assert_not_nil created['email'], 'expected non-nil email'
     assert_nil created['identity_url'], 'expected no identity_url'
 
@@ -106,7 +107,7 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
       vm_uuid: @vm_uuid,
       openid_prefix: 'https://www.google.com/accounts/o8/id',
       user: {
-        uuid: "this_is_agreeable",
+        uuid: 'zzzzz-tpzed-abcdefghijklmno',
         first_name: "in_create_test_first_name",
         last_name: "test_last_name",
         email: "foo@example.com"
@@ -118,7 +119,7 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
     created = find_obj_in_resp response_items, 'User', nil
     assert_equal 'in_create_test_first_name', created['first_name']
     assert_not_nil created['uuid'], 'expected non-null uuid for the new user'
-    assert_equal 'this_is_agreeable', created['uuid']
+    assert_equal 'zzzzz-tpzed-abcdefghijklmno', created['uuid']
     assert_not_nil created['email'], 'expected non-nil email'
     assert_nil created['identity_url'], 'expected no identity_url'
 
@@ -714,12 +715,12 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
       end
 
       if object_type == 'User'
-        if !x['head_kind']
+        if ArvadosModel::resource_class_for_uuid(x['uuid']) == User
           return_obj = x
           break
         end
       else  # looking for a link
-        if x['head_kind'] == head_kind
+        if x['head_uuid'] and ArvadosModel::resource_class_for_uuid(x['head_uuid']).kind == head_kind
           return_obj = x
           break
         end
@@ -745,19 +746,19 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
       assert [] != object, "expected #{class_name} with name #{head_uuid}"
       head_uuid = object.first[:uuid]
     end
-    assert_equal link['link_class'], link_class,
+    assert_equal link_class, link['link_class'],
         "did not find expected link_class for #{link_object_name}"
 
-    assert_equal link['name'], link_name,
+    assert_equal link_name, link['name'],
         "did not find expected link_name for #{link_object_name}"
 
-    assert_equal link['tail_uuid'], tail_uuid,
+    assert_equal tail_uuid, link['tail_uuid'],
         "did not find expected tail_uuid for #{link_object_name}"
 
-    assert_equal link['head_kind'], head_kind,
+    assert_equal head_kind, link['head_kind'],
         "did not find expected head_kind for #{link_object_name}"
 
-    assert_equal link['head_uuid'], head_uuid,
+    assert_equal head_uuid, link['head_uuid'],
         "did not find expected head_uuid for #{link_object_name}"
   end
 
@@ -765,9 +766,8 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
       expect_repo_perms, expect_vm_perms, expect_group_perms, expect_signatures
     # verify that all links are deleted for the user
     oid_login_perms = Link.where(tail_uuid: email,
-                                 head_kind: 'arvados#user',
                                  link_class: 'permission',
-                                 name: 'can_login')
+                                 name: 'can_login').where("head_uuid like ?", User.uuid_like_pattern)
     if expect_oid_login_perms
       assert oid_login_perms.any?, "expected oid_login_perms"
     else
@@ -775,9 +775,8 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
     end
 
     repo_perms = Link.where(tail_uuid: uuid,
-                              head_kind: 'arvados#repository',
                               link_class: 'permission',
-                              name: 'can_write')
+                              name: 'can_write').where("head_uuid like ?", Repository.uuid_like_pattern)
     if expect_repo_perms
       assert repo_perms.any?, "expected repo_perms"
     else
@@ -785,9 +784,8 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
     end
 
     vm_login_perms = Link.where(tail_uuid: uuid,
-                              head_kind: 'arvados#virtualMachine',
                               link_class: 'permission',
-                              name: 'can_login')
+                              name: 'can_login').where("head_uuid like ?", VirtualMachine.uuid_like_pattern)
     if expect_vm_perms
       assert vm_login_perms.any?, "expected vm_login_perms"
     else
@@ -799,7 +797,6 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
     end.first
     group_read_perms = Link.where(tail_uuid: uuid,
                              head_uuid: group[:uuid],
-                             head_kind: 'arvados#group',
                              link_class: 'permission',
                              name: 'can_read')
     if expect_group_perms
@@ -809,7 +806,6 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
     end
 
     signed_uuids = Link.where(link_class: 'signature',
-                                  tail_kind: 'arvados#user',
                                   tail_uuid: uuid)
 
     if expect_signatures
index 16c05a718196f5a3fc3ad9518266be6e44dbb964..6cee757ee1953abbf18b72e956bdd90b16b239cb 100644 (file)
@@ -161,9 +161,7 @@ class UserTest < ActiveSupport::TestCase
     email = 'foo@example.com'
     openid_prefix = 'http://openid/prefix'
 
-    user = User.new
-    user.email = email
-    user.uuid = 'abcdefghijklmnop'
+    user = User.create ({uuid: 'zzzzz-tpzed-abcdefghijklmno', email: email})
 
     vm = VirtualMachine.create
 
@@ -173,8 +171,10 @@ class UserTest < ActiveSupport::TestCase
     verify_user resp_user, email
 
     oid_login_perm = find_obj_in_resp response, 'Link', 'arvados#user'
+
     verify_link oid_login_perm, 'permission', 'can_login', resp_user[:email],
         resp_user[:uuid]
+
     assert_equal openid_prefix, oid_login_perm[:properties][:identity_url_prefix],
         'expected identity_url_prefix not found for oid_login_perm'
 
@@ -194,9 +194,7 @@ class UserTest < ActiveSupport::TestCase
     email = 'foo@example.com'
     openid_prefix = 'http://openid/prefix'
 
-    user = User.new
-    user.email = email
-    user.uuid = 'abcdefghijklmnop'
+    user = User.create ({uuid: 'zzzzz-tpzed-abcdefghijklmno', email: email})
 
     response = User.setup user, openid_prefix
 
@@ -243,16 +241,20 @@ class UserTest < ActiveSupport::TestCase
     verify_link vm_perm, 'permission', 'can_login', resp_user[:uuid], vm.uuid
   end
 
-  def find_obj_in_resp (response, object_type, head_kind=nil)
+  def find_obj_in_resp (response_items, object_type, head_kind=nil)
     return_obj = nil
-    response.each { |x|
-      if x.class.name == object_type
-        if head_kind
-          if x.head_kind == head_kind
-            return_obj = x
-            break
-          end
-        else
+    response_items.each { |x|
+      if !x
+        next
+      end
+
+      if object_type == 'User'
+        if ArvadosModel::resource_class_for_uuid(x['uuid']) == User
+          return_obj = x
+          break
+        end
+      else  # looking for a link
+        if ArvadosModel::resource_class_for_uuid(x['head_uuid']).kind == head_kind
           return_obj = x
           break
         end
@@ -269,18 +271,18 @@ class UserTest < ActiveSupport::TestCase
   end
 
   def verify_link (link_object, link_class, link_name, tail_uuid, head_uuid)
-    assert_not_nil link_object, 'expected link for #{link_class} #{link_name}'
+    assert_not_nil link_object, "expected link for #{link_class} #{link_name}"
     assert_not_nil link_object[:uuid],
-        'expected non-nil uuid for link for #{link_class} #{link_name}'
+        "expected non-nil uuid for link for #{link_class} #{link_name}"
     assert_equal link_class, link_object[:link_class],
-        'expected link_class not found for #{link_class} #{link_name}'
+        "expected link_class not found for #{link_class} #{link_name}"
     assert_equal link_name, link_object[:name],
-        'expected link_name not found for #{link_class} #{link_name}'
+        "expected link_name not found for #{link_class} #{link_name}"
     assert_equal tail_uuid, link_object[:tail_uuid],
-        'expected tail_uuid not found for #{link_class} #{link_name}'
+        "expected tail_uuid not found for #{link_class} #{link_name}"
     if head_uuid
       assert_equal head_uuid, link_object[:head_uuid],
-          'expected head_uuid not found for #{link_class} #{link_name}'
+          "expected head_uuid not found for #{link_class} #{link_name}"
     end
   end