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
@@ -1,112 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), %w[.. spec_helper])
|
2
|
-
|
3
|
-
class TestAController
|
4
|
-
include Lockdown::Session
|
5
|
-
end
|
6
|
-
|
7
|
-
describe Lockdown::Session do
|
8
|
-
before do
|
9
|
-
@controller = TestAController.new
|
10
|
-
|
11
|
-
@actions = %w(posts/index posts/show posts/new posts/edit posts/create posts/update posts/destroy)
|
12
|
-
|
13
|
-
@session = {:access_rights => @actions}
|
14
|
-
|
15
|
-
@controller.stub!(:session).and_return(@session)
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "#logged_in?" do
|
19
|
-
it "should return false withou current_user_id" do
|
20
|
-
@controller.send(:logged_in?).should == false
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "#current_user_id" do
|
25
|
-
it "should return false withou current_user_id" do
|
26
|
-
@session[:current_user_id] = 2
|
27
|
-
@controller.send(:current_user_id).should == 2
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "#nil_lockdown_values" do
|
32
|
-
it "should nil access_rights" do
|
33
|
-
@controller.send :nil_lockdown_values
|
34
|
-
@session[:access_rights].should == nil
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "#current_user_access_in_group?" do
|
39
|
-
it "should return true if current user is admin" do
|
40
|
-
@actions = :all
|
41
|
-
@session = {:access_rights => @actions}
|
42
|
-
@controller.stub!(:session).and_return(@session)
|
43
|
-
|
44
|
-
@controller.send(:current_user_access_in_group?,:group).should == true
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should return true if current_user has access" do
|
48
|
-
user_groups = {:public_group => [:public_access]}
|
49
|
-
hash = {:public_access => ["posts/index", "posts/show"]}
|
50
|
-
Lockdown::System.stub!(:permissions).and_return(hash)
|
51
|
-
|
52
|
-
Lockdown::System.stub!(:user_groups).and_return(user_groups)
|
53
|
-
@controller.send(:current_user_access_in_group?,:public_group).should be_true
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should return false if current_user has access" do
|
57
|
-
user_groups = {:public_group => [:public_access]}
|
58
|
-
hash = {:public_access => ["books/edit", "books/update"]}
|
59
|
-
Lockdown::System.stub!(:permissions).and_return(hash)
|
60
|
-
|
61
|
-
Lockdown::System.stub!(:user_groups).and_return(user_groups)
|
62
|
-
@controller.send(:current_user_access_in_group?,:public_group).should be_false
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
describe "#current_user_is_admin?" do
|
67
|
-
it "should return true if access_rights == :all" do
|
68
|
-
@actions = :all
|
69
|
-
@session = {:access_rights => @actions}
|
70
|
-
@controller.stub!(:session).and_return(@session)
|
71
|
-
|
72
|
-
@controller.send(:current_user_is_admin?).should == true
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe "#add_lockdown_session_values" do
|
77
|
-
it "should set the access_rights from the user list" do
|
78
|
-
array = ["posts/index", "posts/show"]
|
79
|
-
Lockdown::System.stub!(:access_rights_for_user).and_return(array)
|
80
|
-
usr = mock('user')
|
81
|
-
usr.should_receive(:id).and_return(1234)
|
82
|
-
@controller.send(:add_lockdown_session_values, usr)
|
83
|
-
@session[:access_rights].should == array
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
|
88
|
-
describe "#access_in_perm" do
|
89
|
-
it "should return false if permissions nil" do
|
90
|
-
Lockdown::System.stub!(:permissions).and_return({})
|
91
|
-
@controller.send(:access_in_perm?,:dummy).should be_false
|
92
|
-
end
|
93
|
-
|
94
|
-
it "should return true if permission found" do
|
95
|
-
hash = {:public => ["posts/index", "posts/show"]}
|
96
|
-
Lockdown::System.stub!(:permissions).and_return(hash)
|
97
|
-
@controller.send(:access_in_perm?,:public).should be_true
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
describe "#session_access_rights_include?" do
|
102
|
-
it "should return true for posts/index" do
|
103
|
-
@controller.send(:session_access_rights_include?,'posts/index').
|
104
|
-
should == true
|
105
|
-
end
|
106
|
-
|
107
|
-
it "should return false for pages/index" do
|
108
|
-
@controller.send(:session_access_rights_include?,'pages/index').
|
109
|
-
should == false
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), %w[.. spec_helper])
|
2
|
-
require File.join(File.dirname(__FILE__), %w[.. .. lib lockdown rules])
|
3
|
-
|
4
|
-
describe Lockdown::System do
|
5
|
-
it "should fetch the option" do
|
6
|
-
Lockdown::System.options = {}
|
7
|
-
Lockdown::System.options['test'] = "my test"
|
8
|
-
Lockdown::System.fetch('test').should == "my test"
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "#configure" do
|
12
|
-
it "should call the methods responsible for defining the rules" do
|
13
|
-
Lockdown::System.stub!(:skip_sync?).and_return(false)
|
14
|
-
|
15
|
-
Lockdown::System.should_receive :set_defaults
|
16
|
-
|
17
|
-
Lockdown::System.should_receive :instance_eval
|
18
|
-
|
19
|
-
Lockdown::System.should_receive :process_rules
|
20
|
-
|
21
|
-
Lockdown::Database.should_receive :sync_with_db
|
22
|
-
|
23
|
-
Lockdown.should_receive :caching?
|
24
|
-
|
25
|
-
Lockdown::System.configure do
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe "#paths_for" do
|
31
|
-
it "should join the str_sym to the methods" do
|
32
|
-
Lockdown::System.paths_for(:users, :show, :edit).
|
33
|
-
should == ["users/show", "users/edit"]
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should add users to the array if access is granted on index" do
|
37
|
-
Lockdown::System.paths_for(:users, :index, :show, :edit).
|
38
|
-
should == ["users/index", "users/show", "users/edit", "users"]
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should build the paths from the controller class if no methods specified" do
|
42
|
-
methods = ["new","edit","create","update"]
|
43
|
-
Lockdown.stub!(:fetch_controller_class)
|
44
|
-
Lockdown::System.stub!(:available_actions).
|
45
|
-
and_return(methods)
|
46
|
-
|
47
|
-
Lockdown::System.paths_for(:users).
|
48
|
-
should == ["users/new","users/edit","users/create","users/update"]
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
data/spec/lockdown_spec.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
-
|
3
|
-
describe Lockdown do
|
4
|
-
before do
|
5
|
-
Lockdown.stub!(:version).and_return('1.2.3')
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should return the correct major version" do
|
9
|
-
Lockdown.major_version.should equal(1)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should return the correct minor version" do
|
13
|
-
Lockdown.minor_version.should equal(2)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should return the correct patch version" do
|
17
|
-
Lockdown.patch_version.should equal(3)
|
18
|
-
end
|
19
|
-
end
|
data/spec/rcov.opts
DELETED
data/spec/spec.opts
DELETED