Skip to content

Commit

Permalink
Ensure that aliquot works on Ruby 3.1 (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbobach authored Sep 5, 2023
1 parent 1860ff2 commit 741644d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ jobs:
version:
- '2.7'
- '3.0'
- '3.1'
- '3.2'
steps:
- uses: ruby/setup-ruby@v1
with:
Expand Down
4 changes: 2 additions & 2 deletions aliquot.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

Gem::Specification.new do |s|
s.name = 'aliquot'
s.version = '2.2.0'
s.version = '2.3.0'
s.author = 'Clearhaus'
s.email = 'hello@clearhaus.com'
s.summary = 'Validates Google Pay tokens'
Expand All @@ -18,7 +18,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'excon', '~> 0.71.0'
s.add_runtime_dependency 'hkdf', '~> 0.3'

s.add_development_dependency 'aliquot-pay', '~> 2.1'
s.add_development_dependency 'aliquot-pay', '~> 3.0'
s.add_development_dependency 'rspec', '~> 3'
s.add_development_dependency 'pry', '~> 0.14.1'
end
8 changes: 4 additions & 4 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
e = StandardError.new('stub method')
allow(Aliquot::Validator::Token).to receive(:new).and_raise(e)

is_expected.to raise_error(e)
expect { subject.call }.to raise_error(e)

expect(Aliquot::Validator::Token).to have_received(:new).with(token)
end
Expand All @@ -18,7 +18,7 @@
e = StandardError.new('stub method')
allow(Aliquot::Validator::SignedMessage).to receive(:new).and_raise(e)

is_expected.to raise_error(e)
expect { subject.call }.to raise_error(e)

expect(Aliquot::Validator::SignedMessage).to have_received(:new).with(generator.build_signed_message)
end
Expand All @@ -27,7 +27,7 @@
e = StandardError.new('stub method')
allow(Aliquot::Validator::EncryptedMessageValidator).to receive(:new).and_raise(e)

is_expected.to raise_error(e)
expect { subject.call }.to raise_error(e)

expect(Aliquot::Validator::EncryptedMessageValidator).to have_received(:new).with(generator.build_cleartext_message)
end
Expand Down Expand Up @@ -61,7 +61,7 @@
e = StandardError.new('stub method')
allow(Aliquot::Validator::SignedKeyValidator).to receive(:new).and_raise(e)

is_expected.to raise_error(e)
expect { subject.call }.to raise_error(e)

expect(Aliquot::Validator::SignedKeyValidator).to have_received(:new).with(generator.build_signed_key)
end
Expand Down
24 changes: 12 additions & 12 deletions spec/lib/aliquot/payment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
shared_examples Aliquot::Payment do

it 'decrypts' do
is_expected.to_not raise_error
expect { subject.call }.to_not raise_error
expect(subject.call[:paymentMethodDetails]).to include(authMethod: 'PAN_ONLY')
end

it 'decrypts with CRYPTOGRAM_3DS' do
generator.auth_method = 'CRYPTOGRAM_3DS'
is_expected.to_not raise_error
expect { subject.call }.to_not raise_error
expect(subject.call[:paymentMethodDetails]).to include(authMethod: 'CRYPTOGRAM_3DS')
end

Expand All @@ -26,15 +26,15 @@

it 'rejects invalid protocolVersion' do
generator.token['protocolVersion'] = 'InvalidProtocolVersion'
is_expected.to raise_error(Aliquot::Error, 'supported protocol versions are ECv1, ECv2')
expect { subject.call }.to raise_error(Aliquot::Error, 'supported protocol versions are ECv1, ECv2')
end

# KSE: Don't know how to trigger this.
it 'fails gracefully when deriving keys'

it 'fails gracefully when MAC is invalid' do
generator.tag = Base64.strict_encode64(Random.new.bytes(32))
is_expected.to raise_error(Aliquot::InvalidMacError, 'MAC does not match')
expect { subject.call }.to raise_error(Aliquot::InvalidMacError, 'MAC does not match')
end

# CB: Not sure how to trigger this test as JSON.parse has changed since 2.3
Expand All @@ -46,12 +46,12 @@

it 'rejects expired token' do
generator.message_expiration = (Time.now.to_f - 20).round.to_s
is_expected.to raise_error(Aliquot::TokenExpiredError, 'token is expired')
expect { subject.call }.to raise_error(Aliquot::TokenExpiredError, 'token is expired')
end

it 'rejects invalid recipient_id' do
generator.recipient_id = 'Some invalid id'
is_expected.to raise_error(Aliquot::InvalidRecipientIDError)
expect { subject.call }.to raise_error(Aliquot::InvalidRecipientIDError)
end

it 'rejects non-base64 shared_secret' do
Expand All @@ -67,12 +67,12 @@

it 'rejects shared_secret when not 32 bytes' do
generator.shared_secret = 'not 32 bytes'
is_expected.to raise_error(Aliquot::InvalidSharedSecretError, 'shared_secret must be 32 bytes when base64 decoded')
expect { subject.call }.to raise_error(Aliquot::InvalidSharedSecretError, 'shared_secret must be 32 bytes when base64 decoded')
end

it 'rejects when signature of signedMessage does not match' do
generator.signature = AliquotPay.new.build_signature
is_expected.to raise_error(Aliquot::InvalidSignatureError, 'signature of signedMessage does not match')
expect { subject.call }.to raise_error(Aliquot::InvalidSignatureError, 'signature of signedMessage does not match')
end

it 'rejects when failing to verify signature' do
Expand All @@ -81,7 +81,7 @@
der = asn1.to_der

generator.signature = Base64.strict_encode64(der)
is_expected.to raise_error(Aliquot::InvalidSignatureError, /\Aerror verifying signature,/)
expect { subject.call }.to raise_error(Aliquot::InvalidSignatureError, /\Aerror verifying signature,/)
end
end

Expand All @@ -108,12 +108,12 @@

it 'rejects expired intermediateSigningKey' do
generator.key_expiration = "#{Time.now.to_i - 1}000"
is_expected.to raise_error(Aliquot::InvalidSignatureError, 'intermediate certificate is expired')
expect { subject.call }.to raise_error(Aliquot::InvalidSignatureError, 'intermediate certificate is expired')
end

it 'rejects when no signature of intermediateKey is found' do
generator.signatures = AliquotPay.new.build_signatures
is_expected.to raise_error(Aliquot::InvalidSignatureError, 'no valid signature of intermediate key')
expect { subject.call }.to raise_error(Aliquot::InvalidSignatureError, 'no valid signature of intermediate key')
end

it 'allows invalid intermediate signatures to be present' do
Expand All @@ -125,7 +125,7 @@
expect(token['intermediateSigningKey']['signatures']).to include(fake_signature)
expect(token['intermediateSigningKey']['signatures']).to include(real_signature)

is_expected.to_not raise_error
expect { subject.call }.to_not raise_error
end
end
end

0 comments on commit 741644d

Please sign in to comment.