rails_ip_validator 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +26 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +59 -0
- data/Rakefile +47 -0
- data/VERSION +1 -0
- data/init.rb +1 -0
- data/lib/rails_ip_validator.rb +53 -0
- data/rails_ip_validator.gemspec +71 -0
- data/test/helper.rb +19 -0
- data/test/test_rails_ip_validator.rb +211 -0
- metadata +163 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
gem "activemodel", ">= 3.0.0"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "bundler", "~> 1.0.0"
|
10
|
+
gem "jeweler", "~> 1.5.1"
|
11
|
+
gem "ipaddress"
|
12
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activemodel (3.0.3)
|
5
|
+
activesupport (= 3.0.3)
|
6
|
+
builder (~> 2.1.2)
|
7
|
+
i18n (~> 0.4)
|
8
|
+
activesupport (3.0.3)
|
9
|
+
builder (2.1.2)
|
10
|
+
git (1.2.5)
|
11
|
+
i18n (0.5.0)
|
12
|
+
ipaddress (0.7.0)
|
13
|
+
jeweler (1.5.2)
|
14
|
+
bundler (~> 1.0.0)
|
15
|
+
git (>= 1.2.5)
|
16
|
+
rake
|
17
|
+
rake (0.8.7)
|
18
|
+
|
19
|
+
PLATFORMS
|
20
|
+
ruby
|
21
|
+
|
22
|
+
DEPENDENCIES
|
23
|
+
activemodel (>= 3.0.0)
|
24
|
+
bundler (~> 1.0.0)
|
25
|
+
ipaddress
|
26
|
+
jeweler (~> 1.5.1)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Marco Scholl
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
= rails_ip_validator
|
2
|
+
|
3
|
+
== Installation
|
4
|
+
Add the following line to your Gemfile
|
5
|
+
gem "rails_ip_validator"
|
6
|
+
|
7
|
+
If you want to use it as plugin
|
8
|
+
rails plugin install git://github.com/traxanos/rails_ip_validator.git
|
9
|
+
|
10
|
+
== Using
|
11
|
+
Use to validate ip
|
12
|
+
validates :ip, :ip => true
|
13
|
+
|
14
|
+
Use ip validation with forbidden ipv6
|
15
|
+
validates :ip, :ip => { :forbidden => :ipv6 }
|
16
|
+
|
17
|
+
Use ip validation with forbidden ipv4
|
18
|
+
validates :ip, :ip => { :forbidden => :ipv4 }
|
19
|
+
|
20
|
+
Use ip validation with forbidden netmask (10.20.30.40/24)
|
21
|
+
validates :ip, :ip => { :forbidden => :netmask }
|
22
|
+
|
23
|
+
Use ip validation with forbidden ipv6 and private addresses
|
24
|
+
validates :ip, :ip => { :forbidden => [:priavte, :ipv6] }
|
25
|
+
|
26
|
+
Use ip validation with additional custom validation
|
27
|
+
validates :ip, :ip => { :custom => Proc.new { |ip| ip.prefix == 24 } }
|
28
|
+
|
29
|
+
== Features
|
30
|
+
|
31
|
+
* validates ip
|
32
|
+
* validates with forbiddens
|
33
|
+
* ipv4 and ipv6 support
|
34
|
+
* custom validation
|
35
|
+
* tests for validator
|
36
|
+
|
37
|
+
== Forbidden list
|
38
|
+
|
39
|
+
* :a - Class A IP address
|
40
|
+
* :b - Class B IP address
|
41
|
+
* :c - Class C IP address
|
42
|
+
* :netmask - 10.20.30.10/24
|
43
|
+
* :private - Class A/B/C IP address
|
44
|
+
* :ipv4 - 10.20.30.40
|
45
|
+
* :ipv6 - ::ffff:192.168.0.1 or 2001:db8:0:cd30::
|
46
|
+
|
47
|
+
== Contributing to rails_ip_validator
|
48
|
+
|
49
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
50
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
51
|
+
* Fork the project
|
52
|
+
* Start a feature/bugfix branch
|
53
|
+
* Commit and push until you are happy with your contribution
|
54
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
55
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
56
|
+
|
57
|
+
== Copyright
|
58
|
+
|
59
|
+
Copyright (c) 2010 Marco Scholl. See LICENSE.txt for further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "rails_ip_validator"
|
16
|
+
gem.homepage = "http://github.com/traxanos/rails_ip_validator"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{an ip validator for rails}
|
19
|
+
gem.description = %Q{a class to validate ip. it builded for rails}
|
20
|
+
gem.email = "develop@marco-scholl.de"
|
21
|
+
gem.authors = ["Marco Scholl"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
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'
|
26
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
27
|
+
end
|
28
|
+
Jeweler::RubygemsDotOrgTasks.new
|
29
|
+
|
30
|
+
require 'rake/testtask'
|
31
|
+
Rake::TestTask.new(:test) do |test|
|
32
|
+
test.libs << 'lib' << 'test'
|
33
|
+
test.pattern = 'test/**/test_*.rb'
|
34
|
+
test.verbose = true
|
35
|
+
end
|
36
|
+
|
37
|
+
task :default => :test
|
38
|
+
|
39
|
+
require 'rake/rdoctask'
|
40
|
+
Rake::RDocTask.new do |rdoc|
|
41
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
42
|
+
|
43
|
+
rdoc.rdoc_dir = 'rdoc'
|
44
|
+
rdoc.title = "rails_ip_validator #{version}"
|
45
|
+
rdoc.rdoc_files.include('README*')
|
46
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
47
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'rails_ip_validator'
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding:utf-8
|
2
|
+
|
3
|
+
require 'active_model'
|
4
|
+
require 'ipaddress'
|
5
|
+
|
6
|
+
# Validator for email
|
7
|
+
class IpValidator < ActiveModel::EachValidator
|
8
|
+
|
9
|
+
def forbidden
|
10
|
+
unless @forbidden.is_a? Array
|
11
|
+
if options[:forbidden].nil?
|
12
|
+
# default
|
13
|
+
@forbidden = []
|
14
|
+
else
|
15
|
+
@forbidden = options[:forbidden].is_a?(Array) ? options[:forbidden] : [options[:forbidden]]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
@forbidden
|
19
|
+
end
|
20
|
+
|
21
|
+
def forbidden? key
|
22
|
+
forbidden.include? key
|
23
|
+
end
|
24
|
+
|
25
|
+
# main validator for email
|
26
|
+
def validate_each(record, attribute, value)
|
27
|
+
unless value.blank?
|
28
|
+
|
29
|
+
# pre var
|
30
|
+
valid = true
|
31
|
+
|
32
|
+
begin
|
33
|
+
ip = IPAddress.parse(value.to_s)
|
34
|
+
|
35
|
+
valid = false if forbidden? :netmask and value =~ /\//
|
36
|
+
valid = false if forbidden? :a and ip.a?
|
37
|
+
valid = false if forbidden? :b and ip.b?
|
38
|
+
valid = false if forbidden? :c and ip.c?
|
39
|
+
valid = false if forbidden? :private and ip.private?
|
40
|
+
valid = false if forbidden? :ipv4 and ip.class == IPAddress::IPv4
|
41
|
+
valid = false if forbidden? :ipv6 and (ip.class == IPAddress::IPv6 or ip.class == IPAddress::IPv6::Mapped)
|
42
|
+
if options[:custom].is_a? Proc
|
43
|
+
valid = false unless options[:custom].call(ip)
|
44
|
+
end
|
45
|
+
rescue
|
46
|
+
valid = false
|
47
|
+
end
|
48
|
+
|
49
|
+
# ip valid
|
50
|
+
record.errors.add(attribute, :invalid) unless valid
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{rails_ip_validator}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Marco Scholl"]
|
12
|
+
s.date = %q{2011-01-22}
|
13
|
+
s.description = %q{a class to validate ip. it builded for rails}
|
14
|
+
s.email = %q{develop@marco-scholl.de}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"init.rb",
|
28
|
+
"lib/rails_ip_validator.rb",
|
29
|
+
"rails_ip_validator.gemspec",
|
30
|
+
"test/helper.rb",
|
31
|
+
"test/test_rails_ip_validator.rb"
|
32
|
+
]
|
33
|
+
s.homepage = %q{http://github.com/traxanos/rails_ip_validator}
|
34
|
+
s.licenses = ["MIT"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubygems_version = %q{1.3.7}
|
37
|
+
s.summary = %q{an ip validator for rails}
|
38
|
+
s.test_files = [
|
39
|
+
"test/helper.rb",
|
40
|
+
"test/test_rails_ip_validator.rb"
|
41
|
+
]
|
42
|
+
|
43
|
+
if s.respond_to? :specification_version then
|
44
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
45
|
+
s.specification_version = 3
|
46
|
+
|
47
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_runtime_dependency(%q<activemodel>, [">= 3.0.0"])
|
49
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
50
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
|
51
|
+
s.add_development_dependency(%q<ipaddress>, [">= 0"])
|
52
|
+
s.add_runtime_dependency(%q<activemodel>, [">= 3.0.0"])
|
53
|
+
s.add_runtime_dependency(%q<ipaddress>, [">= 0"])
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<activemodel>, [">= 3.0.0"])
|
56
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
57
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
58
|
+
s.add_dependency(%q<ipaddress>, [">= 0"])
|
59
|
+
s.add_dependency(%q<activemodel>, [">= 3.0.0"])
|
60
|
+
s.add_dependency(%q<ipaddress>, [">= 0"])
|
61
|
+
end
|
62
|
+
else
|
63
|
+
s.add_dependency(%q<activemodel>, [">= 3.0.0"])
|
64
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
65
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
66
|
+
s.add_dependency(%q<ipaddress>, [">= 0"])
|
67
|
+
s.add_dependency(%q<activemodel>, [">= 3.0.0"])
|
68
|
+
s.add_dependency(%q<ipaddress>, [">= 0"])
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
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 'test/unit'
|
13
|
+
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
16
|
+
require 'rails_ip_validator'
|
17
|
+
|
18
|
+
class Test::Unit::TestCase
|
19
|
+
end
|
@@ -0,0 +1,211 @@
|
|
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
|
metadata
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_ip_validator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Marco Scholl
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-01-22 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: activemodel
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 3
|
29
|
+
- 0
|
30
|
+
- 0
|
31
|
+
version: 3.0.0
|
32
|
+
type: :runtime
|
33
|
+
prerelease: false
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: bundler
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 1
|
44
|
+
- 0
|
45
|
+
- 0
|
46
|
+
version: 1.0.0
|
47
|
+
type: :development
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: jeweler
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 1
|
59
|
+
- 5
|
60
|
+
- 1
|
61
|
+
version: 1.5.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: *id003
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: ipaddress
|
67
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
type: :development
|
76
|
+
prerelease: false
|
77
|
+
version_requirements: *id004
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: activemodel
|
80
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
segments:
|
86
|
+
- 3
|
87
|
+
- 0
|
88
|
+
- 0
|
89
|
+
version: 3.0.0
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: *id005
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: ipaddress
|
95
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
version: "0"
|
103
|
+
type: :runtime
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: *id006
|
106
|
+
description: a class to validate ip. it builded for rails
|
107
|
+
email: develop@marco-scholl.de
|
108
|
+
executables: []
|
109
|
+
|
110
|
+
extensions: []
|
111
|
+
|
112
|
+
extra_rdoc_files:
|
113
|
+
- LICENSE.txt
|
114
|
+
- README.rdoc
|
115
|
+
files:
|
116
|
+
- .document
|
117
|
+
- Gemfile
|
118
|
+
- Gemfile.lock
|
119
|
+
- LICENSE.txt
|
120
|
+
- README.rdoc
|
121
|
+
- Rakefile
|
122
|
+
- VERSION
|
123
|
+
- init.rb
|
124
|
+
- lib/rails_ip_validator.rb
|
125
|
+
- rails_ip_validator.gemspec
|
126
|
+
- test/helper.rb
|
127
|
+
- test/test_rails_ip_validator.rb
|
128
|
+
has_rdoc: true
|
129
|
+
homepage: http://github.com/traxanos/rails_ip_validator
|
130
|
+
licenses:
|
131
|
+
- MIT
|
132
|
+
post_install_message:
|
133
|
+
rdoc_options: []
|
134
|
+
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
hash: 2079695135441663721
|
143
|
+
segments:
|
144
|
+
- 0
|
145
|
+
version: "0"
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
none: false
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
segments:
|
152
|
+
- 0
|
153
|
+
version: "0"
|
154
|
+
requirements: []
|
155
|
+
|
156
|
+
rubyforge_project:
|
157
|
+
rubygems_version: 1.3.7
|
158
|
+
signing_key:
|
159
|
+
specification_version: 3
|
160
|
+
summary: an ip validator for rails
|
161
|
+
test_files:
|
162
|
+
- test/helper.rb
|
163
|
+
- test/test_rails_ip_validator.rb
|