rack-ip_filter 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rack/ip_filter.rb +1 -1
- data/rack-ip_filter.gemspec +3 -1
- data/test/helper.rb +4 -0
- data/test/test_ip_filter.rb +44 -0
- metadata +12 -8
data/lib/rack/ip_filter.rb
CHANGED
data/rack-ip_filter.gemspec
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
2
|
+
lib = File.expand_path('../lib/', __FILE__)
|
3
|
+
$:.unshift lib unless $:.include?(lib)
|
4
|
+
require 'rack/ip_filter'
|
3
5
|
|
4
6
|
Gem::Specification.new do |gem|
|
5
7
|
gem.authors = ["Mike Evans"]
|
data/test/helper.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class IpWhitelistTest < MiniTest::Unit::TestCase
|
4
|
+
include Rack::Test::Methods
|
5
|
+
|
6
|
+
LOCAL_IP = '127.0.0.1'
|
7
|
+
GOOD_IP = '24.40.64.23'
|
8
|
+
BAD_IP = '9.9.9.9'
|
9
|
+
|
10
|
+
def app
|
11
|
+
Rack::IpFilter.new(lambda {|env| [200, {}, []] }, ['24.40.64.0/20'], '/')
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_local_ip_address_admitted
|
15
|
+
get '/', {}, { 'REQUEST_PATH' => '/', 'REMOTE_ADDR' => LOCAL_IP }
|
16
|
+
assert last_response.ok?
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_allowed_remote_ip_address_admitted
|
20
|
+
get '/', {}, { 'REQUEST_PATH' => '/', 'REMOTE_ADDR' => GOOD_IP }
|
21
|
+
assert last_response.ok?
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_outside_remote_ip_address_rejected
|
25
|
+
get '/', {}, { 'REQUEST_PATH' => '/', 'REMOTE_ADDR' => BAD_IP }
|
26
|
+
assert !last_response.ok?
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_local_ip_address_admitted_via_proxy
|
30
|
+
get '/', {}, { 'REQUEST_PATH' => '/', 'HTTP_X_FORWARDED_FOR' => [LOCAL_IP, BAD_IP].join(', ') }
|
31
|
+
assert last_response.ok?
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_allowed_remote_ip_address_admitted_via_proxy
|
35
|
+
get '/', {}, { 'REQUEST_PATH' => '/', 'HTTP_X_FORWARDED_FOR' => [GOOD_IP, BAD_IP].join(', ') }
|
36
|
+
assert last_response.ok?
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_outside_remote_ip_address_rejected_via_proxy
|
40
|
+
get '/', {}, { 'REQUEST_PATH' => '/', 'HTTP_X_FORWARDED_FOR' => [BAD_IP, GOOD_IP].join(', ') }
|
41
|
+
assert !last_response.ok?
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-ip_filter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-05-10 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: netaddr
|
16
|
-
requirement: &
|
16
|
+
requirement: &70234347589200 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70234347589200
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rack
|
27
|
-
requirement: &
|
27
|
+
requirement: &70234347588740 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70234347588740
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rack-test
|
38
|
-
requirement: &
|
38
|
+
requirement: &70234347588320 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70234347588320
|
47
47
|
description: White and clacklist IPs
|
48
48
|
email:
|
49
49
|
- mike@urlgonomics.com
|
@@ -59,6 +59,8 @@ files:
|
|
59
59
|
- lib/ip_filter.rb
|
60
60
|
- lib/rack/ip_filter.rb
|
61
61
|
- rack-ip_filter.gemspec
|
62
|
+
- test/helper.rb
|
63
|
+
- test/test_ip_filter.rb
|
62
64
|
homepage: ''
|
63
65
|
licenses: []
|
64
66
|
post_install_message:
|
@@ -83,4 +85,6 @@ rubygems_version: 1.8.17
|
|
83
85
|
signing_key:
|
84
86
|
specification_version: 3
|
85
87
|
summary: ''
|
86
|
-
test_files:
|
88
|
+
test_files:
|
89
|
+
- test/helper.rb
|
90
|
+
- test/test_ip_filter.rb
|