rack-block 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.rspec +1 -1
- data/.travis.yml +4 -5
- data/README.md +1 -0
- data/Rakefile +2 -2
- data/lib/rack/block/dsl/matchers.rb +3 -0
- data/lib/rack/block/ipaddr/monkeypatch.rb +7 -0
- data/lib/rack/block/version.rb +1 -1
- data/rack-block.gemspec +2 -1
- data/spec/integrations/ip_blocking_spec.rb +48 -35
- data/spec/spec_helper.rb +2 -0
- metadata +82 -51
- data/Gemfile.lock +0 -61
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0c2f1a087957bf72667d02d6fcf99f1364d1c1cb
|
4
|
+
data.tar.gz: ffa62d33a25ab0c38bec661c0233bffbb5dc8289
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bb66d510b1e728481724e710ad5f56d491219650041d81217a0ac5622d3524cf0222b3674db7e904f1013259579c653ffccf69287e2c9b2c288bd5b7b5f5817f
|
7
|
+
data.tar.gz: 07e27e0b4de75b704b34c0a4ed69cade6e2825deb190a8bb5ecc1efa39b4ff32f720abf972158ea5b2a18d072096d5c677e428c33853e3f7bfdd3357d83b3f7e
|
data/.rspec
CHANGED
@@ -1 +1 @@
|
|
1
|
-
-
|
1
|
+
-f documentation --color
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -96,6 +96,7 @@ Or please look into `spec/*`
|
|
96
96
|
* (rubygems.org)[https://rubygems.org/gems/rack-block]
|
97
97
|
* (github)[https://github.com/udzura/rack-block]
|
98
98
|
* (travis-ci)[http://travis-ci.org/udzura/rack-block] / <img src="https://secure.travis-ci.org/udzura/rack-block.png" alt="build status" />
|
99
|
+
* (gemnagium)[https://gemnasium.com/udzura/rack-block] / <img src="https://gemnasium.com/udzura/rack-block.png" alt="dep status" />
|
99
100
|
* (author's blog)[http://blog.udzura.jp] (Japanese)
|
100
101
|
|
101
102
|
## Todo
|
data/Rakefile
CHANGED
@@ -5,12 +5,12 @@ begin
|
|
5
5
|
require 'rspec/core/rake_task'
|
6
6
|
RSpec::Core::RakeTask.new(:spec) do |spec|
|
7
7
|
spec.pattern = FileList['spec/**/*_spec.rb']
|
8
|
-
spec.rspec_opts = "-
|
8
|
+
spec.rspec_opts = "-f documentation --color"
|
9
9
|
end
|
10
10
|
|
11
11
|
RSpec::Core::RakeTask.new(:"spec:integrations") do |spec|
|
12
12
|
spec.pattern = FileList['spec/integrations/**/*_spec.rb']
|
13
|
-
spec.rspec_opts = "-
|
13
|
+
spec.rspec_opts = "-f documentation --color"
|
14
14
|
end
|
15
15
|
task :default => :spec
|
16
16
|
rescue LoadError
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rack/block/dsl/builtin_bot_pattern'
|
2
|
+
require 'rack/block/ipaddr/monkeypatch'
|
2
3
|
module Rack::Block::DSL
|
3
4
|
module Matchers
|
4
5
|
def bot_access(&block)
|
@@ -42,6 +43,8 @@ module Rack::Block::DSL
|
|
42
43
|
when /^(\d+)(\.\d+){0,2}\.?$/
|
43
44
|
ip_pattern = ip_pattern.sub(/\.$/, '')
|
44
45
|
Regexp.compile("^" + ip_pattern.gsub('.', '\\.') + '(\\.\\d+)+' + "$")
|
46
|
+
when /^\d+\.\d+\.\d+\.\d+\/\d+$/
|
47
|
+
IPAddr.new(ip_pattern)
|
45
48
|
else
|
46
49
|
raise ArgumentError, 'passed invalid IP string'
|
47
50
|
end
|
data/lib/rack/block/version.rb
CHANGED
data/rack-block.gemspec
CHANGED
@@ -20,10 +20,11 @@ Gem::Specification.new do |s|
|
|
20
20
|
|
21
21
|
s.add_runtime_dependency "rack", '>= 1.3'
|
22
22
|
|
23
|
-
s.add_development_dependency "bundler", '~> 1.1.rc'
|
23
|
+
#s.add_development_dependency "bundler", '~> 1.1.rc'
|
24
24
|
s.add_development_dependency "pry"
|
25
25
|
s.add_development_dependency "rake", '> 0'
|
26
26
|
s.add_development_dependency "rspec", '>= 2'
|
27
|
+
s.add_development_dependency "mocha", '>= 0'
|
27
28
|
s.add_development_dependency "rack-test", '> 0'
|
28
29
|
s.add_development_dependency "sinatra", '> 1.0'
|
29
30
|
s.add_development_dependency "guard-rspec"
|
@@ -2,6 +2,10 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + '/mock_app_helper')
|
3
3
|
|
4
4
|
describe "Blocking by IP" do
|
5
|
+
before do
|
6
|
+
Rack::Request.any_instance.stubs(:ip).returns('10.20.30.40')
|
7
|
+
end
|
8
|
+
|
5
9
|
it 'blocks accesses from a specific IP' do
|
6
10
|
mock_app {
|
7
11
|
use Rack::Block do
|
@@ -11,58 +15,67 @@ describe "Blocking by IP" do
|
|
11
15
|
end
|
12
16
|
run DEFAULT_APP
|
13
17
|
}
|
14
|
-
|
15
|
-
header "X-Forwarded-For", "10.20.30.40"
|
18
|
+
|
16
19
|
['/', '/any', '/path/blocked'].each do |path|
|
17
20
|
get path
|
18
21
|
last_response.should be_not_found
|
19
22
|
end
|
20
23
|
end
|
21
24
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
describe 'blocks accesses from a specific IP pattern' do
|
26
|
+
before do
|
27
|
+
mock_app {
|
28
|
+
use Rack::Block do
|
29
|
+
ip_pattern '10.20.30.' do
|
30
|
+
halt 404
|
31
|
+
end
|
27
32
|
end
|
33
|
+
run DEFAULT_APP
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'blocks 10.20.30.40 when supplied with 10.20.30.' do
|
38
|
+
['/', '/any', '/path/blocked'].each do |path|
|
39
|
+
get path
|
40
|
+
last_response.should be_not_found
|
28
41
|
end
|
29
|
-
run DEFAULT_APP
|
30
|
-
}
|
31
|
-
|
32
|
-
header "X-Forwarded-For", "10.20.30.40"
|
33
|
-
['/', '/any', '/path/blocked'].each do |path|
|
34
|
-
get path
|
35
|
-
last_response.should be_not_found
|
36
42
|
end
|
37
43
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
44
|
+
it 'blocks 10.20.30.50 when supplied with 10.20.30.' do
|
45
|
+
Rack::Request.any_instance.stubs(:ip).returns('10.20.30.50')
|
46
|
+
['/', '/any', '/path/blocked'].each do |path|
|
47
|
+
get path
|
48
|
+
last_response.should be_not_found
|
49
|
+
end
|
42
50
|
end
|
43
51
|
end
|
44
52
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
53
|
+
describe 'blocks accesses from a specific IP pattern(with a netmask)' do
|
54
|
+
before do
|
55
|
+
mock_app {
|
56
|
+
use Rack::Block do
|
57
|
+
ip_pattern '10.20.30.0/24' do
|
58
|
+
halt 404
|
59
|
+
end
|
51
60
|
end
|
61
|
+
run DEFAULT_APP
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'blocks 10.20.30.40 when supplied with 10.20.30.0/24' do
|
66
|
+
Rack::Request.any_instance.stubs(:ip).returns('10.20.30.40')
|
67
|
+
['/', '/any', '/path/blocked'].each do |path|
|
68
|
+
get path
|
69
|
+
last_response.should be_not_found
|
52
70
|
end
|
53
|
-
run DEFAULT_APP
|
54
|
-
}
|
55
|
-
|
56
|
-
header "X-Forwarded-For", "10.20.30.40"
|
57
|
-
['/', '/any', '/path/blocked'].each do |path|
|
58
|
-
get path
|
59
|
-
last_response.should be_not_found
|
60
71
|
end
|
61
72
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
73
|
+
it 'does not block 10.20.31.0 when supplied with 10.20.30.0/24' do
|
74
|
+
Rack::Request.any_instance.stubs(:ip).returns('10.20.31.0')
|
75
|
+
['/', '/any', '/path/blocked'].each do |path|
|
76
|
+
get path
|
77
|
+
last_response.should be_ok
|
78
|
+
end
|
66
79
|
end
|
67
80
|
end
|
68
81
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,12 +3,14 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
3
3
|
require 'rspec'
|
4
4
|
require 'rack/test'
|
5
5
|
require 'rack-block'
|
6
|
+
require 'mocha'
|
6
7
|
|
7
8
|
# Requires supporting files with custom matchers and macros, etc,
|
8
9
|
# in ./support/ and its subdirectories.
|
9
10
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
10
11
|
|
11
12
|
RSpec.configure do |config|
|
13
|
+
config.mock_framework = :mocha
|
12
14
|
#...
|
13
15
|
end
|
14
16
|
|
metadata
CHANGED
@@ -1,104 +1,127 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-block
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Uchio Kondo
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2017-11-24 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rack
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '1.3'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: bundler
|
27
|
-
requirement: &72148500 !ruby/object:Gem::Requirement
|
28
|
-
none: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
29
23
|
requirements:
|
30
|
-
- -
|
24
|
+
- - ">="
|
31
25
|
- !ruby/object:Gem::Version
|
32
|
-
version: 1.
|
33
|
-
type: :development
|
34
|
-
prerelease: false
|
35
|
-
version_requirements: *72148500
|
26
|
+
version: '1.3'
|
36
27
|
- !ruby/object:Gem::Dependency
|
37
28
|
name: pry
|
38
|
-
requirement:
|
39
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
40
30
|
requirements:
|
41
|
-
- -
|
31
|
+
- - ">="
|
42
32
|
- !ruby/object:Gem::Version
|
43
33
|
version: '0'
|
44
34
|
type: :development
|
45
35
|
prerelease: false
|
46
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
47
41
|
- !ruby/object:Gem::Dependency
|
48
42
|
name: rake
|
49
|
-
requirement:
|
50
|
-
none: false
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
51
44
|
requirements:
|
52
|
-
- -
|
45
|
+
- - ">"
|
53
46
|
- !ruby/object:Gem::Version
|
54
47
|
version: '0'
|
55
48
|
type: :development
|
56
49
|
prerelease: false
|
57
|
-
version_requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
58
55
|
- !ruby/object:Gem::Dependency
|
59
56
|
name: rspec
|
60
|
-
requirement:
|
61
|
-
none: false
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
62
58
|
requirements:
|
63
|
-
- -
|
59
|
+
- - ">="
|
64
60
|
- !ruby/object:Gem::Version
|
65
61
|
version: '2'
|
66
62
|
type: :development
|
67
63
|
prerelease: false
|
68
|
-
version_requirements:
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: mocha
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rack-test
|
71
|
-
requirement:
|
72
|
-
none: false
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
73
86
|
requirements:
|
74
|
-
- -
|
87
|
+
- - ">"
|
75
88
|
- !ruby/object:Gem::Version
|
76
89
|
version: '0'
|
77
90
|
type: :development
|
78
91
|
prerelease: false
|
79
|
-
version_requirements:
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
80
97
|
- !ruby/object:Gem::Dependency
|
81
98
|
name: sinatra
|
82
|
-
requirement:
|
83
|
-
none: false
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
84
100
|
requirements:
|
85
|
-
- -
|
101
|
+
- - ">"
|
86
102
|
- !ruby/object:Gem::Version
|
87
103
|
version: '1.0'
|
88
104
|
type: :development
|
89
105
|
prerelease: false
|
90
|
-
version_requirements:
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.0'
|
91
111
|
- !ruby/object:Gem::Dependency
|
92
112
|
name: guard-rspec
|
93
|
-
requirement:
|
94
|
-
none: false
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
95
114
|
requirements:
|
96
|
-
- -
|
115
|
+
- - ">="
|
97
116
|
- !ruby/object:Gem::Version
|
98
117
|
version: '0'
|
99
118
|
type: :development
|
100
119
|
prerelease: false
|
101
|
-
version_requirements:
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
102
125
|
description: A rack middleware for controlling accesses by search bot or not, remote
|
103
126
|
ip address, etc.
|
104
127
|
email:
|
@@ -107,11 +130,10 @@ executables: []
|
|
107
130
|
extensions: []
|
108
131
|
extra_rdoc_files: []
|
109
132
|
files:
|
110
|
-
- .gitignore
|
111
|
-
- .rspec
|
112
|
-
- .travis.yml
|
133
|
+
- ".gitignore"
|
134
|
+
- ".rspec"
|
135
|
+
- ".travis.yml"
|
113
136
|
- Gemfile
|
114
|
-
- Gemfile.lock
|
115
137
|
- Guardfile
|
116
138
|
- LICENSE
|
117
139
|
- README.md
|
@@ -124,6 +146,7 @@ files:
|
|
124
146
|
- lib/rack/block/dsl/builtin_bot_pattern.rb
|
125
147
|
- lib/rack/block/dsl/matchers.rb
|
126
148
|
- lib/rack/block/dsl/responses.rb
|
149
|
+
- lib/rack/block/ipaddr/monkeypatch.rb
|
127
150
|
- lib/rack/block/version.rb
|
128
151
|
- rack-block.gemspec
|
129
152
|
- spec/integrations/bot_pattern_spec.rb
|
@@ -137,27 +160,35 @@ files:
|
|
137
160
|
- spec/spec_helper.rb
|
138
161
|
homepage: http://udzura.jp/rack-block
|
139
162
|
licenses: []
|
163
|
+
metadata: {}
|
140
164
|
post_install_message:
|
141
165
|
rdoc_options: []
|
142
166
|
require_paths:
|
143
167
|
- lib
|
144
168
|
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
-
none: false
|
146
169
|
requirements:
|
147
|
-
- -
|
170
|
+
- - ">="
|
148
171
|
- !ruby/object:Gem::Version
|
149
172
|
version: '0'
|
150
173
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
|
-
none: false
|
152
174
|
requirements:
|
153
|
-
- -
|
175
|
+
- - ">="
|
154
176
|
- !ruby/object:Gem::Version
|
155
177
|
version: '0'
|
156
178
|
requirements: []
|
157
179
|
rubyforge_project: rack-block
|
158
|
-
rubygems_version:
|
180
|
+
rubygems_version: 2.5.1
|
159
181
|
signing_key:
|
160
|
-
specification_version:
|
182
|
+
specification_version: 4
|
161
183
|
summary: A rack middleware for controlling accesses by search bot or not, remote ip
|
162
184
|
address, etc.
|
163
|
-
test_files:
|
185
|
+
test_files:
|
186
|
+
- spec/integrations/bot_pattern_spec.rb
|
187
|
+
- spec/integrations/ip_blocking_spec.rb
|
188
|
+
- spec/integrations/mock_app_helper.rb
|
189
|
+
- spec/integrations/mock_app_works_spec.rb
|
190
|
+
- spec/integrations/normally_passes_access.rb
|
191
|
+
- spec/integrations/path_matching_spec.rb
|
192
|
+
- spec/integrations/response_verbs_spec.rb
|
193
|
+
- spec/integrations/ua_blocking_spec.rb
|
194
|
+
- spec/spec_helper.rb
|
data/Gemfile.lock
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
rack-block (0.1.1)
|
5
|
-
rack (>= 1.3)
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: http://rubygems.org/
|
9
|
-
specs:
|
10
|
-
coderay (0.9.8)
|
11
|
-
diff-lcs (1.1.3)
|
12
|
-
ffi (1.0.11)
|
13
|
-
guard (0.9.4)
|
14
|
-
ffi (>= 0.5.0)
|
15
|
-
thor (~> 0.14.6)
|
16
|
-
guard-rspec (0.5.10)
|
17
|
-
guard (>= 0.8.4)
|
18
|
-
method_source (0.6.7)
|
19
|
-
ruby_parser (>= 2.3.1)
|
20
|
-
pry (0.9.7.4)
|
21
|
-
coderay (~> 0.9.8)
|
22
|
-
method_source (~> 0.6.7)
|
23
|
-
ruby_parser (>= 2.3.1)
|
24
|
-
slop (~> 2.1.0)
|
25
|
-
rack (1.3.5)
|
26
|
-
rack-protection (1.1.4)
|
27
|
-
rack
|
28
|
-
rack-test (0.6.1)
|
29
|
-
rack (>= 1.0)
|
30
|
-
rake (0.9.2.2)
|
31
|
-
rspec (2.7.0)
|
32
|
-
rspec-core (~> 2.7.0)
|
33
|
-
rspec-expectations (~> 2.7.0)
|
34
|
-
rspec-mocks (~> 2.7.0)
|
35
|
-
rspec-core (2.7.1)
|
36
|
-
rspec-expectations (2.7.0)
|
37
|
-
diff-lcs (~> 1.1.2)
|
38
|
-
rspec-mocks (2.7.0)
|
39
|
-
ruby_parser (2.3.1)
|
40
|
-
sexp_processor (~> 3.0)
|
41
|
-
sexp_processor (3.0.9)
|
42
|
-
sinatra (1.3.1)
|
43
|
-
rack (~> 1.3, >= 1.3.4)
|
44
|
-
rack-protection (~> 1.1, >= 1.1.2)
|
45
|
-
tilt (~> 1.3, >= 1.3.3)
|
46
|
-
slop (2.1.0)
|
47
|
-
thor (0.14.6)
|
48
|
-
tilt (1.3.3)
|
49
|
-
|
50
|
-
PLATFORMS
|
51
|
-
ruby
|
52
|
-
|
53
|
-
DEPENDENCIES
|
54
|
-
bundler (~> 1.1.rc)
|
55
|
-
guard-rspec
|
56
|
-
pry
|
57
|
-
rack-block!
|
58
|
-
rack-test (> 0)
|
59
|
-
rake (> 0)
|
60
|
-
rspec (>= 2)
|
61
|
-
sinatra (> 1.0)
|