lockdown 1.6.5 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
 - data/README.txt +8 -5
 - data/Rakefile +43 -26
 - data/lib/lockdown/access.rb +108 -0
 - data/lib/lockdown/configuration.rb +201 -0
 - data/lib/lockdown/database.rb +31 -36
 - data/lib/lockdown/delivery.rb +26 -0
 - data/lib/lockdown/errors.rb +3 -7
 - data/lib/lockdown/frameworks/rails/controller.rb +21 -59
 - data/lib/lockdown/frameworks/rails/view.rb +1 -1
 - data/lib/lockdown/frameworks/rails.rb +7 -43
 - data/lib/lockdown/helper.rb +14 -85
 - data/lib/lockdown/orms/active_record.rb +7 -9
 - data/lib/lockdown/permission.rb +37 -203
 - data/lib/lockdown/resource.rb +54 -0
 - data/lib/lockdown/session.rb +16 -25
 - data/lib/lockdown/user_group.rb +16 -0
 - data/lib/lockdown.rb +15 -60
 - data/lockdown.gemspec +29 -69
 - data/test/helper.rb +9 -0
 - data/test/lockdown/test_access.rb +80 -0
 - data/test/lockdown/test_configuration.rb +194 -0
 - data/test/lockdown/test_delivery.rb +163 -0
 - data/test/lockdown/test_helper.rb +33 -0
 - data/test/lockdown/test_permission.rb +73 -0
 - data/test/lockdown/test_resource.rb +47 -0
 - data/test/lockdown/test_session.rb +31 -0
 - data/test/lockdown/test_user_group.rb +17 -0
 - data/test/test_lockdown.rb +11 -0
 - metadata +41 -78
 - data/lib/lockdown/context.rb +0 -41
 - data/lib/lockdown/references.rb +0 -19
 - data/lib/lockdown/rspec_helper.rb +0 -118
 - data/lib/lockdown/rules.rb +0 -372
 - data/lib/lockdown/system.rb +0 -58
 - data/rails_generators/lockdown/lockdown_generator.rb +0 -274
 - data/rails_generators/lockdown/templates/app/controllers/permissions_controller.rb +0 -22
 - data/rails_generators/lockdown/templates/app/controllers/sessions_controller.rb +0 -39
 - data/rails_generators/lockdown/templates/app/controllers/user_groups_controller.rb +0 -122
 - data/rails_generators/lockdown/templates/app/controllers/users_controller.rb +0 -117
 - data/rails_generators/lockdown/templates/app/helpers/permissions_helper.rb +0 -2
 - data/rails_generators/lockdown/templates/app/helpers/user_groups_helper.rb +0 -2
 - data/rails_generators/lockdown/templates/app/helpers/users_helper.rb +0 -2
 - data/rails_generators/lockdown/templates/app/models/permission.rb +0 -13
 - data/rails_generators/lockdown/templates/app/models/profile.rb +0 -10
 - data/rails_generators/lockdown/templates/app/models/user.rb +0 -95
 - data/rails_generators/lockdown/templates/app/models/user_group.rb +0 -15
 - data/rails_generators/lockdown/templates/app/views/permissions/index.html.erb +0 -16
 - data/rails_generators/lockdown/templates/app/views/permissions/show.html.erb +0 -26
 - data/rails_generators/lockdown/templates/app/views/sessions/new.html.erb +0 -12
 - data/rails_generators/lockdown/templates/app/views/user_groups/edit.html.erb +0 -33
 - data/rails_generators/lockdown/templates/app/views/user_groups/index.html.erb +0 -20
 - data/rails_generators/lockdown/templates/app/views/user_groups/new.html.erb +0 -31
 - data/rails_generators/lockdown/templates/app/views/user_groups/show.html.erb +0 -29
 - data/rails_generators/lockdown/templates/app/views/users/edit.html.erb +0 -51
 - data/rails_generators/lockdown/templates/app/views/users/index.html.erb +0 -22
 - data/rails_generators/lockdown/templates/app/views/users/new.html.erb +0 -50
 - data/rails_generators/lockdown/templates/app/views/users/show.html.erb +0 -33
 - data/rails_generators/lockdown/templates/config/initializers/lockit.rb +0 -1
 - data/rails_generators/lockdown/templates/db/migrate/create_admin_user.rb +0 -17
 - data/rails_generators/lockdown/templates/db/migrate/create_permissions.rb +0 -19
 - data/rails_generators/lockdown/templates/db/migrate/create_profiles.rb +0 -26
 - data/rails_generators/lockdown/templates/db/migrate/create_user_groups.rb +0 -19
 - data/rails_generators/lockdown/templates/db/migrate/create_users.rb +0 -17
 - data/rails_generators/lockdown/templates/lib/lockdown/README +0 -42
 - data/rails_generators/lockdown/templates/lib/lockdown/init.rb +0 -131
 - data/spec/lockdown/context_spec.rb +0 -191
 - data/spec/lockdown/database_spec.rb +0 -162
 - data/spec/lockdown/frameworks/rails/controller_spec.rb +0 -215
 - data/spec/lockdown/frameworks/rails/view_spec.rb +0 -96
 - data/spec/lockdown/frameworks/rails_spec.rb +0 -163
 - data/spec/lockdown/permission_spec.rb +0 -156
 - data/spec/lockdown/rspec_helper_spec.rb +0 -40
 - data/spec/lockdown/rules_spec.rb +0 -245
 - data/spec/lockdown/session_spec.rb +0 -112
 - data/spec/lockdown/system_spec.rb +0 -51
 - data/spec/lockdown_spec.rb +0 -19
 - data/spec/rcov.opts +0 -5
 - data/spec/spec.opts +0 -3
 - data/spec/spec_helper.rb +0 -8
 
| 
         @@ -0,0 +1,54 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # encoding: utf-8
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module Lockdown
         
     | 
| 
      
 4 
     | 
    
         
            +
              class Resource
         
     | 
| 
      
 5 
     | 
    
         
            +
                class << self
         
     | 
| 
      
 6 
     | 
    
         
            +
                  attr_accessor :resources, :resources_regex
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
                  # When a new resource is created, this method is called to register the root
         
     | 
| 
      
 9 
     | 
    
         
            +
                  def register_regex(resource)
         
     | 
| 
      
 10 
     | 
    
         
            +
                    resource = "(#{resource})"
         
     | 
| 
      
 11 
     | 
    
         
            +
                    @resources << resource unless @resources.include?(resource)
         
     | 
| 
      
 12 
     | 
    
         
            +
                  end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                  # @return [Regexp] created from resources' base regex
         
     | 
| 
      
 15 
     | 
    
         
            +
                  def regex
         
     | 
| 
      
 16 
     | 
    
         
            +
                    @resources_regex ||= Lockdown.regex(@resources.join("|"))
         
     | 
| 
      
 17 
     | 
    
         
            +
                  end
         
     | 
| 
      
 18 
     | 
    
         
            +
                end # class block
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                # Initialize resources to empty array
         
     | 
| 
      
 21 
     | 
    
         
            +
                @resources = []
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                # Name of the resource
         
     | 
| 
      
 24 
     | 
    
         
            +
                attr_accessor :name
         
     | 
