validators 3.1.1 → 3.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +1 -0
  3. data/.gitignore +1 -0
  4. data/.rubocop.yml +11 -1
  5. data/README.md +49 -29
  6. data/Rakefile +0 -1
  7. data/data/reserved_subdomains.txt +2830 -0
  8. data/lib/validators.rb +12 -4
  9. data/lib/validators/constants.rb +1 -1
  10. data/lib/validators/disposable_domains.rb +18 -0
  11. data/lib/validators/disposable_emails.rb +22 -0
  12. data/lib/validators/locale/en.yml +5 -2
  13. data/lib/validators/locale/pt-BR.yml +1 -0
  14. data/lib/validators/{reserved_hostnames.rb → reserved_subdomains.rb} +3 -5
  15. data/lib/validators/tld.rb +7 -5
  16. data/lib/validators/validates_cnpj_format_of.rb +1 -2
  17. data/lib/validators/validates_cpf_format_of.rb +1 -2
  18. data/lib/validators/validates_email_format_of.rb +19 -4
  19. data/lib/validators/validates_ssh_private_key.rb +1 -3
  20. data/lib/validators/validates_ssh_public_key.rb +1 -3
  21. data/lib/validators/validates_subdomain.rb +69 -0
  22. data/lib/validators/validates_username.rb +15 -0
  23. data/lib/validators/version.rb +1 -1
  24. data/test/test_helper.rb +17 -2
  25. data/test/validators/disposable_email_test.rb +18 -5
  26. data/test/validators/validates_cnpj_format_of_test.rb +3 -3
  27. data/test/validators/validates_cpf_format_of_test.rb +3 -3
  28. data/test/validators/validates_email_format_of_test.rb +27 -2
  29. data/test/validators/validates_ssh_private_key/common_test.rb +3 -3
  30. data/test/validators/validates_ssh_public_key_test.rb +3 -3
  31. data/test/validators/validates_subdomain_test.rb +75 -0
  32. data/test/validators/validates_url_format_of/with_tld_validation_test.rb +18 -0
  33. data/test/validators/validates_url_format_of/without_tld_validation_test.rb +18 -0
  34. data/test/validators/{validates_reserved_username_test.rb → validates_username_test.rb} +27 -4
  35. data/validators.gemspec +11 -1
  36. metadata +116 -22
  37. data/bin/sync-disposable-hostnames +0 -35
  38. data/bin/sync-tld +0 -17
  39. data/data/disposable.json +0 -60403
  40. data/data/reserved_hostnames.json +0 -2836
  41. data/data/tld.json +0 -1516
  42. data/lib/validators/disposable_hostnames.rb +0 -11
  43. data/lib/validators/validates_reserved_hostname.rb +0 -45
  44. data/lib/validators/validates_reserved_username.rb +0 -29
  45. data/test/validators/validates_reserved_hostname_test.rb +0 -40
@@ -15,10 +15,10 @@ class ValidatesCpfFormatOfTest < Minitest::Test
15
15
  end
16
16
  end
17
17
 
18
- test "fails when gem is not available" do
19
- assert_raises do
18
+ test "fails when cpf_cnpj is not available" do
19
+ assert_raises(StandardError, /cpf_cnpj is not part of the bundle/) do
20
20
  Class.new do
21
- expects(:require).with("cpf").raises(LoadError)
21
+ Validators.expects(:require).with("cpf_cnpj").raises(LoadError, "-- cpf_cnpj")
22
22
 
23
23
  include ActiveModel::Model
24
24
  validates_cpf_format_of :document
@@ -9,13 +9,38 @@ class ValidatesEmailFormatOfTest < Minitest::Test
9
9
  Person.validates :email, email: true
10
10
  end
11
11
 
12
+ test "fails when email_data is not available" do
13
+ assert_raises(StandardError, /email_data is not part of the bundle/) do
14
+ Class.new do
15
+ Validators.expects(:require).with("root_domain")
16
+ Validators.expects(:require).with("email_data").raises(LoadError, "-- email_data")
17
+
18
+ include ActiveModel::Model
19
+ validates_email :email
20
+ end
21
+ end
22
+ end
23
+
24
+ test "fails when root_domain is not available" do
25
+ assert_raises(StandardError, /root_domain is not part of the bundle/) do
26
+ Class.new do
27
+ Validators.expects(:require).with("root_domain").raises(LoadError, "-- root_domain")
28
+
29
+ include ActiveModel::Model
30
+ validates_email :email
31
+ end
32
+ end
33
+ end
34
+
12
35
  VALID_EMAILS.each do |email|
