rpush 4.2.0 → 7.0.1
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -1,59 +1,6 @@
|
|
1
1
|
require 'unit_spec_helper'
|
2
|
-
require 'unit/notification_shared.rb'
|
3
2
|
|
4
3
|
describe Rpush::Client::ActiveRecord::Pushy::Notification do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
it_behaves_like 'an Notification subclass'
|
9
|
-
|
10
|
-
describe 'validates' do
|
11
|
-
let(:app) { Rpush::Client::ActiveRecord::Pushy::App.create!(name: 'MyApp', api_key: 'my_api_key') }
|
12
|
-
|
13
|
-
describe 'data' do
|
14
|
-
subject { described_class.new(app: app, registration_ids: ['id']) }
|
15
|
-
it 'validates presence' do
|
16
|
-
is_expected.not_to be_valid
|
17
|
-
expect(subject.errors[:data]).to eq ["can't be blank"]
|
18
|
-
end
|
19
|
-
|
20
|
-
it "has a 'data' payload limit of 4096 bytes" do
|
21
|
-
subject.data = { message: 'a' * 4096 }
|
22
|
-
is_expected.not_to be_valid
|
23
|
-
expected_errors = ["Notification payload data cannot be larger than 4096 bytes."]
|
24
|
-
expect(subject.errors[:base]).to eq expected_errors
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe 'registration_ids' do
|
29
|
-
subject { described_class.new(app: app, data: { message: 'test' }) }
|
30
|
-
it 'validates presence' do
|
31
|
-
is_expected.not_to be_valid
|
32
|
-
expect(subject.errors[:registration_ids]).to eq ["can't be blank"]
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'limits the number of registration ids to 1000' do
|
36
|
-
subject.registration_ids = ['a'] * (1000 + 1)
|
37
|
-
is_expected.not_to be_valid
|
38
|
-
expected_errors = ["Number of registration_ids cannot be larger than 1000."]
|
39
|
-
expect(subject.errors[:base]).to eq expected_errors
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe 'time_to_live' do
|
44
|
-
subject { described_class.new(app: app, data: { message: 'test' }, registration_ids: ['id']) }
|
45
|
-
|
46
|
-
it 'should be > 0' do
|
47
|
-
subject.time_to_live = -1
|
48
|
-
is_expected.not_to be_valid
|
49
|
-
expect(subject.errors[:time_to_live]).to eq ['must be greater than 0']
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'should be <= 1.year.seconds' do
|
53
|
-
subject.time_to_live = 2.years.seconds.to_i
|
54
|
-
is_expected.not_to be_valid
|
55
|
-
expect(subject.errors[:time_to_live]).to eq ['The maximum value is 1 year']
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
4
|
+
it_behaves_like 'Rpush::Client::Pushy::Notification'
|
5
|
+
it_behaves_like 'Rpush::Client::ActiveRecord::Notification'
|
59
6
|
end if active_record?
|
@@ -0,0 +1,14 @@
|
|
1
|
+
shared_examples_for 'Rpush::Client::ActiveRecord::App' do
|
2
|
+
it 'validates the uniqueness of name within type and environment' do
|
3
|
+
Rpush::Apns::App.create!(name: 'test', environment: 'production', certificate: TEST_CERT)
|
4
|
+
app = Rpush::Apns::App.new(name: 'test', environment: 'production', certificate: TEST_CERT)
|
5
|
+
expect(app.valid?).to eq(false)
|
6
|
+
expect(app.errors[:name]).to eq ['has already been taken']
|
7
|
+
|
8
|
+
app = Rpush::Apns::App.new(name: 'test', environment: 'development', certificate: TEST_CERT)
|
9
|
+
expect(app.valid?).to eq(true)
|
10
|
+
|
11
|
+
app = Rpush::Gcm::App.new(name: 'test', environment: 'production', auth_key: TEST_CERT)
|
12
|
+
expect(app.valid?).to eq(true)
|
13
|
+
end
|
14
|
+
end
|
@@ -1,16 +1,21 @@
|
|
1
|
-
shared_examples_for '
|
1
|
+
shared_examples_for 'Rpush::Client::ActiveRecord::Notification' do
|
2
|
+
let(:notification) { described_class.new }
|
3
|
+
|
4
|
+
it 'allows assignment of a single registration ID' do
|
5
|
+
notification.registration_ids = 'a'
|
6
|
+
expect(notification.registration_ids).to eq ['a']
|
7
|
+
end
|
8
|
+
|
2
9
|
describe 'when assigning data for the device' do
|
3
10
|
before { allow(Rpush::Deprecation).to receive(:warn) }
|
4
11
|
|
5
12
|
it 'calls MultiJson.dump when multi_json responds to :dump' do
|
6
|
-
notification = notification_class.new
|
7
13
|
allow(MultiJson).to receive(:respond_to?).with(:dump).and_return(true)
|
8
14
|
expect(MultiJson).to receive(:dump).with(any_args)
|
9
15
|
notification.data = { pirates: 1 }
|
10
16
|
end
|
11
17
|
|
12
18
|
it 'calls MultiJson.encode when multi_json does not respond to :dump' do
|
13
|
-
notification = notification_class.new
|
14
19
|
allow(MultiJson).to receive(:respond_to?).with(:dump).and_return(false)
|
15
20
|
expect(MultiJson).to receive(:encode).with(any_args)
|
16
21
|
notification.data = { ninjas: 1 }
|
@@ -23,12 +28,12 @@ shared_examples_for 'an Notification subclass' do
|
|
23
28
|
end
|
24
29
|
|
25
30
|
it 'encodes the given Hash as JSON' do
|
26
|
-
notification.data = { hi: 'mom'}
|
31
|
+
notification.data = { hi: 'mom' }
|
27
32
|
expect(notification.read_attribute(:data)).to eq('{"hi":"mom"}')
|
28
33
|
end
|
29
34
|
|
30
35
|
it 'decodes the JSON when using the reader method' do
|
31
|
-
notification.data = { hi: 'mom'}
|
36
|
+
notification.data = { hi: 'mom' }
|
32
37
|
expect(notification.data).to eq('hi' => 'mom')
|
33
38
|
end
|
34
39
|
end
|
@@ -41,12 +46,12 @@ shared_examples_for 'an Notification subclass' do
|
|
41
46
|
end
|
42
47
|
|
43
48
|
it 'encodes the given Hash as JSON' do
|
44
|
-
notification.notification = { hi: 'dad'}
|
49
|
+
notification.notification = { hi: 'dad' }
|
45
50
|
expect(notification.read_attribute(:notification)).to eq('{"hi":"dad"}')
|
46
51
|
end
|
47
52
|
|
48
53
|
it 'decodes the JSON when using the reader method' do
|
49
|
-
notification.notification = { hi: 'dad'}
|
54
|
+
notification.notification = { hi: 'dad' }
|
50
55
|
expect(notification.notification).to eq('hi' => 'dad')
|
51
56
|
end
|
52
57
|
end
|
@@ -1,15 +1,5 @@
|
|
1
1
|
require 'unit_spec_helper'
|
2
2
|
|
3
3
|
describe Rpush::Client::ActiveRecord::Wns::BadgeNotification do
|
4
|
-
|
5
|
-
notif = Rpush::Client::ActiveRecord::Wns::BadgeNotification.new
|
6
|
-
notif.app = Rpush::Client::ActiveRecord::Wns::App.new(name: "aname")
|
7
|
-
notif.uri = 'https://db5.notify.windows.com/?token=TOKEN'
|
8
|
-
notif.badge = 42
|
9
|
-
notif
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'should allow a notification without data' do
|
13
|
-
expect(notification.valid?).to be(true)
|
14
|
-
end
|
4
|
+
it_behaves_like 'Rpush::Client::Wns::BadgeNotification'
|
15
5
|
end if active_record?
|
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'unit_spec_helper'
|
2
2
|
|
3
3
|
describe Rpush::Client::ActiveRecord::Wns::RawNotification do
|
4
|
+
it_behaves_like 'Rpush::Client::Wns::RawNotification'
|
4
5
|
let(:notification) do
|
5
|
-
notif =
|
6
|
-
notif.app = Rpush::
|
6
|
+
notif = described_class.new
|
7
|
+
notif.app = Rpush::Wns::App.create!(name: "MyApp", client_id: "someclient", client_secret: "somesecret")
|
7
8
|
notif.uri = 'https://db5.notify.windows.com/?token=TOKEN'
|
8
9
|
notif.data = { foo: 'foo', bar: 'bar' }
|
9
10
|
notif
|
@@ -13,14 +14,4 @@ describe Rpush::Client::ActiveRecord::Wns::RawNotification do
|
|
13
14
|
allow(notification).to receive(:payload_data_size) { 5121 }
|
14
15
|
expect(notification.valid?).to be(false)
|
15
16
|
end
|
16
|
-
|
17
|
-
it 'allows exact payload of 5 KB' do
|
18
|
-
allow(notification).to receive(:payload_data_size) { 5120 }
|
19
|
-
expect(notification.valid?).to be(true)
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'allows the size of payload under 5 KB' do
|
23
|
-
allow(notification).to receive(:payload_data_size) { 5119 }
|
24
|
-
expect(notification.valid?).to be(true)
|
25
|
-
end
|
26
17
|
end if active_record?
|
@@ -1,21 +1,6 @@
|
|
1
1
|
require 'unit_spec_helper'
|
2
|
-
require 'unit/notification_shared.rb'
|
3
2
|
|
4
3
|
describe Rpush::Client::ActiveRecord::Wpns::Notification do
|
5
|
-
|
6
|
-
|
7
|
-
let(:notification_class) { Rpush::Client::ActiveRecord::Wpns::Notification }
|
8
|
-
let(:notification) { notification_class.new }
|
9
|
-
|
10
|
-
it "should have an url in the uri parameter" do
|
11
|
-
notification = Rpush::Client::ActiveRecord::Wpns::Notification.new(uri: "somthing")
|
12
|
-
notification.valid?
|
13
|
-
expect(notification.errors[:uri]).to include('is invalid')
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should be invalid if there's no data" do
|
17
|
-
notification = Rpush::Client::ActiveRecord::Wpns::Notification.new(data: {})
|
18
|
-
notification.valid?
|
19
|
-
expect(notification.errors[:data]).to include("can't be blank")
|
20
|
-
end
|
4
|
+
it_behaves_like 'Rpush::Client::Wpns::Notification'
|
5
|
+
it_behaves_like 'Rpush::Client::ActiveRecord::Notification'
|
21
6
|
end if active_record?
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: US-ASCII
|
2
|
+
|
3
|
+
require "unit_spec_helper"
|
4
|
+
|
5
|
+
describe Rpush::Client::Redis::Apns::Notification do
|
6
|
+
it_behaves_like 'Rpush::Client::Apns::Notification'
|
7
|
+
|
8
|
+
it "should validate the length of the binary conversion of the notification" do
|
9
|
+
notification = described_class.new
|
10
|
+
notification.app = Rpush::Apns2::App.create(name: 'test', environment: 'development', certificate: TEST_CERT)
|
11
|
+
notification.device_token = "a" * 108
|
12
|
+
notification.alert = ""
|
13
|
+
|
14
|
+
notification.alert << "a" until notification.payload.bytesize == 2048
|
15
|
+
expect(notification.valid?).to be_truthy
|
16
|
+
expect(notification.errors[:base]).to be_empty
|
17
|
+
|
18
|
+
notification.alert << "a"
|
19
|
+
expect(notification.valid?).to be_falsey
|
20
|
+
expect(notification.errors[:base].include?("APN notification cannot be larger than 2048 bytes. Try condensing your alert and device attributes.")).to be_truthy
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should default the sound to 'default'" do
|
24
|
+
notification = described_class.new
|
25
|
+
expect(notification.sound).to eq('default')
|
26
|
+
end
|
27
|
+
|
28
|
+
# skipping these tests because data= for redis doesn't merge existing data
|
29
|
+
xit 'does not overwrite the mutable-content flag when setting attributes for the device' do
|
30
|
+
notification.mutable_content = true
|
31
|
+
notification.data = { 'hi' => 'mom' }
|
32
|
+
expect(notification.as_json['aps']['mutable-content']).to eq 1
|
33
|
+
expect(notification.as_json['hi']).to eq 'mom'
|
34
|
+
end
|
35
|
+
|
36
|
+
xit 'does not overwrite the content-available flag when setting attributes for the device' do
|
37
|
+
notification.content_available = true
|
38
|
+
notification.data = { 'hi' => 'mom' }
|
39
|
+
expect(notification.as_json['aps']['content-available']).to eq 1
|
40
|
+
expect(notification.as_json['hi']).to eq 'mom'
|
41
|
+
end
|
42
|
+
|
43
|
+
# redis does not use alert_is_json - unclear if that is a bug or desired behavior
|
44
|
+
xit 'does confuse a JSON looking string as JSON if the alert_is_json attribute is not present' do
|
45
|
+
notification = described_class.new
|
46
|
+
allow(notification).to receive_messages(has_attribute?: false)
|
47
|
+
notification.alert = "{\"one\":2}"
|
48
|
+
expect(notification.alert).to eq('one' => 2)
|
49
|
+
end
|
50
|
+
end if redis?
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: US-ASCII
|
2
|
+
|
3
|
+
require "unit_spec_helper"
|
4
|
+
|
5
|
+
describe Rpush::Client::Redis::Apns2::Notification do
|
6
|
+
it_behaves_like 'Rpush::Client::Apns::Notification'
|
7
|
+
|
8
|
+
it "should validate the length of the binary conversion of the notification" do
|
9
|
+
notification = described_class.new
|
10
|
+
notification.app = Rpush::Apns2::App.create(name: 'test', environment: 'development', certificate: TEST_CERT)
|
11
|
+
notification.device_token = "a" * 108
|
12
|
+
notification.alert = ""
|
13
|
+
|
14
|
+
notification.alert << "a" until notification.payload.bytesize == 4096
|
15
|
+
expect(notification.valid?).to be_truthy
|
16
|
+
expect(notification.errors[:base]).to be_empty
|
17
|
+
|
18
|
+
notification.alert << "a"
|
19
|
+
expect(notification.valid?).to be_falsey
|
20
|
+
expect(notification.errors[:base].include?("APN notification cannot be larger than 4096 bytes. Try condensing your alert and device attributes.")).to be_truthy
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should default the sound to 'default'" do
|
24
|
+
notification = described_class.new
|
25
|
+
expect(notification.sound).to eq('default')
|
26
|
+
end
|
27
|
+
|
28
|
+
# skipping these tests because data= for redis doesn't merge existing data
|
29
|
+
xit 'does not overwrite the mutable-content flag when setting attributes for the device' do
|
30
|
+
notification.mutable_content = true
|
31
|
+
notification.data = { 'hi' => 'mom' }
|
32
|
+
expect(notification.as_json['aps']['mutable-content']).to eq 1
|
33
|
+
expect(notification.as_json['hi']).to eq 'mom'
|
34
|
+
end
|
35
|
+
|
36
|
+
xit 'does not overwrite the content-available flag when setting attributes for the device' do
|
37
|
+
notification.content_available = true
|
38
|
+
notification.data = { 'hi' => 'mom' }
|
39
|
+
expect(notification.as_json['aps']['content-available']).to eq 1
|
40
|
+
expect(notification.as_json['hi']).to eq 'mom'
|
41
|
+
end
|
42
|
+
|
43
|
+
# redis does not use alert_is_json - unclear if that is a bug or desired behavior
|
44
|
+
xit 'does confuse a JSON looking string as JSON if the alert_is_json attribute is not present' do
|
45
|
+
notification = described_class.new
|
46
|
+
allow(notification).to receive_messages(has_attribute?: false)
|
47
|
+
notification.alert = "{\"one\":2}"
|
48
|
+
expect(notification.alert).to eq('one' => 2)
|
49
|
+
end
|
50
|
+
end if redis?
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "unit_spec_helper"
|
2
|
+
|
3
|
+
describe Rpush::Client::Redis::Apnsp8::Notification do
|
4
|
+
after do
|
5
|
+
Rpush::Apnsp8::App.all.select { |a| a.environment == "development" && a.apn_key == "1" }.each(&:destroy)
|
6
|
+
end
|
7
|
+
|
8
|
+
it_behaves_like "Rpush::Client::Apns::Notification"
|
9
|
+
|
10
|
+
it "should validate the length of the binary conversion of the notification", :aggregate_failures do
|
11
|
+
notification = described_class.new
|
12
|
+
notification.app = Rpush::Apnsp8::App.create(apn_key: "1",
|
13
|
+
apn_key_id: "2",
|
14
|
+
name: 'test',
|
15
|
+
environment: 'development',
|
16
|
+
team_id: "3",
|
17
|
+
bundle_id: "4")
|
18
|
+
notification.device_token = "a" * 108
|
19
|
+
notification.alert = ""
|
20
|
+
|
21
|
+
notification.alert << "a" until notification.payload.bytesize == 4096
|
22
|
+
expect(notification.valid?).to be_truthy
|
23
|
+
expect(notification.errors[:base]).to be_empty
|
24
|
+
|
25
|
+
notification.alert << "a"
|
26
|
+
expect(notification.valid?).to be_falsey
|
27
|
+
expect(notification.errors[:base].include?("APN notification cannot be larger than 4096 bytes. Try condensing your alert and device attributes.")).to be_truthy
|
28
|
+
end
|
29
|
+
end if redis?
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'unit_spec_helper'
|
2
|
+
|
3
|
+
describe Rpush::Client::Redis::Wns::RawNotification do
|
4
|
+
it_behaves_like 'Rpush::Client::Wns::RawNotification'
|
5
|
+
|
6
|
+
subject(:notification) do
|
7
|
+
notif = described_class.new
|
8
|
+
notif.app = Rpush::Wns::App.create!(name: "MyApp", client_id: "someclient", client_secret: "somesecret")
|
9
|
+
notif.uri = 'https://db5.notify.windows.com/?token=TOKEN'
|
10
|
+
notif.data = { foo: 'foo', bar: 'bar' }
|
11
|
+
notif
|
12
|
+
end
|
13
|
+
|
14
|
+
# This fails because the length validation is only on active record
|
15
|
+
# Attempting to move to active model in rails 6 fails
|
16
|
+
# because wns_notification#as_json is not defined
|
17
|
+
# and the active_model#as_json version results in a stack level too deep error
|
18
|
+
xit 'does not allow the size of payload over 5 KB' do
|
19
|
+
allow(notification).to receive(:payload_data_size) { 5121 }
|
20
|
+
expect(notification.valid?).to be(false)
|
21
|
+
end
|
22
|
+
end if redis?
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'unit_spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'Rpush::Client::Adm::App' do
|
4
|
+
subject { described_class.new(name: 'test', environment: 'development', client_id: 'CLIENT_ID', client_secret: 'CLIENT_SECRET') }
|
5
|
+
|
6
|
+
it 'should be valid if properly instantiated' do
|
7
|
+
expect(subject).to be_valid
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should be invalid if name' do
|
11
|
+
subject.name = nil
|
12
|
+
expect(subject).not_to be_valid
|
13
|
+
expect(subject.errors[:name]).to eq ["can't be blank"]
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should be invalid if missing client_id' do
|
17
|
+
subject.client_id = nil
|
18
|
+
expect(subject).not_to be_valid
|
19
|
+
expect(subject.errors[:client_id]).to eq ["can't be blank"]
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should be invalid if missing client_secret' do
|
23
|
+
subject.client_secret = nil
|
24
|
+
expect(subject).not_to be_valid
|
25
|
+
expect(subject.errors[:client_secret]).to eq ["can't be blank"]
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#access_token_expired?' do
|
29
|
+
before(:each) do
|
30
|
+
Timecop.freeze(Time.now)
|
31
|
+
end
|
32
|
+
|
33
|
+
after do
|
34
|
+
Timecop.return
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should return true if access_token_expiration is nil' do
|
38
|
+
expect(subject.access_token_expired?).to eq(true)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should return true if expired' do
|
42
|
+
subject.access_token_expiration = Time.now - 5.minutes
|
43
|
+
expect(subject.access_token_expired?).to eq(true)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should return false if not expired' do
|
47
|
+
subject.access_token_expiration = Time.now + 5.minutes
|
48
|
+
expect(subject.access_token_expired?).to eq(false)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'unit_spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'Rpush::Client::Adm::Notification' do
|
4
|
+
let(:app) { Rpush::Adm::App.create!(name: 'test', client_id: 'CLIENT_ID', client_secret: 'CLIENT_SECRET') }
|
5
|
+
let(:notification) { described_class.new }
|
6
|
+
|
7
|
+
it "has a 'data' payload limit of 6144 bytes" do
|
8
|
+
notification.data = { key: "a" * 6144 }
|
9
|
+
expect(notification.valid?).to eq(false)
|
10
|
+
expect(notification.errors[:base]).to eq ["Notification payload data cannot be larger than 6144 bytes."]
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'limits the number of registration ids to 100' do
|
14
|
+
notification.registration_ids = ['a'] * (100 + 1)
|
15
|
+
expect(notification.valid?).to eq(false)
|
16
|
+
expect(notification.errors[:base]).to eq ["Number of registration_ids cannot be larger than 100."]
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'validates data can be blank if collapse_key is set' do
|
20
|
+
notification.app = app
|
21
|
+
notification.registration_ids = ['a']
|
22
|
+
notification.collapse_key = 'test'
|
23
|
+
notification.data = nil
|
24
|
+
expect(notification.valid?).to eq(true)
|
25
|
+
expect(notification.errors[:data]).to be_empty
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'validates data is present if collapse_key is not set' do
|
29
|
+
notification.collapse_key = nil
|
30
|
+
notification.data = nil
|
31
|
+
expect(notification.valid?).to eq(false)
|
32
|
+
expect(notification.errors[:data]).to eq ['must be set unless collapse_key is specified']
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'includes expiresAfter in the payload' do
|
36
|
+
notification.expiry = 100
|
37
|
+
expect(notification.as_json['expiresAfter']).to eq 100
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'unit_spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'Rpush::Client::Apns::App' do
|
4
|
+
it 'does not validate an app with an invalid certificate' do
|
5
|
+
app = described_class.new(name: 'test', environment: 'development', certificate: 'foo')
|
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 = described_class.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 = described_class.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 = described_class.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
|
29
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'unit_spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'Rpush::Client::Apns::Feedback' do
|
4
|
+
it 'validates the format of the device_token' do
|
5
|
+
notification = described_class.new(device_token: "{$%^&*()}")
|
6
|
+
expect(notification.valid?).to be_falsey
|
7
|
+
expect(notification.errors[:device_token]).to include('is invalid')
|
8
|
+
end
|
9
|
+
end
|