Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Update Rapns::App validation to not swallow unexpected exceptions during validation #192

Merged
merged 1 commit into from

2 participants

@mattconnolly

This may help people with OpenSSL errors, which may be the case reported in #176.

@ileitch ileitch merged commit d018740 into ileitch:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 19 additions and 4 deletions.
  1. +5 −4 lib/rapns/apns/app.rb
  2. +14 −0 spec/unit/app_spec.rb
View
9 lib/rapns/apns/app.rb
@@ -10,10 +10,11 @@ class App < Rapns::App
def certificate_has_matching_private_key
result = false
if certificate.present?
- x509 = OpenSSL::X509::Certificate.new(certificate) rescue nil
- pkey = OpenSSL::PKey::RSA.new(certificate, password) rescue nil
- result = !x509.nil? && !pkey.nil?
- unless result
+ begin
+ x509 = OpenSSL::X509::Certificate.new(certificate)
+ pkey = OpenSSL::PKey::RSA.new(certificate, password)
+ result = !x509.nil? && !pkey.nil?
+ rescue OpenSSL::OpenSSLError
errors.add :certificate, 'Certificate value must contain a certificate and a private key.'
end
end
View
14 spec/unit/app_spec.rb
@@ -13,4 +13,18 @@
app = Rapns::Gcm::App.new(:name => 'test', :environment => 'production', :auth_key => TEST_CERT)
app.valid?.should be_true
end
+
+ context 'validating certificates' do
+ it 'rescues from certificate error' do
+ app = Rapns::Apns::App.new(:name => 'test', :environment => 'development', :certificate => 'bad')
+ expect{app.valid?}.not_to raise_error
+ expect(app.valid?).to be_false
+ end
+
+ it 'raises other errors' do
+ app = Rapns::Apns::App.new(:name => 'test', :environment => 'development', :certificate => 'bad')
+ OpenSSL::X509::Certificate.stub(:new).and_raise(NameError, 'simulating no openssl')
+ expect{app.valid?}.to raise_error(NameError)
+ end
+ end
end
Something went wrong with that request. Please try again.