domain_name_validator 0.3 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog.md CHANGED
@@ -1,3 +1,14 @@
1
+ 0.4 (2013-07-17)
2
+ ----------------
3
+
4
+ * By request, added rudimentary TLD checking. A TLD, the right-most label of a
5
+ domain name, should be either 2 or 3 characters, unless it's "aero", "arpa",
6
+ "museum" or begins with "xn--" (for a normalized Unicode TLD). This check
7
+ does not validate against a master list of TLD's, but basically just fails
8
+ a domain name if the TLD basically could not be valid under any
9
+ circumstances. This validation would, for example, reject a domain name
10
+ such as "test.domain".
11
+
1
12
  0.3 (2013-06-28)
2
13
  ----------------
3
14
 
data/Developers.md ADDED
@@ -0,0 +1,52 @@
1
+ For Developers Only
2
+ ===================
3
+
4
+ Building and testing the domain_name_validator gem is pretty easy.
5
+
6
+ Gemspec
7
+ -------
8
+
9
+ The gemspec file for the gem, domain_name_validator.gemspec, is an active
10
+ file containing Ruby code. In other words, the gemspec file itself has code
11
+ to figure out what files should be included in the gem, etc. Each time a
12
+ release is done, the only thing that needs to be edited is the "gem.date"
13
+ property.
14
+
15
+ Version
16
+ -------
17
+
18
+ The version number is defined in the version.rb file, located in the lib
19
+ directory tree. The version number should be bumped up in some fashion with
20
+ each release. Version numbers often have 3 digits, e.g. - 1.2.3. The left-most
21
+ number is a release, followed by a sub-release and a patch. All versions
22
+ within a release should generally be backwards compatible. A sub-release
23
+ generally include significant new features, whilea patch is generally a minor
24
+ update (often a bug fix).
25
+
26
+ The gemspec file automatically picks up the version number from the version.rb
27
+ file, so make sure you keep it updated properly.
28
+
29
+ Testing the Code
30
+ ----------------
31
+
32
+ Testing the code is simple. Run the following command from the top level
33
+ of the gem's directory tree:
34
+
35
+ $ bundle exec rspec spec
36
+
37
+ Creating the Gem
38
+ ----------------
39
+
40
+ To create the gem file for this gem, run the following command from the top
41
+ level of the gem's directory tree:
42
+
43
+ $ gem build domain_name_validator.gemspec
44
+
45
+ Pushing to RubyGems
46
+ -------------------
47
+
48
+ Obviously, you can only do this step if you've got the appropriate privileges
49
+ at RubyGems.org and everything is properly configured.
50
+
51
+ $ gem push domain_name_validator.gem
52
+
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- domain_name_validator (0.3)
4
+ domain_name_validator (0.4)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/README.md CHANGED
@@ -14,7 +14,7 @@ There are other gems and libraries that parse domain names into their various
14
14
  components, or parse URLS, or properly handle Unicode domain names, etc. Use
15
15
  them; many of them are very good at their well-defined roles. But none of the
16
16
  ones that I came across were very good at simply telling me whether a domain
17
- names was valid.
17
+ names was valid, or WHY it was invalid if it failed the validations.
18
18
 
19
19
  How It Works
20
20
  ------------
@@ -120,8 +120,10 @@ Road Map
120
120
  --------
121
121
 
122
122
  More types of checks will be added as they are identified. Support for
123
- validating top-level domains is also in the works (it's a bit more complex
124
- than you might imagine).
123
+ validating top-level domains (TLD's) is also in the works (it's a bit more
124
+ complex than you might imagine). This will also bring in the capability to
125
+ validate effective TLD's as well, i.e. - strings that are treated as top-level
126
+ domains by registrars around the world.
125
127
 
126
128
  Alternative Gems
127
129
  ----------------
@@ -139,7 +141,7 @@ Author
139
141
 
140
142
  David Keener
141
143
 
142
- He's is a long-time Rubyist, with extensive experience both in the Internet
144
+ He's a long-time Rubyist, with extensive experience both in the Internet
143
145
  startup world and government contracting. He is one of the founders of the
144
146
  RubyNation and DevIgnition conferences. He speaks often at technical
145
147
  conferences, and blogs regularly on Internet-related subjects at
@@ -149,7 +151,8 @@ Contributors
149
151
  ------------
150
152
 
151
153
  Many thanks for the support of General Dynamics and the Department of
152
- Homeland Security (DHS).
154
+ Homeland Security (DHS). And more specifically on input from Andrew Finch,
155
+ Josh Lentz, Jonathan Quigg and Dave Roberts.
153
156
 
154
157
  YOUR SUPPORT
155
158
  ------------
@@ -5,7 +5,7 @@ require "domain_name_validator/version"
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = "domain_name_validator"
7
7
  gem.version = DomainNameValidator::VERSION
8
- gem.date = '2013-06-28'
8
+ gem.date = '2013-07-17'
9
9
  gem.platform = Gem::Platform::RUBY
10
10
  gem.authors = ["David Keener"]
11
11
  gem.email = ["dkeener@keenertech.com"]
@@ -7,9 +7,21 @@ class DomainNameValidator
7
7
  MAX_DOMAIN_LENGTH = 253
8
8
  MAX_LABEL_LENGTH = 63
