From 741644d71bf32f614b11620189b8820adc6dea49 Mon Sep 17 00:00:00 2001 From: Christian Bobach Date: Tue, 5 Sep 2023 11:25:13 +0200 Subject: [PATCH] Ensure that `aliquot` works on Ruby 3.1 (#26) --- .github/workflows/test.yml | 2 ++ aliquot.gemspec | 4 ++-- spec/integration_spec.rb | 8 ++++---- spec/lib/aliquot/payment_spec.rb | 24 ++++++++++++------------ 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9f67628..3fdcc62 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,6 +10,8 @@ jobs: version: - '2.7' - '3.0' + - '3.1' + - '3.2' steps: - uses: ruby/setup-ruby@v1 with: diff --git a/aliquot.gemspec b/aliquot.gemspec index 806f658..7e3e914 100644 --- a/aliquot.gemspec +++ b/aliquot.gemspec @@ -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' @@ -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 diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index 9a21762..e952685 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/spec/lib/aliquot/payment_spec.rb b/spec/lib/aliquot/payment_spec.rb index 8e2ee81..9524930 100644 --- a/spec/lib/aliquot/payment_spec.rb +++ b/spec/lib/aliquot/payment_spec.rb @@ -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 @@ -26,7 +26,7 @@ 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. @@ -34,7 +34,7 @@ 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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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