13
36
  test "accepts #{email.inspect} as a valid email" do
14
37
  user = User.new(email: email, corporate_email: email)
15
- assert user.valid?
38
+ user.valid?
39
+ assert_empty user.errors
16
40
 
17
41
  user = Person.new(email: email)
18
- assert user.valid?
42
+ user.valid?
43
+ assert_empty user.errors
19
44
  end
20
45
  end
21
46
 
@@ -15,10 +15,10 @@ class ValidatesSshPrivateKeyCommonTest < Minitest::Test
15
15
  end
16
16
  end
17
17
 
18
- test "fails when gem is not available" do
19
- assert_raises do
18
+ test "fails when sshkey is not available" do
19
+ assert_raises(StandardError, /sshkey is not part of the bundle/) do
20
20
  Class.new do
21
- expects(:require).with("sshkey").raises(LoadError)
21
+ Validators.expects(:require).with("sshkey").raises(LoadError.new("-- sshkey"))
22
22
 
23
23
  include ActiveModel::Model
24
24
  validates_ssh_private_key :key
@@ -15,10 +15,10 @@ class ValidatesSsshPublicKeyCommonTest < Minitest::Test
15
15
  end
16
16
  end
17
17
 
18
- test "fails when gem is not available" do
19
- assert_raises do
18
+ test "fails when sshkey is not available" do
19
+ assert_raises(StandardError, /sshkey is not part of the bundle/) do
20
20
  Class.new do
21
- expects(:require).with("sshkey").raises(LoadError)
21
+ Validators.expects(:require).with("sshkey").raises(LoadError, "-- sshkey")
22
22
 
23
23
  include ActiveModel::Model
24
24
  validates_ssh_public_key :key
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class ValidatesSubdomainTest < Minitest::Test
6
+ test "don't explode with nil values" do
7
+ model = build_model do
8
+ attr_accessor :subdomain
9
+ validates_subdomain :subdomain
10
+ end
11
+
12
+ instance = model.new(subdomain: nil)
13
+
14
+ refute instance.valid?
15
+ assert_includes instance.errors[:subdomain], "is invalid"
16
+ end
17
+
18
+ test "rejects invalid subdomain" do
19
+ model = build_model do
20
+ attr_accessor :subdomain
21
+ validates_subdomain :subdomain
22
+ end
23
+
24
+ instance = model.new(subdomain: "1234")
25
+
26
+ refute instance.valid?
27
+ assert_includes instance.errors[:subdomain], "is invalid"
28
+ end
29
+
30
+ test "rejects reserved subdomain" do
31
+ model = build_model do
32
+ attr_accessor :subdomain
33
+ validates_subdomain :subdomain
34
+ end
35
+
36
+ instance = model.new(subdomain: "www")
37
+
38
+ refute instance.valid?
39
+ assert_includes instance.errors[:subdomain],
40
+ "www is a reserved subdomain"
41
+ end
42
+
43
+ test "rejects reserved subdomain with pattern" do
44
+ model = build_model do
45
+ attr_accessor :subdomain
46
+ validates_subdomain :subdomain
47
+ end
48
+
49
+ instance = model.new(subdomain: "www1234")
50
+
51
+ refute instance.valid?
52
+ end
53
+
54
+ test "uses custom list" do
55
+ model = build_model do
56
+ attr_accessor :subdomain
57
+ validates_subdomain :subdomain, in: %w[nope]
58
+ end
59
+
60
+ instance = model.new(subdomain: "nope")
61
+
62
+ refute instance.valid?
63
+ end
64
+
65
+ test "ignores reserved subdomain validation" do
66
+ model = build_model do
67
+ attr_accessor :subdomain
68
+ validates_subdomain :subdomain, reserved: false
69
+ end
70
+
71
+ instance = model.new(subdomain: "www")
72
+
73
+ assert instance.valid?
74
+ end
75
+ end
@@ -14,4 +14,22 @@ class ValidatesurlFormatUrlWithTldValidationTest < Minitest::Test
14
14
  assert user.valid?
