aegis 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -64,6 +64,7 @@ There is an awesome {documentation wiki}[http://wiki.github.com/makandra/aegis/]
64
64
  * {Handling denied permissions in your controllers}[http://wiki.github.com/makandra/aegis/handling-denied-permissions-in-your-controllers]
65
65
  * {Changing behavior when a permission is undefined}[http://wiki.github.com/makandra/aegis/changing-behavior-when-a-permission-is-undefined]
66
66
  * {Multiple roles per user}[http://wiki.github.com/makandra/aegis/multiple-roles-per-user]
67
+ * {Testing permissions}[http://wiki.github.com/makandra/aegis/testing-permissions]
67
68
  * {Upgrading to Aegis 2}[http://wiki.github.com/makandra/aegis/upgrading-to-aegis-2]
68
69
 
69
70
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.2.0
1
+ 2.3.0
data/aegis.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{aegis}
8
- s.version = "2.2.0"
8
+ s.version = "2.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Henning Koch", "Tobias Kraze"]
12
- s.date = %q{2010-08-13}
12
+ s.date = %q{2010-09-01}
13
13
  s.description = %q{Aegis is an authorization solution for Ruby on Rails that supports roles and a RESTish, resource-style declaration of permission rules.}
14
14
  s.email = %q{henning.koch@makandra.de}
15
15
  s.extra_rdoc_files = [
@@ -34,9 +34,15 @@ Gem::Specification.new do |s|
34
34
  "lib/aegis/role.rb",
35
35
  "lib/aegis/sieve.rb",
36
36
  "lib/aegis/spec.rb",
37
+ "lib/aegis/spec/matchers.rb",
37
38
  "lib/rails/action_controller.rb",
38
39
  "lib/rails/active_record.rb",
39
- "spec/action_controller_spec.rb",
40
+ "spec/aegis/action_controller_spec.rb",
41
+ "spec/aegis/has_role_spec.rb",
42
+ "spec/aegis/loader_spec.rb",
43
+ "spec/aegis/permissions_spec.rb",
44
+ "spec/aegis/sieve_spec.rb",
45
+ "spec/aegis/spec/matchers_spec.rb",
40
46
  "spec/app_root/app/controllers/application_controller.rb",
41
47
  "spec/app_root/app/controllers/reviews_controller.rb",
42
48
  "spec/app_root/app/controllers/songs_controller.rb",
@@ -60,11 +66,7 @@ Gem::Specification.new do |s|
60
66
  "spec/app_root/log/.gitignore",
61
67
  "spec/app_root/script/console",
62
68
  "spec/controllers/reviews_controller_spec.rb",
63
- "spec/has_role_spec.rb",
64
- "spec/loader_spec.rb",
65
- "spec/permissions_spec.rb",
66
69
  "spec/rcov.opts",
67
- "spec/sieve_spec.rb",
68
70
  "spec/spec.opts",
69
71
  "spec/spec_helper.rb"
70
72
  ]
@@ -93,13 +95,14 @@ Gem::Specification.new do |s|
93
95
  "spec/app_root/db/migrate/002_create_properties.rb",
94
96
  "spec/app_root/db/migrate/003_create_reviews.rb",
95
97
  "spec/app_root/lib/console_with_fixtures.rb",
96
- "spec/action_controller_spec.rb",
97
98
  "spec/controllers/reviews_controller_spec.rb",
98
99
  "spec/spec_helper.rb",
99
- "spec/loader_spec.rb",
100
- "spec/has_role_spec.rb",
101
- "spec/permissions_spec.rb",
102
- "spec/sieve_spec.rb"
100
+ "spec/aegis/action_controller_spec.rb",
101
+ "spec/aegis/has_role_spec.rb",
102
+ "spec/aegis/loader_spec.rb",
103
+ "spec/aegis/permissions_spec.rb",
104
+ "spec/aegis/sieve_spec.rb",
105
+ "spec/aegis/spec/matchers_spec.rb"
103
106
  ]
104
107
 
105
108
  if s.respond_to? :specification_version then
@@ -112,3 +115,4 @@ Gem::Specification.new do |s|
112
115
  else
113
116
  end
114
117
  end
118
+
@@ -0,0 +1,63 @@
1
+ module Aegis
2
+ module Spec
3
+ module Matchers
4
+
5
+ class CheckPermissions
6
+
7
+ def initialize(expected_resource, expected_options = {})
8
+ @expected_resource = expected_resource
9
+ @expected_options = expected_options
10
+ end
11
+
12
+ def matches?(controller)
13
+ @controller_class = controller.class
14
+ @actual_resource = @controller_class.instance_variable_get('@aegis_permissions_resource')
15
+ @actual_options = @controller_class.instance_variable_get('@aegis_permissions_options')
16
+ @actual_resource == @expected_resource && @actual_options == @expected_options
17
+ end
18
+
19
+ def failure_message
20
+ if @actual_resource != @expected_resource
21
+ "expected #{@controller_class} to check permissions against resource #{@expected_resource.inspect}, but it checked against #{@actual_resource.inspect}"
22
+ else
23
+ "expected #{@controller_class} to check permissions with options #{@expected_options.inspect}, but options were #{@actual_options.inspect}"
24
+ end
25
+ end
26
+
27
+ def negative_failure_message
28
+ if @actual_resource == @expected_resource
29
+ "expected #{@controller_class} to not check permissions against resource #{@expected_resource.inspect}"
30
+ else
31
+ "expected #{@controller_class} to not check permissions with options #{@expected_options.inspect}"
32
+ end
33
+ end
34
+
35
+ def description
36
+ description = "check permissions against resource #{@expected_resource.inspect}"
37
+ description << " with options #{@expected_options.inspect}" if @expected_options.any?
38
+ description
39
+ end
40
+
41
+ end
42
+
43
+ def check_permissions(*args)
44
+ CheckPermissions.new(*args)
45
+ end
46
+
47
+ def be_allowed_to(*args)
48
+ simple_matcher do |user, matcher|
49
+ action, *action_args = args
50
+ target = action.to_s + (action_args.present? ? " given #{action_args.inspect}" : "")
51
+ matcher.description = "be allowed to " + target
52
+ matcher.failure_message = "expected #{user.inspect} to be allowed to #{target}"
53
+ matcher.negative_failure_message = "expected #{user.inspect} to be denied to #{target}"
54
+ user.send("may_#{action}?", *action_args)
55
+ end
56
+ end
57
+
58
+ end
59
+ end
60
+ end
61
+
62
+ ActiveSupport::TestCase.send :include, Aegis::Spec::Matchers
63
+
data/lib/aegis/spec.rb CHANGED
@@ -1,86 +1,4 @@
1
- module Aegis
2
- module Matchers
1
+ # Support aegis/spec for old code.
2
+ # Maybe remove this some day.
3
+ require 'aegis/spec/matchers'
3
4
 
4
- class CheckPermissions
5
-
6
- def initialize(expected_resource, expected_options = {})
7
- @expected_resource = expected_resource
8
- @expected_options = expected_options
9
- end
10
-
11
- def matches?(controller)
12
- @controller_class = controller.class
13
- @actual_resource = @controller_class.instance_variable_get('@aegis_permissions_resource')
14
- @actual_options = @controller_class.instance_variable_get('@aegis_permissions_options')
15
- @actual_resource == @expected_resource && @actual_options == @expected_options
16
- end
17
-
18
- def failure_message
19
- if @actual_resource != @expected_resource
20
- "expected #{@controller_class} to check permissions against resource #{@expected_resource.inspect}, but it checked against #{@actual_resource.inspect}"
21
- else
22
- "expected #{@controller_class} to check permissions with options #{@expected_options.inspect}, but options were #{@actual_options.inspect}"
23
- end
24
- end
25
-
26
- def negative_failure_message
27
- if @actual_resource == @expected_resource
28
- "expected #{@controller_class} to not check permissions against resource #{@expected_resource.inspect}"
29
- else
30
- "expected #{@controller_class} to not check permissions with options #{@expected_options.inspect}"
31
- end
32
- end
33
-
34
- def description
35
- description = "check permissions against resource #{@expected_resource.inspect}"
36
- description << " with options #{@expected_options.inspect}" if @expected_options.any?
37
- description
38
- end
39
-
40
- end
41
-
42
- def check_permissions(*args)
43
- CheckPermissions.new(*args)
44
- end
45
-
46
- end
47
- end
48
-
49
-
50
- ActiveSupport::TestCase.send :include, Aegis::Matchers
51
-
52
- #Spec::Rails::Example::ControllerExampleGroup.extend Aegis::ControllerSpecMacros
53
-
54
-
55
- # def it_should_allow_access_for(*allowed_roles, &block)
56
- #
57
- # denied_roles = Permissions.roles.collect(&:name) - allowed_roles
58
- #
59
- # describe 'permissions' do
60
- #
61
- # before :each do
62
- # sign_out
63
- # end
64
- #
65
- # it "should deny access when no user is signed in" do
66
- # expect { instance_eval(&block) }.to raise_error(Aegis::AccessDenied)
67
- # end
68
- #
69
- # allowed_roles.each do |role|
70
- # it "should allow access for an authenticated #{role}" do
71
- # sign_in User.new(:role_name => role)
72
- # expect { instance_eval(&block) }.to_not raise_error
73
- # response.code.should == '200'
74
- # end
75
- # end
76
- #
77
- # denied_roles.each do |role|
78
- # it "should deny access for an authenticated #{role}" do
79
- # sign_in User.new(:role_name => role)
80
- # expect { instance_eval(&block) }.to raise_error(Aegis::AccessDenied)
81
- # end
82
- # end
83
- #
84
- # end
85
- #
86
- # end
@@ -1,6 +1,6 @@
1
- require File.dirname(__FILE__) + "/spec_helper"
1
+ require "spec_helper"
2
2
 
3
- describe 'Aegis::ActionController' do
3
+ describe Aegis::ActionController do
4
4
 
5
5
  before(:each) do
6
6
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/spec_helper"
1
+ require "spec_helper"
2
2
 
3
3
  describe Aegis::HasRole do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/spec_helper"
1
+ require "spec_helper"
2
2
 
3
3
  describe Aegis::Loader do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/spec_helper"
1
+ require "spec_helper"
2
2
 
3
3
  describe Aegis::Permissions do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/spec_helper"
1
+ require "spec_helper"
2
2
 
3
3
  describe Aegis::Sieve do
4
4
 
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe Aegis::Spec::Matchers do
4
+
5
+ describe 'be_allowed_to' do
6
+
7
+ before(:each) do
8
+
9
+ permissions = @permissions = Class.new(Aegis::Permissions) do
10
+ role :user
11
+ resources :files do
12
+ allow :user do
13
+ object == 'allowed-file'
14
+ end
15
+ end
16
+ end
17
+
18
+ @user_class = Class.new(ActiveRecord::Base) do
19
+ set_table_name 'users'
20
+ has_role :permissions => permissions
21
+ end
22
+
23
+ @user = @user_class.new(:role_name => 'user')
24
+
25
+ end
26
+
27
+ it 'should match the positive case' do
28
+ @user.should be_allowed_to(:update_file, 'allowed-file')
29
+ end
30
+
31
+ it 'should match the negative case' do
32
+ @user.should_not be_allowed_to(:update_file, 'denied-file')
33
+ end
34
+
35
+ end
36
+
37
+ describe 'check_permissions' do
38
+
39
+ before(:each) do
40
+ @controller = Class.new(ActionController::Base) do
41
+ permissions :post
42
+ end.new
43
+ end
44
+
45
+ it 'should match the positive case' do
46
+ @controller.should check_permissions(:post)
47
+ end
48
+
49
+ it 'should match the negative case' do
50
+ @controller.should_not check_permissions(:reviews)
51
+ end
52
+
53
+ end
54
+
55
+ end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 2
7
- - 2
7
+ - 3
8
8
  - 0
9
- version: 2.2.0
9
+ version: 2.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Henning Koch
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-13 00:00:00 +02:00
18
+ date: 2010-09-01 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -46,9 +46,15 @@ files:
46
46
  - lib/aegis/role.rb
47
47
  - lib/aegis/sieve.rb
48
48
  - lib/aegis/spec.rb
49
+ - lib/aegis/spec/matchers.rb
49
50
  - lib/rails/action_controller.rb
50
51
  - lib/rails/active_record.rb
51
- - spec/action_controller_spec.rb
52
+ - spec/aegis/action_controller_spec.rb
53
+ - spec/aegis/has_role_spec.rb
54
+ - spec/aegis/loader_spec.rb
55
+ - spec/aegis/permissions_spec.rb
56
+ - spec/aegis/sieve_spec.rb
57
+ - spec/aegis/spec/matchers_spec.rb
52
58
  - spec/app_root/app/controllers/application_controller.rb
53
59
  - spec/app_root/app/controllers/reviews_controller.rb
54
60
  - spec/app_root/app/controllers/songs_controller.rb
@@ -72,11 +78,7 @@ files:
72
78
  - spec/app_root/log/.gitignore
73
79
  - spec/app_root/script/console
74
80
  - spec/controllers/reviews_controller_spec.rb
75
- - spec/has_role_spec.rb
76
- - spec/loader_spec.rb
77
- - spec/permissions_spec.rb
78
81
  - spec/rcov.opts
79
- - spec/sieve_spec.rb
80
82
  - spec/spec.opts
81
83
  - spec/spec_helper.rb
82
84
  has_rdoc: true
@@ -129,10 +131,11 @@ test_files:
129
131
  - spec/app_root/db/migrate/002_create_properties.rb
130
132
  - spec/app_root/db/migrate/003_create_reviews.rb
131
133
  - spec/app_root/lib/console_with_fixtures.rb
132
- - spec/action_controller_spec.rb
133
134
  - spec/controllers/reviews_controller_spec.rb
134
135
  - spec/spec_helper.rb
135
- - spec/loader_spec.rb
136
- - spec/has_role_spec.rb
137
- - spec/permissions_spec.rb
138
- - spec/sieve_spec.rb
136
+ - spec/aegis/action_controller_spec.rb
137
+ - spec/aegis/has_role_spec.rb
138
+ - spec/aegis/loader_spec.rb
139
+ - spec/aegis/permissions_spec.rb
140
+ - spec/aegis/sieve_spec.rb
141
+ - spec/aegis/spec/matchers_spec.rb