validators 3.1.0 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +1 -0
  3. data/.gitignore +1 -0
  4. data/.rubocop.yml +10 -0
  5. data/README.md +23 -8
  6. data/Rakefile +0 -1
  7. data/data/reserved_subdomains.txt +2830 -0
  8. data/lib/validators.rb +5 -4
  9. data/lib/validators/constants.rb +1 -1
  10. data/lib/validators/disposable_domains.rb +19 -0
  11. data/lib/validators/disposable_emails.rb +23 -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 +9 -5
  16. data/lib/validators/validates_email_format_of.rb +19 -4
  17. data/lib/validators/validates_subdomain.rb +69 -0
  18. data/lib/validators/validates_username.rb +15 -0
  19. data/lib/validators/version.rb +1 -1
  20. data/test/test_helper.rb +17 -2
  21. data/test/validators/disposable_email_test.rb +18 -5
  22. data/test/validators/validates_email_format_of_test.rb +4 -2
  23. data/test/validators/validates_subdomain_test.rb +75 -0
  24. data/test/validators/validates_url_format_of/with_tld_validation_test.rb +18 -0
  25. data/test/validators/validates_url_format_of/without_tld_validation_test.rb +18 -0
  26. data/test/validators/{validates_reserved_username_test.rb → validates_username_test.rb} +27 -4
  27. data/validators.gemspec +11 -1
  28. metadata +116 -22
  29. data/bin/sync-disposable-hostnames +0 -35
  30. data/bin/sync-tld +0 -17
  31. data/data/disposable.json +0 -57281
  32. data/data/reserved_hostnames.json +0 -1399
  33. data/data/tld.json +0 -1516
  34. data/lib/validators/disposable_hostnames.rb +0 -11
  35. data/lib/validators/validates_reserved_hostname.rb +0 -45
  36. data/lib/validators/validates_reserved_username.rb +0 -29
  37. data/test/validators/validates_reserved_hostname_test.rb +0 -40
@@ -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.0
4
+ version: 3.4.0
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-26 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
@@ -1,35 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require "open-uri"
5
- require "json"
6
-
7
- urls = %w[
8
- https://raw.githubusercontent.com/ivolo/disposable-email-domains/master/index.json
9
- https://raw.githubusercontent.com/andreis/disposable-email-domains/master/domains.json
10
- https://raw.githubusercontent.com/FGRibreau/mailchecker/master/list.txt
11
- https://raw.githubusercontent.com/willwhite/freemail/master/data/disposable.txt
12
- ]
13
-
14
- domains = urls.each_with_object([]) do |url, buffer|
15
- ext = File.extname(url)
16
-
17
- result = case ext
18
- when ".json"
19
- JSON.parse(URI.open(url).read)
20
- when ".txt"
21
- URI.open(url).read.lines.map(&:chomp)
22
- else
23
- raise "Unknown extension"
24
- end
25
-
26
- buffer.push(*result)
27
- end
28
-
29
- domains.map!(&:downcase)
30
- domains.uniq!
31
- domains.sort!
32
-
33
- File.open("./data/disposable.json", "w") do |file|
34
- file << JSON.pretty_generate(domains)
35
- end
@@ -1,17 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require "open-uri"
5
- require "json"
6
-
7
- tlds = URI.open("https://data.iana.org/TLD/tlds-alpha-by-domain.txt").read.lines
8
- tlds.shift # remove update notice
9
-
10
- tlds.map!(&:downcase)
11
- tlds.map!(&:strip)
12
- tlds.sort!
13
- tlds.uniq!
14
-
15
- File.open("./data/tld.json", "w") do |file|
16
- file << JSON.pretty_generate(tlds)
17
- end