15
15
  end
16
16
  end
17
+
18
+ test "rejects invalid TLD (alternative syntax)" do
19
+ user_model = Class.new do
20
+ include ActiveModel::Validations
21
+ attr_accessor :site_url
22
+
23
+ def self.name
24
+ "User"
25
+ end
26
+
27
+ validates :site_url, url: {tld: true}
28
+ end
29
+
30
+ user = user_model.new
31
+ user.site_url = "https://example.xy"
32
+
33
+ refute user.valid?
34
+ end
17
35
  end
@@ -47,4 +47,22 @@ class ValidatesurlFormatUrlWithoutTldValidationTest < Minitest::Test
47
47
  user = User.new(url: "")
48
48
  refute user.valid?
49
49
  end
50
+
51
+ test "accepts invalid TLD (alternative syntax)" do
52
+ user_model = Class.new do
53
+ include ActiveModel::Validations
54
+ attr_accessor :site_url
55
+
56
+ def self.name
57
+ "User"
58
+ end
59
+
60
+ validates :site_url, url: {tld: false}
61
+ end
62
+
63
+ user = user_model.new
64
+ user.site_url = "https://example.xy"
65
+
66
+ assert user.valid?
67
+ end
50
68
  end
@@ -2,11 +2,23 @@
2
2
 
3
3
  require "test_helper"
4
4
 
5
- class ValidatesReservedUsernameTest < Minitest::Test
5
+ class ValidatesUsernameTest < Minitest::Test
6
+ test "rejects invalid username" do
7
+ model = build_model do
8
+ attr_accessor :username
9
+ validates_username :username
10
+ end
11
+
12
+ instance = model.new(username: "1234")
13
+
14
+ refute instance.valid?
15
+ assert_includes instance.errors[:username], "is invalid"
16
+ end
17
+
6
18
  test "rejects reserved username" do
7
19
  model = build_model do
8
20
  attr_accessor :username
9
- validates_reserved_username :username
21
+ validates_username :username
10
22
  end
11
23
 
12
24
  instance = model.new(username: "www")
@@ -19,7 +31,7 @@ class ValidatesReservedUsernameTest < Minitest::Test
19
31
  test "rejects reserved username with pattern" do
20
32
  model = build_model do
21
33
  attr_accessor :username
22
- validates_reserved_username :username
34
+ validates_username :username
23
35
  end
24
36
 
25
37
  instance = model.new(username: "www1234")
@@ -30,11 +42,22 @@ class ValidatesReservedUsernameTest < Minitest::Test
30
42
  test "uses custom list" do
31
43
  model = build_model do
32
44
  attr_accessor :username
33
- validates_reserved_username :username, in: %w[nope]
45
+ validates_username :username, in: %w[nope]
34
46
  end
35
47
 
36
48
  instance = model.new(username: "nope")
37
49
 
38
50
  refute instance.valid?
39
51
  end
52
+
53
+ test "ignores reserved username validation" do
54
+ model = build_model do
55
+ attr_accessor :username
56
+ validates_username :username, reserved: false
57
+ end
58
+
59
+ instance = model.new(username: "www")
60
+
61
+ assert instance.valid?
62
+ end
40
63
  end
@@ -12,22 +12,32 @@ Gem::Specification.new do |s|
12
12
  s.summary = "Add some nice ActiveModel/ActiveRecord validators."
13
13
  s.description = s.summary
14
14
  s.license = "MIT"
15
+ s.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
15
16
 
16
17
  s.files = `git ls-files`.split("\n")
17
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- s.executables = `git ls-files -- bin/*`.split("\n").map {|f| File.basename(f) }
19
+ s.executables = `git ls-files -- bin/*`
20
+ .split("\n")
21
+ .map {|f| File.basename(f) }
19
22
  s.require_paths = ["lib"]
20
23
 
21
24
  s.add_development_dependency "activerecord"
25
+ s.add_development_dependency "aitch"
22
26
  s.add_development_dependency "cpf_cnpj"
