firewall_constraint 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 34a491e27e3a54bc88f94ef75a4c4078b9f0a69a
4
- data.tar.gz: fa210df3f6bae145a5a13f8716f44a7629f1a3c9
3
+ metadata.gz: 502e9d611ee75a4ff89fec91897d9a87a85fb7f6
4
+ data.tar.gz: 79dd258d71e248fc4eb5ffe37965ca9dab1b2d3b
5
5
  SHA512:
6
- metadata.gz: dcde9b10b5a98e9c2fe8ce4d0234f12c3d364bf04348e23443f6af643fcbc7ec083d07ec3da10bc4407d58cefe8aaba8abd0f0c52298ff8b29903c4c4a721bf5
7
- data.tar.gz: 0442c151b90e9678b6ccdb4d16f62a89cada1c71ad8feefd3a623453f5e9dee5dd9f76a4a34c614d305e092477d112e5480d1473da45195e069ab1d0b12c84eb
6
+ metadata.gz: 3594f8cce23a0db8275ee5715baa423097bf2eb0c489b4213b998cc90aed7641d5bec1daa40aa18b5838d32d1d29840465ef2bc8d4fcd4437546815c75283648
7
+ data.tar.gz: caf17eb249c6ab734ee0e0acb820b076fcec102136697cdddfe8e592fc9e6056c1b292702b01e6f0a99e875707aa06280de6e852b8ffa8fc5c4ea92c1c8cc3ab
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- firewall_constraint (0.1.1)
4
+ firewall_constraint (0.1.2)
5
5
  ipaddress (~> 0.8)
6
6
  rails (> 3.0.0, < 5.0.0)
7
7
 
@@ -1,3 +1,3 @@
1
1
  module FirewallConstraint
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -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
@@ -1,4 +1,5 @@
1
1
  class DummyController < ApplicationController
2
+
2
3
  def index
3
4
  render :text => "index"
4
5
  end
@@ -22,4 +23,5 @@ class DummyController < ApplicationController
22
23
  def blocked_by_proc
23
24
  render :text => "proc"
24
25
  end
25
- end
26
+
27
+ 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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: firewall_constraint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Auclair