tuersteher 0.6.7 → 0.7.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.
- checksums.yaml +7 -0
- data/Gemfile +2 -2
- data/Rakefile +1 -0
- data/lib/tuersteher.rb +38 -0
- data/samples/access_rules.rb +1 -0
- data/spec/acces_rules_storage_spec.rb +2 -2
- data/spec/access_rules_spec.rb +41 -41
- data/spec/model_access_rule_spec.rb +16 -16
- data/spec/model_extensions_spec.rb +1 -1
- data/spec/path_access_rule_spec.rb +71 -48
- data/tuersteher.gemspec +4 -6
- metadata +44 -13
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6348fe3992d663e9b6a01a8271c2773449dad6ab
|
4
|
+
data.tar.gz: e7fe4ecfcb3d72f9b5edacdb712bc7decebb3b08
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 97f4fe7a0d7927a4a34d9be4c2a420c92edf641d6eb8dbd04efb45d72e608620711fba2e52c57b6c10793a44ccf0c6bcc3b2b92bf5236a8ad8071cb924f89aee
|
7
|
+
data.tar.gz: 2af00ecf5eefe5debce58d7370190a48c49236324ac961da9240a76e9a3f9261c0fc394f5c8d97fda3e4423d136ddd086d27c235f9fd1c88fc5a1cc5c267a35e
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/lib/tuersteher.rb
CHANGED
@@ -460,6 +460,26 @@ module Tuersteher
|
|
460
460
|
end
|
461
461
|
end
|
462
462
|
|
463
|
+
class RightSpecification
|
464
|
+
attr_reader :rights, :negation
|
465
|
+
|
466
|
+
def initialize right, negation
|
467
|
+
@negation = negation
|
468
|
+
@rights = [right]
|
469
|
+
end
|
470
|
+
|
471
|
+
def grant? path_or_model, method, login_ctx
|
472
|
+
return false if login_ctx.nil?
|
473
|
+
rc =@rights.any?{|right| login_ctx.has_right?(right) }
|
474
|
+
rc = !rc if @negation
|
475
|
+
rc
|
476
|
+
end
|
477
|
+
|
478
|
+
def to_s
|
479
|
+
"#{@negation && 'not.'}rights(#{@right.join(',')})"
|
480
|
+
end
|
481
|
+
end
|
482
|
+
|
463
483
|
class MethodSpecification
|
464
484
|
def initialize method, negation
|
465
485
|
@method, @negation = method, negation
|
@@ -527,6 +547,24 @@ module Tuersteher
|
|
527
547
|
def initialize
|
528
548
|
@rule_spezifications = []
|
529
549
|
@last_role_specification
|
550
|
+
@last_right_specification
|
551
|
+
end
|
552
|
+
|
553
|
+
# add right
|
554
|
+
def right(right_name)
|
555
|
+
return self if right_name==:all # :all is only syntax sugar
|
556
|
+
raise "wrong right '#{right_name}'! Must be a symbol " unless right_name.is_a?(Symbol)
|
557
|
+
# rights are OR-linked (per default)
|
558
|
+
# => add the right to RightSpecification, create only new RightSpecification if not exist
|
559
|
+
if @last_right_specification
|
560
|
+
raise("Mixin of right and not.right are yet not implemented!") if @negation != @last_right_specification.negation
|
561
|
+
@last_right_specification.rights << right_name
|
562
|
+
else
|
563
|
+
@last_right_specification = RightSpecification.new(right_name, @negation)
|
564
|
+
@rule_spezifications << @last_right_specification
|
565
|
+
end
|
566
|
+
@negation = false if @negation
|
567
|
+
self
|
530
568
|
end
|
531
569
|
|
532
570
|
# add role
|
data/samples/access_rules.rb
CHANGED
@@ -17,6 +17,7 @@
|
|
17
17
|
path('/').grant.method(:get)
|
18
18
|
path(:all).grant.role(:ADMIN)
|
19
19
|
path('/user/lock').deny.role(:USER).role(:APPROVER)
|
20
|
+
path('/statistic').grant.right(:STATISTIK_SHOW)
|
20
21
|
path('/special').grant.extension(:special?, :area1)
|
21
22
|
path('/pictures') do
|
22
23
|
grant.role(:admin)
|
data/spec/access_rules_spec.rb
CHANGED
@@ -13,7 +13,7 @@ module Tuersteher
|
|
13
13
|
PathAccessRule.new('/status').method(:get).role(:system)
|
14
14
|
]
|
15
15
|
AccessRulesStorage.instance.stub(:path_rules).and_return(rules)
|
16
|
-
@user =
|
16
|
+
@user = double('user')
|
17
17
|
end
|
18
18
|
|
19
19
|
|
@@ -23,15 +23,15 @@ module Tuersteher
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should be true for this paths" do
|
26
|
-
AccessRules.path_access?(@user, '/', :get).should
|
27
|
-
AccessRules.path_access?(@user, '/', :post).should
|
28
|
-
AccessRules.path_access?(@user, '/images', :get).should
|
26
|
+
AccessRules.path_access?(@user, '/', :get).should be_truthy
|
27
|
+
AccessRules.path_access?(@user, '/', :post).should be_truthy
|
28
|
+
AccessRules.path_access?(@user, '/images', :get).should be_truthy
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should not be true for this paths" do
|
32
|
-
AccessRules.path_access?(@user, '/admin', :get).should_not
|
33
|
-
AccessRules.path_access?(@user, '/images', :post).should_not
|
34
|
-
AccessRules.path_access?(@user, '/status', :get).should_not
|
32
|
+
AccessRules.path_access?(@user, '/admin', :get).should_not be_truthy
|
33
|
+
AccessRules.path_access?(@user, '/images', :post).should_not be_truthy
|
34
|
+
AccessRules.path_access?(@user, '/status', :get).should_not be_truthy
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -42,15 +42,15 @@ module Tuersteher
|
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should be true for this paths" do
|
45
|
-
AccessRules.path_access?(@user, '/', :get).should
|
46
|
-
AccessRules.path_access?(@user, '/admin', :post).should
|
47
|
-
AccessRules.path_access?(@user, '/images', :get).should
|
45
|
+
AccessRules.path_access?(@user, '/', :get).should be_truthy
|
46
|
+
AccessRules.path_access?(@user, '/admin', :post).should be_truthy
|
47
|
+
AccessRules.path_access?(@user, '/images', :get).should be_truthy
|
48
48
|
end
|
49
49
|
|
50
50
|
it "should not be true for this paths" do
|
51
|
-
AccessRules.path_access?(@user, '/xyz', :get).should_not
|
52
|
-
AccessRules.path_access?(@user, '/images', :post).should_not
|
53
|
-
AccessRules.path_access?(@user, '/status', :get).should_not
|
51
|
+
AccessRules.path_access?(@user, '/xyz', :get).should_not be_truthy
|
52
|
+
AccessRules.path_access?(@user, '/images', :post).should_not be_truthy
|
53
|
+
AccessRules.path_access?(@user, '/status', :get).should_not be_truthy
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -61,25 +61,25 @@ module Tuersteher
|
|
61
61
|
end
|
62
62
|
|
63
63
|
it "should be true for this paths" do
|
64
|
-
AccessRules.path_access?(@user, '/', :get).should
|
65
|
-
AccessRules.path_access?(@user, '/status', :get).should
|
64
|
+
AccessRules.path_access?(@user, '/', :get).should be_truthy
|
65
|
+
AccessRules.path_access?(@user, '/status', :get).should be_truthy
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should not be true for this paths" do
|
69
|
-
AccessRules.path_access?(@user, '/xyz', :get).should_not
|
70
|
-
AccessRules.path_access?(@user, '/admin', :post).should_not
|
69
|
+
AccessRules.path_access?(@user, '/xyz', :get).should_not be_truthy
|
70
|
+
AccessRules.path_access?(@user, '/admin', :post).should_not be_truthy
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
74
|
|
75
75
|
context "without user" do
|
76
76
|
it "should be true for this paths" do
|
77
|
-
AccessRules.path_access?(nil, '/', :get).should
|
77
|
+
AccessRules.path_access?(nil, '/', :get).should be_truthy
|
78
78
|
end
|
79
79
|
|
80
80
|
it "should not be true for this paths" do
|
81
|
-
AccessRules.path_access?(nil, '/xyz', :get).should_not
|
82
|
-
AccessRules.path_access?(nil, '/admin', :post).should_not
|
81
|
+
AccessRules.path_access?(nil, '/xyz', :get).should_not be_truthy
|
82
|
+
AccessRules.path_access?(nil, '/admin', :post).should_not be_truthy
|
83
83
|
end
|
84
84
|
end
|
85
85
|
end
|
@@ -100,7 +100,7 @@ module Tuersteher
|
|
100
100
|
ModelAccessRule.new(SampleModel2).grant.method(:all).role(:admin),
|
101
101
|
]
|
102
102
|
AccessRulesStorage.instance.stub(:model_rules).and_return(rules)
|
103
|
-
@user =
|
103
|
+
@user = double('user')
|
104
104
|
@model1 = SampleModel1.new
|
105
105
|
@model2 = SampleModel2.new
|
106
106
|
@model2.stub(:owner?).and_return(false)
|
@@ -113,15 +113,15 @@ module Tuersteher
|
|
113
113
|
end
|
114
114
|
|
115
115
|
it "should be true for this" do
|
116
|
-
AccessRules.model_access?(@user, @model1, :xyz).should
|
116
|
+
AccessRules.model_access?(@user, @model1, :xyz).should be_truthy
|
117
117
|
@model2.stub(:owner?).and_return true
|
118
|
-
AccessRules.model_access?(@user, @model2, :read).should
|
119
|
-
AccessRules.model_access?(@user, @model2, :update).should
|
118
|
+
AccessRules.model_access?(@user, @model2, :read).should be_truthy
|
119
|
+
AccessRules.model_access?(@user, @model2, :update).should be_truthy
|
120
120
|
end
|
121
121
|
|
122
122
|
it "should not be true for this" do
|
123
|
-
AccessRules.model_access?(@user, @model2, :update).should_not
|
124
|
-
AccessRules.model_access?(@user, @model2, :delete).should_not
|
123
|
+
AccessRules.model_access?(@user, @model2, :update).should_not be_truthy
|
124
|
+
AccessRules.model_access?(@user, @model2, :delete).should_not be_truthy
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
@@ -132,14 +132,14 @@ module Tuersteher
|
|
132
132
|
end
|
133
133
|
|
134
134
|
it "should be true for this" do
|
135
|
-
AccessRules.model_access?(@user, @model1, :xyz).should
|
136
|
-
AccessRules.model_access?(@user, @model2, :read).should
|
137
|
-
AccessRules.model_access?(@user, @model2, :update).should
|
138
|
-
AccessRules.model_access?(@user, @model2, :delete).should
|
135
|
+
AccessRules.model_access?(@user, @model1, :xyz).should be_truthy
|
136
|
+
AccessRules.model_access?(@user, @model2, :read).should be_truthy
|
137
|
+
AccessRules.model_access?(@user, @model2, :update).should be_truthy
|
138
|
+
AccessRules.model_access?(@user, @model2, :delete).should be_truthy
|
139
139
|
end
|
140
140
|
|
141
141
|
it "should not be true for this" do
|
142
|
-
AccessRules.model_access?(@user, @model2, :create).should_not
|
142
|
+
AccessRules.model_access?(@user, @model2, :create).should_not be_truthy
|
143
143
|
end
|
144
144
|
end
|
145
145
|
|
@@ -150,24 +150,24 @@ module Tuersteher
|
|
150
150
|
end
|
151
151
|
|
152
152
|
it "should be true for this" do
|
153
|
-
AccessRules.model_access?(@user, "test", :xyz).should
|
154
|
-
AccessRules.model_access?(@user, @model1, :xyz).should
|
155
|
-
AccessRules.model_access?(@user, @model2, :read).should
|
156
|
-
AccessRules.model_access?(@user, @model2, :update).should
|
157
|
-
AccessRules.model_access?(@user, @model2, :delete).should
|
158
|
-
AccessRules.model_access?(@user, @model2, :create).should
|
153
|
+
AccessRules.model_access?(@user, "test", :xyz).should be_truthy
|
154
|
+
AccessRules.model_access?(@user, @model1, :xyz).should be_truthy
|
155
|
+
AccessRules.model_access?(@user, @model2, :read).should be_truthy
|
156
|
+
AccessRules.model_access?(@user, @model2, :update).should be_truthy
|
157
|
+
AccessRules.model_access?(@user, @model2, :delete).should be_truthy
|
158
|
+
AccessRules.model_access?(@user, @model2, :create).should be_truthy
|
159
159
|
end
|
160
160
|
end
|
161
161
|
|
162
162
|
|
163
163
|
context "without user" do
|
164
164
|
it "should be true for this models" do
|
165
|
-
AccessRules.model_access?(nil, @model1, :xyz).should
|
166
|
-
AccessRules.model_access?(nil, @model2, :read).should
|
165
|
+
AccessRules.model_access?(nil, @model1, :xyz).should be_truthy
|
166
|
+
AccessRules.model_access?(nil, @model2, :read).should be_truthy
|
167
167
|
end
|
168
168
|
|
169
169
|
it "should not be true for this models" do
|
170
|
-
AccessRules.model_access?(nil, @model2, :update).should_not
|
170
|
+
AccessRules.model_access?(nil, @model2, :update).should_not be_truthy
|
171
171
|
end
|
172
172
|
end
|
173
173
|
end # of context 'model_access?'
|
@@ -186,7 +186,7 @@ module Tuersteher
|
|
186
186
|
ModelAccessRule.new(SampleModel).method(:update).role(:user).extension(:owner?),
|
187
187
|
]
|
188
188
|
AccessRulesStorage.instance.stub(:model_rules).and_return(rules)
|
189
|
-
@user =
|
189
|
+
@user = double('user')
|
190
190
|
@model1 = SampleModel.new
|
191
191
|
@model2 = SampleModel.new
|
192
192
|
@model3 = SampleModel.new
|
@@ -10,12 +10,12 @@ module Tuersteher
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should fired without user" do
|
13
|
-
@rule.fired?("test", :read, nil).should
|
13
|
+
@rule.fired?("test", :read, nil).should be_truthy
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should fired with user" do
|
17
|
-
@user =
|
18
|
-
@rule.fired?("test", :read, @user).should
|
17
|
+
@user = double('user')
|
18
|
+
@rule.fired?("test", :read, @user).should be_truthy
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -28,67 +28,67 @@ module Tuersteher
|
|
28
28
|
|
29
29
|
context "for User with role :admin" do
|
30
30
|
before do
|
31
|
-
@user =
|
31
|
+
@user = double('user')
|
32
32
|
@user.stub(:has_role?) { |role| role==:admin }
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should be fired for String-Object and access-type :read" do
|
36
|
-
@rule.fired?("test", :read, @user).should
|
36
|
+
@rule.fired?("test", :read, @user).should be_truthy
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should not be fired for Non-String-Object" do
|
40
|
-
@rule.fired?(12345, :read, @user).should_not
|
40
|
+
@rule.fired?(12345, :read, @user).should_not be_truthy
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should not be fired for String-Object and other access-method as :read" do
|
44
|
-
@rule.fired?("test", :delete, @user).should_not
|
44
|
+
@rule.fired?("test", :delete, @user).should_not be_truthy
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
context "for User without role :admin" do
|
49
49
|
before do
|
50
|
-
@user =
|
50
|
+
@user = double('user')
|
51
51
|
@user.stub(:has_role?).and_return(false)
|
52
52
|
end
|
53
53
|
|
54
54
|
specify do
|
55
|
-
@rule.fired?("test", :read, @user).should_not
|
55
|
+
@rule.fired?("test", :read, @user).should_not be_truthy
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
context "for :all Model-Instances" do
|
60
60
|
before do
|
61
61
|
@rule_all = ModelAccessRule.new(:all).grant.role(:admin)
|
62
|
-
@user =
|
62
|
+
@user = double('user')
|
63
63
|
end
|
64
64
|
|
65
65
|
it "should fired for user with role :admin" do
|
66
66
|
@user.stub(:has_role?) { |role| role==:admin }
|
67
|
-
@rule_all.fired?("test", :xyz, @user).should
|
67
|
+
@rule_all.fired?("test", :xyz, @user).should be_truthy
|
68
68
|
end
|
69
69
|
|
70
70
|
it "should fired for user with role :admin" do
|
71
71
|
@user.stub(:has_role?).and_return(false)
|
72
|
-
@rule_all.fired?("test", :xyz, @user).should_not
|
72
|
+
@rule_all.fired?("test", :xyz, @user).should_not be_truthy
|
73
73
|
end
|
74
74
|
end
|
75
75
|
end # of context "grant with roles"
|
76
76
|
|
77
77
|
|
78
78
|
context "deny with not.role" do
|
79
|
-
before
|
79
|
+
before do
|
80
80
|
@rule = ModelAccessRule.new(String).deny.method(:append).not.role(:admin)
|
81
|
-
@user =
|
81
|
+
@user = double('user')
|
82
82
|
end
|
83
83
|
|
84
84
|
it "should not fired for user with role :admin" do
|
85
85
|
@user.stub(:has_role?){|role| role==:admin}
|
86
|
-
@rule.fired?("/admin", :append, @user).should_not
|
86
|
+
@rule.fired?("/admin", :append, @user).should_not be_truthy
|
87
87
|
end
|
88
88
|
|
89
89
|
it "should fired for user with role :user" do
|
90
90
|
@user.stub(:has_role?){|role| role==:user}
|
91
|
-
@rule.fired?("/admin", :append, @user).should
|
91
|
+
@rule.fired?("/admin", :append, @user).should be_truthy
|
92
92
|
end
|
93
93
|
end # of context "deny with not.role"
|
94
94
|
|
@@ -16,7 +16,7 @@ module Tuersteher
|
|
16
16
|
before do
|
17
17
|
rules = [ModelAccessRule.new(SampleModel).grant.method(:deactived).role(:admin)]
|
18
18
|
AccessRulesStorage.instance.stub(:model_rules).and_return(rules)
|
19
|
-
@user =
|
19
|
+
@user = double('user')
|
20
20
|
Thread.current[:user] = @user
|
21
21
|
end
|
22
22
|
|
@@ -12,183 +12,206 @@ module Tuersteher
|
|
12
12
|
|
13
13
|
context "for User with role :admin" do
|
14
14
|
before do
|
15
|
-
@user =
|
15
|
+
@user = double('user')
|
16
16
|
@user.stub(:has_role?){|role| role==:admin}
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should be fired for path='/admin/xyz' and method :get" do
|
20
|
-
@rule.fired?("/admin/xyz", :get, @user).should
|
20
|
+
@rule.fired?("/admin/xyz", :get, @user).should be_truthy
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should not be fired for other path" do
|
24
|
-
@rule.fired?('/todos/admin', :get, @user).should_not
|
24
|
+
@rule.fired?('/todos/admin', :get, @user).should_not be_truthy
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should not be fired for other method as :get" do
|
28
|
-
@rule.fired?("/admin/xyz", :post, @user).should_not
|
28
|
+
@rule.fired?("/admin/xyz", :post, @user).should_not be_truthy
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
|
33
33
|
context "for User without role :admin" do
|
34
34
|
before do
|
35
|
-
@user =
|
35
|
+
@user = double('user')
|
36
36
|
@user.stub(:has_role?).and_return(false)
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should not be fired for correct path and method" do
|
40
|
-
@rule.fired?("/admin/xyz", :get, @user).should_not
|
40
|
+
@rule.fired?("/admin/xyz", :get, @user).should_not be_truthy
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
|
45
45
|
context "Rule with :all as Path-Matcher" do
|
46
|
-
before
|
46
|
+
before do
|
47
47
|
@rule = PathAccessRule.new(:all).method(:get).role(:sysadmin).role(:admin)
|
48
|
-
@user =
|
48
|
+
@user = double('user')
|
49
49
|
@user.stub(:has_role?).and_return(true)
|
50
50
|
end
|
51
51
|
|
52
52
|
it "should fired for several paths" do
|
53
|
-
@rule.fired?("/admin/xyz", :get, @user).should
|
54
|
-
@rule.fired?("/xyz", :get, @user).should
|
55
|
-
@rule.fired?("/", :get, @user).should
|
53
|
+
@rule.fired?("/admin/xyz", :get, @user).should be_truthy
|
54
|
+
@rule.fired?("/xyz", :get, @user).should be_truthy
|
55
|
+
@rule.fired?("/", :get, @user).should be_truthy
|
56
56
|
end
|
57
57
|
|
58
58
|
it "should not be fired with other method" do
|
59
|
-
@rule.fired?("/admin/xyz", :post, @user).should_not
|
59
|
+
@rule.fired?("/admin/xyz", :post, @user).should_not be_truthy
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
63
|
|
64
64
|
context "Rule with no Methode spezifed => all methods allowed" do
|
65
|
-
before
|
65
|
+
before do
|
66
66
|
@rule = PathAccessRule.new('/admin').role(:sysadmin).role(:admin)
|
67
|
-
@user =
|
67
|
+
@user = double('user')
|
68
68
|
@user.stub(:has_role?).and_return(true)
|
69
69
|
end
|
70
70
|
|
71
71
|
it "should fired for several methods" do
|
72
|
-
@rule.fired?("/admin/xyz", :get, @user).should
|
73
|
-
@rule.fired?("/admin/xyz", :post, @user).should
|
74
|
-
@rule.fired?("/admin/xyz", :put, @user).should
|
75
|
-
@rule.fired?("/admin/xyz", :delete, @user).should
|
72
|
+
@rule.fired?("/admin/xyz", :get, @user).should be_truthy
|
73
|
+
@rule.fired?("/admin/xyz", :post, @user).should be_truthy
|
74
|
+
@rule.fired?("/admin/xyz", :put, @user).should be_truthy
|
75
|
+
@rule.fired?("/admin/xyz", :delete, @user).should be_truthy
|
76
76
|
end
|
77
77
|
|
78
78
|
it "should not be fired with other path" do
|
79
|
-
@rule.fired?("/xyz", :post, @user).should_not
|
79
|
+
@rule.fired?("/xyz", :post, @user).should_not be_truthy
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
83
|
|
84
|
-
context "Rule with no role spezifed =>
|
85
|
-
before
|
84
|
+
context "Rule with no role spezifed => no role needed" do
|
85
|
+
before do
|
86
86
|
@rule = PathAccessRule.new('/public').method(:get)
|
87
|
-
@user =
|
87
|
+
@user = double('user')
|
88
88
|
@user.stub(:has_role?).and_return(false)
|
89
89
|
end
|
90
90
|
|
91
91
|
it "should fired for user with no roles" do
|
92
|
-
@rule.fired?("/public/xyz", :get, @user).should
|
92
|
+
@rule.fired?("/public/xyz", :get, @user).should be_truthy
|
93
93
|
end
|
94
94
|
|
95
95
|
it "should fired for non user" do
|
96
|
-
@rule.fired?("/public/xyz", :get, nil).should
|
96
|
+
@rule.fired?("/public/xyz", :get, nil).should be_truthy
|
97
97
|
end
|
98
98
|
|
99
99
|
it "should not be fired with other path" do
|
100
|
-
@rule.fired?("/xyz", :get, @user).should_not
|
100
|
+
@rule.fired?("/xyz", :get, @user).should_not be_truthy
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
104
|
|
105
105
|
context "Rule with extension" do
|
106
|
-
before
|
106
|
+
before do
|
107
107
|
@rule = PathAccessRule.new('/admin').method(:get).extension(:modul_function?, :testvalue)
|
108
108
|
@rule2 = PathAccessRule.new('/admin').method(:get).extension(:modul_function2?)
|
109
|
-
@user =
|
109
|
+
@user = double('user')
|
110
110
|
@user.stub(:has_role?).and_return(false)
|
111
111
|
end
|
112
112
|
|
113
113
|
it "should not be fired with user have not the check_extension" do
|
114
|
-
@rule.fired?("/admin", :get, @user).should_not
|
114
|
+
@rule.fired?("/admin", :get, @user).should_not be_truthy
|
115
115
|
end
|
116
116
|
|
117
117
|
it "should fired for user with true for check-extension" do
|
118
118
|
@user.should_receive(:modul_function?).with(:testvalue).and_return(true)
|
119
|
-
@rule.fired?("/admin/xyz", :get, @user).should
|
119
|
+
@rule.fired?("/admin/xyz", :get, @user).should be_truthy
|
120
120
|
end
|
121
121
|
|
122
122
|
it "should not be fired for user with false for check-extension" do
|
123
123
|
@user.should_receive(:modul_function?).with(:testvalue).and_return(false)
|
124
|
-
@rule.fired?("/admin/xyz", :get, @user).should_not
|
124
|
+
@rule.fired?("/admin/xyz", :get, @user).should_not be_truthy
|
125
125
|
end
|
126
126
|
|
127
127
|
it "should fired for rule2 and user with true for check-extension" do
|
128
128
|
@user.should_receive(:modul_function2?).and_return(true)
|
129
|
-
@rule2.fired?("/admin/xyz", :get, @user).should
|
129
|
+
@rule2.fired?("/admin/xyz", :get, @user).should be_truthy
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context "Rule with right" do
|
134
|
+
before do
|
135
|
+
@rule = PathAccessRule.new('/admin').right(:test1).right(:test2)
|
136
|
+
@user = double('user')
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should not be fired with user have not the right" do
|
140
|
+
@user.stub(:has_right?).and_return(false)
|
141
|
+
@rule.fired?("/admin", :get, @user).should be_falsey
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should fired for user with the right :test1" do
|
145
|
+
@user.should_receive(:has_right?).with(:test1).and_return(true)
|
146
|
+
@rule.fired?("/admin", :get, @user).should be_truthy
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should fired for user with the right :test2" do
|
150
|
+
@user.should_receive(:has_right?).with(:test1).and_return(false)
|
151
|
+
@user.should_receive(:has_right?).with(:test2).and_return(true)
|
152
|
+
@rule.fired?("/admin", :get, @user).should be_truthy
|
130
153
|
end
|
131
154
|
end
|
132
155
|
end # of context "grant" do
|
133
156
|
|
134
157
|
|
135
158
|
context "deny" do
|
136
|
-
before
|
159
|
+
before do
|
137
160
|
@rule = PathAccessRule.new('/admin').deny.role(:user)
|
138
|
-
@user =
|
161
|
+
@user = double('user')
|
139
162
|
end
|
140
163
|
|
141
164
|
it "should fired for user with role :user" do
|
142
165
|
@user.stub(:has_role?){|role| role==:user}
|
143
|
-
@rule.fired?("/admin", :get, @user).should
|
166
|
+
@rule.fired?("/admin", :get, @user).should be_truthy
|
144
167
|
end
|
145
168
|
|
146
169
|
it "should not fired for user with role :admin" do
|
147
170
|
@user.stub(:has_role?){|role| role==:admin}
|
148
|
-
@rule.fired?("/admin", :get, @user).should_not
|
171
|
+
@rule.fired?("/admin", :get, @user).should_not be_truthy
|
149
172
|
end
|
150
173
|
end # of context "deny" do
|
151
174
|
|
152
175
|
|
153
176
|
context "with not" do
|
154
177
|
context "as prefix for role" do
|
155
|
-
before
|
178
|
+
before do
|
156
179
|
@rule = PathAccessRule.new('/admin').deny.not.role(:admin)
|
157
|
-
@user =
|
180
|
+
@user = double('user')
|
158
181
|
end
|
159
182
|
|
160
183
|
it "should not fired for user with role :admin" do
|
161
184
|
@user.stub(:has_role?){|role| role==:admin}
|
162
|
-
@rule.fired?("/admin", :get, @user).should_not
|
185
|
+
@rule.fired?("/admin", :get, @user).should_not be_truthy
|
163
186
|
end
|
164
187
|
|
165
188
|
it "should fired for user with role :user" do
|
166
189
|
@user.stub(:has_role?){|role| role==:user}
|
167
|
-
@rule.fired?("/admin", :get, @user).should
|
190
|
+
@rule.fired?("/admin", :get, @user).should be_truthy
|
168
191
|
end
|
169
192
|
end
|
170
193
|
|
171
194
|
context "as prefix for extension" do
|
172
|
-
before
|
195
|
+
before do
|
173
196
|
@rule = PathAccessRule.new('/admin').grant.role(:admin).not.extension(:login_ctx_method)
|
174
|
-
@user =
|
197
|
+
@user = double('user')
|
175
198
|
end
|
176
199
|
|
177
200
|
it "should fired for user with role :admin and false for extension" do
|
178
201
|
@user.stub(:has_role?){|role| role==:admin}
|
179
202
|
@user.should_receive(:login_ctx_method).and_return(false)
|
180
|
-
@rule.fired?("/admin", :get, @user).should
|
203
|
+
@rule.fired?("/admin", :get, @user).should be_truthy
|
181
204
|
end
|
182
205
|
|
183
206
|
it "should not fired for user with role :admin and true for extension" do
|
184
207
|
@user.stub(:has_role?){|role| role==:admin}
|
185
208
|
@user.should_receive(:login_ctx_method).and_return(true)
|
186
|
-
@rule.fired?("/admin", :get, @user).should_not
|
209
|
+
@rule.fired?("/admin", :get, @user).should_not be_truthy
|
187
210
|
end
|
188
211
|
|
189
212
|
it "should not fired for user with role :user" do
|
190
213
|
@user.stub(:has_role?){|role| role==:user}
|
191
|
-
@rule.fired?("/admin", :get, @user).should
|
214
|
+
@rule.fired?("/admin", :get, @user).should be_falsey
|
192
215
|
end
|
193
216
|
|
194
217
|
end
|
@@ -196,21 +219,21 @@ module Tuersteher
|
|
196
219
|
|
197
220
|
|
198
221
|
context "add multiple roles" do
|
199
|
-
before
|
222
|
+
before do
|
200
223
|
@rule = PathAccessRule.new('/admin').roles(:admin1, :admin2).roles([:s1, :s2])
|
201
|
-
@user =
|
224
|
+
@user = double('user')
|
202
225
|
end
|
203
226
|
|
204
227
|
it "should fired for user with role which specified in the rule" do
|
205
228
|
[:admin1, :admin2, :s1, :s2].each do |role_name|
|
206
229
|
@user.stub(:has_role?){|role| role==role_name}
|
207
|
-
@rule.fired?("/admin", :get, @user).should
|
230
|
+
@rule.fired?("/admin", :get, @user).should be_truthy
|
208
231
|
end
|
209
232
|
end
|
210
233
|
|
211
234
|
it "should not fired for user with role :user" do
|
212
235
|
@user.stub(:has_role?){|role| role==:user}
|
213
|
-
@rule.fired?("/admin", :get, @user).should_not
|
236
|
+
@rule.fired?("/admin", :get, @user).should_not be_truthy
|
214
237
|
end
|
215
238
|
end
|
216
239
|
end
|
data/tuersteher.gemspec
CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = 'tuersteher'
|
6
|
-
s.version = '0.
|
6
|
+
s.version = '0.7.0'
|
7
7
|
s.authors = ["Bernd Ledig"]
|
8
8
|
s.email = ["bernd@ledig.info"]
|
9
9
|
s.homepage = "http://github.com/bledig/tuersteher"
|
@@ -20,12 +20,10 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
21
|
s.require_paths = ["lib"]
|
22
22
|
|
23
|
-
# specify any dependencies here; for example:
|
24
|
-
#s.add_runtime_dependency "rsolr", '>1.0', '<2.0'
|
25
|
-
#s.add_runtime_dependency "activesupport", '>3.0', '<4.0'
|
26
23
|
#s.add_runtime_dependency "i18n"
|
27
24
|
|
28
|
-
|
29
|
-
|
25
|
+
s.add_development_dependency "rake"
|
26
|
+
s.add_development_dependency "rspec", '>2.7', '<3.0'
|
27
|
+
|
30
28
|
end
|
31
29
|
|
metadata
CHANGED
@@ -1,19 +1,51 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tuersteher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.7.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Bernd Ledig
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-
|
13
|
-
dependencies:
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
date: 2014-08-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>'
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.7'
|
34
|
+
- - <
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '3.0'
|
37
|
+
type: :development
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - '>'
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '2.7'
|
44
|
+
- - <
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '3.0'
|
47
|
+
description: |2
|
48
|
+
Security-Layer for Rails-Application acts like a firewall.
|
17
49
|
email:
|
18
50
|
- bernd@ledig.info
|
19
51
|
executables: []
|
@@ -40,26 +72,25 @@ files:
|
|
40
72
|
- tuersteher.gemspec
|
41
73
|
homepage: http://github.com/bledig/tuersteher
|
42
74
|
licenses: []
|
75
|
+
metadata: {}
|
43
76
|
post_install_message:
|
44
77
|
rdoc_options: []
|
45
78
|
require_paths:
|
46
79
|
- lib
|
47
80
|
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
-
none: false
|
49
81
|
requirements:
|
50
|
-
- -
|
82
|
+
- - '>='
|
51
83
|
- !ruby/object:Gem::Version
|
52
84
|
version: '0'
|
53
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
-
none: false
|
55
86
|
requirements:
|
56
|
-
- -
|
87
|
+
- - '>='
|
57
88
|
- !ruby/object:Gem::Version
|
58
89
|
version: '0'
|
59
90
|
requirements: []
|
60
91
|
rubyforge_project: tuersteher
|
61
|
-
rubygems_version:
|
92
|
+
rubygems_version: 2.2.2
|
62
93
|
signing_key:
|
63
|
-
specification_version:
|
94
|
+
specification_version: 4
|
64
95
|
summary: summary of the gem
|
65
96
|
test_files: []
|