| 
      
 25 
     | 
    
         
            +
                # Regular expression pattern
         
     | 
| 
      
 26 
     | 
    
         
            +
                attr_accessor :regex_pattern
         
     | 
| 
      
 27 
     | 
    
         
            +
                # The only methods restricted on the resource
         
     | 
| 
      
 28 
     | 
    
         
            +
                attr_accessor :exceptions
         
     | 
| 
      
 29 
     | 
    
         
            +
                # The only methods allowed on the resource
         
     | 
| 
      
 30 
     | 
    
         
            +
                attr_accessor :inclusions
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                # @param [String,Symbol] name resource reference. 
         
     | 
| 
      
 34 
     | 
    
         
            +
                def initialize(name)
         
     | 
| 
      
 35 
     | 
    
         
            +
                  @name = name.to_s
         
     | 
| 
      
 36 
     | 
    
         
            +
                  @regex_pattern = "\/#{@name}(\/.*)?"
         
     | 
| 
      
 37 
     | 
    
         
            +
                  self.class.register_regex(@regex_pattern)
         
     | 
| 
      
 38 
     | 
    
         
            +
                end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                # @param *[String,Symbol] only methods restricted on the resource
         
     | 
| 
      
 41 
     | 
    
         
            +
                def except(*methods)
         
     | 
| 
      
 42 
     | 
    
         
            +
                  return if methods.empty?
         
     | 
| 
      
 43 
     | 
    
         
            +
                  @exceptions = methods.collect{|m| m.to_s}
         
     | 
| 
      
 44 
     | 
    
         
            +
                  @regex_pattern = "\/#{@name}(?!\/(#{@exceptions.join('|')}))(\/.*)?"
         
     | 
| 
      
 45 
     | 
    
         
            +
                end
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                # @param *[String,Symbol] only methods allowed on the resource
         
     | 
| 
      
 48 
     | 
    
         
            +
                def only(*methods)
         
     | 
| 
      
 49 
     | 
    
         
            +
                  return if methods.empty?
         
     | 
| 
      
 50 
     | 
    
         
            +
                  @inclusions = methods.collect{|m| m.to_s}
         
     | 
| 
      
 51 
     | 
    
         
            +
                  @regex_pattern = "\/#{@name}\/(#{@inclusions.join('|')})(\/)?"
         
     | 
| 
      
 52 
     | 
    
         
            +
                end
         
     | 
| 
      
 53 
     | 
    
         
            +
              end # Resource
         
     | 
| 
      
 54 
     | 
    
         
            +
            end # Lockdown
         
     | 
    
        data/lib/lockdown/session.rb
    CHANGED
    
    | 
         @@ -1,51 +1,44 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # encoding: utf-8
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            module Lockdown
         
     | 
| 
       2 
4 
     | 
    
         
             
              module Session
         
     | 
| 
       3 
5 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
                protected
         
     | 
| 
       5 
6 
     | 
    
         | 
| 
       6 
7 
     | 
    
         
             
                def add_lockdown_session_values(user = nil)
         
     | 
| 
       7 
8 
     | 
    
         
             
                  user ||= current_user
         
     | 
| 
       8 
9 
     | 
    
         | 
| 
       9 
10 
     | 
    
         
             
                  if user
         
     | 
| 
       10 
     | 
    
         
            -
                    session[:access_rights] = Lockdown:: 
     | 
| 
      
 11 
     | 
    
         
            +
                    session[:access_rights] = Lockdown::Configuration.access_rights_for_user(user)
         
     | 
| 
       11 
12 
     | 
    
         
             
                    session[:current_user_id] = user.id
         
     | 
| 
       12 
13 
     | 
    
         
             
                  else
         
     | 
| 
       13 
     | 
    
         
            -
                    session[:access_rights] = Lockdown:: 
     | 
| 
      
 14 
     | 
    
         
            +
                    session[:access_rights] = Lockdown::Configuration.public_access
         
     | 
| 
       14 
15 
     | 
    
         
             
                  end
         
     | 
| 
       15 
16 
     | 
    
         
             
                end
         
     | 
| 
       16 
17 
     | 
    
         | 
| 
      
 18 
     | 
    
         
            +
                # Tests for current_user_id > 0
         
     | 
| 
      
 19 
     | 
    
         
            +
                # @return [True|False] 
         
     | 
| 
       17 
20 
     | 
    
         
             
                def logged_in?
         
     | 
| 
       18 
21 
     | 
    
         
             
                  current_user_id.to_i > 0
         
     | 
| 
       19 
22 
     | 
    
         
             
                end
         
     | 
| 
       20 
23 
     | 
    
         | 
| 
      
 24 
     | 
    
         
            +
                # @return session value of current_user_id
         
     | 
| 
       21 
25 
     | 
    
         
             
                def current_user_id
         
     | 
| 
       22 
26 
     | 
    
         
             
                  session[:current_user_id]
         
     | 
| 
       23 
27 
     | 
    
         
             
                end
         
     | 
| 
       24 
28 
     | 
    
         | 
| 
       25 
     | 
    
         
            -
                 
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
                 
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
                def  
     | 
| 
       30 
     | 
    
         
            -
                   
     | 
| 
       31 
     | 
    
         
            -
                     
     | 
| 
       32 
     | 
    
         
            -
                      return true if access_in_perm?(perm)
         
     | 
| 
       33 
     | 
    
         
            -
                    end
         
     | 
| 
       34 
     | 
    
         
            -
                  false
         
     | 
| 
       35 
     | 
    
         
            -
                end
         
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
                def access_in_perm?(perm)
         
     | 
| 
       38 
     | 
    
         
            -
                  if Lockdown::System.permissions[perm]
         
     | 
| 
       39 
     | 
    
         
            -
                    Lockdown::System.permissions[perm].each do |ar|
         
     | 
| 
       40 
     | 
    
         
            -
                      return true if session_access_rights_include?(ar)
         
     | 
| 
       41 
     | 
    
         
            -
                    end 
         
     | 
| 
      
 29 
     | 
    
         
            +
                # Returns true if the permission's regex_pattern is 
         
     | 
| 
      
 30 
     | 
    
         
            +
                # in session[:access_rights]
         
     | 
| 
      
 31 
     | 
    
         
            +
                # @param [String] name permission name
         
     | 
| 
      
 32 
     | 
    
         
            +
                # @return [True|False] 
         
     | 
| 
      
 33 
     | 
    
         
            +
                def access_in_perm?(name)
         
     | 
| 
      
 34 
     | 
    
         
            +
                  if perm = Lockdown::Configuration.permission(name)
         
     | 
| 
      
 35 
     | 
    
         
            +
                    return session_access_rights.include?(perm.regex_pattern)
         
     | 
| 
       42 
36 
     | 
    
         
             
                  end
         
     | 
| 
       43 
37 
     | 
    
         
             
                  false
         
     | 
| 
       44 
38 
     | 
    
         
             
                end
         
     | 
| 
       45 
39 
     | 
    
         | 
| 
       46 
     | 
    
         
            -
                def  
     | 
| 
       47 
     | 
    
         
            -
                   
     | 
| 
       48 
     | 
    
         
            -
                  session[:access_rights].include?(str)
         
     | 
| 
      
 40 
     | 
    
         
            +
                def session_access_rights
         
     | 