9
9
  MAX_LEVELS = 127
10
+ MAX_TLD_LENGTH = 3 # Except for "aero", "arpa", and "museum"
10
11
  MIN_LEVELS = 2
12
+ MIN_TLD_LENGTH = 2
11
13
 
12
14
  ERRS = {
15
+ :bogus_tld =>
16
+ 'Malformed TLD',
17
+ :illegal_chars =>
18
+ 'Domain label contains an illegal character',
19
+ :illegal_start =>
20
+ 'No domain name may start with a period',
21
+ :label_dash_begin =>
22
+ 'No domain label may begin with a dash',
23
+ :label_dash_end =>
24
+ 'No domain label may end with a dash',
13
25
  :max_domain_size =>
14
26
  'Maximum domain length of 253 exceeded',
15
27
  :max_label_size =>
@@ -18,16 +30,8 @@ class DomainNameValidator
18
30
  'Maximum domain level limit of 127 exceeded',
19
31
  :min_level_size =>
20
32
  'Minimum domain level limit of 2 not achieved',
21
- :label_dash_begin =>
22
- 'No domain label may begin with a dash',
23
- :label_dash_end =>
24
- 'No domain label may end with a dash',
25
33
  :top_numerical =>
26
- 'The top-level domain (the extension) cannot be numerical',
27
- :illegal_chars =>
28
- 'Domain label contains an illegal character',
29
- :illegal_start =>
30
- 'No domain name may start with a period'
34
+ 'The top-level domain (TLD) cannot be numerical'
31
35
  }
32
36
 
33
37
  # Validates the proper formatting of a normalized domain name, i.e. - a
@@ -55,6 +59,14 @@ class DomainNameValidator
55
59
  errs << ERRS[:illegal_chars] unless p.match(/^[a-z0-9\-\_]+$/)
56
60
  end
57
61
  errs << ERRS[:top_numerical] if parts.last.match(/^[0-9]+$/)
62
+ if parts.last.size < MIN_TLD_LENGTH || parts.last.size > MAX_TLD_LENGTH
63
+ unless parts.last == 'arpa' ||
64
+ parts.last == 'aero' ||
65
+ parts.last == 'museum' ||
66
+ parts.last.match(/^xn--/)
67
+ errs << ERRS[:bogus_tld]
68
+ end
69
+ end
58
70
  errs << ERRS[:illegal_start] if parts.first[0] == '.'
59
71
 
60
72
  errs.size == 0 # TRUE if valid, FALSE otherwise
@@ -1,3 +1,3 @@
1
1
  class DomainNameValidator
2
- VERSION = "0.3"
2
+ VERSION = "0.4"
3
3
  end
@@ -57,7 +57,7 @@ describe DomainNameValidator do
57
57
 
58
58
  describe 'Internationalized (normalized) domain names' do
59
59
 
60
- it 'should pass when a normalized international domain name' do
60
+ it 'should pass with a normalized international domain name' do
61
61
  domain = "xn--kbenhavn-54.eu"
62
62
  response = @validator.validate(domain)
63
63
  response.should be == true
@@ -65,9 +65,44 @@ describe DomainNameValidator do
65
65
 
66
66
  end
67
67
 
68
- # TODO: (2013/06/24) TLD checking will be added soon....
68
+ describe 'Rudimentary TLD Checking' do
69
+
70
+ it 'should fail if the TLD is too short' do
71
+ domain = "test.a"
72
+ response = @validator.validate(domain)
73
+ response.should be == false
74
+ end
75
+
76
+ it 'should fail if the TLD is too long' do
77
+ domain = "test.domain"
78
+ response = @validator.validate(domain)
79
+ response.should be == false
80
+ end
81
+
82
+ it "should succeed if the TLD is too long but equals 'aero'" do
83
+ domain = "test.aero"
84
+ response = @validator.validate(domain)
85
+ response.should be == true
86
+ end
87
+
88
+ it "should succeed if the TLD is too long but equals 'arpa'" do
89
+ domain = "test.arpa"
90
+ response = @validator.validate(domain)
91
+ response.should be == true
92
+ end
93
+
94
+ it "should succeed if the TLD is too long but equals 'museum'" do
95
+ domain = "test.museum"
96
+ response = @validator.validate(domain)
97
+ response.should be == true
98
+ end
99
+
100
+ it "should succeed if the TLD is too long but matches 'xn--'" do
101
+ domain = "test.xn--really-long-text"
102
+ response = @validator.validate(domain)
103
+ response.should be == true
104
+ end
69
105
 
70
- describe 'TLD Checking' do
71
106
  end
72
107
 
73
108
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: domain_name_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: '0.4'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-28 00:00:00.000000000 Z
12
+ date: 2013-07-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &31251708 !ruby/object:Gem::Requirement
16
+ requirement: &28073220 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *31251708
24
+ version_requirements: *28073220
25
25
  description: Checks the validity of domain names.
26
26
  email:
27
27
  - dkeener@keenertech.com
@@ -30,6 +30,7 @@ extensions: []
30
30
  extra_rdoc_files: []
31
31
  files:
32
32
  - ChangeLog.md
33
+ - Developers.md
33
34
  - Gemfile
34
35
  - Gemfile.lock
35
36
  - LICENSE.txt