floodgate 0.0.10 → 0.0.11
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 +4 -4
- data/lib/floodgate/config.rb +9 -3
- data/lib/floodgate/version.rb +1 -1
- data/spec/lib/floodgate/config_spec.rb +75 -21
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d934a5e26e5c75cb0b000f321de8a0ccfc42c010
|
4
|
+
data.tar.gz: 82b0183c0ec1edf9d9703635c2f003e856a65795
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da323e40805cee980fac69efa28f8ee1e803c81c55b2d792f0444e17c879aa370325a3e6841c0c8f8c1132faf2b35405920ef421dc962594ed71783be34a8bc7
|
7
|
+
data.tar.gz: 5aa2e49eeefd7c396c3f21d7403c630f222b581e9d61fc20bb50288a715f3f25d45baaa593a3ca5c8478e98a9e33c87d8ab3bdbd7e7e2f5b30bdc898de84a5e1
|
data/lib/floodgate/config.rb
CHANGED
@@ -18,12 +18,18 @@ module Floodgate
|
|
18
18
|
@allowed_ip_addresses = json['allowed_ip_addresses'] || []
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
22
|
-
|
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 && !
|
32
|
+
filter_traffic && !client_allowed?(env)
|
27
33
|
end
|
28
34
|
|
29
35
|
def redirect?
|
data/lib/floodgate/version.rb
CHANGED
@@ -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 '#
|
24
|
-
context 'when the
|
25
|
-
let(:
|
26
|
-
|
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
|
-
|
29
|
-
|
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
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
38
|
-
|
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
|
43
|
-
let(:
|
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 '
|
46
|
-
let(:
|
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
|
49
|
-
expect(config.
|
81
|
+
it 'is false' do
|
82
|
+
expect(config.client_allowed?(env)).to be_false
|
50
83
|
end
|
51
84
|
end
|
52
85
|
|
53
|
-
context '
|
54
|
-
let(:
|
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.
|
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
|