Module: Lowdown::Mock
- Defined in:
- lib/lowdown/mock.rb
Overview
Provides a collection of test helpers.
This file is not loaded by default.
Defined Under Namespace
Classes: Connection
Class Method Summary collapse
-
.certificate(app_bundle_id) ⇒ Certificate
Generates a Certificate configured with a self-signed Universal Certificate.
-
.client(uri: nil, app_bundle_id: "com.example.MockApp", keep_alive: false) ⇒ Client
Generates a Client with a mock Connection and a self-signed Universal Certificate.
-
.ssl_certificate_and_key(app_bundle_id) ⇒ Array<OpenSSL::X509::Certificate, OpenSSL::PKey::RSA>
Generates a self-signed Universal Certificate.
Class Method Details
.certificate(app_bundle_id) ⇒ Certificate
Generates a Certificate configured with a self-signed Universal Certificate.
51 52 53 |
# File 'lib/lowdown/mock.rb', line 51 def self.certificate(app_bundle_id) Certificate.new(*ssl_certificate_and_key(app_bundle_id)) end |
.client(uri: nil, app_bundle_id: "com.example.MockApp", keep_alive: false) ⇒ Client
Generates a Client with a mock Connection and a self-signed Universal Certificate.
66 67 68 69 70 71 |
# File 'lib/lowdown/mock.rb', line 66 def self.client(uri: nil, app_bundle_id: "com.example.MockApp", keep_alive: false) certificate = certificate(app_bundle_id) connection = Connection.new(uri, certificate.ssl_context, keep_alive) connection.connect if keep_alive Client.client_with_connection(connection, certificate: certificate) end |
.ssl_certificate_and_key(app_bundle_id) ⇒ Array<OpenSSL::X509::Certificate, OpenSSL::PKey::RSA>
Generates a self-signed Universal Certificate.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/lowdown/mock.rb', line 21 def self.ssl_certificate_and_key(app_bundle_id) key = OpenSSL::PKey::RSA.new(1024) name = OpenSSL::X509::Name.parse("/UID=#{app_bundle_id}/CN=Stubbed APNS Certificate: #{app_bundle_id}") cert = OpenSSL::X509::Certificate.new cert.subject = name cert.not_before = Time.now cert.not_after = cert.not_before + 3600 cert.public_key = key.public_key cert.sign(key, OpenSSL::Digest::SHA1.new) # Make it a Universal Certificate ext_name = Lowdown::Certificate::UNIVERSAL_CERTIFICATE_EXTENSION ext_value = OpenSSL::ASN1::Sequence.new( [ OpenSSL::ASN1::UTF8String.new(app_bundle_id), OpenSSL::ASN1::Sequence.new([OpenSSL::ASN1::UTF8String.new("app")]), ] ).to_der cert.extensions = [OpenSSL::X509::Extension.new(ext_name, ext_value)] [cert, key] end |