27
+ s.add_development_dependency "email_data"
23
28
  s.add_development_dependency "minitest-utils"
24
29
  s.add_development_dependency "mocha"
30
+ s.add_development_dependency "nokogiri"
25
31
  s.add_development_dependency "pry-meta"
26
32
  s.add_development_dependency "rake"
33
+ s.add_development_dependency "root_domain"
27
34
  s.add_development_dependency "rubocop"
28
35
  s.add_development_dependency "rubocop-fnando"
29
36
  s.add_development_dependency "simplecov"
30
37
  s.add_development_dependency "simplecov-console"
38
+ s.add_development_dependency "simpleidn"
31
39
  s.add_development_dependency "sqlite3", "~> 1.4"
32
40
  s.add_development_dependency "sshkey"
41
+ s.add_development_dependency "whois"
42
+ s.add_development_dependency "whois-parser"
33
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validators
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-26 00:00:00.000000000 Z
11
+ date: 2020-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: aitch
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: cpf_cnpj
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +52,20 @@ dependencies:
38
52
  - - ">="
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: email_data
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: minitest-utils
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +94,20 @@ dependencies:
66
94
  - - ">="
67
95
  - !ruby/object:Gem::Version
68
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: nokogiri
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
69
111
  - !ruby/object:Gem::Dependency
70
112
  name: pry-meta
71
113
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +136,20 @@ dependencies:
94
136
  - - ">="
95
137
  - !ruby/object:Gem::Version
96
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: root_domain
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
97
153
  - !ruby/object:Gem::Dependency
98
154
  name: rubocop
99
155
  requirement: !ruby/object:Gem::Requirement
@@ -150,6 +206,20 @@ dependencies:
150
206
  - - ">="
151
207
  - !ruby/object:Gem::Version
152
208
  version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: simpleidn
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
153
223
  - !ruby/object:Gem::Dependency
154
224
  name: sqlite3
155
225
  requirement: !ruby/object:Gem::Requirement
@@ -178,34 +248,58 @@ dependencies:
178
248
  - - ">="
179
249
  - !ruby/object:Gem::Version
180
250
  version: '0'
251
+ - !ruby/object:Gem::Dependency
252
+ name: whois
253
+ requirement: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - ">="
256
+ - !ruby/object:Gem::Version
257
+ version: '0'
258
+ type: :development
259
+ prerelease: false
260
+ version_requirements: !ruby/object:Gem::Requirement
261
+ requirements:
262
+ - - ">="
263
+ - !ruby/object:Gem::Version
264
+ version: '0'
265
+ - !ruby/object:Gem::Dependency
266
+ name: whois-parser
267
+ requirement: !ruby/object:Gem::Requirement
268
+ requirements:
269
+ - - ">="
270
+ - !ruby/object:Gem::Version
271
+ version: '0'
272
+ type: :development
273
+ prerelease: false
274
+ version_requirements: !ruby/object:Gem::Requirement
275
+ requirements:
276
+ - - ">="
277
+ - !ruby/object:Gem::Version
278
+ version: '0'
181
279
  description: Add some nice ActiveModel/ActiveRecord validators.
182
280
  email:
183
281
  - fnando.vieira@gmail.com
184
- executables:
185
- - sync-disposable-hostnames
186
- - sync-tld
282
+ executables: []
187
283
  extensions: []
188
284
  extra_rdoc_files: []
189
285
  files:
286
+ - ".github/FUNDING.yml"
190
287
  - ".gitignore"
191
288
  - ".rubocop.yml"
192
289
  - ".travis.yml"
193
290
  - Gemfile
194
291
  - README.md
195
292
  - Rakefile
196
- - bin/sync-disposable-hostnames
197
- - bin/sync-tld
198
- - data/disposable.json
199
- - data/reserved_hostnames.json
200
- - data/tld.json
293
+ - data/reserved_subdomains.txt
201
294
  - lib/validators.rb
202
295
  - lib/validators/constants.rb
203
- - lib/validators/disposable_hostnames.rb
296
+ - lib/validators/disposable_domains.rb
297
+ - lib/validators/disposable_emails.rb
204
298
  - lib/validators/hostname.rb
