rails_ip_validator 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -2
- data/Gemfile.lock +17 -9
- data/Rakefile +10 -29
- data/VERSION +1 -1
- data/rails_ip_validator.gemspec +20 -21
- data/spec/rails_ip_validator_spec.rb +286 -0
- data/spec/spec_helper.rb +14 -0
- metadata +21 -49
- data/test/helper.rb +0 -20
- data/test/test_rails_ip_validator.rb +0 -211
data/Gemfile
CHANGED
@@ -7,7 +7,9 @@ source "http://rubygems.org"
|
|
7
7
|
# Include everything needed to run rake, tests, features, etc.
|
8
8
|
group :development do
|
9
9
|
gem "bundler", "~> 1.0.0"
|
10
|
-
gem "jeweler", "~> 1.5.
|
10
|
+
gem "jeweler", "~> 1.5.2"
|
11
11
|
gem "ipaddress"
|
12
|
-
gem
|
12
|
+
gem 'simplecov', '>= 0.3.8', :require => false
|
13
|
+
gem "rspec", "~> 2.3.0"
|
14
|
+
gem "yard", "~> 0.6.0"
|
13
15
|
end
|
data/Gemfile.lock
CHANGED
@@ -7,13 +7,8 @@ GEM
|
|
7
7
|
i18n (~> 0.4)
|
8
8
|
activesupport (3.0.3)
|
9
9
|
builder (2.1.2)
|
10
|
-
|
11
|
-
yamler (>= 0.1.0)
|
12
|
-
cover_me (1.0.0.rc5)
|
13
|
-
configatron
|
14
|
-
hashie
|
10
|
+
diff-lcs (1.1.2)
|
15
11
|
git (1.2.5)
|
16
|
-
hashie (0.4.0)
|
17
12
|
i18n (0.5.0)
|
18
13
|
ipaddress (0.7.0)
|
19
14
|
jeweler (1.5.2)
|
@@ -21,7 +16,18 @@ GEM
|
|
21
16
|
git (>= 1.2.5)
|
22
17
|
rake
|
23
18
|
rake (0.8.7)
|
24
|
-
|
19
|
+
rspec (2.3.0)
|
20
|
+
rspec-core (~> 2.3.0)
|
21
|
+
rspec-expectations (~> 2.3.0)
|
22
|
+
rspec-mocks (~> 2.3.0)
|
23
|
+
rspec-core (2.3.1)
|
24
|
+
rspec-expectations (2.3.0)
|
25
|
+
diff-lcs (~> 1.1.2)
|
26
|
+
rspec-mocks (2.3.0)
|
27
|
+
simplecov (0.4.0)
|
28
|
+
simplecov-html (~> 0.4.0)
|
29
|
+
simplecov-html (0.4.3)
|
30
|
+
yard (0.6.4)
|
25
31
|
|
26
32
|
PLATFORMS
|
27
33
|
ruby
|
@@ -29,6 +35,8 @@ PLATFORMS
|
|
29
35
|
DEPENDENCIES
|
30
36
|
activemodel (>= 3.0.0)
|
31
37
|
bundler (~> 1.0.0)
|
32
|
-
cover_me
|
33
38
|
ipaddress
|
34
|
-
jeweler (~> 1.5.
|
39
|
+
jeweler (~> 1.5.2)
|
40
|
+
rspec (~> 2.3.0)
|
41
|
+
simplecov (>= 0.3.8)
|
42
|
+
yard (~> 0.6.0)
|
data/Rakefile
CHANGED
@@ -13,7 +13,7 @@ require 'jeweler'
|
|
13
13
|
Jeweler::Tasks.new do |gem|
|
14
14
|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
15
|
gem.name = "rails_ip_validator"
|
16
|
-
gem.homepage = "http://github.com/
|
16
|
+
gem.homepage = "http://github.com/phatworx/rails_ip_validator"
|
17
17
|
gem.license = "MIT"
|
18
18
|
gem.summary = %Q{an ip validator for rails}
|
19
19
|
gem.description = %Q{a class to validate ip. it builded for rails}
|
@@ -21,38 +21,19 @@ Jeweler::Tasks.new do |gem|
|
|
21
21
|
gem.authors = ["Marco Scholl"]
|
22
22
|
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
23
|
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
-
gem.add_runtime_dependency 'activemodel', '>= 3.0.0'
|
25
|
-
gem.add_runtime_dependency 'ipaddress'
|
24
|
+
#gem.add_runtime_dependency 'activemodel', '>= 3.0.0'
|
25
|
+
#gem.add_runtime_dependency 'ipaddress'
|
26
26
|
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
27
27
|
end
|
28
28
|
Jeweler::RubygemsDotOrgTasks.new
|
29
29
|
|
30
|
-
require '
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
test.verbose = true
|
30
|
+
require 'rspec/core'
|
31
|
+
require 'rspec/core/rake_task'
|
32
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
33
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
35
34
|
end
|
36
35
|
|
37
|
-
|
38
|
-
task :report do
|
39
|
-
require 'cover_me'
|
40
|
-
CoverMe.complete!
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
task :test do
|
45
|
-
Rake::Task['cover_me:report'].invoke
|
46
|
-
end
|
36
|
+
task :default => :spec
|
47
37
|
|
48
|
-
|
49
|
-
|
50
|
-
require 'rake/rdoctask'
|
51
|
-
Rake::RDocTask.new do |rdoc|
|
52
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
53
|
-
|
54
|
-
rdoc.rdoc_dir = 'rdoc'
|
55
|
-
rdoc.title = "rails_ip_validator #{version}"
|
56
|
-
rdoc.rdoc_files.include('README*')
|
57
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
58
|
-
end
|
38
|
+
require 'yard'
|
39
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/rails_ip_validator.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rails_ip_validator}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Marco Scholl"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-02-13}
|
13
13
|
s.description = %q{a class to validate ip. it builded for rails}
|
14
14
|
s.email = %q{develop@marco-scholl.de}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -27,48 +27,47 @@ Gem::Specification.new do |s|
|
|
27
27
|
"init.rb",
|
28
28
|
"lib/rails_ip_validator.rb",
|
29
29
|
"rails_ip_validator.gemspec",
|
30
|
-
"
|
31
|
-
"
|
30
|
+
"spec/rails_ip_validator_spec.rb",
|
31
|
+
"spec/spec_helper.rb"
|
32
32
|
]
|
33
|
-
s.homepage = %q{http://github.com/
|
33
|
+
s.homepage = %q{http://github.com/phatworx/rails_ip_validator}
|
34
34
|
s.licenses = ["MIT"]
|
35
35
|
s.require_paths = ["lib"]
|
36
|
-
s.rubygems_version = %q{1.
|
36
|
+
s.rubygems_version = %q{1.5.0}
|
37
37
|
s.summary = %q{an ip validator for rails}
|
38
38
|
s.test_files = [
|
39
|
-
"
|
40
|
-
"
|
39
|
+
"spec/rails_ip_validator_spec.rb",
|
40
|
+
"spec/spec_helper.rb"
|
41
41
|
]
|
42
42
|
|
43
43
|
if s.respond_to? :specification_version then
|
44
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
45
44
|
s.specification_version = 3
|
46
45
|
|
47
46
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
48
47
|
s.add_runtime_dependency(%q<activemodel>, [">= 3.0.0"])
|
49
48
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
50
|
-
s.add_development_dependency(%q<jeweler>, ["~> 1.5.
|
49
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
51
50
|
s.add_development_dependency(%q<ipaddress>, [">= 0"])
|
52
|
-
s.add_development_dependency(%q<
|
53
|
-
s.
|
54
|
-
s.
|
51
|
+
s.add_development_dependency(%q<simplecov>, [">= 0.3.8"])
|
52
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
53
|
+
s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
|
55
54
|
else
|
56
55
|
s.add_dependency(%q<activemodel>, [">= 3.0.0"])
|
57
56
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
58
|
-
s.add_dependency(%q<jeweler>, ["~> 1.5.
|
59
|
-
s.add_dependency(%q<ipaddress>, [">= 0"])
|
60
|
-
s.add_dependency(%q<cover_me>, [">= 0"])
|
61
|
-
s.add_dependency(%q<activemodel>, [">= 3.0.0"])
|
57
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
62
58
|
s.add_dependency(%q<ipaddress>, [">= 0"])
|
59
|
+
s.add_dependency(%q<simplecov>, [">= 0.3.8"])
|
60
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
61
|
+
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
63
62
|
end
|
64
63
|
else
|
65
64
|
s.add_dependency(%q<activemodel>, [">= 3.0.0"])
|
66
65
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
67
|
-
s.add_dependency(%q<jeweler>, ["~> 1.5.
|
68
|
-
s.add_dependency(%q<ipaddress>, [">= 0"])
|
69
|
-
s.add_dependency(%q<cover_me>, [">= 0"])
|
70
|
-
s.add_dependency(%q<activemodel>, [">= 3.0.0"])
|
66
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
71
67
|
s.add_dependency(%q<ipaddress>, [">= 0"])
|
68
|
+
s.add_dependency(%q<simplecov>, [">= 0.3.8"])
|
69
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
70
|
+
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
72
71
|
end
|
73
72
|
end
|
74
73
|
|
@@ -0,0 +1,286 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe IpValidator do
|
5
|
+
before do
|
6
|
+
class ValidateIp
|
7
|
+
include ActiveModel::Validations
|
8
|
+
attr_accessor :ip
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_ipv4s
|
13
|
+
[
|
14
|
+
'0.0.0.0',
|
15
|
+
'127.0.0.1',
|
16
|
+
'88.88.88.88',
|
17
|
+
'10.0.0.1',
|
18
|
+
'172.16.0.1',
|
19
|
+
'192.168.0.1',
|
20
|
+
'192.167.10.2/24'
|
21
|
+
]
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_ipv6s
|
25
|
+
[
|
26
|
+
1,
|
27
|
+
'123',
|
28
|
+
'::',
|
29
|
+
'::1',
|
30
|
+
'::/128',
|
31
|
+
'ac10:0a01',
|
32
|
+
'::ffff:192.168.0.1',
|
33
|
+
'1080:0000:0000:0000:0008:0800:200c:417a',
|
34
|
+
'1080::8:800:200c:417a',
|
35
|
+
'1080::8:800:200c:417a/64',
|
36
|
+
'2001:db8:0:cd30::',
|
37
|
+
'0000:0000:0000:0000:0000:0000:0000:0000'
|
38
|
+
]
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "default ip validation" do
|
42
|
+
|
43
|
+
before do
|
44
|
+
class ValidateIpDefault < ValidateIp
|
45
|
+
validates :ip, :ip => true
|
46
|
+
end
|
47
|
+
@object = ValidateIpDefault.new
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "test with valid ips" do
|
51
|
+
it "should validate without errors" do
|
52
|
+
(get_ipv4s + get_ipv6s).each do |ip|
|
53
|
+
@object.ip = ip
|
54
|
+
@object.should be_valid
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "test with invalid ips" do
|
60
|
+
it "should validate with error" do
|
61
|
+
[
|
62
|
+
'127.0.0.',
|
63
|
+
'127.0.0.a',
|
64
|
+
'127.0.0.1/a',
|
65
|
+
'sdfsd',
|
66
|
+
'1123.123.123.123',
|
67
|
+
3.3
|
68
|
+
].each do |ip|
|
69
|
+
@object.ip = ip
|
70
|
+
@object.should_not be_valid
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "custom validation" do
|
78
|
+
before do
|
79
|
+
class ValidateIpCustom < ValidateIp
|
80
|
+
validates :ip, :ip => {:custom => Proc.new { |ip| ip.prefix == 24 }}
|
81
|
+
end
|
82
|
+
@object = ValidateIpCustom.new
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "test with valid ips" do
|
86
|
+
it "should validate without errors" do
|
87
|
+
[
|
88
|
+
'192.168.10.1/24',
|
89
|
+
'127.0.0.1/24'
|
90
|
+
].each do |ip|
|
91
|
+
@object.ip = ip
|
92
|
+
@object.should be_valid
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
describe "test with invalid ips" do
|
99
|
+
it "should validate with error" do
|
100
|
+
[
|
101
|
+
'192.168.10.1/32',
|
102
|
+
'127.0.0.1/32'
|
103
|
+
].each do |ip|
|
104
|
+
@object.ip = ip
|
105
|
+
@object.should_not be_valid
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
describe "forbidden a network" do
|
113
|
+
before do
|
114
|
+
class ValidateIpForbiddenA < ValidateIp
|
115
|
+
validates :ip, :ip => {:forbidden => :a}
|
116
|
+
end
|
117
|
+
@object = ValidateIpForbiddenA.new
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "test with b addresses" do
|
121
|
+
it "should validate with errors" do
|
122
|
+
[
|
123
|
+
'10.0.0.1',
|
124
|
+
'::ffff:10.0.0.1'
|
125
|
+
].each do |ip|
|
126
|
+
@object.ip = ip
|
127
|
+
@object.should_not be_valid
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe "forbidden b network" do
|
134
|
+
before do
|
135
|
+
class ValidateIpForbiddenB < ValidateIp
|
136
|
+
validates :ip, :ip => {:forbidden => :b}
|
137
|
+
end
|
138
|
+
@object = ValidateIpForbiddenB.new
|
139
|
+
end
|
140
|
+
|
141
|
+
describe "test with b addresses" do
|
142
|
+
it "should validate with errors" do
|
143
|
+
[
|
144
|
+
'172.16.0.1',
|
145
|
+
'::ffff:172.16.0.1'
|
146
|
+
].each do |ip|
|
147
|
+
@object.ip = ip
|
148
|
+
@object.should_not be_valid
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe "forbidden c network" do
|
155
|
+
before do
|
156
|
+
class ValidateIpForbiddenC < ValidateIp
|
157
|
+
validates :ip, :ip => {:forbidden => :c}
|
158
|
+
end
|
159
|
+
@object = ValidateIpForbiddenC.new
|
160
|
+
end
|
161
|
+
|
162
|
+
describe "test with c addresses" do
|
163
|
+
it "should validate with errors" do
|
164
|
+
[
|
165
|
+
'192.168.0.1',
|
166
|
+
'::ffff:192.168.0.1'
|
167
|
+
].each do |ip|
|
168
|
+
@object.ip = ip
|
169
|
+
@object.should_not be_valid
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
describe "forbidden private network" do
|
176
|
+
before do
|
177
|
+
class ValidateIpForbiddenPrivate < ValidateIp
|
178
|
+
validates :ip, :ip => {:forbidden => :private}
|
179
|
+
end
|
180
|
+
@object = ValidateIpForbiddenPrivate.new
|
181
|
+
end
|
182
|
+
|
183
|
+
describe "test with private addresses" do
|
184
|
+
it "should validate with errors" do
|
185
|
+
[
|
186
|
+
'10.0.0.1',
|
187
|
+
'::ffff:10.0.0.1',
|
188
|
+
'172.16.0.1',
|
189
|
+
'::ffff:172.16.0.1',
|
190
|
+
'192.168.0.1',
|
191
|
+
'::ffff:192.168.0.1'
|
192
|
+
].each do |ip|
|
193
|
+
@object.ip = ip
|
194
|
+
@object.should_not be_valid
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
describe "forbidden ipv4 network" do
|
201
|
+
before do
|
202
|
+
class ValidateIpForbiddenIpv4 < ValidateIp
|
203
|
+
validates :ip, :ip => {:forbidden => :ipv4}
|
204
|
+
end
|
205
|
+
@object = ValidateIpForbiddenIpv4.new
|
206
|
+
end
|
207
|
+
|
208
|
+
describe "test with ipv4 addresses" do
|
209
|
+
it "should validate with errors" do
|
210
|
+
get_ipv4s.each do |ip|
|
211
|
+
@object.ip = ip
|
212
|
+
@object.should_not be_valid
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
describe "test with ipv6 addresses" do
|
218
|
+
it "should validate without errors" do
|
219
|
+
get_ipv6s.each do |ip|
|
220
|
+
@object.ip = ip
|
221
|
+
@object.should be_valid
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
describe "forbidden ipv6 network" do
|
228
|
+
before do
|
229
|
+
class ValidateIpForbiddenIpv6 < ValidateIp
|
230
|
+
validates :ip, :ip => {:forbidden => :ipv6}
|
231
|
+
end
|
232
|
+
@object = ValidateIpForbiddenIpv6.new
|
233
|
+
end
|
234
|
+
|
235
|
+
describe "test with ipv4 addresses" do
|
236
|
+
it "should validate without errors" do
|
237
|
+
get_ipv4s.each do |ip|
|
238
|
+
@object.ip = ip
|
239
|
+
@object.should be_valid
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
describe "test with ipv6 addresses" do
|
245
|
+
it "should validate with errors" do
|
246
|
+
get_ipv6s.each do |ip|
|
247
|
+
@object.ip = ip
|
248
|
+
@object.should_not be_valid
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
describe "forbidden netmask" do
|
255
|
+
before do
|
256
|
+
class ValidateIpForbiddenNetmask < ValidateIp
|
257
|
+
validates :ip, :ip => {:forbidden => :netmask}
|
258
|
+
end
|
259
|
+
@object = ValidateIpForbiddenNetmask.new
|
260
|
+
end
|
261
|
+
|
262
|
+
describe "test with netmask" do
|
263
|
+
it "should validate with errors" do
|
264
|
+
[
|
265
|
+
'192.168.0.1/12',
|
266
|
+
'::ffff:192.168.0.1/12'
|
267
|
+
].each do |ip|
|
268
|
+
@object.ip = ip
|
269
|
+
@object.should_not be_valid
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
describe "test with netmask" do
|
275
|
+
it "should validate without errors" do
|
276
|
+
[
|
277
|
+
'192.168.0.1',
|
278
|
+
'::ffff:192.168.0.1'
|
279
|
+
].each do |ip|
|
280
|
+
@object.ip = ip
|
281
|
+
@object.should be_valid
|
282
|
+
end
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start 'rails'
|
5
|
+
require 'rspec'
|
6
|
+
require 'rails_ip_validator'
|
7
|
+
|
8
|
+
# Requires supporting files with custom matchers and macros, etc,
|
9
|
+
# in ./support/ and its subdirectories.
|
10
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
|
14
|
+
end
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_ip_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 1
|
8
|
-
- 1
|
9
|
-
version: 0.1.1
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.2
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Marco Scholl
|
@@ -14,7 +10,7 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date: 2011-
|
13
|
+
date: 2011-02-13 00:00:00 +01:00
|
18
14
|
default_executable:
|
19
15
|
dependencies:
|
20
16
|
- !ruby/object:Gem::Dependency
|
@@ -24,10 +20,6 @@ dependencies:
|
|
24
20
|
requirements:
|
25
21
|
- - ">="
|
26
22
|
- !ruby/object:Gem::Version
|
27
|
-
segments:
|
28
|
-
- 3
|
29
|
-
- 0
|
30
|
-
- 0
|
31
23
|
version: 3.0.0
|
32
24
|
type: :runtime
|
33
25
|
prerelease: false
|
@@ -39,10 +31,6 @@ dependencies:
|
|
39
31
|
requirements:
|
40
32
|
- - ~>
|
41
33
|
- !ruby/object:Gem::Version
|
42
|
-
segments:
|
43
|
-
- 1
|
44
|
-
- 0
|
45
|
-
- 0
|
46
34
|
version: 1.0.0
|
47
35
|
type: :development
|
48
36
|
prerelease: false
|
@@ -54,11 +42,7 @@ dependencies:
|
|
54
42
|
requirements:
|
55
43
|
- - ~>
|
56
44
|
- !ruby/object:Gem::Version
|
57
|
-
|
58
|
-
- 1
|
59
|
-
- 5
|
60
|
-
- 1
|
61
|
-
version: 1.5.1
|
45
|
+
version: 1.5.2
|
62
46
|
type: :development
|
63
47
|
prerelease: false
|
64
48
|
version_requirements: *id003
|
@@ -69,51 +53,41 @@ dependencies:
|
|
69
53
|
requirements:
|
70
54
|
- - ">="
|
71
55
|
- !ruby/object:Gem::Version
|
72
|
-
segments:
|
73
|
-
- 0
|
74
56
|
version: "0"
|
75
57
|
type: :development
|
76
58
|
prerelease: false
|
77
59
|
version_requirements: *id004
|
78
60
|
- !ruby/object:Gem::Dependency
|
79
|
-
name:
|
61
|
+
name: simplecov
|
80
62
|
requirement: &id005 !ruby/object:Gem::Requirement
|
81
63
|
none: false
|
82
64
|
requirements:
|
83
65
|
- - ">="
|
84
66
|
- !ruby/object:Gem::Version
|
85
|
-
|
86
|
-
- 0
|
87
|
-
version: "0"
|
67
|
+
version: 0.3.8
|
88
68
|
type: :development
|
89
69
|
prerelease: false
|
90
70
|
version_requirements: *id005
|
91
71
|
- !ruby/object:Gem::Dependency
|
92
|
-
name:
|
72
|
+
name: rspec
|
93
73
|
requirement: &id006 !ruby/object:Gem::Requirement
|
94
74
|
none: false
|
95
75
|
requirements:
|
96
|
-
- -
|
76
|
+
- - ~>
|
97
77
|
- !ruby/object:Gem::Version
|
98
|
-
|
99
|
-
|
100
|
-
- 0
|
101
|
-
- 0
|
102
|
-
version: 3.0.0
|
103
|
-
type: :runtime
|
78
|
+
version: 2.3.0
|
79
|
+
type: :development
|
104
80
|
prerelease: false
|
105
81
|
version_requirements: *id006
|
106
82
|
- !ruby/object:Gem::Dependency
|
107
|
-
name:
|
83
|
+
name: yard
|
108
84
|
requirement: &id007 !ruby/object:Gem::Requirement
|
109
85
|
none: false
|
110
86
|
requirements:
|
111
|
-
- -
|
87
|
+
- - ~>
|
112
88
|
- !ruby/object:Gem::Version
|
113
|
-
|
114
|
-
|
115
|
-
version: "0"
|
116
|
-
type: :runtime
|
89
|
+
version: 0.6.0
|
90
|
+
type: :development
|
117
91
|
prerelease: false
|
118
92
|
version_requirements: *id007
|
119
93
|
description: a class to validate ip. it builded for rails
|
@@ -136,10 +110,10 @@ files:
|
|
136
110
|
- init.rb
|
137
111
|
- lib/rails_ip_validator.rb
|
138
112
|
- rails_ip_validator.gemspec
|
139
|
-
-
|
140
|
-
-
|
113
|
+
- spec/rails_ip_validator_spec.rb
|
114
|
+
- spec/spec_helper.rb
|
141
115
|
has_rdoc: true
|
142
|
-
homepage: http://github.com/
|
116
|
+
homepage: http://github.com/phatworx/rails_ip_validator
|
143
117
|
licenses:
|
144
118
|
- MIT
|
145
119
|
post_install_message:
|
@@ -152,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
152
126
|
requirements:
|
153
127
|
- - ">="
|
154
128
|
- !ruby/object:Gem::Version
|
155
|
-
hash: -
|
129
|
+
hash: -2766598769291703740
|
156
130
|
segments:
|
157
131
|
- 0
|
158
132
|
version: "0"
|
@@ -161,16 +135,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
135
|
requirements:
|
162
136
|
- - ">="
|
163
137
|
- !ruby/object:Gem::Version
|
164
|
-
segments:
|
165
|
-
- 0
|
166
138
|
version: "0"
|
167
139
|
requirements: []
|
168
140
|
|
169
141
|
rubyforge_project:
|
170
|
-
rubygems_version: 1.
|
142
|
+
rubygems_version: 1.5.0
|
171
143
|
signing_key:
|
172
144
|
specification_version: 3
|
173
145
|
summary: an ip validator for rails
|
174
146
|
test_files:
|
175
|
-
-
|
176
|
-
-
|
147
|
+
- spec/rails_ip_validator_spec.rb
|
148
|
+
- spec/spec_helper.rb
|
data/test/helper.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'bundler'
|
5
|
-
begin
|
6
|
-
Bundler.setup(:default, :development)
|
7
|
-
rescue Bundler::BundlerError => e
|
8
|
-
$stderr.puts e.message
|
9
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
-
exit e.status_code
|
11
|
-
end
|
12
|
-
require 'cover_me'
|
13
|
-
require 'test/unit'
|
14
|
-
|
15
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
16
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
17
|
-
require 'rails_ip_validator'
|
18
|
-
|
19
|
-
class Test::Unit::TestCase
|
20
|
-
end
|
@@ -1,211 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
|
5
|
-
class ValidateIp
|
6
|
-
include ActiveModel::Validations
|
7
|
-
attr_accessor :ip
|
8
|
-
end
|
9
|
-
|
10
|
-
class ValidateIpDefault < ValidateIp
|
11
|
-
validates :ip, :ip => true
|
12
|
-
end
|
13
|
-
|
14
|
-
class ValidateIpCustom < ValidateIp
|
15
|
-
validates :ip, :ip => {:custom => Proc.new { |ip| ip.prefix == 24 }}
|
16
|
-
end
|
17
|
-
|
18
|
-
class ValidateIpForbiddenPrivate < ValidateIp
|
19
|
-
validates :ip, :ip => {:forbidden => :private}
|
20
|
-
end
|
21
|
-
|
22
|
-
class ValidateIpForbiddenA < ValidateIp
|
23
|
-
validates :ip, :ip => {:forbidden => :a}
|
24
|
-
end
|
25
|
-
|
26
|
-
class ValidateIpForbiddenB < ValidateIp
|
27
|
-
validates :ip, :ip => {:forbidden => :b}
|
28
|
-
end
|
29
|
-
|
30
|
-
class ValidateIpForbiddenC < ValidateIp
|
31
|
-
validates :ip, :ip => {:forbidden => :c}
|
32
|
-
end
|
33
|
-
|
34
|
-
class ValidateIpForbiddenIpv4 < ValidateIp
|
35
|
-
validates :ip, :ip => {:forbidden => :ipv4}
|
36
|
-
end
|
37
|
-
|
38
|
-
class ValidateIpForbiddenIpv6 < ValidateIp
|
39
|
-
validates :ip, :ip => {:forbidden => :ipv6}
|
40
|
-
end
|
41
|
-
|
42
|
-
class ValidateIpForbiddenNetmask < ValidateIp
|
43
|
-
validates :ip, :ip => {:forbidden => :netmask}
|
44
|
-
end
|
45
|
-
|
46
|
-
class TestRailsIpValidator < Test::Unit::TestCase
|
47
|
-
|
48
|
-
def get_ipv4s
|
49
|
-
[
|
50
|
-
'0.0.0.0',
|
51
|
-
'127.0.0.1',
|
52
|
-
'88.88.88.88',
|
53
|
-
'10.0.0.1',
|
54
|
-
'172.16.0.1',
|
55
|
-
'192.168.0.1',
|
56
|
-
'192.167.10.2/24'
|
57
|
-
]
|
58
|
-
end
|
59
|
-
|
60
|
-
def get_ipv6s
|
61
|
-
[
|
62
|
-
1,
|
63
|
-
'123',
|
64
|
-
'::',
|
65
|
-
'::1',
|
66
|
-
'::/128',
|
67
|
-
'ac10:0a01',
|
68
|
-
'::ffff:192.168.0.1',
|
69
|
-
'1080:0000:0000:0000:0008:0800:200c:417a',
|
70
|
-
'1080::8:800:200c:417a',
|
71
|
-
'1080::8:800:200c:417a/64',
|
72
|
-
'2001:db8:0:cd30::',
|
73
|
-
'0000:0000:0000:0000:0000:0000:0000:0000'
|
74
|
-
]
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_default_validations
|
78
|
-
instance = ValidateIpDefault.new
|
79
|
-
(get_ipv4s + get_ipv6s).each do |ip|
|
80
|
-
instance.ip = ip
|
81
|
-
assert instance.valid?, ip.to_s
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_invalid_ips
|
86
|
-
instance = ValidateIpDefault.new
|
87
|
-
[
|
88
|
-
'127.0.0.',
|
89
|
-
'127.0.0.a',
|
90
|
-
'127.0.0.1/a',
|
91
|
-
'sdfsd',
|
92
|
-
'1123.123.123.123',
|
93
|
-
3.3
|
94
|
-
].each do |ip|
|
95
|
-
instance.ip = ip
|
96
|
-
assert !instance.valid?, ">>#{ip.to_s}<<"
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_custom
|
101
|
-
instance = ValidateIpCustom.new
|
102
|
-
[
|
103
|
-
'192.168.10.1/24',
|
104
|
-
'127.0.0.1/24'
|
105
|
-
].each do |ip|
|
106
|
-
instance.ip = ip
|
107
|
-
assert instance.valid?, ip.to_s
|
108
|
-
end
|
109
|
-
|
110
|
-
instance = ValidateIpCustom.new
|
111
|
-
[
|
112
|
-
'192.168.10.1/32',
|
113
|
-
'127.0.0.1/32'
|
114
|
-
].each do |ip|
|
115
|
-
instance.ip = ip
|
116
|
-
assert !instance.valid?, ip.to_s
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
def test_forbidden_a
|
121
|
-
klass = ValidateIp
|
122
|
-
instance = ValidateIpForbiddenA.new
|
123
|
-
[
|
124
|
-
'10.0.0.1',
|
125
|
-
'::ffff:10.0.0.1'
|
126
|
-
].each do |ip|
|
127
|
-
instance.ip = ip
|
128
|
-
assert !instance.valid?, ip.to_s
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
def test_forbidden_b
|
133
|
-
instance = ValidateIpForbiddenB.new
|
134
|
-
[
|
135
|
-
'172.16.0.1',
|
136
|
-
'::ffff:172.16.0.1'
|
137
|
-
].each do |ip|
|
138
|
-
instance.ip = ip
|
139
|
-
assert !instance.valid?, ip.to_s
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
def test_forbidden_c
|
144
|
-
instance = ValidateIpForbiddenC.new
|
145
|
-
[
|
146
|
-
'192.168.0.1',
|
147
|
-
'::ffff:192.168.0.1'
|
148
|
-
].each do |ip|
|
149
|
-
instance.ip = ip
|
150
|
-
assert !instance.valid?, ip.to_s
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
def test_forbidden_private
|
155
|
-
instance = ValidateIpForbiddenPrivate.new
|
156
|
-
[
|
157
|
-
'10.0.0.1',
|
158
|
-
'::ffff:10.0.0.1',
|
159
|
-
'172.16.0.1',
|
160
|
-
'::ffff:172.16.0.1',
|
161
|
-
'192.168.0.1',
|
162
|
-
'::ffff:192.168.0.1'
|
163
|
-
].each do |ip|
|
164
|
-
instance.ip = ip
|
165
|
-
assert !instance.valid?, ip.to_s
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
def test_forbidden_ipv4
|
170
|
-
instance = ValidateIpForbiddenIpv4.new
|
171
|
-
get_ipv4s.each do |ip|
|
172
|
-
instance.ip = ip
|
173
|
-
assert !instance.valid?, ip.to_s
|
174
|
-
end
|
175
|
-
get_ipv6s.each do |ip|
|
176
|
-
instance.ip = ip
|
177
|
-
assert instance.valid?, ip.to_s
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
def test_forbidden_ipv6
|
182
|
-
instance = ValidateIpForbiddenIpv6.new
|
183
|
-
get_ipv4s.each do |ip|
|
184
|
-
instance.ip = ip
|
185
|
-
assert instance.valid?, ip.to_s
|
186
|
-
end
|
187
|
-
get_ipv6s.each do |ip|
|
188
|
-
instance.ip = ip
|
189
|
-
assert !instance.valid?, ip.to_s
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
def test_forbidden_c
|
194
|
-
instance = ValidateIpForbiddenNetmask.new
|
195
|
-
[
|
196
|
-
'192.168.0.1/12',
|
197
|
-
'::ffff:192.168.0.1/12'
|
198
|
-
].each do |ip|
|
199
|
-
instance.ip = ip
|
200
|
-
assert !instance.valid?, ip.to_s
|
201
|
-
end
|
202
|
-
|
203
|
-
[
|
204
|
-
'192.168.0.1',
|
205
|
-
'::ffff:192.168.0.1'
|
206
|
-
].each do |ip|
|
207
|
-
instance.ip = ip
|
208
|
-
assert instance.valid?, ip.to_s
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|