crusade-apns 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.travis.yml +9 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +29 -0
  7. data/Rakefile +8 -0
  8. data/crusade-apns.gemspec +28 -0
  9. data/lib/crusade/apns.rb +3 -0
  10. data/lib/crusade/apns/configuration.rb +52 -0
  11. data/lib/crusade/apns/crypto/user_token_generator.rb +23 -0
  12. data/lib/crusade/apns/push_package/directory_structure_generator.rb +38 -0
  13. data/lib/crusade/apns/push_package/manifest_generator.rb +42 -0
  14. data/lib/crusade/apns/push_package/signature_generator.rb +45 -0
  15. data/lib/crusade/apns/push_package/website_file_generator.rb +37 -0
  16. data/lib/crusade/apns/push_package/zip_file_generator.rb +31 -0
  17. data/lib/crusade/apns/push_package_generator.rb +50 -0
  18. data/lib/crusade/apns/version.rb +5 -0
  19. data/signature +0 -0
  20. data/test/fixtures/config.yml +23 -0
  21. data/test/fixtures/icons/icon_128x128.png +0 -0
  22. data/test/fixtures/icons/icon_128x128@2x.png +0 -0
  23. data/test/fixtures/icons/icon_16x16.png +0 -0
  24. data/test/fixtures/icons/icon_16x16@2x.png +0 -0
  25. data/test/fixtures/icons/icon_32x32.png +0 -0
  26. data/test/fixtures/icons/icon_32x32@2x.png +0 -0
  27. data/test/fixtures/ssl/ca.crt +33 -0
  28. data/test/fixtures/ssl/ca.key +51 -0
  29. data/test/fixtures/ssl/certificate.p12 +0 -0
  30. data/test/fixtures/ssl/hash +1 -0
  31. data/test/fixtures/ssl/ia.crt +29 -0
  32. data/test/fixtures/ssl/ia.csr +27 -0
  33. data/test/fixtures/ssl/ia.key +51 -0
  34. data/test/fixtures/ssl/manifest_example.json +4 -0
  35. data/test/fixtures/ssl/signature +0 -0
  36. data/test/fixtures/ssl/signature_example +0 -0
  37. data/test/integration/push_package_generator_test.rb +40 -0
  38. data/test/integration/user_token_generator_test.rb +19 -0
  39. data/test/support/fixtures.rb +18 -0
  40. data/test/support/ssl_support.rb +19 -0
  41. data/test/support/zip_support.rb +13 -0
  42. data/test/test_helper.rb +9 -0
  43. data/test/unit/configuration_test.rb +155 -0
  44. data/test/unit/push_package/directory_structure_generator_test.rb +39 -0
  45. data/test/unit/push_package/manifest_generator_test.rb +37 -0
  46. data/test/unit/push_package/signature_generator_test.rb +41 -0
  47. data/test/unit/push_package/website_file_generator_test.rb +41 -0
  48. data/test/unit/push_package/zip_file_generator_test.rb +51 -0
  49. data/test/unit/push_package_generator_test.rb +6 -0
  50. metadata +206 -0
