lowdown 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cac86340acb40e426c4d36fe8b65f6d023166293
4
- data.tar.gz: 645fdfd12c742e514b7613f3283da11141c08d17
3
+ metadata.gz: 1fa2be0e57306efb793fb262856aa2a1bea16c03
4
+ data.tar.gz: 151af85c92ff4c4553244f78c70721bf41cc31a9
5
5
  SHA512:
6
- metadata.gz: d46552ff47566b8efe60b8684151e0f443468bab5175446d9853ce868640d1ace5364f19ce6cef8c05118be94136d58ffc7d901b5fb303b0cee26e29f28e2960
7
- data.tar.gz: 47cee9254108a7b687a50e437ef4adf7c49d243c552516131fc5764a38843b68b79597a4fa0a705c7557d958a44e75b3df393384682feb2417a8e3f1b7c6709f
6
+ metadata.gz: c6aab49b75690c5aac492d6d1ffd137bb5b548b2377e7f391e2bb7095b03661a80ba920388e89e24f1f2f24826946b81274e94d12cdf49bf9d737e80db539289
7
+ data.tar.gz: e0ccfd14e17cbe9b7e96b2401ea493396eab4a0acd72c472b4383dd95c3b20e0aab469ebdba38d663648dd09a26d2cd235ff95cd7d472f026a5e5cd91170ae0e
data/bin/lowdown CHANGED
@@ -45,7 +45,7 @@ OPTION_PARSER = OptionParser.new do |opts|
45
45
  options[:topic] = topic
46
46
  end
47
47
 
48
- opts.on("-e", "--environment ENV", "Environment to send push notification (production or development), defaults to certificate purpose or development") do |env|
48
+ opts.on("-e", "--environment ENV", "Environment to send push notification (production or development), defaults to production if the certificate supports that or otherwise development") do |env|
49
49
  options[:env] = env
50
50
  end
51
51
 
@@ -81,10 +81,10 @@ if options[:env]
81
81
  end
82
82
  production = options[:env] == "production"
83
83
  else
84
- if certificate.development?
85
- production = false
86
- elsif certificate.production?
84
+ if certificate.production?
87
85
  production = true
86
+ elsif certificate.development?
87
+ production = false
88
88
  end
89
89
  end
90
90
 
@@ -18,17 +18,17 @@ module Lowdown
18
18
  def self.from_pem_data(data, passphrase = nil)
19
19
  key = OpenSSL::PKey::RSA.new(data, passphrase)
20
20
  certificate = OpenSSL::X509::Certificate.new(data)
21
- new(key, certificate)
21
+ new(certificate, key)
22
22
  end
23
23
 
24
24
  attr_reader :key, :certificate
25
25
 
26
- def initialize(key, certificate)
26
+ def initialize(certificate, key = nil)
27
27
  @key, @certificate = key, certificate
28
28
  end
29
29
 
30
30
  def to_pem
31
- "#{@key.to_pem}\n#{@certificate.to_pem}"
31
+ [@key, @certificate].compact.map(&:to_pem).join("\n")
32
32
  end
33
33
 
34
34
  def ssl_context
@@ -59,14 +59,14 @@ module Lowdown
59
59
  end
60
60
  end
61
61
 
62
+ def app_bundle_id
63
+ @certificate.subject.to_a.find { |key, *_| key == 'UID' }[1]
64
+ end
65
+
62
66
  private
63
67
 
64
68
  def extension(oid)
65
69
  @certificate.extensions.find { |ext| ext.oid == oid }
66
70
  end
67
-
68
- def app_bundle_id
69
- @certificate.subject.to_a.find { |key, *_| key == 'UID' }[1]
70
- end
71
71
  end
72
72
  end
@@ -26,8 +26,11 @@ module Lowdown
26
26
 
27
27
  def self.client(uri, certificate_or_data)
28
28
  certificate = Lowdown.Certificate(certificate_or_data)
29
- default_topic = certificate.topics.first if certificate.universal?
30
- new(Connection.new(uri, certificate.ssl_context), default_topic)
29
+ client_with_connection(Connection.new(uri, certificate.ssl_context), certificate)
30
+ end
31
+
32
+ def self.client_with_connection(connection, certificate)
33
+ new(connection, certificate.universal? ? certificate.topics.first : nil)
31
34
  end
32
35
 
33
36
  attr_reader :connection, :default_topic
@@ -1,14 +1,48 @@
1
+ require "lowdown/certificate"
2
+ require "lowdown/client"
1
3
  require "lowdown/response"
2
4
 
3
5
  module Lowdown
4
- class Connection
5
- class Mock
6
+ module Mock
7
+ def self.ssl_certificate_and_key(app_bundle_id)
8
+ key = OpenSSL::PKey::RSA.new(1024)
9
+ name = OpenSSL::X509::Name.parse("/UID=#{app_bundle_id}/CN=Stubbed APNS Certificate: #{app_bundle_id}")
10
+ cert = OpenSSL::X509::Certificate.new
11
+ cert.subject = name
12
+ cert.not_before = Time.now
13
+ cert.not_after = cert.not_before + 3600
14
+ cert.public_key = key.public_key
15
+ cert.sign(key, OpenSSL::Digest::SHA1.new)
16
+
17
+ # Make it a Universal Certificate
18
+ ext_name = Lowdown::Certificate::UNIVERSAL_CERTIFICATE_EXTENSION
19
+ cert.extensions = [OpenSSL::X509::Extension.new(ext_name, "0d..#{app_bundle_id}0...app")]
20
+
21
+ [cert, key]
22
+ end
23
+
24
+ def self.certificate(app_bundle_id)
25
+ Certificate.new(*ssl_certificate_and_key(app_bundle_id))
26
+ end
27
+
28
+ def self.client(uri: nil, app_bundle_id: "com.example.MockApp")
29
+ certificate = certificate(app_bundle_id)
30
+ connection = Connection.new(uri: uri, ssl_context: certificate.ssl_context)
31
+ Client.client_with_connection(connection, certificate)
32
+ end
33
+
34
+ class Connection
6
35
  Request = Struct.new(:path, :headers, :body, :response)
7
36
 
37
+ # Mock API
8
38
  attr_reader :requests, :responses
9
39
 
10
- def initialize(responses = [])
11
- @responses = responses
40
+ # Real API
41
+ attr_reader :uri, :ssl_context
42
+
43
+ def initialize(uri: nil, ssl_context: nil)
44
+ @uri, @ssl_context = uri, ssl_context
45
+ @responses = []
12
46
  @requests = []
13
47
  end
14
48
 
@@ -1,3 +1,3 @@
1
1
  module Lowdown
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lowdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eloy Durán
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-04 00:00:00.000000000 Z
11
+ date: 2016-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http-2
@@ -86,7 +86,7 @@ files:
86
86
  - lib/lowdown/certificate.rb
87
87
  - lib/lowdown/client.rb
88
88
  - lib/lowdown/connection.rb
89
- - lib/lowdown/connection/mock.rb
89
+ - lib/lowdown/mock.rb
90
90
  - lib/lowdown/notification.rb
91
91
  - lib/lowdown/response.rb
92
92
  - lib/lowdown/threading.rb