kangal 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/SECURITY.md +7 -0
- data/config/locales/en.yml +2 -0
- data/config/locales/fr.yml +2 -0
- data/config/locales/tr.yml +3 -1
- data/lib/kangal.rb +1 -0
- data/lib/kangal/email.rb +6 -10
- data/lib/kangal/identity_number.rb +6 -4
- data/lib/kangal/ip.rb +12 -0
- data/lib/kangal/subdomain.rb +5 -0
- data/lib/kangal/tax_number.rb +7 -5
- data/lib/kangal/version.rb +1 -1
- data/spec/ip_spec.rb +44 -0
- data/spec/subdomain_spec.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6bd8a15b84a66f86f63627a1d21f00fa8024f3f
|
4
|
+
data.tar.gz: cd4ef8987f3e905d8877b8d5a425b6ac4606e1b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7794dee17a3dfe11dec2ac7be8db4bc30073ad5aa64af43fdca1df4c5e65465997f7b50276f4aa2b5933724e8a2dfc81b1fb518240143750956727d8f82456aa
|
7
|
+
data.tar.gz: c316de0ddb2a5d48937380faafa23dfcd6cbe8dada74e97245fe3649e82261337630e1b998c19dac00bc3e2ca6e5f11e7f41027a49879d3524c671ee2c1be439
|
data/SECURITY.md
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# Reporting Security Issues
|
2
|
+
|
3
|
+
If you discover a security issue in Kangel, please report it by sending an email to info@lab2023.com
|
4
|
+
|
5
|
+
This will allow us to assess the risk, and make a fix available before we add a bug report to the Github repo.
|
6
|
+
|
7
|
+
Thanks for helping make Kangal safe for everyone.
|
data/config/locales/en.yml
CHANGED
data/config/locales/fr.yml
CHANGED
data/config/locales/tr.yml
CHANGED
data/lib/kangal.rb
CHANGED
data/lib/kangal/email.rb
CHANGED
@@ -4,24 +4,20 @@ require 'mail'
|
|
4
4
|
|
5
5
|
class EmailValidator < ActiveModel::EachValidator
|
6
6
|
|
7
|
-
def validate_each(
|
8
|
-
|
7
|
+
def validate_each(object, attribute, value)
|
8
|
+
|
9
|
+
return if options[:allow_nil] && value.nil?
|
10
|
+
return if options[:allow_blank] && value.blank?
|
11
|
+
|
9
12
|
begin
|
10
13
|
m = Mail::Address.new(value)
|
11
|
-
# We must check that value contains a domain and that value is an email address
|
12
14
|
r = m.domain && m.address == value
|
13
15
|
t = m.__send__(:tree)
|
14
|
-
# We need to dig into treetop
|
15
|
-
# A valid domain must have dot_atom_text elements size > 1
|
16
|
-
# user@localhost is excluded
|
17
|
-
# treetop must respond to domain
|
18
|
-
# We exclude valid email values like <user@localhost.com>
|
19
|
-
# Hence we use m.__send__(tree).domain
|
20
16
|
r &&= (t.domain.dot_atom_text.elements.size > 1)
|
21
17
|
rescue Exception => e
|
22
18
|
r = false
|
23
19
|
end
|
24
|
-
|
20
|
+
object.errors.add attribute, (options[:message] || I18n.t(:invalid, :scope => 'kangal.validations.email')) unless r
|
25
21
|
end
|
26
22
|
|
27
23
|
end
|
@@ -2,16 +2,18 @@ require 'active_model'
|
|
2
2
|
require 'active_model/validations'
|
3
3
|
|
4
4
|
class IdentityNumberValidator < ActiveModel::EachValidator
|
5
|
-
|
6
5
|
def validate_each(record, attribute, value)
|
7
|
-
|
6
|
+
|
7
|
+
return if options[:allow_nil] && value.nil?
|
8
|
+
return if options[:allow_blank] && value.blank?
|
9
|
+
|
10
|
+
valid = false
|
8
11
|
val = value.to_s
|
12
|
+
|
9
13
|
if val.size == 11 && val[0].to_i != 0
|
10
14
|
valid = check_tenth_character(val)
|
11
15
|
valid = check_eleventh_character(val)
|
12
16
|
valid = double_check_eleventh_character(val)
|
13
|
-
else
|
14
|
-
valid = false
|
15
17
|
end
|
16
18
|
|
17
19
|
record.errors.add attribute, (options[:message] || I18n.t(:invalid, :scope => 'kangal.validations.identity_number')) unless valid
|
data/lib/kangal/ip.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'active_model'
|
2
|
+
require 'active_model/validations'
|
3
|
+
|
4
|
+
class IpValidator < ActiveModel::EachValidator
|
5
|
+
def validate_each(object, attribute, value)
|
6
|
+
|
7
|
+
return if options[:allow_nil] && value.nil?
|
8
|
+
return if options[:allow_blank] && value.blank?
|
9
|
+
|
10
|
+
object.errors[attribute] << I18n.t(:invalid, scope: 'kangal.validations.ip') unless value =~ /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/i
|
11
|
+
end
|
12
|
+
end
|
data/lib/kangal/subdomain.rb
CHANGED
@@ -3,9 +3,14 @@ require 'active_model/validations'
|
|
3
3
|
|
4
4
|
class SubdomainValidator < ActiveModel::EachValidator
|
5
5
|
def validate_each(object, attribute, value)
|
6
|
+
|
7
|
+
return if options[:allow_nil] && value.nil?
|
8
|
+
return if options[:allow_blank] && value.blank?
|
6
9
|
return unless value.present?
|
10
|
+
|
7
11
|
reserved_names = %w(www ftp mail pop smtp admin ssl sftp http https)
|
8
12
|
reserved_names = options[:reserved] if options[:reserved]
|
13
|
+
|
9
14
|
if reserved_names.include?(value)
|
10
15
|
object.errors[attribute] << I18n.t(:reserved, scope: 'kangal.validations.subdomain')
|
11
16
|
end
|
data/lib/kangal/tax_number.rb
CHANGED
@@ -2,9 +2,12 @@ require 'active_model'
|
|
2
2
|
require 'active_model/validations'
|
3
3
|
|
4
4
|
class TaxNumberValidator < ActiveModel::EachValidator
|
5
|
+
def validate_each(object, attribute, value)
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
return if options[:allow_nil] && value.nil?
|
8
|
+
return if options[:allow_blank] && value.blank?
|
9
|
+
|
10
|
+
valid = false
|
8
11
|
val = value.to_s
|
9
12
|
if val.size == 10
|
10
13
|
val1 = Array.new
|
@@ -37,9 +40,8 @@ class TaxNumberValidator < ActiveModel::EachValidator
|
|
37
40
|
|
38
41
|
valid = (sum == last_digit)
|
39
42
|
|
40
|
-
else
|
41
|
-
valid = false
|
42
43
|
end
|
43
|
-
|
44
|
+
|
45
|
+
object.errors.add attribute, (options[:message] || I18n.t(:invalid, :scope => 'kangal.validations.tax_number')) unless valid
|
44
46
|
end
|
45
47
|
end
|
data/lib/kangal/version.rb
CHANGED
data/spec/ip_spec.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class Server < SpecModel
|
4
|
+
validates :ip, ip: true
|
5
|
+
end
|
6
|
+
|
7
|
+
describe 'Ip format' do
|
8
|
+
|
9
|
+
let(:invalid_ips) do
|
10
|
+
%w(
|
11
|
+
10.10.10
|
12
|
+
10.10
|
13
|
+
10
|
14
|
+
a.a.a.a
|
15
|
+
10.0.0.a
|
16
|
+
10.10.10.256
|
17
|
+
10.10.10.256
|
18
|
+
999.10.10.20
|
19
|
+
2222.22.22.22
|
20
|
+
22.2222.22.2
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:valid_ips) do
|
25
|
+
%w(
|
26
|
+
1.1.1.1
|
27
|
+
255.255.255.255
|
28
|
+
192.168.1.1
|
29
|
+
10.10.1.1
|
30
|
+
132.254.111.10
|
31
|
+
26.10.2.10
|
32
|
+
127.0.0.1
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should be invalid' do
|
37
|
+
invalid_ips.each { |ip| Server.new(ip: ip).valid?.should be_false }
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should be valid' do
|
41
|
+
valid_ips.each { |ip| Server.new(ip: ip).valid?.should be_true }
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/spec/subdomain_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kangal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- lab2023
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-01-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- LICENSE.txt
|
97
97
|
- README.md
|
98
98
|
- Rakefile
|
99
|
+
- SECURITY.md
|
99
100
|
- config/locales/en.yml
|
100
101
|
- config/locales/fr.yml
|
101
102
|
- config/locales/tr.yml
|
@@ -103,11 +104,13 @@ files:
|
|
103
104
|
- lib/kangal.rb
|
104
105
|
- lib/kangal/email.rb
|
105
106
|
- lib/kangal/identity_number.rb
|
107
|
+
- lib/kangal/ip.rb
|
106
108
|
- lib/kangal/subdomain.rb
|
107
109
|
- lib/kangal/tax_number.rb
|
108
110
|
- lib/kangal/version.rb
|
109
111
|
- spec/email_spec.rb
|
110
112
|
- spec/identity_number_spec.rb
|
113
|
+
- spec/ip_spec.rb
|
111
114
|
- spec/spec_helper.rb
|
112
115
|
- spec/subdomain_spec.rb
|
113
116
|
- spec/tax_number_spec.rb
|
@@ -131,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
134
|
version: '0'
|
132
135
|
requirements: []
|
133
136
|
rubyforge_project:
|
134
|
-
rubygems_version: 2.0
|
137
|
+
rubygems_version: 2.2.0
|
135
138
|
signing_key:
|
136
139
|
specification_version: 4
|
137
140
|
summary: Kangal brings you a nice set of custom validators for Rails 4.
|