205
299
  - lib/validators/ip.rb
206
300
  - lib/validators/locale/en.yml
207
301
  - lib/validators/locale/pt-BR.yml
208
- - lib/validators/reserved_hostnames.rb
302
+ - lib/validators/reserved_subdomains.rb
209
303
  - lib/validators/tld.rb
210
304
  - lib/validators/validates_cnpj_format_of.rb
211
305
  - lib/validators/validates_cpf_format_of.rb
@@ -214,11 +308,11 @@ files:
214
308
  - lib/validators/validates_hostname_format_of.rb
215
309
  - lib/validators/validates_ip_address.rb
216
310
  - lib/validators/validates_ownership_of.rb
217
- - lib/validators/validates_reserved_hostname.rb
218
- - lib/validators/validates_reserved_username.rb
219
311
  - lib/validators/validates_ssh_private_key.rb
220
312
  - lib/validators/validates_ssh_public_key.rb
313
+ - lib/validators/validates_subdomain.rb
221
314
  - lib/validators/validates_url_format_of.rb
315
+ - lib/validators/validates_username.rb
222
316
  - lib/validators/version.rb
223
317
  - test/schema.rb
224
318
  - test/support/dates.rb
@@ -242,21 +336,21 @@ files:
242
336
  - test/validators/validates_ip_address/ipv6_test.rb
243
337
  - test/validators/validates_ip_address_test.rb
244
338
  - test/validators/validates_ownership_of_test.rb
245
- - test/validators/validates_reserved_hostname_test.rb
246
- - test/validators/validates_reserved_username_test.rb
247
339
  - test/validators/validates_ssh_private_key/bits_test.rb
248
340
  - test/validators/validates_ssh_private_key/common_test.rb
249
341
  - test/validators/validates_ssh_private_key/dsa_test.rb
250
342
  - test/validators/validates_ssh_private_key/rsa_test.rb
251
343
  - test/validators/validates_ssh_public_key_test.rb
344
+ - test/validators/validates_subdomain_test.rb
252
345
  - test/validators/validates_url_format_of/with_tld_validation_test.rb
253
346
  - test/validators/validates_url_format_of/without_tld_validation_test.rb
347
+ - test/validators/validates_username_test.rb
254
348
  - validators.gemspec
255
349
  homepage: http://rubygems.org/gems/validators
256
350
  licenses:
257
351
  - MIT
258
352
  metadata: {}
259
- post_install_message:
353
+ post_install_message:
260
354
  rdoc_options: []
261
355
  require_paths:
262
356
  - lib
@@ -264,7 +358,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
264
358
  requirements:
265
359
  - - ">="
266
360
  - !ruby/object:Gem::Version
267
- version: '0'
361
+ version: 2.3.0
268
362
  required_rubygems_version: !ruby/object:Gem::Requirement
269
363
  requirements:
270
364
  - - ">="
@@ -272,7 +366,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
272
366
  version: '0'
273
367
  requirements: []
274
368
  rubygems_version: 3.1.2
275
- signing_key:
369
+ signing_key:
276
370
  specification_version: 4
277
371
  summary: Add some nice ActiveModel/ActiveRecord validators.
278
372
  test_files:
@@ -298,12 +392,12 @@ test_files:
298
392
  - test/validators/validates_ip_address/ipv6_test.rb
299
393
  - test/validators/validates_ip_address_test.rb
300
394
  - test/validators/validates_ownership_of_test.rb
301
- - test/validators/validates_reserved_hostname_test.rb
302
- - test/validators/validates_reserved_username_test.rb
303
395
  - test/validators/validates_ssh_private_key/bits_test.rb
304
396
  - test/validators/validates_ssh_private_key/common_test.rb
305
397
  - test/validators/validates_ssh_private_key/dsa_test.rb
306
398
  - test/validators/validates_ssh_private_key/rsa_test.rb
307
399
  - test/validators/validates_ssh_public_key_test.rb
400
+ - test/validators/validates_subdomain_test.rb
308
401
  - test/validators/validates_url_format_of/with_tld_validation_test.rb
309
402
  - test/validators/validates_url_format_of/without_tld_validation_test.rb
403
+ - test/validators/validates_username_test.rb