aclatraz 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +0 -11
- data/CHANGELOG.rdoc +6 -0
- data/Rakefile +43 -41
- data/aclatraz.gemspec +20 -91
- data/lib/aclatraz.rb +7 -6
- data/lib/aclatraz/acl.rb +6 -8
- data/lib/aclatraz/store.rb +1 -0
- data/lib/aclatraz/store/cassandra.rb +2 -3
- data/lib/aclatraz/store/mongo.rb +56 -0
- data/lib/aclatraz/store/redis.rb +2 -3
- data/lib/aclatraz/store/riak.rb +2 -3
- data/spec/aclatraz/acl_spec.rb +34 -30
- data/spec/aclatraz/guard_spec.rb +136 -147
- data/spec/aclatraz/stores_spec.rb +54 -50
- data/spec/aclatraz/suspect_spec.rb +72 -70
- data/spec/aclatraz_spec.rb +14 -9
- data/spec/alcatraz_bm.rb +1 -1
- data/spec/spec_helper.rb +20 -0
- metadata +20 -26
- data/.document +0 -5
- data/VERSION +0 -1
@@ -5,97 +5,99 @@ describe "Aclatraz suspect" do
|
|
5
5
|
subject { StubSuspect.new }
|
6
6
|
let(:target) { StubTarget.new }
|
7
7
|
|
8
|
-
|
8
|
+
it "#acl_suspect? should be true" do
|
9
|
+
subject.should be_acl_suspect
|
10
|
+
end
|
9
11
|
|
10
|
-
it "
|
11
|
-
subject.roles.assign(:
|
12
|
-
subject.roles.assign(:
|
13
|
-
subject.roles.assign(:
|
12
|
+
it "should properly set given role" do
|
13
|
+
subject.roles.assign(:first)
|
14
|
+
subject.roles.assign(:second, StubTarget)
|
15
|
+
subject.roles.assign(:third, target)
|
14
16
|
|
15
|
-
subject.roles.has?(:
|
16
|
-
subject.roles.has?(:
|
17
|
-
subject.roles.has?(:
|
17
|
+
subject.roles.has?(:first).should be_true
|
18
|
+
subject.roles.has?(:second, StubTarget).should be_true
|
19
|
+
subject.roles.has?(:third, target).should be_true
|
18
20
|
end
|
19
21
|
|
20
|
-
it "
|
21
|
-
subject.roles.has?(:
|
22
|
-
subject.roles.has?(:
|
23
|
-
subject.roles.has?(:
|
24
|
-
subject.roles.has?(:
|
22
|
+
it "should properly check given permissions" do
|
23
|
+
subject.roles.has?(:first).should be_true
|
24
|
+
subject.roles.has?(:second, StubTarget).should be_true
|
25
|
+
subject.roles.has?(:third, target).should be_true
|
26
|
+
subject.roles.has?(:first, StubTarget).should be_false
|
25
27
|
end
|
26
28
|
|
27
|
-
it "
|
28
|
-
(subject.roles.all - ["
|
29
|
+
it "should allow to get list of roles assigned to user" do
|
30
|
+
(subject.roles.all - ["first", "second", "third"]) .should be_empty
|
29
31
|
end
|
30
32
|
|
31
|
-
it "
|
32
|
-
subject.roles.delete(:
|
33
|
-
subject.roles.delete(:
|
34
|
-
subject.roles.delete(:
|
33
|
+
it "should properly remove given permissions" do
|
34
|
+
subject.roles.delete(:first)
|
35
|
+
subject.roles.delete(:second, StubTarget)
|
36
|
+
subject.roles.delete(:third, target)
|
35
37
|
|
36
|
-
subject.roles.has?(:
|
37
|
-
subject.roles.has?(:
|
38
|
-
subject.roles.has?(:
|
38
|
+
subject.roles.has?(:first).should be_false
|
39
|
+
subject.roles.has?(:second, StubTarget).should be_false
|
40
|
+
subject.roles.has?(:third, target).should be_false
|
39
41
|
end
|
40
42
|
|
41
43
|
context "syntactic sugars" do
|
42
|
-
it "
|
43
|
-
subject.is.
|
44
|
-
subject.is.
|
45
|
-
subject.is.
|
46
|
-
subject.is.
|
47
|
-
subject.is.
|
48
|
-
subject.is.
|
49
|
-
subject.is.
|
44
|
+
it "should properly set given role" do
|
45
|
+
subject.is.first!
|
46
|
+
subject.is.second_of!(StubTarget)
|
47
|
+
subject.is.third_for!(target)
|
48
|
+
subject.is.fourth_on!(target)
|
49
|
+
subject.is.fifth_at!(target)
|
50
|
+
subject.is.sixth_by!(target)
|
51
|
+
subject.is.seventh_in!(target)
|
50
52
|
|
51
|
-
subject.roles.has?(:
|
52
|
-
subject.roles.has?(:
|
53
|
-
subject.roles.has?(:
|
54
|
-
subject.roles.has?(:
|
55
|
-
subject.roles.has?(:
|
56
|
-
subject.roles.has?(:
|
57
|
-
subject.roles.has?(:
|
53
|
+
subject.roles.has?(:first).should be_true
|
54
|
+
subject.roles.has?(:second_of, StubTarget).should be_true
|
55
|
+
subject.roles.has?(:third_for, target).should be_true
|
56
|
+
subject.roles.has?(:fourth_of, target).should be_true
|
57
|
+
subject.roles.has?(:fifth_at, target).should be_true
|
58
|
+
subject.roles.has?(:sixth_by, target).should be_true
|
59
|
+
subject.roles.has?(:seventh_in, target).should be_true
|
58
60
|
end
|
59
61
|
|
60
|
-
it "
|
61
|
-
subject.is.
|
62
|
-
subject.is.
|
63
|
-
subject.is.
|
64
|
-
subject.is.
|
65
|
-
subject.is.
|
66
|
-
subject.is.
|
67
|
-
subject.is.
|
68
|
-
subject.is.
|
62
|
+
it "should properly check given permissions" do
|
63
|
+
subject.is.first?.should be_true
|
64
|
+
subject.is.second_of?(StubTarget).should be_true
|
65
|
+
subject.is.third_for?(target).should be_true
|
66
|
+
subject.is.fourth_on?(target).should be_true
|
67
|
+
subject.is.fifth_at?(target).should be_true
|
68
|
+
subject.is.sixth_by?(target).should be_true
|
69
|
+
subject.is.seventh_in?(target).should be_true
|
70
|
+
subject.is.eighth_in?.should be_false
|
69
71
|
|
70
|
-
subject.is_not.
|
71
|
-
subject.is_not.
|
72
|
-
subject.is_not.
|
73
|
-
subject.is_not.
|
74
|
-
subject.is_not.
|
75
|
-
subject.is_not.
|
76
|
-
subject.is_not.
|
77
|
-
subject.is_not.
|
72
|
+
subject.is_not.first?.should be_false
|
73
|
+
subject.is_not.second_of?(StubTarget).should be_false
|
74
|
+
subject.is_not.third_for?(target).should be_false
|
75
|
+
subject.is_not.fourth_on?(target).should be_false
|
76
|
+
subject.is_not.fifth_at?(target).should be_false
|
77
|
+
subject.is_not.sixth_by?(target).should be_false
|
78
|
+
subject.is_not.seventh_in?(target).should be_false
|
79
|
+
subject.is_not.eighth_in?.should be_true
|
78
80
|
end
|
79
81
|
|
80
|
-
it "
|
81
|
-
subject.is_not.
|
82
|
-
subject.is_not.
|
83
|
-
subject.is_not.
|
84
|
-
subject.is_not.
|
85
|
-
subject.is_not.
|
86
|
-
subject.is_not.
|
87
|
-
subject.is_not.
|
82
|
+
it "should properly remove given permissions" do
|
83
|
+
subject.is_not.first!
|
84
|
+
subject.is_not.second_of!(StubTarget)
|
85
|
+
subject.is_not.third_for!(target)
|
86
|
+
subject.is_not.fourth_on!(target)
|
87
|
+
subject.is_not.fifth_at!(target)
|
88
|
+
subject.is_not.sixth_by!(target)
|
89
|
+
subject.is_not.seventh_in!(target)
|
88
90
|
|
89
|
-
subject.is.
|
90
|
-
subject.is.
|
91
|
-
subject.is.
|
92
|
-
subject.is.
|
93
|
-
subject.is.
|
94
|
-
subject.is.
|
95
|
-
subject.is.
|
91
|
+
subject.is.first?.should be_false
|
92
|
+
subject.is.second_of?(StubTarget).should be_false
|
93
|
+
subject.is.third_for?(target).should be_false
|
94
|
+
subject.is.fourth_on?(target).should be_false
|
95
|
+
subject.is.fifth_at?(target).should be_false
|
96
|
+
subject.is.sixth_by?(target).should be_false
|
97
|
+
subject.is.seventh_in?(target).should be_false
|
96
98
|
end
|
97
99
|
|
98
|
-
it "
|
100
|
+
it "should raise NoMethodError when there is not checker or setter/deleter called" do
|
99
101
|
lambda { subject.is.foobar }.should raise_error(NoMethodError)
|
100
102
|
lambda { subject.is_not.foobar }.should raise_error(NoMethodError)
|
101
103
|
end
|
data/spec/aclatraz_spec.rb
CHANGED
@@ -2,19 +2,24 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "Aclatraz" do
|
4
4
|
context "on init" do
|
5
|
-
it "should raise
|
6
|
-
lambda {
|
5
|
+
it "should raise error when given store is invalid" do
|
6
|
+
lambda {
|
7
|
+
Aclatraz.init(:invalid_data_store)
|
8
|
+
}.should raise_error(Aclatraz::InvalidStore)
|
7
9
|
end
|
8
10
|
|
9
|
-
it "should
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
it "should set data store when it is valid" do
|
12
|
+
lambda {
|
13
|
+
Aclatraz.init(StubStore)
|
14
|
+
Aclatraz.store.should be_kind_of(StubStore)
|
15
|
+
}.should_not raise_error
|
13
16
|
end
|
14
17
|
end
|
15
18
|
|
16
|
-
it "should raise
|
17
|
-
|
18
|
-
|
19
|
+
it "should raise error when store has not been initialized yet" do
|
20
|
+
lambda {
|
21
|
+
Aclatraz.instance_variable_set('@store', nil)
|
22
|
+
Aclatraz.store
|
23
|
+
}.should raise_error(Aclatraz::StoreNotInitialized)
|
19
24
|
end
|
20
25
|
end
|
data/spec/alcatraz_bm.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -5,6 +5,7 @@ $VERBOSE = nil
|
|
5
5
|
|
6
6
|
require 'rubygems'
|
7
7
|
require 'aclatraz'
|
8
|
+
require 'mocha'
|
8
9
|
require 'rspec'
|
9
10
|
|
10
11
|
RSpec.configure do |config|
|
@@ -30,3 +31,22 @@ end
|
|
30
31
|
class StubOwner
|
31
32
|
def id; 15; end
|
32
33
|
end
|
34
|
+
|
35
|
+
class GuardedParent
|
36
|
+
include Aclatraz::Guard
|
37
|
+
def user; @user ||= StubSuspect.new; end
|
38
|
+
suspects :user do
|
39
|
+
allow :cooker
|
40
|
+
deny :waiter
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class GuardedChild < GuardedParent
|
45
|
+
suspects do
|
46
|
+
deny :cooker
|
47
|
+
allow :manager
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class StubStore
|
52
|
+
end
|
metadata
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aclatraz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 4
|
10
|
+
version: 0.1.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
|
-
-
|
13
|
+
- Chris Kowalik
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-04 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
requirement: &id003 !ruby/object:Gem::Requirement
|
55
55
|
none: false
|
56
56
|
requirements:
|
57
|
-
- -
|
57
|
+
- - ">="
|
58
58
|
- !ruby/object:Gem::Version
|
59
59
|
hash: 25
|
60
60
|
segments:
|
@@ -69,7 +69,7 @@ dependencies:
|
|
69
69
|
requirement: &id004 !ruby/object:Gem::Requirement
|
70
70
|
none: false
|
71
71
|
requirements:
|
72
|
-
- -
|
72
|
+
- - ">="
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
hash: 3
|
75
75
|
segments:
|
@@ -84,7 +84,7 @@ dependencies:
|
|
84
84
|
requirement: &id005 !ruby/object:Gem::Requirement
|
85
85
|
none: false
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
hash: 27
|
90
90
|
segments:
|
@@ -99,7 +99,7 @@ dependencies:
|
|
99
99
|
requirement: &id006 !ruby/object:Gem::Requirement
|
100
100
|
none: false
|
101
101
|
requirements:
|
102
|
-
- -
|
102
|
+
- - ">="
|
103
103
|
- !ruby/object:Gem::Version
|
104
104
|
hash: 27
|
105
105
|
segments:
|
@@ -108,8 +108,9 @@ dependencies:
|
|
108
108
|
version: "0.8"
|
109
109
|
type: :development
|
110
110
|
version_requirements: *id006
|
111
|
-
description:
|
112
|
-
email:
|
111
|
+
description: Extremaly fast, flexible and intuitive access control mechanism, powered by fast key value stores like Redis.
|
112
|
+
email:
|
113
|
+
- chris@nu7hat.ch
|
113
114
|
executables: []
|
114
115
|
|
115
116
|
extensions: []
|
@@ -117,15 +118,15 @@ extensions: []
|
|
117
118
|
extra_rdoc_files:
|
118
119
|
- LICENSE
|
119
120
|
- README.rdoc
|
121
|
+
- CHANGELOG.rdoc
|
122
|
+
- TODO.rdoc
|
120
123
|
files:
|
121
|
-
- .document
|
122
124
|
- .gitignore
|
123
125
|
- CHANGELOG.rdoc
|
124
126
|
- LICENSE
|
125
127
|
- README.rdoc
|
126
128
|
- Rakefile
|
127
129
|
- TODO.rdoc
|
128
|
-
- VERSION
|
129
130
|
- aclatraz.gemspec
|
130
131
|
- examples/dinner.rb
|
131
132
|
- lib/aclatraz.rb
|
@@ -134,6 +135,7 @@ files:
|
|
134
135
|
- lib/aclatraz/helpers.rb
|
135
136
|
- lib/aclatraz/store.rb
|
136
137
|
- lib/aclatraz/store/cassandra.rb
|
138
|
+
- lib/aclatraz/store/mongo.rb
|
137
139
|
- lib/aclatraz/store/redis.rb
|
138
140
|
- lib/aclatraz/store/riak.rb
|
139
141
|
- lib/aclatraz/suspect.rb
|
@@ -150,8 +152,8 @@ homepage: http://github.com/nu7hatch/aclatraz
|
|
150
152
|
licenses: []
|
151
153
|
|
152
154
|
post_install_message:
|
153
|
-
rdoc_options:
|
154
|
-
|
155
|
+
rdoc_options: []
|
156
|
+
|
155
157
|
require_paths:
|
156
158
|
- lib
|
157
159
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -178,14 +180,6 @@ rubyforge_project:
|
|
178
180
|
rubygems_version: 1.3.7
|
179
181
|
signing_key:
|
180
182
|
specification_version: 3
|
181
|
-
summary: Flexible access control
|
182
|
-
test_files:
|
183
|
-
|
184
|
-
- spec/spec_helper.rb
|
185
|
-
- spec/aclatraz/guard_spec.rb
|
186
|
-
- spec/aclatraz/helpers_spec.rb
|
187
|
-
- spec/aclatraz/acl_spec.rb
|
188
|
-
- spec/aclatraz/stores_spec.rb
|
189
|
-
- spec/aclatraz/suspect_spec.rb
|
190
|
-
- spec/aclatraz_spec.rb
|
191
|
-
- examples/dinner.rb
|
183
|
+
summary: Flexible access control mechanism!
|
184
|
+
test_files: []
|
185
|
+
|
data/.document
DELETED
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.1.3
|