ssn_validation 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 055a5606a0f3628720394e6fadc9d7d031cccfd56ae1004184bc7e1c741881b2
4
- data.tar.gz: 9fa6a0e907840f4b7e04981144e6d13930a1af4d53103d29ed0d61ad691a0c2b
3
+ metadata.gz: 0d6fc2b63bb6a88c25c5f12e6893f8981a38b5c370401208ae3545f5a5de62ba
4
+ data.tar.gz: b8d05dcfcf93ef235727dd14e495e84219ca3bdf58f560f93c60538ed9dd62a0
5
5
  SHA512:
6
- metadata.gz: 77969a0983d95df462807ea033cf37aca5142e1122d28867e736fcf1515f53b3cf72ed8e8722b1c38603f07f162a225406702fb0ce7671d3510459c38faacffe
7
- data.tar.gz: 58ec9cef29eed8d78060b14a3a7d006c746816ab1f6b37f9a3bb2111359b8ad9cd5ae3866fc4850207ed0620e21a44d372ba54cbe0b72c3ac342d18570396620
6
+ metadata.gz: f851627f3d715d7df181ce92c1039296ae1ab535fca5459632d4b584f317fcb2c79bc18b634993caa56d1508e5d353c69b55c5f4b5f05b864753ff65bd1e0682
7
+ data.tar.gz: 4c8b4e5b1b27975e0348222ff73bf4c85a104ee5d677953a80f928b8ac4be0702eb57368fa0a2a86b10c026147219f4c38a3ae999ec82ee1cbc62438dbf6e258
@@ -18,15 +18,23 @@ module SsnValidation
18
18
  (ssn[0..2] == "000") && errors[:zero_area] = "SSN value contains zeros in area number 000-xx-xxxx"
19
19
  (ssn[3..4] == "00") && errors[:zero_group] = "SSN value contains zeros in group number xxx-00-xxxx"
20
20
  (ssn[5..8] == "0000") && errors[:zero_serial] = "SSN value contains zeros in serial number xxx-xx-0000"
21
- ascending?(ssn) && errors[:ascending] = "SSN value contains all ASCENDING digits"
22
- descending?(ssn) && errors[:descending] = "SSN value contains all DESCENDING digits"
23
21
  return errors if errors.any? # return if ssn conditions fail
24
22
 
25
23
  # check valid ITIN format last
26
24
  invalid_itin?(ssn) && errors[:invalid_itin] = "SSN value contains invalid ITIN format 9xx-[x]x-xxxx"
25
+
26
+ # check extra validations for possible fake ssns if enabled
27
+ errors.merge!(validate_ascending_descending(ssn)) if enable_ascending?
27
28
  errors
28
29
  end
29
30
 
31
+ def self.validate_ascending_descending(ssn)
32
+ errors = {}
33
+ ascending?(ssn) && errors[:ascending] = "SSN value contains all ASCENDING digits"
34
+ descending?(ssn) && errors[:descending] = "SSN value contains all DESCENDING digits"
35
+ return errors
36
+ end
37
+
30
38
  def self.ascending?(ssn)
31
39
  return true if ssn.chars == DIGITS.rotate(ssn[0].to_i)[0..8]
32
40
  return true if ssn.chars == DIGITS_EX0.rotate(ssn[0].to_i - 1)
@@ -48,6 +56,10 @@ module SsnValidation
48
56
  def self.test_ssn?(ssn)
49
57
  SsnValidation.config.test_ssns.any? {|p| p.match(ssn)}
50
58
  end
59
+
60
+ def self.enable_ascending?
61
+ SsnValidation.config.enable_ascending
62
+ end
51
63
  end
52
64
 
53
65
  def self.validate(ssn)
@@ -10,9 +10,11 @@ module SsnValidation
10
10
 
11
11
  class Configuration
12
12
  attr_accessor :test_ssns
13
+ attr_accessor :enable_ascending
13
14
 
14
15
  def initialize
15
16
  @test_ssns = []
17
+ @enable_ascending = false
16
18
  end
17
19
  end
18
20
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module SsnValidation
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
Binary file
@@ -52,6 +52,21 @@ class SsnTest < Minitest::Test
52
52
  assert_equal({nine_digits: 'SSN value is not 9 digits'}, Ssn.validate('303'))
53
53
  end
54
54
  end
55
+ describe 'repeating digits invalid' do
56
+ it 'is invalid' do
57
+ assert_equal({repeating: 'SSN value contains repeating digits'}, Ssn.validate('888888888'))
58
+ end
59
+ end
60
+ describe 'invalid ITIN' do
61
+ it 'is invalid' do
62
+ assert_equal({invalid_itin: 'SSN value contains invalid ITIN format 9xx-[x]x-xxxx'}, Ssn.validate('900991234'))
63
+ end
64
+ end
65
+ end
66
+ describe 'do extra validations based on probably bogus SSNSs' do
67
+ before do
68
+ SsnValidation.config.enable_ascending = true
69
+ end
55
70
  describe 'ascending digits invalid' do
56
71
  it 'is invalid' do
57
72
  assert_equal({ascending: 'SSN value contains all ASCENDING digits'}, Ssn.validate('123456789'))
@@ -69,7 +84,7 @@ class SsnTest < Minitest::Test
69
84
  it 'is invalid' do
70
85
  assert_equal({descending: 'SSN value contains all DESCENDING digits'}, Ssn.validate('876543210'))
71
86
  assert_equal({descending: 'SSN value contains all DESCENDING digits'}, Ssn.validate('321098765'))
72
- assert_equal({descending: 'SSN value contains all DESCENDING digits'}, Ssn.validate('987654321'))
87
+ assert_equal({descending: 'SSN value contains all DESCENDING digits'}, Ssn.validate('765432109'))
73
88
  end
74
89
  end
75
90
  describe 'descending digits ex 0 invalid' do
@@ -78,16 +93,6 @@ class SsnTest < Minitest::Test
78
93
  assert_equal({descending: 'SSN value contains all DESCENDING digits'}, Ssn.validate('765432198'))
79
94
  end
80
95
  end
81
- describe 'repeating digits invalid' do
82
- it 'is invalid' do
83
- assert_equal({repeating: 'SSN value contains repeating digits'}, Ssn.validate('888888888'))
84
- end
85
- end
86
- describe 'invalid ITIN' do
87
- it 'is invalid' do
88
- assert_equal({invalid_itin: 'SSN value contains invalid ITIN format 9xx-[x]x-xxxx'}, Ssn.validate('900991234'))
89
- end
90
- end
91
96
  end
92
97
  describe 'allowing dummy ssns' do
93
98
  it 'allows 666xxxxx' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ssn_validation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Stewart
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-26 00:00:00.000000000 Z
11
+ date: 2019-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -50,6 +50,7 @@ files:
50
50
  - lib/ssn_validation/ssn_validation.rb
51
51
  - lib/validators/social_security_number_validator.rb
52
52
  - lib/version.rb
53
+ - ssn_validation-0.1.2.gem
53
54
  - ssn_validation.gemspec
54
55
  - test/lib/ssn_validation/ssn_test.rb
55
56
  - test/lib/ssn_validation_test.rb