rpush 4.2.0 → 7.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +307 -163
- data/README.md +105 -19
- data/lib/generators/templates/add_adm.rb +1 -1
- data/lib/generators/templates/add_alert_is_json_to_rapns_notifications.rb +2 -2
- data/lib/generators/templates/add_app_to_rapns.rb +2 -2
- data/lib/generators/templates/add_fail_after_to_rpush_notifications.rb +1 -1
- data/lib/generators/templates/add_gcm.rb +11 -25
- data/lib/generators/templates/add_rpush.rb +33 -83
- data/lib/generators/templates/add_wpns.rb +1 -1
- data/lib/generators/templates/create_rapns_apps.rb +1 -1
- data/lib/generators/templates/create_rapns_feedback.rb +3 -9
- data/lib/generators/templates/create_rapns_notifications.rb +3 -9
- data/lib/generators/templates/rename_rapns_to_rpush.rb +9 -33
- data/lib/generators/templates/rpush.rb +5 -4
- data/lib/generators/templates/rpush_2_0_0_updates.rb +10 -18
- data/lib/generators/templates/rpush_2_1_0_updates.rb +1 -1
- data/lib/generators/templates/rpush_2_6_0_updates.rb +1 -1
- data/lib/generators/templates/rpush_2_7_0_updates.rb +1 -1
- data/lib/generators/templates/rpush_3_0_0_updates.rb +1 -1
- data/lib/generators/templates/rpush_3_0_1_updates.rb +1 -1
- data/lib/generators/templates/rpush_3_1_0_add_pushy.rb +1 -1
- data/lib/generators/templates/rpush_3_1_1_updates.rb +1 -1
- data/lib/generators/templates/rpush_3_2_0_add_apns_p8.rb +1 -1
- data/lib/generators/templates/rpush_3_2_4_updates.rb +1 -1
- data/lib/generators/templates/rpush_3_3_0_updates.rb +1 -1
- data/lib/generators/templates/rpush_3_3_1_updates.rb +3 -3
- data/lib/generators/templates/rpush_4_1_0_updates.rb +1 -1
- data/lib/generators/templates/rpush_4_1_1_updates.rb +1 -1
- data/lib/generators/templates/rpush_4_2_0_updates.rb +1 -1
- data/lib/rpush/cli.rb +1 -1
- data/lib/rpush/client/active_model/adm/data_validator.rb +1 -1
- data/lib/rpush/client/active_model/apns/app.rb +1 -17
- data/lib/rpush/client/active_model/apns/device_token_format_validator.rb +2 -2
- data/lib/rpush/client/active_model/apns/notification.rb +13 -1
- data/lib/rpush/client/active_model/apns/notification_payload_size_validator.rb +15 -0
- data/lib/rpush/client/active_model/apns2/app.rb +7 -1
- data/lib/rpush/client/active_model/apns2/notification.rb +14 -0
- data/lib/rpush/client/active_model/certificate_private_key_validator.rb +19 -0
- data/lib/rpush/client/active_model/gcm/expiry_collapse_key_mutual_inclusion_validator.rb +1 -1
- data/lib/rpush/client/active_model/gcm/notification.rb +2 -2
- data/lib/rpush/client/active_model/payload_data_size_validator.rb +1 -1
- data/lib/rpush/client/active_model/registration_ids_count_validator.rb +1 -1
- data/lib/rpush/client/active_model/webpush/app.rb +41 -0
- data/lib/rpush/client/active_model/webpush/notification.rb +66 -0
- data/lib/rpush/client/active_model.rb +5 -1
- data/lib/rpush/client/active_record/apns/active_record_serializable_notification.rb +65 -0
- data/lib/rpush/client/active_record/apns/notification.rb +1 -57
- data/lib/rpush/client/active_record/apns2/notification.rb +4 -1
- data/lib/rpush/client/active_record/apnsp8/notification.rb +1 -0
- data/lib/rpush/client/active_record/webpush/app.rb +11 -0
- data/lib/rpush/client/active_record/webpush/notification.rb +12 -0
- data/lib/rpush/client/active_record.rb +4 -0
- data/lib/rpush/client/redis/apns2/notification.rb +1 -0
- data/lib/rpush/client/redis/apnsp8/notification.rb +2 -0
- data/lib/rpush/client/redis/pushy/notification.rb +0 -1
- data/lib/rpush/client/redis/webpush/app.rb +15 -0
- data/lib/rpush/client/redis/webpush/notification.rb +15 -0
- data/lib/rpush/client/redis.rb +3 -0
- data/lib/rpush/configuration.rb +3 -2
- data/lib/rpush/daemon/apns/feedback_receiver.rb +1 -1
- data/lib/rpush/daemon/apns2/delivery.rb +14 -2
- data/lib/rpush/daemon/apnsp8/delivery.rb +14 -3
- data/lib/rpush/daemon/app_runner.rb +1 -1
- data/lib/rpush/daemon/batch.rb +12 -5
- data/lib/rpush/daemon/delivery.rb +1 -2
- data/lib/rpush/daemon/store/active_record/reconnectable.rb +1 -1
- data/lib/rpush/daemon/store/active_record.rb +11 -7
- data/lib/rpush/daemon/store/redis.rb +6 -6
- data/lib/rpush/daemon/string_helpers.rb +1 -1
- data/lib/rpush/daemon/webpush/delivery.rb +114 -0
- data/lib/rpush/daemon/webpush.rb +10 -0
- data/lib/rpush/daemon.rb +4 -1
- data/lib/rpush/logger.rb +2 -1
- data/lib/rpush/version.rb +3 -3
- data/spec/functional/apns2_spec.rb +99 -2
- data/spec/functional/gcm_priority_spec.rb +40 -0
- data/spec/functional/retry_spec.rb +1 -1
- data/spec/functional/webpush_spec.rb +31 -0
- data/spec/spec_helper.rb +3 -1
- data/spec/support/active_record_setup.rb +4 -3
- data/spec/support/config/database.yml +4 -4
- data/spec/support/simplecov_helper.rb +2 -2
- data/spec/unit/client/active_record/adm/app_spec.rb +2 -54
- data/spec/unit/client/active_record/adm/notification_spec.rb +2 -39
- data/spec/unit/client/active_record/apns/app_spec.rb +3 -26
- data/spec/unit/client/active_record/apns/feedback_spec.rb +1 -5
- data/spec/unit/client/active_record/apns/notification_spec.rb +29 -293
- data/spec/unit/client/active_record/apns2/app_spec.rb +5 -0
- data/spec/unit/client/active_record/apns2/notification_spec.rb +65 -0
- data/spec/unit/client/active_record/apnsp8/notification_spec.rb +28 -0
- data/spec/unit/client/active_record/app_spec.rb +1 -26
- data/spec/unit/client/active_record/gcm/app_spec.rb +3 -1
- data/spec/unit/client/active_record/gcm/notification_spec.rb +6 -88
- data/spec/unit/client/active_record/notification_spec.rb +3 -11
- data/spec/unit/client/active_record/pushy/app_spec.rb +2 -13
- data/spec/unit/client/active_record/pushy/notification_spec.rb +2 -55
- data/spec/unit/client/active_record/shared/app.rb +14 -0
- data/spec/unit/{notification_shared.rb → client/active_record/shared/notification.rb} +12 -7
- data/spec/unit/client/active_record/webpush/app_spec.rb +6 -0
- data/spec/unit/client/active_record/webpush/notification_spec.rb +6 -0
- data/spec/unit/client/active_record/wns/badge_notification_spec.rb +1 -11
- data/spec/unit/client/active_record/wns/raw_notification_spec.rb +3 -12
- data/spec/unit/client/active_record/wpns/app_spec.rb +3 -1
- data/spec/unit/client/active_record/wpns/notification_spec.rb +2 -17
- data/spec/unit/client/redis/adm/app_spec.rb +5 -0
- data/spec/unit/client/redis/adm/notification_spec.rb +5 -0
- data/spec/unit/client/redis/apns/app_spec.rb +5 -0
- data/spec/unit/client/redis/apns/feedback_spec.rb +5 -0
- data/spec/unit/client/redis/apns/notification_spec.rb +50 -0
- data/spec/unit/client/redis/apns2/app_spec.rb +4 -0
- data/spec/unit/client/redis/apns2/notification_spec.rb +50 -0
- data/spec/unit/client/redis/apnsp8/notification_spec.rb +29 -0
- data/spec/unit/client/redis/app_spec.rb +5 -0
- data/spec/unit/client/redis/gcm/app_spec.rb +5 -0
- data/spec/unit/client/redis/gcm/notification_spec.rb +5 -0
- data/spec/unit/client/redis/notification_spec.rb +5 -0
- data/spec/unit/client/redis/pushy/app_spec.rb +5 -0
- data/spec/unit/client/redis/pushy/notification_spec.rb +5 -0
- data/spec/unit/client/redis/webpush/app_spec.rb +5 -0
- data/spec/unit/client/redis/webpush/notification_spec.rb +5 -0
- data/spec/unit/client/redis/wns/badge_notification_spec.rb +5 -0
- data/spec/unit/client/redis/wns/raw_notification_spec.rb +22 -0
- data/spec/unit/client/redis/wpns/app_spec.rb +5 -0
- data/spec/unit/client/redis/wpns/notification_spec.rb +5 -0
- data/spec/unit/client/shared/adm/app.rb +51 -0
- data/spec/unit/client/shared/adm/notification.rb +39 -0
- data/spec/unit/client/shared/apns/app.rb +29 -0
- data/spec/unit/client/shared/apns/feedback.rb +9 -0
- data/spec/unit/client/shared/apns/notification.rb +277 -0
- data/spec/unit/client/shared/app.rb +17 -0
- data/spec/unit/client/shared/gcm/app.rb +4 -0
- data/spec/unit/client/shared/gcm/notification.rb +77 -0
- data/spec/unit/client/shared/notification.rb +10 -0
- data/spec/unit/client/shared/pushy/app.rb +17 -0
- data/spec/unit/client/shared/pushy/notification.rb +55 -0
- data/spec/unit/client/shared/webpush/app.rb +33 -0
- data/spec/unit/client/shared/webpush/notification.rb +83 -0
- data/spec/unit/client/shared/wns/badge_notification.rb +15 -0
- data/spec/unit/client/shared/wns/raw_notification.rb +21 -0
- data/spec/unit/client/shared/wpns/app.rb +4 -0
- data/spec/unit/client/shared/wpns/notification.rb +18 -0
- data/spec/unit/daemon/apnsp8/delivery_spec.rb +53 -0
- data/spec/unit/daemon/batch_spec.rb +50 -2
- data/spec/unit/daemon/delivery_spec.rb +10 -0
- data/spec/unit/daemon/pushy/delivery_spec.rb +5 -3
- data/spec/unit/daemon/shared/store.rb +312 -0
- data/spec/unit/daemon/store/active_record/reconnectable_spec.rb +7 -7
- data/spec/unit/daemon/store/active_record_spec.rb +6 -287
- data/spec/unit/daemon/store/redis_spec.rb +2 -291
- data/spec/unit/daemon/webpush/delivery_spec.rb +144 -0
- data/spec/unit_spec_helper.rb +3 -0
- metadata +145 -18
- data/lib/rpush/client/active_model/apns/binary_notification_validator.rb +0 -16
data/lib/rpush/daemon.rb
CHANGED
|
@@ -68,6 +68,9 @@ require 'rpush/daemon/adm'
|
|
|
68
68
|
require 'rpush/daemon/pushy'
|
|
69
69
|
require 'rpush/daemon/pushy/delivery'
|
|
70
70
|
|
|
71
|
+
require 'rpush/daemon/webpush/delivery'
|
|
72
|
+
require 'rpush/daemon/webpush'
|
|
73
|
+
|
|
71
74
|
module Rpush
|
|
72
75
|
module Daemon
|
|
73
76
|
class << self
|
|
@@ -109,7 +112,7 @@ module Rpush
|
|
|
109
112
|
Feeder.stop
|
|
110
113
|
AppRunner.stop
|
|
111
114
|
delete_pid_file
|
|
112
|
-
puts Rainbow('✔').red if Rpush.config.foreground
|
|
115
|
+
puts Rainbow('✔').red if Rpush.config.foreground && Rpush.config.foreground_logging
|
|
113
116
|
end
|
|
114
117
|
end
|
|
115
118
|
|
data/lib/rpush/logger.rb
CHANGED
|
@@ -69,7 +69,7 @@ module Rpush
|
|
|
69
69
|
msg = "#{msg.class.name}, #{msg.message}\n#{formatted_backtrace}"
|
|
70
70
|
end
|
|
71
71
|
|
|
72
|
-
formatted_msg = "[#{Time.now.
|
|
72
|
+
formatted_msg = "[#{Time.now.to_formatted_s(:db)}]"
|
|
73
73
|
formatted_msg << '[rpush] ' if Rpush.config.embedded
|
|
74
74
|
formatted_msg << "[#{prefix}] " if prefix
|
|
75
75
|
formatted_msg << msg
|
|
@@ -79,6 +79,7 @@ module Rpush
|
|
|
79
79
|
end
|
|
80
80
|
|
|
81
81
|
def log_foreground(io, formatted_msg, inline)
|
|
82
|
+
return unless Rpush.config.foreground_logging
|
|
82
83
|
return unless io == STDERR || Rpush.config.foreground
|
|
83
84
|
|
|
84
85
|
if inline
|
data/lib/rpush/version.rb
CHANGED
|
@@ -42,6 +42,7 @@ describe 'APNs http2 adapter' do
|
|
|
42
42
|
app.certificate = TEST_CERT
|
|
43
43
|
app.name = 'test'
|
|
44
44
|
app.environment = 'development'
|
|
45
|
+
app.bundle_id = 'com.example.app'
|
|
45
46
|
app.save!
|
|
46
47
|
app
|
|
47
48
|
end
|
|
@@ -75,7 +76,13 @@ describe 'APNs http2 adapter' do
|
|
|
75
76
|
:post,
|
|
76
77
|
"/3/device/#{fake_device_token}",
|
|
77
78
|
{ body: "{\"aps\":{\"alert\":\"test\",\"sound\":\"default\",\"content-available\":1}}",
|
|
78
|
-
headers: {
|
|
79
|
+
headers: {
|
|
80
|
+
'apns-expiration' => '0',
|
|
81
|
+
'apns-priority' => '10',
|
|
82
|
+
'apns-topic' => 'com.example.app',
|
|
83
|
+
'apns-push-type' => 'background'
|
|
84
|
+
}
|
|
85
|
+
}
|
|
79
86
|
)
|
|
80
87
|
.and_return(fake_http2_request)
|
|
81
88
|
|
|
@@ -104,7 +111,12 @@ describe 'APNs http2 adapter' do
|
|
|
104
111
|
"/3/device/#{fake_device_token}",
|
|
105
112
|
{ body: "{\"aps\":{\"alert\":\"test\",\"sound\":\"default\","\
|
|
106
113
|
"\"content-available\":1},\"some_field\":\"some value\"}",
|
|
107
|
-
headers: {
|
|
114
|
+
headers: {
|
|
115
|
+
'apns-topic' => bundle_id,
|
|
116
|
+
'apns-expiration' => '0',
|
|
117
|
+
'apns-priority' => '10',
|
|
118
|
+
'apns-push-type' => 'background'
|
|
119
|
+
}
|
|
108
120
|
}
|
|
109
121
|
).and_return(fake_http2_request)
|
|
110
122
|
|
|
@@ -177,6 +189,13 @@ describe 'APNs http2 adapter' do
|
|
|
177
189
|
end
|
|
178
190
|
|
|
179
191
|
context 'when there is SocketError' do
|
|
192
|
+
let(:fake_http_resp_headers) {
|
|
193
|
+
{
|
|
194
|
+
":status" => "500",
|
|
195
|
+
"apns-id"=>"C6D65840-5E3F-785A-4D91-B97D305C12F6"
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
180
199
|
before(:each) do
|
|
181
200
|
expect(fake_client).to receive(:call_async) { raise(SocketError) }
|
|
182
201
|
end
|
|
@@ -201,6 +220,24 @@ describe 'APNs http2 adapter' do
|
|
|
201
220
|
notification = create_notification
|
|
202
221
|
Rpush.push
|
|
203
222
|
end
|
|
223
|
+
|
|
224
|
+
context 'when specific notification was delivered before request failed' do
|
|
225
|
+
let(:fake_http_resp_headers) {
|
|
226
|
+
{
|
|
227
|
+
":status" => "200",
|
|
228
|
+
"apns-id"=>"C6D65840-5E3F-785A-4D91-B97D305C12F6"
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
it 'fails but will not retry this notification' do
|
|
233
|
+
notification = create_notification
|
|
234
|
+
expect do
|
|
235
|
+
Rpush.push
|
|
236
|
+
notification.reload
|
|
237
|
+
end.to change(notification, :retries).by(0)
|
|
238
|
+
.and change(notification, :delivered).to(true)
|
|
239
|
+
end
|
|
240
|
+
end
|
|
204
241
|
end
|
|
205
242
|
|
|
206
243
|
context 'when any StandardError occurs' do
|
|
@@ -228,5 +265,65 @@ describe 'APNs http2 adapter' do
|
|
|
228
265
|
Rpush.push
|
|
229
266
|
end
|
|
230
267
|
end
|
|
268
|
+
|
|
269
|
+
context 'when waiting for requests to complete times out' do
|
|
270
|
+
let(:on_close) do
|
|
271
|
+
proc { |&block| @thread = Thread.new { sleep(0.01) } }
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
before(:each) do
|
|
275
|
+
@thread = nil
|
|
276
|
+
|
|
277
|
+
expect(fake_http2_request).
|
|
278
|
+
to receive(:on).with(:close), &on_close
|
|
279
|
+
|
|
280
|
+
expect(fake_client).to receive(:join) { @thread.join; raise(NetHttp2::AsyncRequestTimeout) }
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
it 'closes the client' do
|
|
284
|
+
create_notification
|
|
285
|
+
expect(fake_client).to receive(:close)
|
|
286
|
+
Rpush.push
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
it 'reflects :error' do
|
|
290
|
+
reflected_error = false
|
|
291
|
+
Rpush.reflect do |on|
|
|
292
|
+
on.error do |error|
|
|
293
|
+
reflected_error = true
|
|
294
|
+
expect(error).to be_kind_of(StandardError)
|
|
295
|
+
reflector.accept
|
|
296
|
+
end
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
notification = create_notification
|
|
300
|
+
Rpush.push
|
|
301
|
+
|
|
302
|
+
expect(reflected_error).to be true
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
it 'fails but retries delivery several times' do
|
|
306
|
+
notification = create_notification
|
|
307
|
+
expect do
|
|
308
|
+
Rpush.push
|
|
309
|
+
notification.reload
|
|
310
|
+
end.to change(notification, :retries)
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
context 'when specific notification was delivered before another async call failed' do
|
|
314
|
+
let(:on_close) do
|
|
315
|
+
proc { |&block| @thread = Thread.new { sleep(0.01); block.call } }
|
|
316
|
+
end
|
|
317
|
+
|
|
318
|
+
it 'fails but retries delivery several times' do
|
|
319
|
+
notification = create_notification
|
|
320
|
+
expect do
|
|
321
|
+
Rpush.push
|
|
322
|
+
notification.reload
|
|
323
|
+
end.to change(notification, :retries).by(0)
|
|
324
|
+
.and change(notification, :delivered).to(true)
|
|
325
|
+
end
|
|
326
|
+
end
|
|
327
|
+
end
|
|
231
328
|
end
|
|
232
329
|
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
require 'functional_spec_helper'
|
|
2
|
+
|
|
3
|
+
describe 'GCM priority' do
|
|
4
|
+
let(:app) { Rpush::Gcm::App.new }
|
|
5
|
+
let(:notification) { Rpush::Gcm::Notification.new }
|
|
6
|
+
let(:hydrated_notification) { Rpush::Gcm::Notification.find(notification.id) }
|
|
7
|
+
let(:response) { double(Net::HTTPResponse, code: 200) }
|
|
8
|
+
let(:http) { double(Net::HTTP::Persistent, request: response, shutdown: nil) }
|
|
9
|
+
let(:priority) { 'normal' }
|
|
10
|
+
|
|
11
|
+
before do
|
|
12
|
+
app.name = 'test'
|
|
13
|
+
app.auth_key = 'abc123'
|
|
14
|
+
app.save!
|
|
15
|
+
|
|
16
|
+
notification.app_id = app.id
|
|
17
|
+
notification.registration_ids = ['foo']
|
|
18
|
+
notification.data = { message: 'test' }
|
|
19
|
+
notification.priority = priority
|
|
20
|
+
notification.save!
|
|
21
|
+
|
|
22
|
+
allow(Net::HTTP::Persistent).to receive_messages(new: http)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'supports normal priority' do
|
|
26
|
+
expect(hydrated_notification.as_json['priority']).to eq('normal')
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
context 'high priority' do
|
|
30
|
+
let(:priority) { 'high' }
|
|
31
|
+
|
|
32
|
+
it 'supports high priority' do
|
|
33
|
+
expect(hydrated_notification.as_json['priority']).to eq('high')
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'does not add an error when receiving expected priority' do
|
|
38
|
+
expect(hydrated_notification.errors.messages[:priority]).to be_empty
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require 'functional_spec_helper'
|
|
2
|
+
|
|
3
|
+
describe 'Webpush' do
|
|
4
|
+
let(:code) { 201 }
|
|
5
|
+
let(:response) { instance_double('Net::HTTPResponse', code: code, body: '') }
|
|
6
|
+
let(:http) { instance_double('Net::HTTP::Persistent', request: response, shutdown: nil) }
|
|
7
|
+
let(:app) { Rpush::Webpush::App.create!(name: 'MyApp', vapid_keypair: VAPID_KEYPAIR) }
|
|
8
|
+
|
|
9
|
+
let(:device_reg) {
|
|
10
|
+
{ endpoint: 'https://webpush-provider.example.org/push/some-id',
|
|
11
|
+
expirationTime: nil,
|
|
12
|
+
keys: {'auth' => 'DgN9EBia1o057BdhCOGURA', 'p256dh' => 'BAtxJ--7vHq9IVm8utUB3peJ4lpxRqk1rukCIkVJOomS83QkCnrQ4EyYQsSaCRgy_c8XPytgXxuyAvRJdnTPK4A'} }
|
|
13
|
+
}
|
|
14
|
+
let(:notification) { Rpush::Webpush::Notification.create!(app: app, registration_ids: [device_reg], data: { message: 'test' }) }
|
|
15
|
+
|
|
16
|
+
before do
|
|
17
|
+
allow(Net::HTTP::Persistent).to receive_messages(new: http)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'deliveres a notification successfully' do
|
|
21
|
+
expect { Rpush.push }.to change { notification.reload.delivered }.to(true)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
context 'when delivery failed' do
|
|
25
|
+
let(:code) { 404 }
|
|
26
|
+
it 'marks a notification as failed' do
|
|
27
|
+
expect { Rpush.push }.to change { notification.reload.failed }.to(true)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
data/spec/spec_helper.rb
CHANGED
|
@@ -3,7 +3,7 @@ def client
|
|
|
3
3
|
(ENV['CLIENT'] || :active_record).to_sym
|
|
4
4
|
end
|
|
5
5
|
|
|
6
|
-
if !ENV['
|
|
6
|
+
if !ENV['CI'] || (ENV['CI'] && ENV['QUALITY'] == 'true')
|
|
7
7
|
begin
|
|
8
8
|
require './spec/support/simplecov_helper'
|
|
9
9
|
include SimpleCovHelper
|
|
@@ -46,6 +46,8 @@ path = File.join(File.dirname(__FILE__), 'support')
|
|
|
46
46
|
TEST_CERT = File.read(File.join(path, 'cert_without_password.pem'))
|
|
47
47
|
TEST_CERT_WITH_PASSWORD = File.read(File.join(path, 'cert_with_password.pem'))
|
|
48
48
|
|
|
49
|
+
VAPID_KEYPAIR = Webpush.generate_key.to_hash.merge(subject: 'rpush-test@example.org').to_json
|
|
50
|
+
|
|
49
51
|
def after_example_cleanup
|
|
50
52
|
Rpush.logger = nil
|
|
51
53
|
Rpush::Daemon.store = nil
|
|
@@ -6,14 +6,15 @@ SPEC_ADAPTER = ENV['ADAPTER'] || 'postgresql'
|
|
|
6
6
|
SPEC_ADAPTER = 'jdbc' + SPEC_ADAPTER if jruby
|
|
7
7
|
|
|
8
8
|
require 'yaml'
|
|
9
|
-
|
|
9
|
+
db_config_path = File.expand_path("config/database.yml", File.dirname(__FILE__))
|
|
10
|
+
db_config = YAML.load(ERB.new(File.read(db_config_path)).result)
|
|
10
11
|
|
|
11
12
|
if db_config[SPEC_ADAPTER].nil?
|
|
12
13
|
puts "No such adapter '#{SPEC_ADAPTER}'. Valid adapters are #{db_config.keys.join(', ')}."
|
|
13
14
|
exit 1
|
|
14
15
|
end
|
|
15
16
|
|
|
16
|
-
if ENV['
|
|
17
|
+
if ENV['CI']
|
|
17
18
|
db_config[SPEC_ADAPTER]['username'] = 'postgres'
|
|
18
19
|
else
|
|
19
20
|
require 'etc'
|
|
@@ -62,7 +63,7 @@ migrations = [
|
|
|
62
63
|
Rpush420Updates
|
|
63
64
|
]
|
|
64
65
|
|
|
65
|
-
unless ENV['
|
|
66
|
+
unless ENV['CI']
|
|
66
67
|
migrations.reverse_each do |m|
|
|
67
68
|
begin
|
|
68
69
|
m.down
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
postgresql:
|
|
4
4
|
adapter: postgresql
|
|
5
|
-
database: rpush_test
|
|
6
|
-
host: localhost
|
|
7
|
-
username: postgres
|
|
8
|
-
password:
|
|
5
|
+
database: <%= ENV.fetch('POSTGRES_DB', 'rpush_test') %>
|
|
6
|
+
host: <%= ENV.fetch('POSTGRES_HOST', 'localhost') %>
|
|
7
|
+
username: <%= ENV.fetch('POSTGRES_USER', 'postgres') %>
|
|
8
|
+
password: <%= ENV.fetch('PGPASSWORD', '') %>
|
|
9
9
|
|
|
10
10
|
jdbcpostgresql:
|
|
11
11
|
adapter: jdbcpostgresql
|
|
@@ -10,7 +10,7 @@ module SimpleCovHelper
|
|
|
10
10
|
|
|
11
11
|
formatters = [SimpleCov::Formatter::QualityFormatter]
|
|
12
12
|
|
|
13
|
-
if ENV['
|
|
13
|
+
if ENV['CI']
|
|
14
14
|
require 'codeclimate-test-reporter'
|
|
15
15
|
|
|
16
16
|
if CodeClimate::TestReporter.run?
|
|
@@ -18,7 +18,7 @@ module SimpleCovHelper
|
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
formatter SimpleCov::Formatter::MultiFormatter
|
|
21
|
+
formatter SimpleCov::Formatter::MultiFormatter.new(formatters)
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
end
|
|
@@ -1,58 +1,6 @@
|
|
|
1
1
|
require 'unit_spec_helper'
|
|
2
2
|
|
|
3
3
|
describe Rpush::Client::ActiveRecord::Adm::App do
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
it 'should be valid if properly instantiated' do
|
|
8
|
-
expect(subject).to be_valid
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it 'should be invalid if name' do
|
|
12
|
-
subject.name = nil
|
|
13
|
-
expect(subject).not_to be_valid
|
|
14
|
-
expect(subject.errors[:name]).to eq ["can't be blank"]
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it 'should be invalid if name is not unique within scope' do
|
|
18
|
-
subject.name = existing_app.name
|
|
19
|
-
expect(subject).not_to be_valid
|
|
20
|
-
expect(subject.errors[:name]).to eq ["has already been taken"]
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it 'should be invalid if missing client_id' do
|
|
24
|
-
subject.client_id = nil
|
|
25
|
-
expect(subject).not_to be_valid
|
|
26
|
-
expect(subject.errors[:client_id]).to eq ["can't be blank"]
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it 'should be invalid if missing client_secret' do
|
|
30
|
-
subject.client_secret = nil
|
|
31
|
-
expect(subject).not_to be_valid
|
|
32
|
-
expect(subject.errors[:client_secret]).to eq ["can't be blank"]
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
describe '#access_token_expired?' do
|
|
36
|
-
before(:each) do
|
|
37
|
-
Timecop.freeze(Time.now)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
after do
|
|
41
|
-
Timecop.return
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it 'should return true if access_token_expiration is nil' do
|
|
45
|
-
expect(subject.access_token_expired?).to eq(true)
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
it 'should return true if expired' do
|
|
49
|
-
subject.access_token_expiration = Time.now - 5.minutes
|
|
50
|
-
expect(subject.access_token_expired?).to eq(true)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
it 'should return false if not expired' do
|
|
54
|
-
subject.access_token_expiration = Time.now + 5.minutes
|
|
55
|
-
expect(subject.access_token_expired?).to eq(false)
|
|
56
|
-
end
|
|
57
|
-
end
|
|
4
|
+
it_behaves_like 'Rpush::Client::Adm::App'
|
|
5
|
+
it_behaves_like 'Rpush::Client::ActiveRecord::App'
|
|
58
6
|
end if active_record?
|
|
@@ -1,43 +1,6 @@
|
|
|
1
1
|
require 'unit_spec_helper'
|
|
2
|
-
require 'unit/notification_shared.rb'
|
|
3
2
|
|
|
4
3
|
describe Rpush::Client::ActiveRecord::Adm::Notification do
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
let(:app) { Rpush::Client::ActiveRecord::Adm::App.create!(name: 'test', client_id: 'CLIENT_ID', client_secret: 'CLIENT_SECRET') }
|
|
8
|
-
let(:notification_class) { Rpush::Client::ActiveRecord::Adm::Notification }
|
|
9
|
-
let(:notification) { notification_class.new }
|
|
10
|
-
|
|
11
|
-
it "has a 'data' payload limit of 6144 bytes" do
|
|
12
|
-
notification.data = { key: "a" * 6144 }
|
|
13
|
-
expect(notification.valid?).to eq(false)
|
|
14
|
-
expect(notification.errors[:base]).to eq ["Notification payload data cannot be larger than 6144 bytes."]
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it 'limits the number of registration ids to 100' do
|
|
18
|
-
notification.registration_ids = ['a'] * (100 + 1)
|
|
19
|
-
expect(notification.valid?).to eq(false)
|
|
20
|
-
expect(notification.errors[:base]).to eq ["Number of registration_ids cannot be larger than 100."]
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it 'validates data can be blank if collapse_key is set' do
|
|
24
|
-
notification.app = app
|
|
25
|
-
notification.registration_ids = 'a'
|
|
26
|
-
notification.collapse_key = 'test'
|
|
27
|
-
notification.data = nil
|
|
28
|
-
expect(notification.valid?).to eq(true)
|
|
29
|
-
expect(notification.errors[:data]).to be_empty
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
it 'validates data is present if collapse_key is not set' do
|
|
33
|
-
notification.collapse_key = nil
|
|
34
|
-
notification.data = nil
|
|
35
|
-
expect(notification.valid?).to eq(false)
|
|
36
|
-
expect(notification.errors[:data]).to eq ['must be set unless collapse_key is specified']
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
it 'includes expiresAfter in the payload' do
|
|
40
|
-
notification.expiry = 100
|
|
41
|
-
expect(notification.as_json['expiresAfter']).to eq 100
|
|
42
|
-
end
|
|
4
|
+
it_behaves_like 'Rpush::Client::Adm::Notification'
|
|
5
|
+
it_behaves_like 'Rpush::Client::ActiveRecord::Notification'
|
|
43
6
|
end if active_record?
|
|
@@ -1,29 +1,6 @@
|
|
|
1
1
|
require 'unit_spec_helper'
|
|
2
2
|
|
|
3
|
-
describe Rpush::Client::ActiveRecord::App do
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
app.valid?
|
|
7
|
-
expect(app.errors[:certificate]).to eq ['value must contain a certificate and a private key.']
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
it 'validates a certificate without a password' do
|
|
11
|
-
app = Rpush::Client::ActiveRecord::Apns::App.new name: 'test', environment: 'development', certificate: TEST_CERT
|
|
12
|
-
app.valid?
|
|
13
|
-
expect(app.errors[:certificate]).to eq []
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it 'validates a certificate with a password' do
|
|
17
|
-
app = Rpush::Client::ActiveRecord::Apns::App.new name: 'test', environment: 'development',
|
|
18
|
-
certificate: TEST_CERT_WITH_PASSWORD, password: 'fubar'
|
|
19
|
-
app.valid?
|
|
20
|
-
expect(app.errors[:certificate]).to eq []
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it 'validates a certificate with an incorrect password' do
|
|
24
|
-
app = Rpush::Client::ActiveRecord::Apns::App.new name: 'test', environment: 'development',
|
|
25
|
-
certificate: TEST_CERT_WITH_PASSWORD, password: 'incorrect'
|
|
26
|
-
app.valid?
|
|
27
|
-
expect(app.errors[:certificate]).to eq ['value must contain a certificate and a private key.']
|
|
28
|
-
end
|
|
3
|
+
describe Rpush::Client::ActiveRecord::Apns::App do
|
|
4
|
+
it_behaves_like 'Rpush::Client::Apns::App'
|
|
5
|
+
it_behaves_like 'Rpush::Client::ActiveRecord::App'
|
|
29
6
|
end if active_record?
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
require 'unit_spec_helper'
|
|
2
2
|
|
|
3
3
|
describe Rpush::Client::ActiveRecord::Apns::Feedback do
|
|
4
|
-
|
|
5
|
-
notification = Rpush::Client::ActiveRecord::Apns::Feedback.new(device_token: "{$%^&*()}")
|
|
6
|
-
expect(notification.valid?).to be_falsey
|
|
7
|
-
expect(notification.errors[:device_token]).to include('is invalid')
|
|
8
|
-
end
|
|
4
|
+
it_behaves_like 'Rpush::Client::Apns::Feedback'
|
|
9
5
|
end if active_record?
|