firewall_constraint 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 502e9d611ee75a4ff89fec91897d9a87a85fb7f6
|
4
|
+
data.tar.gz: 79dd258d71e248fc4eb5ffe37965ca9dab1b2d3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3594f8cce23a0db8275ee5715baa423097bf2eb0c489b4213b998cc90aed7641d5bec1daa40aa18b5838d32d1d29840465ef2bc8d4fcd4437546815c75283648
|
7
|
+
data.tar.gz: caf17eb249c6ab734ee0e0acb820b076fcec102136697cdddfe8e592fc9e6056c1b292702b01e6f0a99e875707aa06280de6e852b8ffa8fc5c4ea92c1c8cc3ab
|
data/Gemfile.lock
CHANGED
data/lib/firewall_constraint.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module FirewallConstraint
|
2
2
|
require 'ipaddress'
|
3
3
|
class Constraint
|
4
|
+
cattr_accessor :config
|
5
|
+
|
4
6
|
def initialize(ips = [])
|
5
7
|
if ips.respond_to? :call
|
6
8
|
@ips = ips
|
@@ -20,9 +22,10 @@ module FirewallConstraint
|
|
20
22
|
rescue NoMethodError => nme
|
21
23
|
end
|
22
24
|
end
|
25
|
+
raise config.raise_exception if config && config.raise_exception
|
23
26
|
false
|
24
27
|
end
|
25
|
-
|
28
|
+
|
26
29
|
def parsed_ips
|
27
30
|
cur_ips = ips
|
28
31
|
if cur_ips == @old_ips
|
@@ -38,8 +41,22 @@ module FirewallConstraint
|
|
38
41
|
@ips.respond_to?(:call) ? @ips.call : @ips
|
39
42
|
end
|
40
43
|
end
|
41
|
-
|
44
|
+
|
45
|
+
class Config
|
46
|
+
attr_accessor :raise_exception
|
47
|
+
end
|
48
|
+
|
42
49
|
def self.new(*args)
|
43
50
|
Constraint.new(*args)
|
44
51
|
end
|
52
|
+
|
53
|
+
def self.config
|
54
|
+
if block_given?
|
55
|
+
c = Constraint.config || Config.new
|
56
|
+
yield c
|
57
|
+
Constraint.config = c
|
58
|
+
else
|
59
|
+
Constraint.config
|
60
|
+
end
|
61
|
+
end
|
45
62
|
end
|
@@ -112,5 +112,19 @@ describe "DummyController", type: :request do
|
|
112
112
|
it 'should not get dynamic constraint' do
|
113
113
|
expect{get '/dummy/blocked_by_dynamic'}.to raise_error ActionController::RoutingError
|
114
114
|
end
|
115
|
+
|
116
|
+
context 'given a provided exception' do
|
117
|
+
around do |example|
|
118
|
+
FirewallConstraint.config do |fc|
|
119
|
+
fc.raise_exception = ActionController::BadRequest
|
120
|
+
end
|
121
|
+
example.run
|
122
|
+
FirewallConstraint.config.raise_exception = nil
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'should throw the correct exception' do
|
126
|
+
expect{get '/dummy/blocked_by_dynamic'}.to raise_error ActionController::BadRequest
|
127
|
+
end
|
128
|
+
end
|
115
129
|
end
|
116
130
|
end
|