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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 346e7e0b14e9e33d3928c36403d99c86fd0ce30d3a4943e7859c4f37ced27e42
|
4
|
+
data.tar.gz: 3684b1d42623226fee3bc29a65a802508156ad47c5c04cb144b30dbe40a1c396
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 27d765ddcb16cbd731d89c5b41a43b012fe68b9bb71af632dd9b992a46df379e73da6f4e4888cfc16073f9bb8918e2f27852cfb89081021dbac5be3bf54e1b93
|
7
|
+
data.tar.gz: df485fac0e5858e6a3eb18d2bb74a66c9518a7a0033a2c36bc7b9e9f3be5d88c0fe0b426f868553102917f92474613c1af5afc266e3b420644652d51410366db
|
@@ -0,0 +1,29 @@
|
|
1
|
+
name: Run Rubocop
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
pull_request:
|
5
|
+
|
6
|
+
jobs:
|
7
|
+
test:
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
|
10
|
+
steps:
|
11
|
+
- uses: actions/checkout@v3
|
12
|
+
|
13
|
+
- name: Install package dependencies
|
14
|
+
run: >
|
15
|
+
sudo apt-get install --yes --quiet pandoc
|
16
|
+
|
17
|
+
- name: Setup Ruby
|
18
|
+
uses: ruby/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
ruby-version: 3.1
|
21
|
+
bundler-cache: true
|
22
|
+
|
23
|
+
- name: Setup gems
|
24
|
+
run: |
|
25
|
+
bundle install --jobs 4 --retry 3
|
26
|
+
|
27
|
+
- name: Run RuboCop
|
28
|
+
run: |
|
29
|
+
bundle exec rubocop -S
|
@@ -0,0 +1,42 @@
|
|
1
|
+
name: Tests
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
pull_request:
|
5
|
+
|
6
|
+
jobs:
|
7
|
+
test:
|
8
|
+
name: ${{ matrix.redmine }} ${{ matrix.db }} ruby-${{ matrix.ruby }}
|
9
|
+
runs-on: ubuntu-latest
|
10
|
+
|
11
|
+
strategy:
|
12
|
+
matrix:
|
13
|
+
ruby: ['2.7', '3.0', '3.1']
|
14
|
+
fail-fast: false
|
15
|
+
|
16
|
+
steps:
|
17
|
+
- uses: actions/checkout@v3
|
18
|
+
|
19
|
+
- name: Update package archives
|
20
|
+
run: sudo apt-get update --yes --quiet
|
21
|
+
|
22
|
+
- name: Install package dependencies
|
23
|
+
run: >
|
24
|
+
sudo apt-get install --yes --quiet
|
25
|
+
build-essential
|
26
|
+
cmake
|
27
|
+
libicu-dev
|
28
|
+
|
29
|
+
- name: Setup Ruby
|
30
|
+
uses: ruby/setup-ruby@v1
|
31
|
+
with:
|
32
|
+
ruby-version: ${{ matrix.ruby }}
|
33
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
34
|
+
|
35
|
+
- name: Install Ruby dependencies
|
36
|
+
run: |
|
37
|
+
bundle install --jobs=4 --retry=3
|
38
|
+
|
39
|
+
- name: Run RSpec
|
40
|
+
env:
|
41
|
+
RAILS_ENV: test
|
42
|
+
run: bundle exec rspec
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-performance
|
3
|
+
- rubocop-rspec
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
TargetRubyVersion: 2.7
|
7
|
+
NewCops: enable
|
8
|
+
Include:
|
9
|
+
- '**/*.rb'
|
10
|
+
- '**/Rakefile'
|
11
|
+
- '**/Gemfile'
|
12
|
+
- 'spec/**/*.rb'
|
13
|
+
|
14
|
+
RSpec/ExampleLength:
|
15
|
+
Enabled: true
|
16
|
+
Max: 25
|
17
|
+
|
18
|
+
RSpec/MultipleExpectations:
|
19
|
+
Enabled: true
|
20
|
+
Max: 10
|
21
|
+
|
22
|
+
Metrics/AbcSize:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Metrics/BlockLength:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Metrics/ParameterLists:
|
29
|
+
Enabled: true
|
30
|
+
CountKeywordArgs: false
|
31
|
+
|
32
|
+
Metrics/ClassLength:
|
33
|
+
Enabled: false
|
34
|
+
|
35
|
+
Metrics/CyclomaticComplexity:
|
36
|
+
Max: 30
|
37
|
+
|
38
|
+
Metrics/PerceivedComplexity:
|
39
|
+
Max: 30
|
40
|
+
|
41
|
+
Layout/LineLength:
|
42
|
+
Max: 140
|
43
|
+
|
44
|
+
Metrics/MethodLength:
|
45
|
+
Max: 60
|
46
|
+
|
47
|
+
Metrics/ModuleLength:
|
48
|
+
Enabled: false
|
49
|
+
|
50
|
+
Style/ExpandPathArguments:
|
51
|
+
Enabled: true
|
52
|
+
Exclude:
|
53
|
+
- redmine_plugin_kit.gemspec
|
54
|
+
- spec/**/*
|
55
|
+
|
56
|
+
Lint/AmbiguousOperatorPrecedence:
|
57
|
+
Enabled: false
|
58
|
+
|
59
|
+
Performance/ChainArrayAllocation:
|
60
|
+
Enabled: true
|
61
|
+
|
62
|
+
Style/AutoResourceCleanup:
|
63
|
+
Enabled: true
|
64
|
+
|
65
|
+
Style/FrozenStringLiteralComment:
|
66
|
+
Enabled: true
|
67
|
+
Exclude:
|
68
|
+
- '/**/*.rsb'
|
69
|
+
|
70
|
+
Style/Documentation:
|
71
|
+
Enabled: false
|
72
|
+
|
73
|
+
Style/OptionHash:
|
74
|
+
Enabled: true
|
75
|
+
SuspiciousParamNames:
|
76
|
+
- options
|
77
|
+
- api_options
|
78
|
+
- opts
|
79
|
+
- args
|
80
|
+
- params
|
81
|
+
- parameters
|
82
|
+
- settings
|
83
|
+
|
84
|
+
Style/ReturnNil:
|
85
|
+
Enabled: true
|
86
|
+
|
87
|
+
Style/UnlessLogicalOperators:
|
88
|
+
Enabled: true
|
89
|
+
|
90
|
+
Style/MethodCallWithArgsParentheses:
|
91
|
+
Enabled: true
|
92
|
+
AllowParenthesesInMultilineCall: true
|
93
|
+
AllowParenthesesInChaining: true
|
94
|
+
EnforcedStyle: omit_parentheses
|
95
|
+
|
96
|
+
Style/HashTransformKeys:
|
97
|
+
Enabled: false
|
98
|
+
|
99
|
+
Style/HashTransformValues:
|
100
|
+
Enabled: false
|
101
|
+
|
102
|
+
Naming/VariableNumber:
|
103
|
+
Enabled: true
|
104
|
+
Exclude:
|
105
|
+
- 'test/**/*'
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 2.0.0 [2022-10-31]
|
4
|
+
|
5
|
+
- fork of <https://github.com/KimNorgaard/validates_hostname>
|
6
|
+
- refactor gem
|
7
|
+
- ruby 2.7 or newer required
|
8
|
+
|
9
|
+
## 1.0.13 [2022-10-14]
|
10
|
+
|
11
|
+
- allow for conditional validation, controlled with model method
|
12
|
+
|
13
|
+
## 1.0.11 [2020-08-18]
|
14
|
+
|
15
|
+
- fixes for ruby 2.7
|
16
|
+
|
17
|
+
## 1.0.0 [2011-01-12]
|
18
|
+
|
19
|
+
- Initial commit
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2009 Kim Nøgaard (jasen@jasen.dk)
|
2
|
+
Copyright (c) 2022 Alexander Meindl (a.meindl@alphanodes.com)
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,206 @@
|
|
1
|
+
# Valid Hostname
|
2
|
+
|
3
|
+
* Source: <https://github.com/AlphaNodes/valid_hostname>
|
4
|
+
* Bugs: <https://github.com/AlphaNodes/valid_hostname/issues>
|
5
|
+
|
6
|
+
[![Run Rubocop](https://github.com/AlphaNodes/valid_hostname/actions/workflows/rubocop.yml/badge.svg)](https://github.com/AlphaNodes/valid_hostname/actions/workflows/rubocop.yml) [![Tests](https://github.com/AlphaNodes/valid_hostname/actions/workflows/tests.yml/badge.svg)](https://github.com/AlphaNodes/valid_hostname/actions/workflows/tests.yml) [![Gem Version](https://badge.fury.io/rb/valid_hostname.png)](http://badge.fury.io/rb/valid_hostname)
|
7
|
+
|
8
|
+
## Description
|
9
|
+
|
10
|
+
Extension to ActiveModel for validating hostnames and domain names.
|
11
|
+
|
12
|
+
## Features
|
13
|
+
|
14
|
+
* Adds validation for hostnames to ActiveModel
|
15
|
+
* Supports I18n for the error messages
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
### in Gemfile
|
20
|
+
|
21
|
+
```Gemfile
|
22
|
+
gem 'valid_hostname', '~> 2.0'
|
23
|
+
```
|
24
|
+
|
25
|
+
### Run bundler
|
26
|
+
|
27
|
+
```shell
|
28
|
+
bundle install
|
29
|
+
```
|
30
|
+
|
31
|
+
## Validations performed
|
32
|
+
|
33
|
+
* maximum length of hostname is 255 characters
|
34
|
+
* maximum length of each hostname label is 63 characters
|
35
|
+
* characters allowed in hostname labels are a-z, A-Z, 0-9 and hyphen
|
36
|
+
* labels do not begin or end with a hyphen
|
37
|
+
* labels do not consist of numeric values only
|
38
|
+
|
39
|
+
## Options
|
40
|
+
|
41
|
+
* option to allow for underscores in hostname labels
|
42
|
+
* option to require that the last label is a valid TLD (ie. require that the name is a FQDN)
|
43
|
+
* option to allow numeric values in the first label of the hostname (exception: the hostname cannot consist of a single numeric label)
|
44
|
+
* option to specify a list of valid TLDs
|
45
|
+
* options to allow for wildcard hostname in first label (for use with DNS)
|
46
|
+
* option to configure error message. verbose: true creates detailed error messages. (only used by )
|
47
|
+
|
48
|
+
See also <https://www.zytrax.com/books/dns/apa/names.html>
|
49
|
+
|
50
|
+
## How to use
|
51
|
+
|
52
|
+
Simple usage
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
class Record < ActiveRecord::Base
|
56
|
+
validates :name, hostname: true
|
57
|
+
end
|
58
|
+
```
|
59
|
+
|
60
|
+
With options
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
class Record < ActiveRecord::Base
|
64
|
+
validates :name, hostname: { OPTIONS }
|
65
|
+
end
|
66
|
+
```
|
67
|
+
|
68
|
+
or static usage
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
ValidateHostname.valid?('localhost')
|
72
|
+
```
|
73
|
+
|
74
|
+
or static usage with options
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
ValidateHostname.valid?('localhost', OPTIONS)
|
78
|
+
```
|
79
|
+
|
80
|
+
## Options and their defaults
|
81
|
+
|
82
|
+
* allow_underscore: false
|
83
|
+
* require_valid_tld: false
|
84
|
+
* valid_tlds: Array of allowed TLDs (can only be used with require_valid_tld: true)
|
85
|
+
* allow_numeric_hostname: false
|
86
|
+
* allow_wildcard_hostname: false
|
87
|
+
* allow_root_label: false
|
88
|
+
* verbose: true
|
89
|
+
|
90
|
+
## Examples
|
91
|
+
|
92
|
+
Without options
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
class Record < ActiveRecord::Base
|
96
|
+
validates :host, hostname: true
|
97
|
+
end
|
98
|
+
```
|
99
|
+
|
100
|
+
```result
|
101
|
+
>> @record = Record.new :name => 'horse'
|
102
|
+
>> @record.save
|
103
|
+
=> true
|
104
|
+
```
|
105
|
+
|
106
|
+
```result
|
107
|
+
>> @record2 = Record.new :name => '_horse'
|
108
|
+
>> @record2.save
|
109
|
+
=> false
|
110
|
+
```
|
111
|
+
|
112
|
+
With :allow_underscore
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
class Record < ActiveRecord::Base
|
116
|
+
validates :name, hostname: { allow_underscore: true }
|
117
|
+
end
|
118
|
+
```
|
119
|
+
|
120
|
+
```result
|
121
|
+
>> @record3 = Record.new :name => '_horse'
|
122
|
+
>> @record3.save
|
123
|
+
=> true
|
124
|
+
```
|
125
|
+
|
126
|
+
With :require_valid_tld
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
class Record < ActiveRecord::Base
|
130
|
+
validates :name, hostname: { require_valid_tld: true }
|
131
|
+
end
|
132
|
+
```
|
133
|
+
|
134
|
+
```result
|
135
|
+
>> @record4 = Record.new :name => 'horse'
|
136
|
+
>> @record4.save
|
137
|
+
=> false
|
138
|
+
```
|
139
|
+
|
140
|
+
```result
|
141
|
+
>> @record5 = Record.new :name => 'horse.com'
|
142
|
+
>> @record5.save
|
143
|
+
=> true
|
144
|
+
```
|
145
|
+
|
146
|
+
With :valid_tlds
|
147
|
+
|
148
|
+
```ruby
|
149
|
+
class Record < ActiveRecord::Base
|
150
|
+
validates :name, hostname: { :require_valid_tld, valid_tlds: %w[com org net] }
|
151
|
+
end
|
152
|
+
```
|
153
|
+
|
154
|
+
```result
|
155
|
+
>> @record6 = Record.new :name => 'horse.info'
|
156
|
+
>> @record6.save
|
157
|
+
=> false
|
158
|
+
```
|
159
|
+
|
160
|
+
With :allow_numeric_hostname
|
161
|
+
|
162
|
+
```ruby
|
163
|
+
class Record < ActiveRecord::Base
|
164
|
+
validates :name, hostname: { allow_numeric_hostname: false }
|
165
|
+
end
|
166
|
+
```
|
167
|
+
|
168
|
+
```result
|
169
|
+
>> @record7 = Record.new :name => '123.info'
|
170
|
+
>> @record7.save
|
171
|
+
=> false
|
172
|
+
```
|
173
|
+
|
174
|
+
With :allow_wildcard_hostname
|
175
|
+
|
176
|
+
```ruby
|
177
|
+
class Record < ActiveRecord::Base
|
178
|
+
validates :name, hostname: { allow_wildcard_hostname: true }
|
179
|
+
end
|
180
|
+
```
|
181
|
+
|
182
|
+
```result
|
183
|
+
>> @record8 = Record.new :name => '*.123.info'
|
184
|
+
>> @record8.save
|
185
|
+
=> true
|
186
|
+
```
|
187
|
+
|
188
|
+
## Extra validators
|
189
|
+
|
190
|
+
### domainname
|
191
|
+
|
192
|
+
* sets require_valid_tld: true
|
193
|
+
* sets allow_numeric_hostname: true
|
194
|
+
* returns error if there is only one label and this label is numeric
|
195
|
+
|
196
|
+
## Credits
|
197
|
+
|
198
|
+
This gem is a fork of <https://github.com/KimNorgaard>.
|
199
|
+
|
200
|
+
* [KimNorgaard](https://github.com/KimNorgaard)
|
201
|
+
* [alexandermeindl](https://github.com/alexandermeindl/awesome-redmine)
|
202
|
+
|
203
|
+
## Copyright
|
204
|
+
|
205
|
+
Copyright (c) 2009-2022 Kim Norgaard. See LICENSE for details
|
206
|
+
Copyright (c) 2022 Alexander Meindl. See LICENSE for details
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
de:
|
2
|
+
errors:
|
3
|
+
messages:
|
4
|
+
hostname:
|
5
|
+
invalid_hostname_length: must be between 1 and 255 characters long
|
6
|
+
invalid_label_length: must be between 1 and 63 characters long
|
7
|
+
label_begins_or_ends_with_hyphen: begins or ends with hyphen
|
8
|
+
label_contains_invalid_characters: "contains invalid characters (valid characters: [%{valid_chars}])"
|
9
|
+
hostname_label_is_numeric: unqualified hostname part cannot consist of numeric values only
|
10
|
+
hostname_is_not_fqdn: is not a fully qualified domain name
|
11
|
+
single_numeric_hostname_label: cannot consist of a single numeric label
|
12
|
+
hostname_contains_consecutive_dots: must not contain consecutive dots
|
13
|
+
hostname_ends_with_dot: must not end with a dot
|
@@ -0,0 +1,13 @@
|
|
1
|
+
en:
|
2
|
+
errors:
|
3
|
+
messages:
|
4
|
+
hostname:
|
5
|
+
invalid_hostname_length: must be between 1 and 255 characters long
|
6
|
+
invalid_label_length: must be between 1 and 63 characters long
|
7
|
+
label_begins_or_ends_with_hyphen: begins or ends with hyphen
|
8
|
+
label_contains_invalid_characters: "contains invalid characters (valid characters: [%{valid_chars}])"
|
9
|
+
hostname_label_is_numeric: unqualified hostname part cannot consist of numeric values only
|
10
|
+
hostname_is_not_fqdn: is not a fully qualified domain name
|
11
|
+
single_numeric_hostname_label: cannot consist of a single numeric label
|
12
|
+
hostname_contains_consecutive_dots: must not contain consecutive dots
|
13
|
+
hostname_ends_with_dot: must not end with a dot
|