Skip to content

Commit

Permalink
Engine: Fixing authorization model tests, refs Katello#3585
Browse files Browse the repository at this point in the history
  • Loading branch information
David Davis authored and bbuckingham committed Nov 22, 2013
1 parent 04db86f commit 4cad074
Show file tree
Hide file tree
Showing 22 changed files with 88 additions and 70 deletions.
2 changes: 1 addition & 1 deletion app/models/katello/authorization/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def no_tag_verbs

def authorized_items(verbs, resource = :organizations)
if !::User.allowed_all_tags?(verbs, resource)
where("organizations.id in (#{::User.allowed_tags_sql(verbs, resource)})")
where("#{Organization.table_name}.id in (#{::User.allowed_tags_sql(verbs, resource)})")
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions app/models/katello/authorization/system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ def readable(org)
if org.systems_readable?
where(:environment_id => org.environment_ids) #list all systems in an org
else #just list for environments the user can access
where_clause = "systems.environment_id in (#{KTEnvironment.systems_readable(org).select(:id).to_sql})"
where_clause = "#{System.table_name}.environment_id in (#{KTEnvironment.systems_readable(org).select(:id).to_sql})"
where_clause += " or "
where_clause += "system_system_groups.system_group_id in (#{SystemGroup.systems_readable(org).select(:id).to_sql})"
joins("left outer join system_system_groups on systems.id =
system_system_groups.system_id").where(where_clause)
where_clause += "#{SystemSystemGroup.table_name}.system_group_id in (#{SystemGroup.systems_readable(org).select(:id).to_sql})"
joins("left outer join #{SystemSystemGroup.table_name} on #{System.table_name}.id =
#{SystemSystemGroup.table_name}.system_id").where(where_clause)
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/katello/authorization/system_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def items(org, verbs)
if ::User.allowed_all_tags?(verbs, resource, org)
where(:organization_id => org)
else
where("system_groups.id in (#{::User.allowed_tags_sql(verbs, resource, org)})")
where("#{SystemGroup.table_name}.id in (#{::User.allowed_tags_sql(verbs, resource, org)})")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/katello/content_view_definition_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

module Katello
class ContentViewDefinitionBase < ActiveRecord::Base
belongs_to :organization, :inverse_of => :content_view_definitions
belongs_to :organization, :inverse_of => :content_view_definitions, :class_name => "Katello::Organization"
has_many :content_view_definition_products, :foreign_key => "content_view_definition_id", :dependent => :destroy
has_many :products, :through => :content_view_definition_products, :after_remove => :remove_product
has_many :content_view_definition_repositories, :foreign_key => "content_view_definition_id", :dependent => :destroy
Expand Down
1 change: 1 addition & 0 deletions lib/katello/tasks/test.rake
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace :test do
t.libs << ["test", "#{Katello::Engine.root}/test", "spec", "#{Katello::Engine.root}/spec"]
t.test_files = [
"#{Katello::Engine.root}/test/glue/pulp/*_test.rb",
"#{Katello::Engine.root}/test/models/authorization/*_test.rb",
"#{Katello::Engine.root}/test/models/repository_test.rb",
"#{Katello::Engine.root}/test/models/system_test.rb",
"#{Katello::Engine.root}/test/models/activation_key_test.rb",
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/models/katello_roles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ admin_own_role:
created_at: <%= Time.now %>
updated_at: <%= Time.now %>

no_perms_own_role:
name: no_perms_own_role
restricted_own_role:
name: restricted_own_role
type: Katello::UserOwnRole
created_at: <%= Time.now %>
updated_at: <%= Time.now %>
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/models/katello_roles_users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ admin_own_role_admin:
user_id: <%= ActiveRecord::Fixtures.identify(:admin) %>

no_perms_user_own_role:
role_id: <%= ActiveRecord::Fixtures.identify(:no_perms_own_role) %>
user_id: <%= ActiveRecord::Fixtures.identify(:no_perms_user) %>
role_id: <%= ActiveRecord::Fixtures.identify(:restricted_own_role) %>
user_id: <%= ActiveRecord::Fixtures.identify(:restricted) %>

hidden_own_role:
role_id: <%= ActiveRecord::Fixtures.identify(:hidden_own_role) %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.

require './test/models/authorization/authorization_base'
require 'models/authorization/authorization_base'

module Katello
class ActivationKeyAuthorizationAdminTest < AuthorizationTestBase

def setup
Expand All @@ -37,7 +38,7 @@ class ActivationKeyAuthorizationNoPermsTest < AuthorizationTestBase

def setup
super
User.current = User.find(users('no_perms_user'))
User.current = User.find(users(:restricted))
end

def test_readable
Expand All @@ -53,3 +54,4 @@ def test_manageable?
end

end
end
21 changes: 8 additions & 13 deletions test/models/authorization/content_view_authorization_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,25 @@
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.

require 'minitest_helper'
require 'katello_test_helper'
require 'support/auth_support'

module Katello
module ContentViewAuthBase
def self.included(base)
base.class_eval do
fixtures :all
include AuthorizationSupportMethods
end
base.extend ClassMethods
end

def setup
@admin = User.find(users(:admin))
@no_perms = User.find(users(:no_perms_user))
@org = Organization.find(organizations(:acme_corporation))
@no_perms = User.find(users(:restricted))
@org = Organization.find(katello_organizations(:acme_corporation))
@view = FactoryGirl.build(:content_view, :organization => @org)
end

def teardown
ContentView.delete_all
User.delete_all
Organization.delete_all
end

module ClassMethods
def before_suite
services = ['Candlepin', 'Pulp', 'ElasticSearch', 'Foreman']
Expand All @@ -44,7 +38,7 @@ def before_suite
end
end

class ContentViewAuthorizationAdminTest < MiniTest::Rails::ActiveSupport::TestCase
class ContentViewAuthorizationAdminTest < ActiveSupport::TestCase
include ContentViewAuthBase

def setup
Expand All @@ -71,7 +65,7 @@ def test_subscribe

end

class ContentViewAuthorizationNoAuthTest < MiniTest::Rails::ActiveSupport::TestCase
class ContentViewAuthorizationNoAuthTest < ActiveSupport::TestCase
include ContentViewAuthBase

def setup
Expand All @@ -94,7 +88,7 @@ def test_subscribable?
end
end

class ContentViewAuthorizationSinglePermTest < MiniTest::Rails::ActiveSupport::TestCase
class ContentViewAuthorizationSinglePermTest < ActiveSupport::TestCase
include ContentViewAuthBase

def setup
Expand All @@ -117,3 +111,4 @@ def test_readable
refute_empty ContentView.readable(@org)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,19 @@
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.

require 'minitest_helper'
require 'katello_test_helper'
require 'support/auth_support'

module Katello
module ContentViewDefinitionAuthBase
def self.included(base)
base.class_eval do
fixtures :all
end
base.extend ClassMethods
end

def setup
@admin = User.find(users(:admin))
@no_perms = User.find(users(:no_perms_user))
@org = Organization.find(organizations(:acme_corporation))
@no_perms = User.find(users(:restricted))
@org = Organization.find(katello_organizations(:acme_corporation))
@cvd = FactoryGirl.create(:content_view_definition, :organization => @org)
end

Expand All @@ -41,7 +39,7 @@ def before_suite
end
end

class ContentViewDefinitionAuthorizationAdminTest < MiniTest::Rails::ActiveSupport::TestCase
class ContentViewDefinitionAuthorizationAdminTest < ActiveSupport::TestCase
include ContentViewDefinitionAuthBase

def setup
Expand Down Expand Up @@ -77,7 +75,7 @@ def test_no_user

end

class ContentViewDefinitionAuthorizationNoPermTest < MiniTest::Rails::ActiveSupport::TestCase
class ContentViewDefinitionAuthorizationNoPermTest < ActiveSupport::TestCase
include ContentViewDefinitionAuthBase

def setup
Expand Down Expand Up @@ -106,7 +104,7 @@ def test_deletable
end
end

class ContentViewDefinitionAuthorizationReadonlyTest < MiniTest::Rails::ActiveSupport::TestCase
class ContentViewDefinitionAuthorizationReadonlyTest < ActiveSupport::TestCase
include ContentViewDefinitionAuthBase, AuthorizationSupportMethods

def setup
Expand Down Expand Up @@ -136,7 +134,7 @@ def test_deletable
end

# random permission
class ContentViewDefinitionAuthorizationTest < MiniTest::Rails::ActiveSupport::TestCase
class ContentViewDefinitionAuthorizationTest < ActiveSupport::TestCase
include ContentViewDefinitionAuthBase, AuthorizationSupportMethods

def setup
Expand All @@ -154,3 +152,4 @@ def test_publishable
end

end
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.

require './test/models/authorization/authorization_base'
require 'models/authorization/authorization_base'

module Katello
class ContentViewVersionAuthorizationAdminTest < AuthorizationTestBase
def setup
super
Expand All @@ -26,10 +27,11 @@ def test_readable
class ContentViewVersionAuthorizationNonAuthUserTest < AuthorizationTestBase
def setup
super
User.current = User.find(users(:no_perms_user))
User.current = User.find(users(:restricted))
end

def test_readable
assert_empty ContentViewVersion.readable(@acme_corporation)
end
end
end
6 changes: 4 additions & 2 deletions test/models/authorization/environment_authorization_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.

require './test/models/authorization/authorization_base'
require 'models/authorization/authorization_base'

module Katello
class EnvironmentAuthorizationAdminTest < AuthorizationTestBase

def setup
Expand Down Expand Up @@ -95,7 +96,7 @@ class EnvironmentAuthorizationNoPermsTest < AuthorizationTestBase

def setup
super
User.current = User.find(users('no_perms_user'))
User.current = User.find(users('restricted'))
@env = @dev
@org = @acme_corporation
end
Expand Down Expand Up @@ -170,3 +171,4 @@ def test_systems_registerable?
end

end
end
10 changes: 6 additions & 4 deletions test/models/authorization/gpg_key_authorization_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.

require './test/models/authorization/authorization_base'
require 'models/authorization/authorization_base'

module Katello
class GpgKeyAuthorizationAdminTest < AuthorizationTestBase

def setup
super
User.current = User.find(users('admin'))
@key = GpgKey.find(gpg_keys('fedora_gpg_key'))
@key = GpgKey.find(katello_gpg_keys('fedora_gpg_key'))
end

def test_readable
Expand Down Expand Up @@ -49,8 +50,8 @@ class GpgKeyAuthorizationNoPermsTest < AuthorizationTestBase

def setup
super
User.current = User.find(users('no_perms_user'))
@key = GpgKey.find(gpg_keys('fedora_gpg_key'))
User.current = User.find(users('restricted'))
@key = GpgKey.find(katello_gpg_keys('fedora_gpg_key'))
end

def test_readable
Expand Down Expand Up @@ -78,3 +79,4 @@ def test_key_manageable?
end

end
end
6 changes: 4 additions & 2 deletions test/models/authorization/organization_authorization_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.

require './test/models/authorization/authorization_base'
require 'models/authorization/authorization_base'

module Katello
class OrganizationAuthorizationAdminTest < AuthorizationTestBase

def setup
Expand Down Expand Up @@ -82,7 +83,7 @@ class OrganizationAuthorizationNoPermsTest < AuthorizationTestBase

def setup
super
User.current = User.find(users('no_perms_user'))
User.current = User.find(users('restricted'))
@org = @acme_corporation
end

Expand Down Expand Up @@ -143,3 +144,4 @@ def test_redhat_manageable?
end

end
end
8 changes: 5 additions & 3 deletions test/models/authorization/product_authorization_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.

require './test/models/authorization/authorization_base'
require 'models/authorization/authorization_base'

module Katello
class ProductAuthorizationAdminTest < AuthorizationTestBase

def setup
Expand Down Expand Up @@ -58,7 +59,7 @@ def test_editable?
end

def test_deletable?
product = Product.find(products(:empty_product))
product = Product.find(katello_products(:empty_product))
assert product.deletable?
end

Expand All @@ -72,7 +73,7 @@ class ProductAuthorizationNoPermsTest < AuthorizationTestBase

def setup
super
User.current = User.find(users('no_perms_user'))
User.current = User.find(users('restricted'))
@prod = @fedora
@org = @acme_corporation
end
Expand Down Expand Up @@ -122,3 +123,4 @@ def test_creatable?
end

end
end
Loading

0 comments on commit 4cad074

Please sign in to comment.