iceburn 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/iceburn/version.rb +1 -1
- data/lib/iceburn/whitelist.rb +17 -6
- data/spec/iceburn/whitelist_spec.rb +30 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6e02310aea7adbca0b0ec5601d1a94fca78b87d
|
4
|
+
data.tar.gz: 93f07e64ad647a36e28797a8e0b0e1cd19067329
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9dfbb362c9709d87d1177858e33cfaa3ca8ef868f63f7f390454b489a51b570e9acf670c5200f1a0c1d814aa8dbdbe7c6ce347ae5db2b89d267e0daba7e3dcd
|
7
|
+
data.tar.gz: d8b05b361fb852cde4c5e8d81437abaae687ab024caf930c6c3fb68c9ca917f97d7d62c47388964fac88dfe6c783433cf99b35be1977fb04569a4cbc7d2e7a5b
|
data/Gemfile.lock
CHANGED
data/lib/iceburn/version.rb
CHANGED
data/lib/iceburn/whitelist.rb
CHANGED
@@ -9,11 +9,11 @@ module Iceburn
|
|
9
9
|
extend ActiveSupport::Concern
|
10
10
|
|
11
11
|
module ClassMethods
|
12
|
-
cattr_accessor :
|
12
|
+
cattr_accessor :iceburn_whitelisted_routes
|
13
13
|
|
14
14
|
# Set the whitelist of controllers not affected by Filters.
|
15
|
-
def iceburn_whitelist(*
|
16
|
-
self.
|
15
|
+
def iceburn_whitelist(*routes)
|
16
|
+
self.iceburn_whitelisted_routes = routes
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -21,11 +21,22 @@ module Iceburn
|
|
21
21
|
# Test if this controller is in the pre-defined whitelist controller
|
22
22
|
# params.
|
23
23
|
def whitelisted?
|
24
|
-
|
24
|
+
controller_whitelisted? || action_whitelisted?
|
25
25
|
end
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
private
|
28
|
+
def controller_whitelisted?
|
29
|
+
iceburn_whitelisted_routes.include? params[:controller]
|
30
|
+
end
|
31
|
+
|
32
|
+
def action_whitelisted?
|
33
|
+
iceburn_whitelisted_routes.any? do |route|
|
34
|
+
route =~ /#{params[:controller]}##{params[:action]}/
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def iceburn_whitelisted_routes
|
39
|
+
self.class.iceburn_whitelisted_routes || []
|
29
40
|
end
|
30
41
|
end
|
31
42
|
end
|
@@ -9,23 +9,48 @@ module Iceburn
|
|
9
9
|
describe Whitelist do
|
10
10
|
subject { Controller.new }
|
11
11
|
|
12
|
-
context "when a whitelist is defined" do
|
12
|
+
context "when a whitelist is defined with only controllers" do
|
13
13
|
before do
|
14
14
|
Controller.class_eval { iceburn_whitelist 'sessions', 'users' }
|
15
15
|
end
|
16
16
|
|
17
17
|
it "defines a whitelist" do
|
18
|
-
expect(Controller.
|
19
|
-
expect(Controller.
|
18
|
+
expect(Controller.iceburn_whitelisted_routes).to include('sessions')
|
19
|
+
expect(Controller.iceburn_whitelisted_routes).to include('users')
|
20
20
|
end
|
21
21
|
|
22
22
|
it "whitelists controllers in the whitelist" do
|
23
23
|
allow(subject).to receive(:params).and_return(:controller => 'sessions')
|
24
|
+
expect(subject.send(:controller_whitelisted?)).to eq(true)
|
24
25
|
expect(subject).to be_whitelisted
|
25
26
|
end
|
26
27
|
|
27
28
|
it "allows other controllers to be filtered html" do
|
28
29
|
allow(subject).to receive(:params).and_return(:controller => 'posts')
|
30
|
+
expect(subject.send(:controller_whitelisted?)).to eq(false)
|
31
|
+
expect(subject).to_not be_whitelisted
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when a whitelist is defined with actions" do
|
36
|
+
before do
|
37
|
+
Controller.class_eval { iceburn_whitelist 'sessions#new' }
|
38
|
+
end
|
39
|
+
|
40
|
+
it "defines a whitelist" do
|
41
|
+
expect(Controller.iceburn_whitelisted_routes).to include('sessions#new')
|
42
|
+
end
|
43
|
+
|
44
|
+
it "whitelists controllers in the whitelist" do
|
45
|
+
allow(subject).to receive(:params).and_return \
|
46
|
+
:controller => 'sessions', :action => 'new'
|
47
|
+
expect(subject).to be_whitelisted
|
48
|
+
expect(subject.send(:action_whitelisted?)).to eq(true)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "allows other controllers to be filtered html" do
|
52
|
+
allow(subject).to receive(:params).and_return(:controller => 'posts')
|
53
|
+
expect(subject.send(:action_whitelisted?)).to eq(false)
|
29
54
|
expect(subject).to_not be_whitelisted
|
30
55
|
end
|
31
56
|
end
|
@@ -37,6 +62,8 @@ module Iceburn
|
|
37
62
|
|
38
63
|
it "allows all controllers to be filtered html" do
|
39
64
|
allow(subject).to receive(:params).and_return(:controller => 'sessions')
|
65
|
+
expect(subject.send(:controller_whitelisted?)).to eq(false)
|
66
|
+
expect(subject.send(:action_whitelisted?)).to eq(false)
|
40
67
|
expect(subject).to_not be_whitelisted
|
41
68
|
end
|
42
69
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iceburn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Scott
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|