floodgate 0.0.10 → 0.0.11

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: b9db86194f10be4b4ce921bb9964d0c3600e4b2d
4
- data.tar.gz: c9b0fafb0e2455a4db2d5c3629798ce7e5edcb45
3
+ metadata.gz: d934a5e26e5c75cb0b000f321de8a0ccfc42c010
4
+ data.tar.gz: 82b0183c0ec1edf9d9703635c2f003e856a65795
5
5
  SHA512:
6
- metadata.gz: fbd81c3f94ca145f550f6d5e8986e3d19bc6f14f1420b9a6028e2109d0ba51cd03770a8dbdf824616ebd1ca1fb87b1a04f59fc4e36601dd63dbb14006af497b1
7
- data.tar.gz: 98ce680b053a23e15d2e5c49faeeb0e1f700c323443491491b879633045611600c0368ef016c79dcc2c18274816b662933f011a93088d3f0d81e8e6b0bcdbb33
6
+ metadata.gz: da323e40805cee980fac69efa28f8ee1e803c81c55b2d792f0444e17c879aa370325a3e6841c0c8f8c1132faf2b35405920ef421dc962594ed71783be34a8bc7
7
+ data.tar.gz: 5aa2e49eeefd7c396c3f21d7403c630f222b581e9d61fc20bb50288a715f3f25d45baaa593a3ca5c8478e98a9e33c87d8ab3bdbd7e7e2f5b30bdc898de84a5e1
@@ -18,12 +18,18 @@ module Floodgate
18
18
  @allowed_ip_addresses = json['allowed_ip_addresses'] || []
19
19
  end
20
20
 
21
- def ip_address_allowed?(ip_address)
22
- allowed_ip_addresses.include?(ip_address)
21
+ def potential_client_addresses(env)
22
+ %w(REMOTE_ADDR HTTP_X_FORWARDED_FOR).map { |name| env[name] }
23
+ end
24
+
25
+ def client_allowed?(env)
26
+ !!potential_client_addresses(env).find do |ip_address|
27
+ allowed_ip_addresses.include?(ip_address)
28
+ end
23
29
  end
24
30
 
25
31
  def filter_traffic?(env)
26
- filter_traffic && !ip_address_allowed?(env['REMOTE_ADDR'])
32
+ filter_traffic && !client_allowed?(env)
27
33
  end
28
34
 
29
35
  def redirect?
@@ -1,3 +1,3 @@
1
1
  module Floodgate
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
@@ -20,41 +20,95 @@ module Floodgate
20
20
  let(:api_token) { 'def456' }
21
21
  let(:config) { Config.new(app_id, api_token) }
22
22
 
23
- describe '#ip_address_allowed?' do
24
- context 'when the allowed ip address list is nil' do
25
- let(:allowed_ip_addresses) { nil }
26
- let(:ip_address) { '127.0.0.1' }
23
+ describe '#client_allowed?' do
24
+ context 'when the environment specifies the client address in REMOTE_ADDR' do
25
+ let(:env) do
26
+ {
27
+ 'REMOTE_ADDR' => ip_address
28
+ }
29
+ end
27
30
 
28
- it 'is false' do
29
- expect(config.ip_address_allowed?(ip_address)).to be_false
31
+ context 'when the allowed ip address list is nil' do
32
+ let(:allowed_ip_addresses) { nil }
33
+ let(:ip_address) { '127.0.0.1' }
34
+
35
+ it 'is false' do
36
+ expect(config.client_allowed?(env)).to be_false
37
+ end
30
38
  end
31
- end
32
39
 
33
- context 'when the allowed ip address list is empty' do
34
- let(:allowed_ip_addresses) { [] }
35
- let(:ip_address) { '127.0.0.1' }
40
+ context 'when the allowed ip address list is empty' do
41
+ let(:allowed_ip_addresses) { [] }
42
+ let(:ip_address) { '127.0.0.1' }
36
43
 
37
- it 'is false' do
38
- expect(config.ip_address_allowed?(ip_address)).to be_false
44
+ it 'is false' do
45
+ expect(config.client_allowed?(env)).to be_false
46
+ end
47
+ end
48
+
49
+ context 'when there are allowed ip addresses' do
50
+ let(:allowed_ip_addresses) { %w(198.81.129.107) }
51
+
52
+ context 'and the specified ip address is in the list' do
53
+ let(:ip_address) { '198.81.129.107' }
54
+
55
+ it 'is true' do
56
+ expect(config.client_allowed?(env)).to be_true
57
+ end
58
+ end
59
+
60
+ context 'but the specified ip address is not in the list' do
61
+ let(:ip_address) { '198.81.129.108' }
62
+
63
+ it 'is false' do
64
+ expect(config.client_allowed?(env)).to be_false
65
+ end
66
+ end
39
67
  end
40
68
  end
41
69
 
42
- context 'when there are allowed ip addresses' do
43
- let(:allowed_ip_addresses) { %w(198.81.129.107) }
70
+ context 'when the environment specifies the client address in HTTP_X_FORWARDED_FOR' do
71
+ let(:env) do
72
+ {
73
+ 'HTTP_X_FORWARDED_FOR' => ip_address
74
+ }
75
+ end
44
76
 
45
- context 'and the specified ip address is in the list' do
46
- let(:ip_address) { '198.81.129.107' }
77
+ context 'when the allowed ip address list is nil' do
78
+ let(:allowed_ip_addresses) { nil }
79
+ let(:ip_address) { '127.0.0.1' }
47
80
 
48
- it 'is true' do
49
- expect(config.ip_address_allowed?(ip_address)).to be_true
81
+ it 'is false' do
82
+ expect(config.client_allowed?(env)).to be_false
50
83
  end
51
84
  end
52
85
 
53
- context 'but the specified ip address is not in the list' do
54
- let(:ip_address) { '198.81.129.108' }
86
+ context 'when the allowed ip address list is empty' do
87
+ let(:allowed_ip_addresses) { [] }
88
+ let(:ip_address) { '127.0.0.1' }
55
89
 
56
90
  it 'is false' do
57
- expect(config.ip_address_allowed?(ip_address)).to be_false
91
+ expect(config.client_allowed?(env)).to be_false
92
+ end
93
+ end
94
+
95
+ context 'when there are allowed ip addresses' do
96
+ let(:allowed_ip_addresses) { %w(198.81.129.107) }
97
+
98
+ context 'and the specified ip address is in the list' do
99
+ let(:ip_address) { '198.81.129.107' }
100
+
101
+ it 'is true' do
102
+ expect(config.client_allowed?(env)).to be_true
103
+ end
104
+ end
105
+
106
+ context 'but the specified ip address is not in the list' do
107
+ let(:ip_address) { '198.81.129.108' }
108
+
109
+ it 'is false' do
110
+ expect(config.client_allowed?(env)).to be_false
111
+ end
58
112
  end
59
113
  end
60
114
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: floodgate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark McEahern