| 
      
 41 
     | 
    
         
            +
                  session[:access_rights].to_s
         
     | 
| 
       49 
42 
     | 
    
         
             
                end
         
     | 
| 
       50 
43 
     | 
    
         | 
| 
       51 
44 
     | 
    
         
             
                def reset_lockdown_session
         
     | 
| 
         @@ -53,7 +46,5 @@ module Lockdown 
     | 
|
| 
       53 
46 
     | 
    
         
             
                    session[val] = nil if session[val]
         
     | 
| 
       54 
47 
     | 
    
         
             
                  end
         
     | 
| 
       55 
48 
     | 
    
         
             
                end 
         
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
                alias_method :nil_lockdown_values, :reset_lockdown_session
         
     | 
| 
       58 
49 
     | 
    
         
             
              end # Session
         
     | 
| 
       59 
50 
     | 
    
         
             
            end # Lockdown
         
     | 
| 
         @@ -0,0 +1,16 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # encoding: utf-8
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module Lockdown
         
     | 
| 
      
 4 
     | 
    
         
            +
              class UserGroup
         
     | 
| 
      
 5 
     | 
    
         
            +
                # Name of permission
         
     | 
| 
      
 6 
     | 
    
         
            +
                attr_accessor :name
         
     | 
| 
      
 7 
     | 
    
         
            +
                # Array of permission objects that define the user group
         
     | 
| 
      
 8 
     | 
    
         
            +
                attr_accessor :permissions
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                # @param [String,Symbol] name permission reference. 
         
     | 
| 
      
 11 
     | 
    
         
            +
                def initialize(name)
         
     | 
| 
      
 12 
     | 
    
         
            +
                  @name = name.to_s
         
     | 
| 
      
 13 
     | 
    
         
            +
                  @permissions = []
         
     | 
| 
      
 14 
     | 
    
         
            +
                end
         
     | 
| 
      
 15 
     | 
    
         
            +
              end # Permission
         
     | 
| 
      
 16 
     | 
    
         
            +
            end # Lockdown
         
     | 
    
        data/lib/lockdown.rb
    CHANGED
    
    | 
         @@ -1,87 +1,42 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # encoding: utf-8
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            $:.unshift File.dirname(__FILE__)
         
     | 
| 
       2 
4 
     | 
    
         | 
| 
       3 
5 
     | 
    
         
             
            require 'logger'
         
     | 
| 
       4 
6 
     | 
    
         | 
| 
       5 
7 
     | 
    
         
             
            require File.join("lockdown", "errors")
         
     | 
| 
       6 
8 
     | 
    
         
             
            require File.join("lockdown", "helper")
         
     | 
| 
      
 9 
     | 
    
         
            +
            require File.join("lockdown", "configuration")
         
     | 
| 
       7 
10 
     | 
    
         
             
            require File.join("lockdown", "session")
         
     | 
