Fix crashing "grant access to my own object" permission check.
authorTom Clegg <tom@curoverse.com>
Sun, 4 May 2014 01:22:17 +0000 (21:22 -0400)
committerTom Clegg <tom@curoverse.com>
Sun, 4 May 2014 01:22:17 +0000 (21:22 -0400)
services/api/app/models/link.rb
services/api/test/test_helper.rb
services/api/test/unit/log_test.rb
services/api/test/unit/permission_test.rb [new file with mode: 0644]

index 26e7183be385dba38da43b85eec02d6649311c6d..787088d53eb54b13d1de44775b76a79b248672e2 100644 (file)
@@ -51,7 +51,7 @@ class Link < ArvadosModel
 
     # All users can grant permissions on objects they own
     head_obj = self.class.
-      kind_class(self.head_uuid).
+      resource_class_for_uuid(self.head_uuid).
       where('uuid=?',head_uuid).
       first
     if head_obj
index 1bd1b51263a1483df79fede893d52e28636e302b..e1738c3aa1fd690e041f0d58ae88f81be54350e2 100644 (file)
@@ -17,10 +17,6 @@ module ArvadosTestSupport
 end
 
 class ActiveSupport::TestCase
-  # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
-  #
-  # Note: You'll currently still have to declare fixtures explicitly in integration tests
-  # -- they do not yet inherit this setting
   fixtures :all
 
   include ArvadosTestSupport
@@ -33,6 +29,13 @@ class ActiveSupport::TestCase
     Thread.current[:user] = nil
   end
 
+  def set_user_from_auth(auth_name)
+    client_auth = api_client_authorizations(auth_name)
+    Thread.current[:api_client_authorization] = client_auth
+    Thread.current[:api_client] = client_auth.api_client
+    Thread.current[:user] = client_auth.user
+  end
+
   def expect_json
     self.request.headers["Accept"] = "text/json"
   end
index be8498d4bac3883621df2688dcf4ad5423f8c900..4fc273be73d20335c971496d6eb50eae65c90225 100644 (file)
@@ -65,13 +65,6 @@ class LogTest < ActiveSupport::TestCase
     end
   end
 
-  def set_user_from_auth(auth_name)
-    client_auth = api_client_authorizations(auth_name)
-    Thread.current[:api_client_authorization] = client_auth
-    Thread.current[:api_client] = client_auth.api_client
-    Thread.current[:user] = client_auth.user
-  end
-
   test "creating a user makes a log" do
     set_user_from_auth :admin_trustedclient
     u = User.new(first_name: "Log", last_name: "Test")
diff --git a/services/api/test/unit/permission_test.rb b/services/api/test/unit/permission_test.rb
new file mode 100644 (file)
index 0000000..c8e00bb
--- /dev/null
@@ -0,0 +1,17 @@
+require 'test_helper'
+
+class PermissionTest < ActiveSupport::TestCase
+  test "Grant permissions on an object I own" do
+    set_user_from_auth :active_trustedclient
+
+    ob = Specimen.create
+    assert ob.save
+
+    # Ensure I have permission to manage this group even when its owner changes
+    perm_link = Link.create(tail_uuid: users(:active).uuid,
+                            head_uuid: ob.uuid,
+                            link_class: 'permission',
+                            name: 'can_manage')
+    assert perm_link.save, "should give myself permission on my own object"
+  end
+end