valid_hostname 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/rubocop.yml +29 -0
- data/.github/workflows/tests.yml +42 -0
- data/.gitignore +7 -0
- data/.rspec +2 -0
- data/.rubocop.yml +105 -0
- data/CHANGELOG.md +19 -0
- data/Gemfile +5 -0
- data/LICENSE +21 -0
- data/README.md +206 -0
- data/Rakefile +12 -0
- data/config/locales/de.yml +13 -0
- data/config/locales/en.yml +13 -0
- data/config/valid_hostname.yml +1491 -0
- data/lib/valid_hostname/domainname_validator.rb +21 -0
- data/lib/valid_hostname/hostname_validator.rb +58 -0
- data/lib/valid_hostname/validate_hostname.rb +132 -0
- data/lib/valid_hostname/version.rb +5 -0
- data/lib/valid_hostname.rb +14 -0
- data/spec/record_valid_hostname_spec.rb +529 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/test_model.rb +75 -0
- data/spec/validate_hostname_spec.rb +148 -0
- data/valid_hostname.gemspec +32 -0
- metadata +195 -0
@@ -0,0 +1,148 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe ValidateHostname do
|
6
|
+
context 'with valid?' do
|
7
|
+
it 'valid single label' do
|
8
|
+
expect(described_class).to be_valid('test')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'valid multiple labels' do
|
12
|
+
expect(described_class).to be_valid('test1.test2.com')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'valid label length' do
|
16
|
+
expect(described_class).not_to be_valid("my#{'t' * 62}.hostname")
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'invalid hostname length' do
|
20
|
+
expect(described_class).not_to be_valid("my#{'t' * 254}.hostname")
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'valid hyphens' do
|
24
|
+
expect(described_class).to be_valid('my-host.hostname')
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'invalid hyphens' do
|
28
|
+
expect(described_class).not_to be_valid('-myhost.hostname')
|
29
|
+
expect(described_class).not_to be_valid('myhost-.hostname')
|
30
|
+
expect(described_class).not_to be_valid('-myhost-.hostname')
|
31
|
+
expect(described_class).not_to be_valid('myhost.-hostname')
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'invalid root label' do
|
35
|
+
expect(described_class).not_to be_valid('.')
|
36
|
+
expect(described_class).not_to be_valid('test.')
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'valid root label with allow_root_label' do
|
40
|
+
expect(described_class).to be_valid('.', allow_root_label: true)
|
41
|
+
expect(described_class).to be_valid('test.', allow_root_label: true)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'with valid_length?' do
|
46
|
+
it 'valid hostname length' do
|
47
|
+
expect(described_class).to be_valid_length("my#{'t' * 253}")
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'invalid hostname length' do
|
51
|
+
expect(described_class).not_to be_valid_length("my#{'t' * 254}")
|
52
|
+
expect(described_class).not_to be_valid_length('')
|
53
|
+
expect(described_class).not_to be_valid_length(nil)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'with valid_label_length?' do
|
58
|
+
it 'valid label length' do
|
59
|
+
expect(described_class).to be_valid_label_length("my#{'t' * 61}.hostname")
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'invalid label length' do
|
63
|
+
expect(described_class).not_to be_valid_label_length("my#{'t' * 62}.hostname")
|
64
|
+
expect(described_class).not_to be_valid_label_length('')
|
65
|
+
expect(described_class).not_to be_valid_label_length(nil)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'with valid_hyphens?' do
|
70
|
+
it 'valid hyphens' do
|
71
|
+
expect(described_class).to be_valid_hyphens('my-host.hostname')
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'invalid hyphens' do
|
75
|
+
expect(described_class).not_to be_valid_hyphens('-myhost.hostname')
|
76
|
+
expect(described_class).not_to be_valid_hyphens('myhost-.hostname')
|
77
|
+
expect(described_class).not_to be_valid_hyphens('-myhost-.hostname')
|
78
|
+
expect(described_class).not_to be_valid_hyphens('myhost.-hostname')
|
79
|
+
expect(described_class).not_to be_valid_hyphens("\n-myhost.hostname")
|
80
|
+
expect(described_class).not_to be_valid_hyphens("myhost.\n-hostname")
|
81
|
+
expect(described_class).not_to be_valid_hyphens("myhost.hostname-\n")
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'with valid_numeric_only?' do
|
86
|
+
it 'valid numeric only' do
|
87
|
+
expect(described_class).to be_valid_numeric_only('my-host.hostname', allow_numeric_hostname: true)
|
88
|
+
expect(described_class).to be_valid_numeric_only('1234.hostname', allow_numeric_hostname: true)
|
89
|
+
expect(described_class).to be_valid_numeric_only('test.1234.hostname')
|
90
|
+
expect(described_class).to be_valid_numeric_only('')
|
91
|
+
expect(described_class).to be_valid_numeric_only(nil)
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'invalid numeric only' do
|
95
|
+
expect(described_class).not_to be_valid_numeric_only('1234.hostname')
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'with valid_dots?' do
|
100
|
+
it 'valid dots' do
|
101
|
+
expect(described_class).to be_valid_dots('test.hostname')
|
102
|
+
expect(described_class).to be_valid_dots('')
|
103
|
+
expect(described_class).to be_valid_dots(nil)
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'invalid dots' do
|
107
|
+
expect(described_class).not_to be_valid_dots('1234..hostname')
|
108
|
+
expect(described_class).not_to be_valid_dots('hostname..')
|
109
|
+
expect(described_class).not_to be_valid_dots('..hostname')
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context 'with valid_characters?' do
|
114
|
+
it 'valid characters' do
|
115
|
+
expect(described_class).to be_valid_characters('localhost')
|
116
|
+
expect(described_class).to be_valid_characters('localhost.domain1')
|
117
|
+
expect(described_class).to be_valid_characters('localhost.dom-ain1')
|
118
|
+
expect(described_class).to be_valid_characters('')
|
119
|
+
expect(described_class).to be_valid_characters(nil)
|
120
|
+
expect(described_class).to be_valid_characters('test.host_name', allow_underscore: true)
|
121
|
+
expect(described_class).to be_valid_characters('*.domain1', allow_wildcard_hostname: true)
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'invalid characters' do
|
125
|
+
expect(described_class).not_to be_valid_characters('test.host_name')
|
126
|
+
expect(described_class).not_to be_valid_characters('*.domain1')
|
127
|
+
expect(described_class).not_to be_valid_characters('localhost.tes,t')
|
128
|
+
expect(described_class).not_to be_valid_characters('localhost.tes;t')
|
129
|
+
expect(described_class).not_to be_valid_characters('localhost.teßt')
|
130
|
+
expect(described_class).not_to be_valid_characters("localhost\n.test")
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
context 'with valid_tld?' do
|
135
|
+
it 'valid tlds' do
|
136
|
+
expect(described_class).to be_valid_tld('test.org')
|
137
|
+
expect(described_class).to be_valid_tld('test.ccc', valid_tlds: ['ccc'])
|
138
|
+
expect(described_class).to be_valid_tld('test.ccc', require_valid_tld: false)
|
139
|
+
expect(described_class).to be_valid_tld('')
|
140
|
+
expect(described_class).to be_valid_tld(nil)
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'invalid tlds' do
|
144
|
+
expect(described_class).not_to be_valid_tld('test.ccc')
|
145
|
+
expect(described_class).not_to be_valid_tld('test')
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path 'lib', __dir__
|
4
|
+
$LOAD_PATH.unshift lib unless $LOAD_PATH.include? lib
|
5
|
+
require 'valid_hostname/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'valid_hostname'
|
9
|
+
spec.version = ValidHostname::VERSION
|
10
|
+
spec.metadata = { 'rubygems_mfa_required' => 'true' }
|
11
|
+
|
12
|
+
spec.authors = ['Kim Nøgaard', 'Alexander Meindl']
|
13
|
+
spec.description = 'Extension to ActiveRecord::Base for validating hostnames'
|
14
|
+
spec.summary = 'Checks for valid hostnames'
|
15
|
+
spec.email = ['jasen@jasen.dk', 'a.meindl@alphanodes.com']
|
16
|
+
spec.homepage = 'https://github.com/AlphaNodes/valid_hostname'
|
17
|
+
spec.licenses = ['MIT']
|
18
|
+
spec.required_ruby_version = '>= 2.7'
|
19
|
+
|
20
|
+
spec.files = `git ls-files`.split "\n"
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_runtime_dependency 'activemodel'
|
24
|
+
spec.add_development_dependency 'bundler'
|
25
|
+
spec.add_development_dependency 'debug' if ENV['ENABLE_DEBUG']
|
26
|
+
spec.add_development_dependency 'rake'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.10'
|
28
|
+
spec.add_development_dependency 'rubocop'
|
29
|
+
spec.add_development_dependency 'rubocop-performance'
|
30
|
+
spec.add_development_dependency 'rubocop-rspec'
|
31
|
+
spec.add_development_dependency 'solargraph'
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,195 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: valid_hostname
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kim Nøgaard
|
8
|
+
- Alexander Meindl
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2022-10-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activemodel
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: bundler
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: debug
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rspec
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '3.10'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '3.10'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rubocop
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: rubocop-performance
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: rubocop-rspec
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: solargraph
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
description: Extension to ActiveRecord::Base for validating hostnames
|
141
|
+
email:
|
142
|
+
- jasen@jasen.dk
|
143
|
+
- a.meindl@alphanodes.com
|
144
|
+
executables: []
|
145
|
+
extensions: []
|
146
|
+
extra_rdoc_files: []
|
147
|
+
files:
|
148
|
+
- ".github/workflows/rubocop.yml"
|
149
|
+
- ".github/workflows/tests.yml"
|
150
|
+
- ".gitignore"
|
151
|
+
- ".rspec"
|
152
|
+
- ".rubocop.yml"
|
153
|
+
- CHANGELOG.md
|
154
|
+
- Gemfile
|
155
|
+
- LICENSE
|
156
|
+
- README.md
|
157
|
+
- Rakefile
|
158
|
+
- config/locales/de.yml
|
159
|
+
- config/locales/en.yml
|
160
|
+
- config/valid_hostname.yml
|
161
|
+
- lib/valid_hostname.rb
|
162
|
+
- lib/valid_hostname/domainname_validator.rb
|
163
|
+
- lib/valid_hostname/hostname_validator.rb
|
164
|
+
- lib/valid_hostname/validate_hostname.rb
|
165
|
+
- lib/valid_hostname/version.rb
|
166
|
+
- spec/record_valid_hostname_spec.rb
|
167
|
+
- spec/spec_helper.rb
|
168
|
+
- spec/test_model.rb
|
169
|
+
- spec/validate_hostname_spec.rb
|
170
|
+
- valid_hostname.gemspec
|
171
|
+
homepage: https://github.com/AlphaNodes/valid_hostname
|
172
|
+
licenses:
|
173
|
+
- MIT
|
174
|
+
metadata:
|
175
|
+
rubygems_mfa_required: 'true'
|
176
|
+
post_install_message:
|
177
|
+
rdoc_options: []
|
178
|
+
require_paths:
|
179
|
+
- lib
|
180
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
181
|
+
requirements:
|
182
|
+
- - ">="
|
183
|
+
- !ruby/object:Gem::Version
|
184
|
+
version: '2.7'
|
185
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
186
|
+
requirements:
|
187
|
+
- - ">="
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: '0'
|
190
|
+
requirements: []
|
191
|
+
rubygems_version: 3.3.7
|
192
|
+
signing_key:
|
193
|
+
specification_version: 4
|
194
|
+
summary: Checks for valid hostnames
|
195
|
+
test_files: []
|