Skip to content

Commit

Permalink
Merge pull request #31 from clearhaus/allow-single-digit-eci
Browse files Browse the repository at this point in the history
Allow single digit ECI
  • Loading branch information
mt-clearhaus authored Aug 1, 2018
2 parents f61aee5 + 3561654 commit a819939
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/pedicel/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module Predicates

predicate(:yymmdd?) { |x| str?(x) && match_b.(x, /\A\d{6}\z/) }

predicate(:eci?) { |x| str?(x) && match_b.(x, /\A\d{2}\z/) }
predicate(:eci?) { |x| str?(x) && match_b.(x, /\A\d{1,2}\z/) }

predicate(:ec_public_key?) { |x| base64?(x) && OpenSSL::PKey::EC.new(Base64.decode64(x)).check_key rescue false }

Expand Down
2 changes: 1 addition & 1 deletion lib/pedicel/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Pedicel
VERSION = '0.0.5'.freeze
VERSION = '0.0.6'.freeze
end
5 changes: 4 additions & 1 deletion spec/lib/pedicel/validator/predicates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,16 @@ def eci?(x); subject.eci?(x); end

it 'is true for valid ECIs' do
expect(eci?('05')).to be true
expect(eci?('5')).to be true
expect(eci?('06')).to be true
expect(eci?('6')).to be true
expect(eci?('07')).to be true
expect(eci?('7')).to be true
end

it 'is false for ECIs of wrong length' do
expect(eci?('')).to be false
expect(eci?('005')).to be false
expect(eci?('5')).to be false
expect(eci?(' 05')).to be false
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,13 @@
is_expected.to satisfy_schema(tdpds)
end

it 'must be filled when present' do
token_data_payment_data_h[:eciIndicator] = ''
is_expected.to dissatisfy_schema(tdpds, eciIndicator: ['must be filled'])
end

it 'errs when invalid' do
%w[1 123 1A].each do |invalid_value|
['123', '1A'].each do |invalid_value|
token_data_payment_data_h[:eciIndicator] = invalid_value

is_expected.to dissatisfy_schema(tdpds, eciIndicator: ['must be an ECI'])
Expand Down

0 comments on commit a819939

Please sign in to comment.