kangal 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c9c6e5ebc471b05747256ef6bf399bc81793402c
4
- data.tar.gz: 765f8597f5d52b33fac03ba7b9ac8bc61ed6e50c
3
+ metadata.gz: f6bd8a15b84a66f86f63627a1d21f00fa8024f3f
4
+ data.tar.gz: cd4ef8987f3e905d8877b8d5a425b6ac4606e1b8
5
5
  SHA512:
6
- metadata.gz: 12b1ec5cf986cf59062ed32380d5305e3ed578839ce2052cecd7701310c8bd5bb15152b75aba0b7556c2ff53644a03c250bdfd99a22817c22f363176b981916d
7
- data.tar.gz: c9d637cf15a46316fc8944ba2f5e1d7892209ab2a4c51e77d3f38b00d434d522c9aaac4b4ab2f1dd940549ee564a20c5e08693ca4019b362b7cb555f04cd797f
6
+ metadata.gz: 7794dee17a3dfe11dec2ac7be8db4bc30073ad5aa64af43fdca1df4c5e65465997f7b50276f4aa2b5933724e8a2dfc81b1fb518240143750956727d8f82456aa
7
+ data.tar.gz: c316de0ddb2a5d48937380faafa23dfcd6cbe8dada74e97245fe3649e82261337630e1b998c19dac00bc3e2ca6e5f11e7f41027a49879d3524c671ee2c1be439
@@ -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.
@@ -10,5 +10,7 @@ en:
10
10
  alphanumeric: 'must be alphanumeric; A-Z, 0-9 or hyphen'
11
11
  identity_number:
12
12
  invalid: 'is invalid.'
13
+ tax_number:
14
+ invalid: 'is invalid.'
13
15
  tax_number:
14
16
  invalid: 'is invalid.'
@@ -12,3 +12,5 @@ en:
12
12
  invalid: 'est invalide.'
13
13
  tax_number:
14
14
  invalid: 'est invalide.'
15
+ ip:
16
+ invalid: 'est invalide.'
@@ -11,4 +11,6 @@ tr:
11
11
  identity_number:
12
12
  invalid: 'geçersizdir.'
13
13
  tax_number:
14
- invalid: 'geçersizdir.'
14
+ invalid: 'geçersizdir.'
15
+ ip:
16
+ invalid: 'geçersizdir.'
@@ -3,5 +3,6 @@ require 'kangal/email'
3
3
  require 'kangal/subdomain'
4
4
  require 'kangal/identity_number'
5
5
  require 'kangal/tax_number'
6
+ require 'kangal/ip'
6
7
 
7
8
  I18n.load_path += Dir.glob(File.expand_path('../../config/locales/**/*',__FILE__))
@@ -4,24 +4,20 @@ require 'mail'
4
4
 
5
5
  class EmailValidator < ActiveModel::EachValidator
6
6
 
7
- def validate_each(record, attribute, value)
8
- # takes from https://github.com/hallelujah/valid_email/blob/master/lib/valid_email/email_validator.rb
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
- record.errors.add attribute, (options[:message] || I18n.t(:invalid, :scope => 'kangal.validations.email')) unless r
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
- valid = true
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
@@ -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
@@ -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
@@ -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
- def validate_each(record, attribute, value)
7
- valid = true
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
- record.errors.add attribute, (options[:message] || I18n.t(:invalid, :scope => 'kangal.validations.tax_number')) unless valid
44
+
45
+ object.errors.add attribute, (options[:message] || I18n.t(:invalid, :scope => 'kangal.validations.tax_number')) unless valid
44
46
  end
45
47
  end
@@ -1,3 +1,3 @@
1
1
  module Kangal
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0'
3
3
  end
@@ -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
@@ -7,7 +7,7 @@ end
7
7
  describe 'Subdomain format' do
8
8
 
9
9
  let(:invalid_subdomains) do
10
- %w(-lab2023 https, ab)
10
+ %w(-lab2023 https ab)
11
11
  end
12
12
 
13
13
  let(:valid_subdomains) do
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.1.0
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: 2013-10-22 00:00:00.000000000 Z
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.6
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.