| 
       8 
     | 
    
         
            -
            require File.join("lockdown", " 
     | 
| 
      
 11 
     | 
    
         
            +
            require File.join("lockdown", "delivery")
         
     | 
| 
      
 12 
     | 
    
         
            +
            require File.join("lockdown", "resource")
         
     | 
| 
       9 
13 
     | 
    
         
             
            require File.join("lockdown", "permission")
         
     | 
| 
      
 14 
     | 
    
         
            +
            require File.join("lockdown", "user_group")
         
     | 
| 
      
 15 
     | 
    
         
            +
            require File.join("lockdown", "access")
         
     | 
| 
       10 
16 
     | 
    
         
             
            require File.join("lockdown", "database")
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
            require File.join("lockdown", "system")
         
     | 
| 
       13 
     | 
    
         
            -
            require File.join("lockdown", "references")
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
       14 
18 
     | 
    
         | 
| 
       15 
19 
     | 
    
         
             
            module Lockdown
         
     | 
| 
       16 
     | 
    
         
            -
              extend Lockdown::References
         
     | 
| 
       17 
20 
     | 
    
         
             
              extend Lockdown::Helper
         
     | 
| 
       18 
21 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
              VERSION = '1.6.5'
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
22 
     | 
    
         
             
              class << self
         
     | 
| 
       22 
23 
     | 
    
         
             
                attr_accessor :logger
         
     | 
| 
       23 
24 
     | 
    
         | 
| 
       24 
     | 
    
         
            -
                #  
     | 
| 
      
 25 
     | 
    
         
            +
                # @return the version string for the library.
         
     | 
| 
       25 
26 
     | 
    
         
             
                def version
         
     | 
| 
       26 
     | 
    
         
            -
                   
     | 
| 
       27 
     | 
    
         
            -
                end
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
                def major_version
         
     | 
| 
       30 
     | 
    
         
            -
                  version.split('.')[0].to_i
         
     | 
| 
       31 
     | 
    
         
            -
                end
         
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
                def minor_version
         
     | 
| 
       34 
     | 
    
         
            -
                  version.split('.')[1].to_i
         
     | 
| 
      
 27 
     | 
    
         
            +
                  '2.0.0'
         
     | 
| 
       35 
28 
     | 
    
         
             
                end
         
     | 
| 
       36 
29 
     | 
    
         | 
| 
       37 
     | 
    
         
            -
                def  
     | 
| 
       38 
     | 
    
         
            -
                   
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
                # Mixin Lockdown code to the appropriate framework and ORM
         
     | 
| 
       42 
     | 
    
         
            -
                def mixin
         
     | 
| 
       43 
     | 
    
         
            -
                  if mixin_resource?("frameworks")
         
     | 
| 
       44 
     | 
    
         
            -
                    unless mixin_resource?("orms")
         
     | 
| 
       45 
     | 
    
         
            -
                      raise NotImplementedError, "ORM unknown to Lockdown!"
         
     | 
| 
       46 
     | 
    
         
            -
                    end
         
     | 
| 
       47 
     | 
    
         
            -
                  else
         
     | 
| 
       48 
     | 
    
         
            -
                    Lockdown.logger.info "=> Note:: Lockdown cannot determine framework and therefore is not active.\n"
         
     | 
| 
       49 
     | 
    
         
            -
                  end
         
     | 
| 
       50 
     | 
    
         
            -
                end # mixin
         
     | 
| 
      
 30 
     | 
    
         
            +
                def rails_mixin
         
     | 
| 
      
 31 
     | 
    
         
            +
                  require File.join("lockdown", "frameworks", "rails")
         
     | 
| 
      
 32 
     | 
    
         
            +
                  include Lockdown::Frameworks::Rails
         
     | 
| 
       51 
33 
     | 
    
         | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
                   
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
                  if File.exists?(Lockdown.init_file)
         
     | 
| 
       56 
     | 
    
         
            -
                    Lockdown.logger.info "=> Requiring Lockdown rules engine: #{Lockdown.init_file} \n"
         
     | 
| 
       57 
     | 
    
         
            -
                    load Lockdown.init_file
         
     | 
| 
       58 
     | 
    
         
            -
                  else
         
     | 
| 
       59 
     | 
    
         
            -
                    Lockdown.logger.info "=> Note:: Lockdown couldn't find init file: #{Lockdown.init_file}\n"
         
     | 
| 
       60 
     | 
    
         
            -
                  end
         
     | 
| 
      
 34 
     | 
    
         
            +
                  require File.join("lockdown", "orms", "active_record")
         
     | 
| 
      
 35 
     | 
    
         
            +
                  include Lockdown::Orms::ActiveRecord
         
     | 
| 
       61 
36 
     | 
    
         
             
                end
         
     | 
| 
       62 
37 
     | 
    
         | 
| 
       63 
     | 
    
         
            -
                private
         
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
                def mixin_resource?(str)
         
     | 
| 
       66 
     | 
    
         
            -
                  wildcard_path = File.join( File.dirname(__FILE__), 'lockdown', str , '*.rb' ) 
         
     | 
| 
       67 
     | 
    
         
            -
                  Dir[wildcard_path].each do |f|
         
     | 
| 
       68 
     | 
    
         
            -
                    require f
         
     | 
| 
       69 
     | 
    
         
            -
                    module_name = File.basename(f).split(".")[0]
         
     | 
| 
       70 
     | 
    
         
            -
                    module_class = eval("Lockdown::#{str.capitalize}::#{Lockdown.camelize(module_name)}")
         
     | 
| 
       71 
     | 
    
         
            -
                    if module_class.use_me?
         
     | 
| 
       72 
     | 
    
         
            -
                      include module_class
         
     | 
| 
       73 
     | 
    
         
            -
                      return true
         
     | 
| 
       74 
     | 
    
         
            -
                    end
         
     | 
| 
       75 
     | 
    
         
            -
                  end
         
     | 
| 
       76 
     | 
    
         
            -
                  false
         
     | 
| 
       77 
     | 
    
         
            -
                end # mixin_resource?
         
     | 
| 
       78 
38 
     | 
    
         
             
              end # class block
         
     | 
| 
       79 
39 
     | 
    
         | 
| 
       80 
40 
     | 
    
         
             
              self.logger = Logger.new(STDOUT)
         
     | 
| 
       81 
41 
     | 
    
         | 
| 
       82 
42 
     | 
    
         
             
            end # Lockdown
         
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
            Lockdown.logger.info "=> Mixing in Lockdown version: #{Lockdown.version} \n"
         
     | 
| 
       85 
     | 
    
         
            -
            Lockdown.mixin
         
     | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
       87 
     | 
    
         
            -
             
     | 
    
        data/lockdown.gemspec
    CHANGED
    
    | 
         @@ -5,11 +5,11 @@ 
     | 
|
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
            Gem::Specification.new do |s|
         
     | 
| 
       7 
7 
     | 
    
         
             
              s.name = %q{lockdown}
         
     | 
| 
       8 
     | 
    
         
            -
              s.version = " 
     | 
| 
      
 8 
     | 
    
         
            +
              s.version = "2.0.0"
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         
     | 
| 
       11 
11 
     | 
    
         
             
              s.authors = ["Andrew Stone"]
         
     | 
| 
       12 
     | 
    
         
            -
              s.date = %q{2010- 
     | 
| 
      
 12 
     | 
    
         
            +
              s.date = %q{2010-09-07}
         
     | 
| 
       13 
13 
     | 
    
         
             
              s.description = %q{Restrict access to your controller actions.  Supports basic model level restrictions as well}
         
     | 
| 
       14 
14 
     | 
    
         
             
              s.email = %q{andy@stonean.com}
         
     | 
| 
       15 
15 
     | 
    
         
             
              s.extra_rdoc_files = [
         
     | 
| 
         @@ -20,8 +20,10 @@ Gem::Specification.new do |s| 
     | 
|
| 
       20 
20 
     | 
    
         
             
                 "README.txt",
         
     | 
| 
       21 
21 
     | 
    
         
             
                 "Rakefile",
         
     | 
| 
       22 
22 
     | 
    
         
             
                 "lib/lockdown.rb",
         
     | 
| 
       23 
     | 
    
         
            -
                 "lib/lockdown/ 
     | 
| 
      
 23 
     | 
    
         
            +
                 "lib/lockdown/access.rb",
         
     | 
| 
      
 24 
     | 
    
         
            +
                 "lib/lockdown/configuration.rb",
         
     | 
| 
       24 
25 
     | 
    
         
             
                 "lib/lockdown/database.rb",
         
     | 
| 
      
 26 
     | 
    
         
            +
                 "lib/lockdown/delivery.rb",
         
     | 
| 
       25 
27 
     | 
    
         
             
                 "lib/lockdown/errors.rb",
         
     | 
| 
       26 
28 
     | 
    
         
             
                 "lib/lockdown/frameworks/rails.rb",
         
     | 
| 
       27 
29 
     | 
    
         
             
                 "lib/lockdown/frameworks/rails/controller.rb",
         
     | 
| 
         @@ -29,90 +31,48 @@ Gem::Specification.new do |s| 
     | 
|
| 
       29 
31 
     | 
    
         
             
                 "lib/lockdown/helper.rb",
         
     | 
| 
       30 
32 
     | 
    
         
             
                 "lib/lockdown/orms/active_record.rb",
         
     | 
| 
       31 
33 
     | 
    
         
             
                 "lib/lockdown/permission.rb",
         
     | 
| 
       32 
     | 
    
         
            -
                 "lib/lockdown/ 
     | 
| 
       33 
     | 
    
         
            -
                 "lib/lockdown/rspec_helper.rb",
         
     | 
| 
       34 
     | 
    
         
            -
                 "lib/lockdown/rules.rb",
         
     | 
| 
      
 34 
     | 
    
         
            +
                 "lib/lockdown/resource.rb",
         
     | 
| 
       35 
35 
     | 
    
         
             
                 "lib/lockdown/session.rb",
         
     | 
| 
       36 
     | 
    
         
            -
                 "lib/lockdown/ 
     | 
| 
      
 36 
     | 
    
         
            +
                 "lib/lockdown/user_group.rb",
         
     | 
| 
       37 
37 
     | 
    
         
             
                 "lockdown.gemspec",
         
     | 
| 
       38 
     | 
    
         
            -
                 " 
     | 
| 
       39 
     | 
    
         
            -
                 " 
     | 
| 
       40 
     | 
    
         
            -
                 " 
     | 
| 
       41 
     | 
    
         
            -
                 " 
     | 
| 
       42 
     | 
    
         
            -
                 " 
     | 
| 
       43 
     | 
    
         
            -
                 " 
     | 
| 
       44 
     | 
    
         
            -
                 " 
     | 
| 
       45 
     | 
    
         
            -
                 " 
     | 
| 
       46 
     | 
    
         
            -
                 " 
     | 
| 
       47 
     | 
    
         
            -
                 " 
     | 
| 
       48 
     | 
    
         
            -
                 "rails_generators/lockdown/templates/app/models/user.rb",
         
     | 
| 
       49 
     | 
    
         
            -
                 "rails_generators/lockdown/templates/app/models/user_group.rb",
         
     | 
| 
       50 
     | 
    
         
            -
                 "rails_generators/lockdown/templates/app/views/permissions/index.html.erb",
         
     | 
| 
       51 
     | 
    
         
            -
                 "rails_generators/lockdown/templates/app/views/permissions/show.html.erb",
         
     | 
| 
       52 
     | 
    
         
            -
                 "rails_generators/lockdown/templates/app/views/sessions/new.html.erb",
         
     | 
| 
       53 
     | 
    
         
            -
                 "rails_generators/lockdown/templates/app/views/user_groups/edit.html.erb",
         
     | 
| 
       54 
     | 
    
         
            -
                 "rails_generators/lockdown/templates/app/views/user_groups/index.html.erb",
         
     | 
| 
       55 
     | 
    
         
            -
                 "rails_generators/lockdown/templates/app/views/user_groups/new.html.erb",
         
     | 
| 
       56 
     | 
    
         
            -
                 "rails_generators/lockdown/templates/app/views/user_groups/show.html.erb",
         
     | 
| 
       57 
     | 
    
         
            -
                 "rails_generators/lockdown/templates/app/views/users/edit.html.erb",
         
     | 
| 
       58 
     | 
    
         
            -
                 "rails_generators/lockdown/templates/app/views/users/index.html.erb",
         
     | 
| 
       59 
     | 
    
         
            -
                 "rails_generators/lockdown/templates/app/views/users/new.html.erb",
         
     | 
| 
       60 
     | 
    
         
            -
                 "rails_generators/lockdown/templates/app/views/users/show.html.erb",
         
     | 
| 
       61 
     | 
    
         
            -
                 "rails_generators/lockdown/templates/config/initializers/lockit.rb",
         
     | 
| 
       62 
     | 
    
         
            -
                 "rails_generators/lockdown/templates/db/migrate/create_admin_user.rb",
         
     | 
| 
       63 
     | 
    
         
            -
                 "rails_generators/lockdown/templates/db/migrate/create_permissions.rb",
         
     | 
| 
       64 
     | 
    
         
            -
                 "rails_generators/lockdown/templates/db/migrate/create_profiles.rb",
         
     | 
| 
       65 
     | 
    
         
            -
                 "rails_generators/lockdown/templates/db/migrate/create_user_groups.rb",
         
     | 
| 
       66 
     | 
    
         
            -
                 "rails_generators/lockdown/templates/db/migrate/create_users.rb",
         
     | 
| 
       67 
     | 
    
         
            -
                 "rails_generators/lockdown/templates/lib/lockdown/README",
         
     | 
| 
       68 
     | 
    
         
            -
                 "rails_generators/lockdown/templates/lib/lockdown/init.rb",
         
     | 
| 
       69 
     | 
    
         
            -
                 "spec/lockdown/context_spec.rb",
         
     | 
| 
       70 
     | 
    
         
            -
                 "spec/lockdown/database_spec.rb",
         
     | 
| 
       71 
     | 
    
         
            -
                 "spec/lockdown/frameworks/rails/controller_spec.rb",
         
     | 
| 
       72 
     | 
    
         
            -
                 "spec/lockdown/frameworks/rails/view_spec.rb",
         
     | 
| 
       73 
     | 
    
         
            -
                 "spec/lockdown/frameworks/rails_spec.rb",
         
     | 
| 
       74 
     | 
    
         
            -
                 "spec/lockdown/permission_spec.rb",
         
     | 
| 
       75 
     | 
    
         
            -
                 "spec/lockdown/rspec_helper_spec.rb",
         
     | 
| 
       76 
     | 
    
         
            -
                 "spec/lockdown/rules_spec.rb",
         
     | 
| 
       77 
     | 
    
         
            -
                 "spec/lockdown/session_spec.rb",
         
     | 
| 
       78 
     | 
    
         
            -
                 "spec/lockdown/system_spec.rb",
         
     | 
| 
       79 
     | 
    
         
            -
                 "spec/lockdown_spec.rb",
         
     | 
| 
       80 
     | 
    
         
            -
                 "spec/rcov.opts",
         
     | 
| 
       81 
     | 
    
         
            -
                 "spec/spec.opts",
         
     | 
| 
       82 
     | 
    
         
            -
                 "spec/spec_helper.rb"
         
     | 
| 
      
 38 
     | 
    
         
            +
                 "test/helper.rb",
         
     | 
| 
      
 39 
     | 
    
         
            +
                 "test/lockdown/test_access.rb",
         
     | 
| 
      
 40 
     | 
    
         
            +
                 "test/lockdown/test_configuration.rb",
         
     | 
| 
      
 41 
     | 
    
         
            +
                 "test/lockdown/test_delivery.rb",
         
     | 
| 
      
 42 
     | 
    
         
            +
                 "test/lockdown/test_helper.rb",
         
     | 
| 
      
 43 
     | 
    
         
            +
                 "test/lockdown/test_permission.rb",
         
     | 
| 
      
 44 
     | 
    
         
            +
                 "test/lockdown/test_resource.rb",
         
     | 
| 
      
 45 
     | 
    
         
            +
                 "test/lockdown/test_session.rb",
         
     | 
| 
      
 46 
     | 
    
         
            +
                 "test/lockdown/test_user_group.rb",
         
     | 
| 
      
 47 
     | 
    
         
            +
                 "test/test_lockdown.rb"
         
     | 
| 
       83 
48 
     | 
    
         
             
              ]
         
     | 
| 
       84 
49 
     | 
    
         
             
              s.homepage = %q{http://stonean.com/wiki/lockdown}
         
     | 
| 
       85 
50 
     | 
    
         
             
              s.rdoc_options = ["--charset=UTF-8"]
         
     | 
| 
       86 
51 
     | 
    
         
             
              s.require_paths = ["lib"]
         
     | 
| 
       87 
52 
     | 
    
         
             
              s.rubyforge_project = %q{lockdown}
         
     | 
| 
       88 
     | 
    
         
            -
              s.rubygems_version = %q{1.3. 
     | 
| 
      
 53 
     | 
    
         
            +
              s.rubygems_version = %q{1.3.7}
         
     | 
| 
       89 
54 
     | 
    
         
             
              s.summary = %q{Authorization system for Rails 2.x}
         
     | 
| 
       90 
55 
     | 
    
         
             
              s.test_files = [
         
     | 
| 
       91 
     | 
    
         
            -
                " 
     | 
| 
       92 
     | 
    
         
            -
                 " 
     | 
| 
       93 
     | 
    
         
            -
                 " 
     | 
| 
       94 
     | 
    
         
            -
                 " 
     | 
| 
       95 
     | 
    
         
            -
                 " 
     | 
| 
       96 
     | 
    
         
            -
                 " 
     | 
| 
       97 
     | 
    
         
            -
                 " 
     | 
| 
       98 
     | 
    
         
            -
                 " 
     | 
| 
       99 
     | 
    
         
            -
                 " 
     | 
| 
       100 
     | 
    
         
            -
                 " 
     | 
| 
       101 
     | 
    
         
            -
                 "spec/lockdown_spec.rb",
         
     | 
| 
       102 
     | 
    
         
            -
                 "spec/spec_helper.rb"
         
     | 
| 
      
 56 
     | 
    
         
            +
                "test/lockdown/test_user_group.rb",
         
     | 
| 
      
 57 
     | 
    
         
            +
                 "test/lockdown/test_delivery.rb",
         
     | 
| 
      
 58 
     | 
    
         
            +
                 "test/lockdown/test_configuration.rb",
         
     | 
| 
      
 59 
     | 
    
         
            +
                 "test/lockdown/test_access.rb",
         
     | 
| 
      
 60 
     | 
    
         
            +
                 "test/lockdown/test_session.rb",
         
     | 
| 
      
 61 
     | 
    
         
            +
                 "test/lockdown/test_permission.rb",
         
     | 
| 
      
 62 
     | 
    
         
            +
                 "test/lockdown/test_helper.rb",
         
     | 
| 
      
 63 
     | 
    
         
            +
                 "test/lockdown/test_resource.rb",
         
     | 
| 
      
 64 
     | 
    
         
            +
                 "test/helper.rb",
         
     | 
| 
      
 65 
     | 
    
         
            +
                 "test/test_lockdown.rb"
         
     | 
| 
       103 
66 
     | 
    
         
             
              ]
         
     | 
| 
       104 
67 
     | 
    
         | 
| 
       105 
68 
     | 
    
         
             
              if s.respond_to? :specification_version then
         
     | 
| 
       106 
69 
     | 
    
         
             
                current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
         
     | 
| 
       107 
70 
     | 
    
         
             
                s.specification_version = 3
         
     | 
| 
       108 
71 
     | 
    
         | 
| 
       109 
     | 
    
         
            -
                if Gem::Version.new(Gem:: 
     | 
| 
       110 
     | 
    
         
            -
                  s.add_development_dependency(%q<rspec>, [">= 0"])
         
     | 
| 
      
 72 
     | 
    
         
            +
                if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
         
     | 
| 
       111 
73 
     | 
    
         
             
                else
         
     | 
| 
       112 
     | 
    
         
            -
                  s.add_dependency(%q<rspec>, [">= 0"])
         
     | 
| 
       113 
74 
     | 
    
         
             
                end
         
     | 
| 
       114 
75 
     | 
    
         
             
              else
         
     | 
| 
       115 
     | 
    
         
            -
                s.add_dependency(%q<rspec>, [">= 0"])
         
     | 
| 
       116 
76 
     | 
    
         
             
              end
         
     | 
| 
       117 
77 
     | 
    
         
             
            end
         
     | 
| 
       118 
78 
     | 
    
         | 
    
        data/test/helper.rb
    ADDED
    
    
| 
         @@ -0,0 +1,80 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class TestLockdownAccess < MiniTest::Unit::TestCase
         
     | 
| 
      
 4 
     | 
    
         
            +
              include Lockdown::Access
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              def teardown
         
     | 
| 
      
 7 
     | 
    
         
            +
                Lockdown::Configuration.reset
         
     | 
| 
      
 8 
     | 
    
         
            +
              end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
              def test_model_responds_to_permission
         
     | 
| 
      
 11 
     | 
    
         
            +
                assert_respond_to self, :permission
         
     | 
| 
      
 12 
     | 
    
         
            +
              end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
              def test_permission_with_single_resource
         
     | 
| 
      
 15 
     | 
    
         
            +
                perm = permission(:my_perm) do 
         
     | 
| 
      
 16 
     | 
    
         
            +
                          resource :my_resource
         
     | 
| 
      
 17 
     | 
    
         
            +
                       end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                resource = perm.resources.first
         
     | 
| 
      
 20 
     | 
    
         
            +
                assert_equal 'my_resource', resource.name
         
     | 
| 
      
 21 
     | 
    
         
            +
                assert_equal "\/my_resource(\/.*)?", resource.regex_pattern
         
     | 
| 
      
 22 
     | 
    
         
            +
              end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
              def test_permission_without_block
         
     | 
| 
      
 25 
     | 
    
         
            +
                perm = permission(:users) 
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                resource = perm.resources.first
         
     | 
| 
      
 28 
     | 
    
         
            +
                assert_equal 'users', resource.name
         
     | 
| 
      
 29 
     | 
    
         
            +
                assert_equal "\/users(\/.*)?", resource.regex_pattern
         
     | 
| 
      
 30 
     | 
    
         
            +
              end
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
              def test_public_access
         
     | 
| 
      
 33 
     | 
    
         
            +
                permission(:site)
         
     | 
| 
      
 34 
     | 
    
         
            +
                public_access :site
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                assert_equal Lockdown::Configuration.public_access, "(\/site(\/.*)?)"
         
     | 
| 
      
 37 
     | 
    
         
            +
              end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
              def test_public_access_with_multiple_permissions
         
     | 
| 
      
 40 
     | 
    
         
            +
                permission(:site)
         
     | 
| 
      
 41 
     | 
    
         
            +
                permission(:registration)
         
     | 
| 
      
 42 
     | 
    
         
            +
                permission(:view_posts)
         
     | 
| 
      
 43 
     | 
    
         
            +
                public_access :site, :registration, :view_posts
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                assert_equal Lockdown::Configuration.public_access, 
         
     | 
| 
      
 46 
     | 
    
         
            +
                  "(\/site(\/.*)?)|(\/registration(\/.*)?)|(\/view_posts(\/.*)?)"
         
     | 
| 
      
 47 
     | 
    
         
            +
              end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
              def test_protected_access
         
     | 
| 
      
 50 
     | 
    
         
            +
                permission(:my_account)
         
     | 
| 
      
 51 
     | 
    
         
            +
                protected_access :my_account
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
                assert_equal Lockdown::Configuration.protected_access, "(\/my_account(\/.*)?)"
         
     | 
| 
      
 54 
     | 
    
         
            +
              end
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
              def test_protected_access_with_multiple_permissions
         
     | 
| 
      
 57 
     | 
    
         
            +
                permission(:my_account)
         
     | 
| 
      
 58 
     | 
    
         
            +
                permission(:edit_posts)
         
     | 
| 
      
 59 
     | 
    
         
            +
                protected_access :my_account, :edit_posts
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
                assert_equal Lockdown::Configuration.protected_access, 
         
     | 
| 
      
 62 
     | 
    
         
            +
                  "(\/my_account(\/.*)?)|(\/edit_posts(\/.*)?)"
         
     | 
| 
      
 63 
     | 
    
         
            +
              end
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
              def test_user_group
         
     | 
| 
      
 66 
     | 
    
         
            +
                permission(:site)
         
     | 
| 
      
 67 
     | 
    
         
            +
                permission(:registration)
         
     | 
| 
      
 68 
     | 
    
         
            +
                permission(:view_posts)
         
     | 
| 
      
 69 
     | 
    
         
            +
                user_group(:all, :site, :registration, :view_posts)
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
                ug =  Lockdown::Configuration.find_or_create_user_group(:all)
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
                assert_equal 'all', ug.name
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
                assert_equal 'view_posts', ug.permissions.pop.name
         
     | 
| 
      
 76 
     | 
    
         
            +
                assert_equal 'registration', ug.permissions.pop.name
         
     | 
| 
      
 77 
     | 
    
         
            +
                assert_equal 'site', ug.permissions.pop.name
         
     | 
| 
      
 78 
     | 
    
         
            +
              end
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,194 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class Authorization
         
     | 
| 
      
 4 
     | 
    
         
            +
              include Lockdown::Access
         
     | 
| 
      
 5 
     | 
    
         
            +
            end
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            class TestLockdownConfiguration < MiniTest::Unit::TestCase
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
              def setup 
         
     | 
| 
      
 10 
     | 
    
         
            +
                @config = Lockdown::Configuration
         
     | 
| 
      
 11 
     | 
    
         
            +
              end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
              def teardown
         
     | 
| 
      
 14 
     | 
    
         
            +
                Lockdown::Configuration.reset
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
              def test_initial_state
         
     | 
| 
      
 18 
     | 
    
         
            +
                assert_equal false, @config.configured
         
     | 
| 
      
 19 
     | 
    
         
            +
                assert_equal "", @config.public_access
         
     | 
| 
      
 20 
     | 
    
         
            +
                assert_equal "", @config.protected_access
         
     | 
| 
      
 21 
     | 
    
         
            +
                assert_equal [], @config.permissions
         
     | 
| 
      
 22 
     | 
    
         
            +
                assert_equal [], @config.user_groups
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                assert_equal :current_user_id, @config.who_did_it
         
     | 
| 
      
 25 
     | 
    
         
            +
                assert_equal 1, @config.default_who_did_it
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                assert_equal "/", @config.access_denied_path
         
     | 
| 
      
 28 
     | 
    
         
            +
                assert_equal "/", @config.successful_login_path
         
     | 
| 
      
 29 
     | 
    
         
            +
                assert_equal false, @config.logout_on_access_violation
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                assert_equal "|", @config.link_separator
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                assert_equal "UserGroup", @config.user_group_model
         
     | 
| 
      
 34 
     | 
    
         
            +
                assert_equal "User", @config.user_model
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                assert_equal ['test'] , @config.skip_db_sync_in
         
     | 
| 
      
 37 
     | 
    
         
            +
              end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
              def test_authenticated_access
         
     | 
| 
      
 40 
     | 
    
         
            +
                Authorization.permission('home')
         
     | 
| 
      
 41 
     | 
    
         
            +
                Authorization.permission('faq')
         
     | 
| 
      
 42 
     | 
    
         
            +
                Authorization.permission('users')
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                Authorization.public_access('home', 'faq')
         
     | 
| 
      
 45 
     | 
    
         
            +
                Authorization.protected_access('users')
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                assert_equal "(/home(/.*)?)|(/faq(/.*)?)|(/users(/.*)?)", @config.authenticated_access
         
     | 
| 
      
 48 
     | 
    
         
            +
              end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
              def test_permission
         
     | 
| 
      
 51 
     | 
    
         
            +
                Authorization.permission('home')
         
     | 
| 
      
 52 
     | 
    
         
            +
                Authorization.permission('faq')
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                perm  = Lockdown::Permission.new('home')
         
     | 
| 
      
 55 
     | 
    
         
            +
                
         
     | 
| 
      
 56 
     | 
    
         
            +
                assert_equal perm.name, @config.permission('home').name
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                assert_raises(Lockdown::PermissionNotFound){ @config.permission('delta') }
         
     | 
| 
      
 59 
     | 
    
         
            +
              end
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
              def test_make_permission_public
         
     | 
| 
      
 62 
     | 
    
         
            +
                Authorization.permission('home')
         
     | 
| 
      
 63 
     | 
    
         
            +
                
         
     | 
| 
      
 64 
     | 
    
         
            +
                @config.make_permission_public('home')
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                perm = @config.permission('home')
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
                assert_equal true, perm.public?
         
     | 
| 
      
 69 
     | 
    
         
            +
              end
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
              def test_has_permission
         
     | 
| 
      
 72 
     | 
    
         
            +
                Authorization.permission('home')
         
     | 
| 
      
 73 
     | 
    
         
            +
                Authorization.permission('faq')
         
     | 
| 
      
 74 
     | 
    
         
            +
                Authorization.permission('about')
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
                perm  = Lockdown::Permission.new('home')
         
     | 
| 
      
 77 
     | 
    
         
            +
                perm2 = Lockdown::Permission.new('homey')
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
                assert_equal true, @config.has_permission?(perm)
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
      
 81 
     | 
    
         
            +
                assert_equal false, @config.has_permission?(perm2)
         
     | 
| 
      
 82 
     | 
    
         
            +
              end
         
     | 
| 
      
 83 
     | 
    
         
            +
             
     | 
| 
      
 84 
     | 
    
         
            +
              def test_permission_names
         
     | 
| 
      
 85 
     | 
    
         
            +
                Authorization.permission('home')
         
     | 
| 
      
 86 
     | 
    
         
            +
                Authorization.permission('faq')
         
     | 
| 
      
 87 
     | 
    
         
            +
                Authorization.permission('about')
         
     | 
| 
      
 88 
     | 
    
         
            +
             
     | 
| 
      
 89 
     | 
    
         
            +
                assert_equal 'about', @config.permissions.pop.name
         
     | 
| 
      
 90 
     | 
    
         
            +
                assert_equal 'faq', @config.permissions.pop.name
         
     | 
| 
      
 91 
     | 
    
         
            +
                assert_equal 'home', @config.permissions.pop.name
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
                assert_equal true, @config.permissions.empty?
         
     | 
| 
      
 94 
     | 
    
         
            +
              end
         
     | 
| 
      
 95 
     | 
    
         
            +
             
     | 
| 
      
 96 
     | 
    
         
            +
              def test_permission_assigned_automatically
         
     | 
| 
      
 97 
     | 
    
         
            +
                Authorization.permission('home')
         
     | 
| 
      
 98 
     | 
    
         
            +
                Authorization.permission('faq')
         
     | 
| 
      
 99 
     | 
    
         
            +
                Authorization.permission('users')
         
     | 
| 
      
 100 
     | 
    
         
            +
             
     | 
| 
      
 101 
     | 
    
         
            +
                Authorization.public_access('home', 'faq')
         
     | 
| 
      
 102 
     | 
    
         
            +
             
     | 
| 
      
 103 
     | 
    
         
            +
                assert_equal true, @config.permission_assigned_automatically?('home')
         
     | 
| 
      
 104 
     | 
    
         
            +
                assert_equal true, @config.permission_assigned_automatically?('faq')
         
     | 
| 
      
 105 
     | 
    
         
            +
                assert_equal false, @config.permission_assigned_automatically?('users')
         
     | 
| 
      
 106 
     | 
    
         
            +
              end
         
     | 
| 
      
 107 
     | 
    
         
            +
             
     | 
| 
      
 108 
     | 
    
         
            +
              def test_user_group
         
     | 
| 
      
 109 
     | 
    
         
            +
                Authorization.permission('home')
         
     | 
| 
      
 110 
     | 
    
         
            +
                Authorization.permission('faq')
         
     | 
| 
      
 111 
     | 
    
         
            +
             
     | 
| 
      
 112 
     | 
    
         
            +
                Authorization.user_group 'all', 'home', 'faq'
         
     | 
| 
      
 113 
     | 
    
         
            +
             
     | 
| 
      
 114 
     | 
    
         
            +
                ug =  @config.user_group('all')
         
     | 
| 
      
 115 
     | 
    
         
            +
             
     | 
| 
      
 116 
     | 
    
         
            +
                assert_equal 'faq', ug.permissions.pop.name
         
     | 
| 
      
 117 
     | 
    
         
            +
                assert_equal 'home',ug.permissions.pop.name
         
     | 
| 
      
 118 
     | 
    
         
            +
              end
         
     | 
| 
      
 119 
     | 
    
         
            +
             
     | 
| 
      
 120 
     | 
    
         
            +
              def test_maybe_add_user_group
         
     | 
| 
      
 121 
     | 
    
         
            +
                Authorization.permission('home')
         
     | 
| 
      
 122 
     | 
    
         
            +
                Authorization.permission('faq')
         
     | 
| 
      
 123 
     | 
    
         
            +
             
     | 
| 
      
 124 
     | 
    
         
            +
                Authorization.user_group 'all', 'home', 'faq'
         
     | 
| 
      
 125 
     | 
    
         
            +
                groups_1 = @config.user_groups
         
     | 
| 
      
 126 
     | 
    
         
            +
             
     | 
| 
      
 127 
     | 
    
         
            +
                Authorization.user_group 'all', 'home', 'faq'
         
     | 
| 
      
 128 
     | 
    
         
            +
                groups_2 = @config.user_groups
         
     | 
| 
      
 129 
     | 
    
         
            +
             
     | 
| 
      
 130 
     | 
    
         
            +
                assert_equal groups_1, groups_2
         
     | 
| 
      
 131 
     | 
    
         
            +
              end
         
     | 
| 
      
 132 
     | 
    
         
            +
             
     | 
| 
      
 133 
     | 
    
         
            +
              def test_find_or_create_user_group
         
     | 
| 
      
 134 
     | 
    
         
            +
                Authorization.permission('home')
         
     | 
| 
      
 135 
     | 
    
         
            +
                Authorization.permission('faq')
         
     | 
| 
      
 136 
     | 
    
         
            +
                Authorization.permission('about')
         
     | 
| 
      
 137 
     | 
    
         
            +
             
     | 
| 
      
 138 
     | 
    
         
            +
                Authorization.user_group 'testone', 'home', 'faq', 'about'
         
     | 
| 
      
 139 
     | 
    
         
            +
             
     | 
| 
      
 140 
     | 
    
         
            +
                ug = @config.find_or_create_user_group('testone')
         
     | 
| 
      
 141 
     | 
    
         
            +
             
     | 
| 
      
 142 
     | 
    
         
            +
                assert_equal 'testone', ug.name
         
     | 
| 
      
 143 
     | 
    
         
            +
             
     | 
| 
      
 144 
     | 
    
         
            +
                assert_equal 'about', ug.permissions.pop.name
         
     | 
| 
      
 145 
     | 
    
         
            +
                assert_equal 'faq', ug.permissions.pop.name
         
     | 
| 
      
 146 
     | 
    
         
            +
                assert_equal 'home', ug.permissions.pop.name
         
     | 
| 
      
 147 
     | 
    
         
            +
             
     | 
| 
      
 148 
     | 
    
         
            +
                assert_equal true, ug.permissions.empty?
         
     | 
| 
      
 149 
     | 
    
         
            +
             
     | 
| 
      
 150 
     | 
    
         
            +
                ug2 = @config.find_or_create_user_group('testtwo')
         
     | 
| 
      
 151 
     | 
    
         
            +
             
     | 
| 
      
 152 
     | 
    
         
            +
                assert_equal 'testtwo', ug2.name
         
     | 
| 
      
 153 
     | 
    
         
            +
                assert_equal true, ug2.permissions.empty?
         
     | 
| 
      
 154 
     | 
    
         
            +
              end
         
     | 
| 
      
 155 
     | 
    
         
            +
             
     | 
| 
      
 156 
     | 
    
         
            +
              def test_user_group_names
         
     | 
| 
      
 157 
     | 
    
         
            +
                Authorization.permission('home')
         
     | 
| 
      
 158 
     | 
    
         
            +
                Authorization.permission('faq')
         
     | 
| 
      
 159 
     | 
    
         
            +
                Authorization.permission('about')
         
     | 
| 
      
 160 
     | 
    
         
            +
             
     | 
| 
      
 161 
     | 
    
         
            +
                Authorization.user_group 'testone', 'home'
         
     | 
| 
      
 162 
     | 
    
         
            +
                Authorization.user_group 'testtwo', 'faq', 'about'
         
     | 
| 
      
 163 
     | 
    
         
            +
                
         
     | 
| 
      
 164 
     | 
    
         
            +
                assert_equal 'testtwo', @config.user_groups.pop.name
         
     | 
| 
      
 165 
     | 
    
         
            +
                assert_equal 'testone', @config.user_groups.pop.name
         
     | 
| 
      
 166 
     | 
    
         
            +
             
     | 
| 
      
 167 
     | 
    
         
            +
                assert_equal true, @config.user_groups.empty?
         
     | 
| 
      
 168 
     | 
    
         
            +
              end
         
     | 
| 
      
 169 
     | 
    
         
            +
             
     | 
| 
      
 170 
     | 
    
         
            +
              def test_user_group_permission_names
         
     | 
| 
      
 171 
     | 
    
         
            +
                Authorization.permission('home')
         
     | 
| 
      
 172 
     | 
    
         
            +
                Authorization.permission('faq')
         
     | 
| 
      
 173 
     | 
    
         
            +
                Authorization.permission('about')
         
     | 
| 
      
 174 
     | 
    
         
            +
             
     | 
| 
      
 175 
     | 
    
         
            +
                Authorization.user_group 'testone', 'home'
         
     | 
| 
      
 176 
     | 
    
         
            +
                Authorization.user_group 'testtwo', 'faq', 'about'
         
     | 
| 
      
 177 
     | 
    
         
            +
                
         
     | 
| 
      
 178 
     | 
    
         
            +
                assert_equal ['home'], @config.user_group_permissions_names('testone')
         
     | 
| 
      
 179 
     | 
    
         
            +
                assert_equal ['faq', 'about'], @config.user_group_permissions_names('testtwo')
         
     | 
| 
      
 180 
     | 
    
         
            +
              end
         
     | 
| 
      
 181 
     | 
    
         
            +
             
     | 
| 
      
 182 
     | 
    
         
            +
              def test_access_rights_for_permissions
         
     | 
| 
      
 183 
     | 
    
         
            +
                Authorization.permission('home')
         
     | 
| 
      
 184 
     | 
    
         
            +
                Authorization.permission('faq')
         
     | 
| 
      
 185 
     | 
    
         
            +
                Authorization.permission('about')
         
     | 
| 
      
 186 
     | 
    
         
            +
             
     | 
| 
      
 187 
     | 
    
         
            +
                assert_equal "((/home(/.*)?))|((/faq(/.*)?))|((/about(/.*)?))", 
         
     | 
| 
      
 188 
     | 
    
         
            +
                  @config.access_rights_for_permissions('home', 'faq', 'about')
         
     | 
| 
      
 189 
     | 
    
         
            +
              end
         
     | 
| 
      
 190 
     | 
    
         
            +
             
     | 
| 
      
 191 
     | 
    
         
            +
              def test_skip_sync?
         
     | 
| 
      
 192 
     | 
    
         
            +
                assert_equal true, @config.skip_sync?
         
     | 
| 
      
 193 
     | 
    
         
            +
              end
         
     | 
| 
      
 194 
     | 
    
         
            +
            end
         
     |