diff --git a/app/models/theme.rb b/app/models/theme.rb index c3fe321..812926e 100644 --- a/app/models/theme.rb +++ b/app/models/theme.rb @@ -49,7 +49,10 @@ class Theme approved = config['public'] unless approved - approved = config['owner_type'] == owner.class.base_class.name || config['owner_type'] == owner.class.name + begin + approved = owner.kind_of?(config['owner_type'].constantize) + rescue + end approved &&= config['owner_id'] == owner.id if config['owner_id'].present? end @@ -58,7 +61,6 @@ class Theme new id, config end end - end class DuplicatedIdentifier < Exception; end diff --git a/test/unit/theme_test.rb b/test/unit/theme_test.rb index f8f21d7..c170ef5 100644 --- a/test/unit/theme_test.rb +++ b/test/unit/theme_test.rb @@ -191,4 +191,22 @@ class ThemeTest < ActiveSupport::TestCase assert ! Theme.new('test').public end + should 'not crash with nil or invalid owner_type' do + profile = fast_create(Profile) + Theme.stubs(:system_themes_dir).returns(TMP_THEMES_DIR) + + t1 = Theme.new('t1').save + t1.send(:write_config) + t2 = Theme.new('t2', {:owner_type => nil}).save + t2.send(:write_config) + t3 = Theme.new('t3', {:owner_type => 'InvalidClass'}).save + t3.send(:write_config) + + assert_nothing_raised do + themes = Theme.approved_themes(profile) + assert_not_includes themes, t1 + assert_not_includes themes, t2 + assert_not_includes themes, t3 + end + end end -- libgit2 0.21.2