@@ -0,0 +1,39 @@
1
+ require File.expand_path '../../../test_helper.rb', __FILE__
2
+ require 'json'
3
+ require 'json_expressions/minitest'
4
+
5
+ require 'crusade/apns/push_package/directory_structure_generator'
6
+
7
+ describe Crusade::APNS::DirectoryStructureGenerator do
8
+ let(:options) { Fixtures.default_configuration }
9
+
10
+ subject { Crusade::APNS::DirectoryStructureGenerator.new options }
11
+
12
+ let(:dir) { subject.generate }
13
+
14
+ describe 'generate' do
15
+ after { FileUtils.remove_entry_secure dir }
16
+
17
+ it 'creates the directory' do
18
+ Dir.exists?(dir).must_be_truthy
19
+ end
20
+
21
+ it 'copies the icon files' do
22
+ %w(16x16 16x16@2x 32x32 32x32@2x 128x128 128x128@2x).each do |size|
23
+ icon = File.join dir, 'icon.iconset', "icon_#{size}.png"
24
+
25
+ File.exists?(icon).must_be_truthy
26
+ end
27
+ end
28
+ end
29
+
30
+ describe 'clean' do
31
+ it 'removes all the data' do
32
+ dir
33
+
34
+ subject.clean
35
+
36
+ Dir.exists?(dir).must_equal false
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,37 @@
1
+ require File.expand_path '../../../test_helper.rb', __FILE__
2
+ require 'tmpdir'
3
+ require 'fileutils'
4
+ require 'json'
5
+
6
+ require 'crusade/apns/push_package/manifest_generator'
7
+
8
+ describe Crusade::APNS::ManifestGenerator do
9
+ let(:dir) { Dir.mktmpdir }
10
+
11
+ before do
12
+ File.open(File.join(dir, 'file_1'), 'w') { |file| file.write("the content\nof the first file")}
13
+ File.open(File.join(dir, 'file_2'), 'w') { |file| file.write("the content\nof the second file")}
14
+ Dir.mkdir File.join(dir, 'sub')
15
+ File.open(File.join(dir, 'sub', 'file_3'), 'w') { |file| file.write("the content\nof the sub file")}
16
+ end
17
+
18
+ after { FileUtils.remove_entry_secure dir }
19
+
20
+ subject { Crusade::APNS::ManifestGenerator.new dir }
21
+
22
+ let(:manifest) { subject.generate }
23
+ let(:parsed) { JSON.parse manifest }
24
+
25
+ describe 'generate' do
26
+ it 'generates one entry per file' do
27
+ parsed.keys.must_equal_contents %w(file_1 file_2 sub/file_3)
28
+ end
29
+
30
+ it 'digest every file via sha1' do
31
+ parsed['file_1'].must_equal '940a456fdb8c106b98f0481b0badde914bcc878b'
32
+ parsed['file_2'].must_equal '00501364e032879f2262a9932c233ed3497f3f5f'
33
+ parsed['sub/file_3'].must_equal '9c100c8aa0b48975b012073b2cf7ab09d63164e9'
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,41 @@
1
+ require File.expand_path '../../../test_helper.rb', __FILE__
2
+ require 'crusade/apns/push_package/signature_generator'
3
+
4
+ require 'ssl_support'
5
+
6
+ require 'tmpdir'
7
+ require 'fileutils'
8
+
9
+ describe Crusade::APNS::SignatureGenerator do
10
+ let(:options) do
11
+ OpenStruct.new(certificate: 'test/fixtures/ssl/certificate.p12',
12
+ certificate_password: 'test')
13
+ end
14
+
15
+ let(:dir) { Dir.mktmpdir }
16
+
17
+ after { FileUtils.remove_entry_secure dir }
18
+
19
+ subject { Crusade::APNS::SignatureGenerator.new options }
20
+
21
+ describe 'sign' do
22
+ let(:manifest) { File.join dir, 'manifest.json' }
23
+ let(:signature) { File.join(dir, 'signature') }
24
+
25
+ before { FileUtils.copy_file "test/fixtures/ssl/manifest_example.json", manifest }
26
+
27
+ it 'generates a signature file in the same directory' do
28
+ subject.sign manifest
29
+
30
+ File.exist?(signature).must_be_truthy
31
+ end
32
+
33
+ it 'uses the certificate to sign the manifest' do
34
+ subject.sign manifest
35
+
36
+ certificate = SslSupport.certificate(options.certificate, options.certificate_password)
37
+
38
+ SslSupport.verify_signature(certificate, manifest, signature).must_be_truthy
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,41 @@
1
+ require File.expand_path '../../../test_helper.rb', __FILE__
2
+ require 'json'
3
+ require 'json_expressions/minitest'
4
+
5
+ require 'crusade/apns/push_package/website_file_generator'
6
+
7
+ describe Crusade::APNS::WebsiteFileGenerator do
8
+ let(:user_id) { 187 }
9
+ let(:options) { Fixtures.default_configuration }
10
+
11
+ subject { Crusade::APNS::WebsiteFileGenerator.new user_id, options }
12
+
13
+ let(:website_json) { subject.generate }
14
+ let(:parsed) { JSON.parse website_json }
15
+
16
+ describe 'generate' do
17
+ before do
18
+ generator = OpenStruct.new generate: 'token'
19
+ Crusade::APNS::UserTokenGenerator.stub(:new, generator) do
20
+ website_json
21
+ end
22
+ end
23
+
24
+ it 'builds a valid json' do
25
+ parsed.wont_be_nil
26
+ end
27
+
28
+ it 'generate the correct json' do
29
+ expected_json = {
30
+ "websiteName" => "Bay Airlines",
31
+ "websitePushID" => "web.com.example.domain",
32
+ "allowedDomains" => ['http://example.com'],
33
+ "urlFormatString" => "http://domain.example.com/%@/?flight=%@",
34
+ "authenticationToken" => "token",
35
+ "webServiceURL" => "https://example.com/push"
36
+ }
37
+
38
+ parsed.must_match_json_expression expected_json
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,51 @@
1
+ require File.expand_path '../../../test_helper.rb', __FILE__
2
+
3
+ require 'zip_support'
4
+
5
+ require 'tmpdir'
6
+ require 'fileutils'
7
+
8
+ require 'crusade/apns/push_package/zip_file_generator'
9
+
10
+ describe Crusade::APNS::ZipFileGenerator do
11
+ let(:options) { Fixtures.default_configuration }
12
+
13
+ subject { Crusade::APNS::ZipFileGenerator.new options, dir, destination }
14
+
15
+ let(:tmp_dir) { Dir.mktmpdir }
16
+ let(:dir) { File.join tmp_dir, 'push_package' }
17
+ let(:destination) { File.join tmp_dir, 'package.zip' }
18
+
19
+ after { FileUtils.remove_entry_secure tmp_dir }
20
+
21
+ before { FileUtils.mkdir dir }
22
+
23
+ describe 'generate' do
24
+ before do
25
+ File.open(File.join(dir, 'file1.json'), 'w') { |f| f.write 'test' }
26
+ Dir.mkdir File.join(dir, 'sub')
27
+ File.open(File.join(dir, 'sub', 'sub_file'), 'w') { |f| f.write 'test2' }
28
+
29
+ subject.generate
30
+ end
31
+
32
+ it 'generate a file' do
33
+ File.exists?(destination).must_be_truthy
34
+ end
35
+
36
+ it 'archives the files in a zip' do
37
+ expected = [ "file1.json", "sub/", "sub/sub_file"]
38
+ ZipSupport.file_names(destination).must_equal_contents expected
39
+ end
40
+ end
41
+
42
+ describe 'clean' do
43
+ it 'removes the zip file' do
44
+ File.open(destination, 'w') { |f| f.write('test') }
45
+
46
+ subject.clean
47
+
48
+ File.exists?(destination).must_equal false
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,6 @@
1
+ require File.expand_path '../../test_helper.rb', __FILE__
2
+
3
+ require 'crusade/apns/push_package_generator'
4
+
5
+ describe Crusade::APNS::PushPackageGenerator do
6
+ end
metadata ADDED
@@ -0,0 +1,206 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: crusade-apns
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - David Rouchy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubyzip
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: json_expressions
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.8.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 5.0.7
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 5.0.7
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest-great_expectations
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 0.0.5
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 0.0.5
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: APNS pluging for crusade
98
+ email:
99
+ - drouchy@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .travis.yml
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - crusade-apns.gemspec
111
+ - lib/crusade/apns.rb
112
+ - lib/crusade/apns/configuration.rb
113
+ - lib/crusade/apns/crypto/user_token_generator.rb
114
+ - lib/crusade/apns/push_package/directory_structure_generator.rb
115
+ - lib/crusade/apns/push_package/manifest_generator.rb
116
+ - lib/crusade/apns/push_package/signature_generator.rb
117
+ - lib/crusade/apns/push_package/website_file_generator.rb
118
+ - lib/crusade/apns/push_package/zip_file_generator.rb
119
+ - lib/crusade/apns/push_package_generator.rb
120
+ - lib/crusade/apns/version.rb
121
+ - signature
122
+ - test/fixtures/config.yml
123
+ - test/fixtures/icons/icon_128x128.png
124
+ - test/fixtures/icons/icon_128x128@2x.png
125
+ - test/fixtures/icons/icon_16x16.png
126
+ - test/fixtures/icons/icon_16x16@2x.png
127
+ - test/fixtures/icons/icon_32x32.png
128
+ - test/fixtures/icons/icon_32x32@2x.png
129
+ - test/fixtures/ssl/ca.crt
130
+ - test/fixtures/ssl/ca.key
131
+ - test/fixtures/ssl/certificate.p12
132
+ - test/fixtures/ssl/hash
133
+ - test/fixtures/ssl/ia.crt
134
+ - test/fixtures/ssl/ia.csr
135
+ - test/fixtures/ssl/ia.key
136
+ - test/fixtures/ssl/manifest_example.json
137
+ - test/fixtures/ssl/signature
138
+ - test/fixtures/ssl/signature_example
139
+ - test/integration/push_package_generator_test.rb
140
+ - test/integration/user_token_generator_test.rb
141
+ - test/support/fixtures.rb
142
+ - test/support/ssl_support.rb
143
+ - test/support/zip_support.rb
144
+ - test/test_helper.rb
145
+ - test/unit/configuration_test.rb
146
+ - test/unit/push_package/directory_structure_generator_test.rb
147
+ - test/unit/push_package/manifest_generator_test.rb
148
+ - test/unit/push_package/signature_generator_test.rb
149
+ - test/unit/push_package/website_file_generator_test.rb
150
+ - test/unit/push_package/zip_file_generator_test.rb
151
+ - test/unit/push_package_generator_test.rb
152
+ homepage: ''
153
+ licenses:
154
+ - MIT
155
+ metadata: {}
156
+ post_install_message:
157
+ rdoc_options: []
158
+ require_paths:
159
+ - lib
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - '>='
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - '>='
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubyforge_project:
172
+ rubygems_version: 2.0.3
173
+ signing_key:
174
+ specification_version: 4
175
+ summary: send push notification to APNS
176
+ test_files:
177
+ - test/fixtures/config.yml
178
+ - test/fixtures/icons/icon_128x128.png
179
+ - test/fixtures/icons/icon_128x128@2x.png
180
+ - test/fixtures/icons/icon_16x16.png
181
+ - test/fixtures/icons/icon_16x16@2x.png
182
+ - test/fixtures/icons/icon_32x32.png
183
+ - test/fixtures/icons/icon_32x32@2x.png
184
+ - test/fixtures/ssl/ca.crt
185
+ - test/fixtures/ssl/ca.key
186
+ - test/fixtures/ssl/certificate.p12
187
+ - test/fixtures/ssl/hash
188
+ - test/fixtures/ssl/ia.crt
189
+ - test/fixtures/ssl/ia.csr
190
+ - test/fixtures/ssl/ia.key
191
+ - test/fixtures/ssl/manifest_example.json
192
+ - test/fixtures/ssl/signature
193
+ - test/fixtures/ssl/signature_example
194
+ - test/integration/push_package_generator_test.rb
195
+ - test/integration/user_token_generator_test.rb
196
+ - test/support/fixtures.rb
197
+ - test/support/ssl_support.rb
198
+ - test/support/zip_support.rb
199
+ - test/test_helper.rb
200
+ - test/unit/configuration_test.rb
201
+ - test/unit/push_package/directory_structure_generator_test.rb
202
+ - test/unit/push_package/manifest_generator_test.rb
203
+ - test/unit/push_package/signature_generator_test.rb
204
+ - test/unit/push_package/website_file_generator_test.rb
205
+ - test/unit/push_package/zip_file_generator_test.rb
206
+ - test/unit/push_package_generator_test.rb