floodgate 0.0.9 → 0.0.10
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/floodgate.gemspec +1 -0
- data/lib/floodgate/config.rb +13 -9
- data/lib/floodgate/version.rb +1 -1
- data/spec/lib/floodgate/config_spec.rb +103 -10
- data/spec/lib/floodgate/control_spec.rb +5 -0
- metadata +15 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b9db86194f10be4b4ce921bb9964d0c3600e4b2d
|
|
4
|
+
data.tar.gz: c9b0fafb0e2455a4db2d5c3629798ce7e5edcb45
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fbd81c3f94ca145f550f6d5e8986e3d19bc6f14f1420b9a6028e2109d0ba51cd03770a8dbdf824616ebd1ca1fb87b1a04f59fc4e36601dd63dbb14006af497b1
|
|
7
|
+
data.tar.gz: 98ce680b053a23e15d2e5c49faeeb0e1f700c323443491491b879633045611600c0368ef016c79dcc2c18274816b662933f011a93088d3f0d81e8e6b0bcdbb33
|
data/floodgate.gemspec
CHANGED
|
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
19
|
spec.require_paths = ['lib']
|
|
20
20
|
|
|
21
|
+
spec.add_development_dependency 'pry'
|
|
21
22
|
spec.add_development_dependency 'rake'
|
|
22
23
|
spec.add_development_dependency 'rspec', '~> 2.14'
|
|
23
24
|
spec.add_development_dependency 'simplecov', '~> 0.8'
|
data/lib/floodgate/config.rb
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
# TODO: Use a real client real soon now, but not now
|
|
2
|
-
require 'open-uri'
|
|
3
|
-
require 'json'
|
|
4
|
-
|
|
5
1
|
module Floodgate
|
|
6
2
|
class Config
|
|
7
|
-
attr_accessor
|
|
3
|
+
attr_accessor \
|
|
4
|
+
:allowed_ip_addresses,
|
|
5
|
+
:api_token,
|
|
6
|
+
:app_id,
|
|
7
|
+
:filter_traffic,
|
|
8
|
+
:redirect_url
|
|
8
9
|
|
|
9
10
|
def initialize(app_id, api_token)
|
|
10
11
|
@app_id = app_id
|
|
@@ -14,16 +15,19 @@ module Floodgate
|
|
|
14
15
|
|
|
15
16
|
@filter_traffic = json['filter_traffic']
|
|
16
17
|
@redirect_url = json['redirect_url']
|
|
18
|
+
@allowed_ip_addresses = json['allowed_ip_addresses'] || []
|
|
17
19
|
end
|
|
18
20
|
|
|
19
|
-
def
|
|
20
|
-
|
|
21
|
+
def ip_address_allowed?(ip_address)
|
|
22
|
+
allowed_ip_addresses.include?(ip_address)
|
|
21
23
|
end
|
|
22
24
|
|
|
23
25
|
def filter_traffic?(env)
|
|
24
|
-
filter_traffic
|
|
26
|
+
filter_traffic && !ip_address_allowed?(env['REMOTE_ADDR'])
|
|
27
|
+
end
|
|
25
28
|
|
|
26
|
-
|
|
29
|
+
def redirect?
|
|
30
|
+
!redirect_url.nil? && !redirect_url.empty?
|
|
27
31
|
end
|
|
28
32
|
end
|
|
29
33
|
end
|
data/lib/floodgate/version.rb
CHANGED
|
@@ -6,33 +6,126 @@ module Floodgate
|
|
|
6
6
|
|
|
7
7
|
let(:json) do
|
|
8
8
|
{
|
|
9
|
+
'allowed_ip_addresses' => allowed_ip_addresses,
|
|
9
10
|
'filter_traffic' => filter_traffic,
|
|
10
|
-
'redirect_url' => redirect_url
|
|
11
|
+
'redirect_url' => redirect_url,
|
|
11
12
|
}
|
|
12
13
|
end
|
|
13
14
|
|
|
15
|
+
let(:allowed_ip_addresses) { [] }
|
|
14
16
|
let(:filter_traffic) { false }
|
|
15
17
|
let(:redirect_url) { nil }
|
|
18
|
+
|
|
16
19
|
let(:app_id) { 'abc123' }
|
|
17
20
|
let(:api_token) { 'def456' }
|
|
18
21
|
let(:config) { Config.new(app_id, api_token) }
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
|
|
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
27
|
|
|
24
|
-
describe '#redirect?' do
|
|
25
28
|
it 'is false' do
|
|
26
|
-
expect(config.
|
|
29
|
+
expect(config.ip_address_allowed?(ip_address)).to be_false
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
context 'when the allowed ip address list is empty' do
|
|
34
|
+
let(:allowed_ip_addresses) { [] }
|
|
35
|
+
let(:ip_address) { '127.0.0.1' }
|
|
36
|
+
|
|
37
|
+
it 'is false' do
|
|
38
|
+
expect(config.ip_address_allowed?(ip_address)).to be_false
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
context 'when there are allowed ip addresses' do
|
|
43
|
+
let(:allowed_ip_addresses) { %w(198.81.129.107) }
|
|
44
|
+
|
|
45
|
+
context 'and the specified ip address is in the list' do
|
|
46
|
+
let(:ip_address) { '198.81.129.107' }
|
|
47
|
+
|
|
48
|
+
it 'is true' do
|
|
49
|
+
expect(config.ip_address_allowed?(ip_address)).to be_true
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
context 'but the specified ip address is not in the list' do
|
|
54
|
+
let(:ip_address) { '198.81.129.108' }
|
|
55
|
+
|
|
56
|
+
it 'is false' do
|
|
57
|
+
expect(config.ip_address_allowed?(ip_address)).to be_false
|
|
58
|
+
end
|
|
27
59
|
end
|
|
28
60
|
end
|
|
29
61
|
end
|
|
30
62
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
63
|
+
describe '#filter_traffic?' do
|
|
64
|
+
context 'when filter_traffic is false' do
|
|
65
|
+
let(:filter_traffic) { false }
|
|
66
|
+
let(:env) { Hash.new }
|
|
67
|
+
|
|
68
|
+
it 'is false' do
|
|
69
|
+
expect(config.filter_traffic?(env)).to be_false
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
context 'when filter_traffic is true' do
|
|
74
|
+
let(:filter_traffic) { true }
|
|
75
|
+
|
|
76
|
+
context 'and the ip address is not allowed' do
|
|
77
|
+
let(:env) do
|
|
78
|
+
{
|
|
79
|
+
'REMOTE_ADDR' => '192.168.0.1'
|
|
80
|
+
}
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
let(:allowed_ip_addresses) { %w(127.0.0.1) }
|
|
84
|
+
|
|
85
|
+
it 'is true' do
|
|
86
|
+
expect(config.filter_traffic?(env)).to be_true
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
context 'and the ip address is allowed' do
|
|
91
|
+
let(:env) do
|
|
92
|
+
{
|
|
93
|
+
'REMOTE_ADDR' => '127.0.0.1'
|
|
94
|
+
}
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
let(:allowed_ip_addresses) { %w(127.0.0.1) }
|
|
98
|
+
|
|
99
|
+
it 'is false' do
|
|
100
|
+
expect(config.filter_traffic?(env)).to be_false
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
describe '#redirect?' do
|
|
107
|
+
context 'when redirect_url is nil' do
|
|
108
|
+
let(:filter_traffic) { false }
|
|
109
|
+
let(:redirect_url) { nil }
|
|
110
|
+
|
|
111
|
+
it 'is false' do
|
|
112
|
+
expect(config.redirect?).to be_false
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
context 'when redirect_url is an empty string' do
|
|
117
|
+
let(:filter_traffic) { false }
|
|
118
|
+
let(:redirect_url) { '' }
|
|
119
|
+
|
|
120
|
+
it 'is false' do
|
|
121
|
+
expect(config.redirect?).to be_false
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
context 'when a redirect_url is specified' do
|
|
126
|
+
let(:filter_traffic) { false }
|
|
127
|
+
let(:redirect_url) { 'someurl' }
|
|
34
128
|
|
|
35
|
-
describe '#redirect?' do
|
|
36
129
|
it 'is true' do
|
|
37
130
|
expect(config.redirect?).to be_true
|
|
38
131
|
end
|
|
@@ -5,12 +5,17 @@ module Floodgate
|
|
|
5
5
|
let(:app) { double().as_null_object }
|
|
6
6
|
let(:control) { Control.new(app, app_id, api_token) }
|
|
7
7
|
let(:env) { Hash.new }
|
|
8
|
+
|
|
8
9
|
let(:app_id) { 'abc123' }
|
|
9
10
|
let(:api_token) { 'def456' }
|
|
11
|
+
|
|
12
|
+
let(:allowed_ip_addresses) { nil }
|
|
10
13
|
let(:filter_traffic) { false }
|
|
11
14
|
let(:redirect_url) { 'something' }
|
|
15
|
+
|
|
12
16
|
let(:json) do
|
|
13
17
|
{
|
|
18
|
+
'allowed_ip_addresses' => allowed_ip_addresses,
|
|
14
19
|
'filter_traffic' => filter_traffic,
|
|
15
20
|
'redirect_url' => redirect_url
|
|
16
21
|
}
|
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.
|
|
4
|
+
version: 0.0.10
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mark McEahern
|
|
@@ -11,6 +11,20 @@ bindir: bin
|
|
|
11
11
|
cert_chain: []
|
|
12
12
|
date: 2014-02-26 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: pry
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
requirements:
|
|
18
|
+
- - '>='
|
|
19
|
+
- !ruby/object:Gem::Version
|
|
20
|
+
version: '0'
|
|
21
|
+
type: :development
|
|
22
|
+
prerelease: false
|
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
24
|
+
requirements:
|
|
25
|
+
- - '>='
|
|
26
|
+
- !ruby/object:Gem::Version
|
|
27
|
+
version: '0'
|
|
14
28
|
- !ruby/object:Gem::Dependency
|
|
15
29
|
name: rake
|
|
16
30
|
requirement: !ruby/object:Gem::Requirement
|