rpush 1.0.0-java → 2.0.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +37 -22
- data/bin/rpush +13 -4
- data/lib/generators/rpush_generator.rb +2 -0
- data/lib/generators/templates/add_adm.rb +5 -5
- data/lib/generators/templates/add_alert_is_json_to_rapns_notifications.rb +1 -1
- 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 +32 -32
- data/lib/generators/templates/add_rpush.rb +67 -67
- data/lib/generators/templates/add_wpns.rb +2 -2
- data/lib/generators/templates/create_rapns_apps.rb +5 -5
- data/lib/generators/templates/create_rapns_feedback.rb +2 -2
- data/lib/generators/templates/create_rapns_notifications.rb +15 -15
- data/lib/generators/templates/rpush.rb +28 -7
- data/lib/generators/templates/rpush_2_0_0_updates.rb +42 -0
- data/lib/rpush/client/active_model/adm/app.rb +23 -0
- data/lib/rpush/client/active_model/adm/data_validator.rb +14 -0
- data/lib/rpush/client/active_model/adm/notification.rb +28 -0
- data/lib/rpush/client/active_model/apns/app.rb +37 -0
- data/lib/rpush/client/active_model/apns/binary_notification_validator.rb +16 -0
- data/lib/rpush/client/active_model/apns/device_token_format_validator.rb +14 -0
- data/lib/rpush/client/active_model/apns/notification.rb +90 -0
- data/lib/rpush/client/active_model/gcm/app.rb +19 -0
- data/lib/rpush/client/active_model/gcm/expiry_collapse_key_mutual_inclusion_validator.rb +14 -0
- data/lib/rpush/client/active_model/gcm/notification.rb +31 -0
- data/lib/rpush/client/active_model/notification.rb +26 -0
- data/lib/rpush/client/active_model/payload_data_size_validator.rb +13 -0
- data/lib/rpush/client/active_model/registration_ids_count_validator.rb +13 -0
- data/lib/rpush/client/active_model/wpns/app.rb +13 -0
- data/lib/rpush/client/active_model/wpns/notification.rb +17 -0
- data/lib/rpush/client/active_model.rb +21 -0
- data/lib/rpush/client/active_record/adm/app.rb +11 -0
- data/lib/rpush/client/active_record/adm/notification.rb +11 -0
- data/lib/rpush/client/active_record/apns/app.rb +11 -0
- data/lib/rpush/client/active_record/apns/feedback.rb +22 -0
- data/lib/rpush/client/active_record/apns/notification.rb +46 -0
- data/lib/rpush/client/active_record/app.rb +17 -0
- data/lib/rpush/client/active_record/gcm/app.rb +11 -0
- data/lib/rpush/client/active_record/gcm/notification.rb +11 -0
- data/lib/rpush/client/active_record/notification.rb +38 -0
- data/lib/rpush/client/active_record/wpns/app.rb +11 -0
- data/lib/rpush/client/active_record/wpns/notification.rb +11 -0
- data/lib/rpush/client/active_record.rb +19 -0
- data/lib/rpush/client/redis/adm/app.rb +14 -0
- data/lib/rpush/client/redis/adm/notification.rb +11 -0
- data/lib/rpush/client/redis/apns/app.rb +11 -0
- data/lib/rpush/client/redis/apns/feedback.rb +20 -0
- data/lib/rpush/client/redis/apns/notification.rb +11 -0
- data/lib/rpush/client/redis/app.rb +24 -0
- data/lib/rpush/client/redis/gcm/app.rb +11 -0
- data/lib/rpush/client/redis/gcm/notification.rb +11 -0
- data/lib/rpush/client/redis/notification.rb +68 -0
- data/lib/rpush/client/redis/wpns/app.rb +11 -0
- data/lib/rpush/client/redis/wpns/notification.rb +11 -0
- data/lib/rpush/client/redis.rb +35 -0
- data/lib/rpush/configuration.rb +27 -6
- data/lib/rpush/daemon/adm/delivery.rb +56 -55
- data/lib/rpush/daemon/apns/delivery.rb +20 -44
- data/lib/rpush/daemon/apns/feedback_receiver.rb +11 -8
- data/lib/rpush/daemon/apns.rb +6 -5
- data/lib/rpush/daemon/app_runner.rb +103 -99
- data/lib/rpush/daemon/batch.rb +54 -40
- data/lib/rpush/daemon/delivery.rb +13 -3
- data/lib/rpush/daemon/delivery_error.rb +10 -2
- data/lib/rpush/daemon/dispatcher/apns_tcp.rb +114 -0
- data/lib/rpush/daemon/dispatcher/http.rb +3 -3
- data/lib/rpush/daemon/dispatcher/tcp.rb +3 -3
- data/lib/rpush/daemon/dispatcher_loop.rb +37 -23
- data/lib/rpush/daemon/errors.rb +18 -0
- data/lib/rpush/daemon/feeder.rb +28 -39
- data/lib/rpush/daemon/gcm/delivery.rb +19 -20
- data/lib/rpush/daemon/interruptible_sleep.rb +26 -45
- data/lib/rpush/daemon/loggable.rb +2 -4
- data/lib/rpush/daemon/proc_title.rb +16 -0
- data/lib/rpush/daemon/queue_payload.rb +12 -0
- data/lib/rpush/daemon/reflectable.rb +3 -5
- data/lib/rpush/daemon/retry_header_parser.rb +6 -6
- data/lib/rpush/daemon/retryable_error.rb +2 -0
- data/lib/rpush/daemon/ring_buffer.rb +16 -0
- data/lib/rpush/daemon/service_config_methods.rb +23 -7
- data/lib/rpush/daemon/signal_handler.rb +56 -0
- data/lib/rpush/daemon/store/active_record/reconnectable.rb +21 -17
- data/lib/rpush/daemon/store/active_record.rb +71 -38
- data/lib/rpush/daemon/store/interface.rb +19 -0
- data/lib/rpush/daemon/store/redis.rb +149 -0
- data/lib/rpush/daemon/string_helpers.rb +15 -0
- data/lib/rpush/daemon/synchronizer.rb +60 -0
- data/lib/rpush/daemon/tcp_connection.rb +6 -11
- data/lib/rpush/daemon/wpns/delivery.rb +21 -30
- data/lib/rpush/daemon.rb +40 -60
- data/lib/rpush/deprecatable.rb +4 -3
- data/lib/rpush/deprecation.rb +7 -10
- data/lib/rpush/embed.rb +8 -3
- data/lib/rpush/logger.rb +11 -15
- data/lib/rpush/push.rb +1 -2
- data/lib/rpush/reflection.rb +8 -12
- data/lib/rpush/version.rb +1 -1
- data/lib/rpush.rb +5 -29
- data/lib/tasks/quality.rake +35 -0
- data/lib/tasks/test.rake +1 -5
- data/spec/.rubocop.yml +4 -0
- data/spec/functional/adm_spec.rb +3 -6
- data/spec/functional/apns_spec.rb +117 -24
- data/spec/functional/embed_spec.rb +20 -20
- data/spec/functional/gcm_spec.rb +4 -7
- data/spec/functional/new_app_spec.rb +59 -0
- data/spec/functional/retry_spec.rb +46 -0
- data/spec/functional/synchronization_spec.rb +68 -0
- data/spec/functional/wpns_spec.rb +3 -6
- data/spec/functional_spec_helper.rb +26 -0
- data/spec/integration/rpush_spec.rb +13 -0
- data/spec/integration/support/gcm_success_response.json +1 -0
- data/spec/spec_helper.rb +60 -0
- data/spec/support/active_record_setup.rb +48 -0
- data/{config → spec/support/config}/database.yml +0 -0
- data/spec/support/install.sh +43 -7
- data/spec/support/simplecov_helper.rb +9 -5
- data/spec/support/simplecov_quality_formatter.rb +10 -6
- data/spec/unit/apns_feedback_spec.rb +3 -3
- data/spec/unit/{adm → client/active_record/adm}/app_spec.rb +3 -3
- data/spec/unit/{adm → client/active_record/adm}/notification_spec.rb +5 -7
- data/spec/unit/client/active_record/apns/app_spec.rb +29 -0
- data/spec/unit/client/active_record/apns/feedback_spec.rb +9 -0
- data/spec/unit/client/active_record/apns/notification_spec.rb +231 -0
- data/spec/unit/client/active_record/app_spec.rb +30 -0
- data/spec/unit/client/active_record/gcm/app_spec.rb +4 -0
- data/spec/unit/{gcm → client/active_record/gcm}/notification_spec.rb +5 -7
- data/spec/unit/client/active_record/notification_spec.rb +21 -0
- data/spec/unit/client/active_record/wpns/app_spec.rb +4 -0
- data/spec/unit/client/active_record/wpns/notification_spec.rb +21 -0
- data/spec/unit/configuration_spec.rb +12 -5
- data/spec/unit/daemon/adm/delivery_spec.rb +66 -55
- data/spec/unit/daemon/apns/certificate_expired_error_spec.rb +3 -3
- data/spec/unit/daemon/apns/delivery_spec.rb +90 -83
- data/spec/unit/daemon/apns/feedback_receiver_spec.rb +22 -17
- data/spec/unit/daemon/app_runner_spec.rb +78 -186
- data/spec/unit/daemon/batch_spec.rb +52 -115
- data/spec/unit/daemon/delivery_spec.rb +15 -1
- data/spec/unit/daemon/dispatcher/http_spec.rb +3 -2
- data/spec/unit/daemon/dispatcher/tcp_spec.rb +10 -9
- data/spec/unit/daemon/dispatcher_loop_spec.rb +6 -24
- data/spec/unit/daemon/feeder_spec.rb +38 -39
- data/spec/unit/daemon/gcm/delivery_spec.rb +122 -101
- data/spec/unit/daemon/reflectable_spec.rb +2 -2
- data/spec/unit/daemon/retryable_error_spec.rb +1 -1
- data/spec/unit/daemon/service_config_methods_spec.rb +6 -3
- data/spec/unit/daemon/signal_handler_spec.rb +95 -0
- data/spec/unit/daemon/store/active_record/reconnectable_spec.rb +48 -27
- data/spec/unit/daemon/store/active_record_spec.rb +38 -47
- data/spec/unit/daemon/tcp_connection_spec.rb +22 -34
- data/spec/unit/daemon/wpns/delivery_spec.rb +58 -50
- data/spec/unit/daemon_spec.rb +48 -82
- data/spec/unit/embed_spec.rb +6 -4
- data/spec/unit/logger_spec.rb +35 -43
- data/spec/unit/notification_shared.rb +9 -79
- data/spec/unit/push_spec.rb +6 -10
- data/spec/unit/reflection_spec.rb +25 -25
- data/spec/unit/rpush_spec.rb +1 -2
- data/spec/unit_spec_helper.rb +33 -88
- metadata +126 -76
- data/lib/rpush/TODO +0 -3
- data/lib/rpush/adm/app.rb +0 -15
- data/lib/rpush/adm/data_validator.rb +0 -11
- data/lib/rpush/adm/notification.rb +0 -29
- data/lib/rpush/apns/app.rb +0 -29
- data/lib/rpush/apns/binary_notification_validator.rb +0 -12
- data/lib/rpush/apns/device_token_format_validator.rb +0 -12
- data/lib/rpush/apns/feedback.rb +0 -16
- data/lib/rpush/apns/notification.rb +0 -84
- data/lib/rpush/app.rb +0 -18
- data/lib/rpush/daemon/apns/certificate_expired_error.rb +0 -20
- data/lib/rpush/daemon/apns/disconnection_error.rb +0 -20
- data/lib/rpush/daemon/dispatcher_loop_collection.rb +0 -33
- data/lib/rpush/daemon/too_many_requests_error.rb +0 -20
- data/lib/rpush/gcm/app.rb +0 -11
- data/lib/rpush/gcm/expiry_collapse_key_mutual_inclusion_validator.rb +0 -11
- data/lib/rpush/gcm/notification.rb +0 -30
- data/lib/rpush/notification.rb +0 -69
- data/lib/rpush/notifier.rb +0 -52
- data/lib/rpush/payload_data_size_validator.rb +0 -10
- data/lib/rpush/railtie.rb +0 -11
- data/lib/rpush/registration_ids_count_validator.rb +0 -10
- data/lib/rpush/wpns/app.rb +0 -9
- data/lib/rpush/wpns/notification.rb +0 -26
- data/lib/tasks/cane.rake +0 -18
- data/lib/tasks/rpush.rake +0 -16
- data/spec/unit/apns/app_spec.rb +0 -29
- data/spec/unit/apns/feedback_spec.rb +0 -9
- data/spec/unit/apns/notification_spec.rb +0 -208
- data/spec/unit/app_spec.rb +0 -30
- data/spec/unit/daemon/apns/disconnection_error_spec.rb +0 -18
- data/spec/unit/daemon/dispatcher_loop_collection_spec.rb +0 -37
- data/spec/unit/daemon/interruptible_sleep_spec.rb +0 -68
- data/spec/unit/daemon/too_many_requests_error_spec.rb +0 -14
- data/spec/unit/gcm/app_spec.rb +0 -4
- data/spec/unit/notification_spec.rb +0 -15
- data/spec/unit/notifier_spec.rb +0 -49
- data/spec/unit/wpns/app_spec.rb +0 -4
- data/spec/unit/wpns/notification_spec.rb +0 -30
@@ -1,6 +1,6 @@
|
|
1
|
-
require '
|
1
|
+
require 'functional_spec_helper'
|
2
2
|
|
3
|
-
describe '
|
3
|
+
describe 'WPNs' do
|
4
4
|
let(:app) { Rpush::Wpns::App.new }
|
5
5
|
let(:notification) { Rpush::Wpns::Notification.new }
|
6
6
|
let(:response) { double(Net::HTTPResponse, code: 200) }
|
@@ -15,14 +15,11 @@ describe 'GCM' do
|
|
15
15
|
notification.alert = 'test'
|
16
16
|
notification.save!
|
17
17
|
|
18
|
-
Rails.stub(root: File.expand_path(File.join(File.dirname(__FILE__), '..', 'tmp')))
|
19
|
-
Rpush.config.logger = ::Logger.new(STDOUT)
|
20
|
-
|
21
18
|
Net::HTTP::Persistent.stub(new: http)
|
22
19
|
end
|
23
20
|
|
24
21
|
it 'delivers a notification successfully' do
|
25
|
-
response.stub(to_hash: {'x-notificationstatus' => ['Received']})
|
22
|
+
response.stub(to_hash: { 'x-notificationstatus' => ['Received'] })
|
26
23
|
|
27
24
|
expect do
|
28
25
|
Rpush.push
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'database_cleaner'
|
4
|
+
DatabaseCleaner.strategy = :truncation
|
5
|
+
|
6
|
+
def functional_example?(example)
|
7
|
+
path = example.metadata[:example_group][:file_path]
|
8
|
+
path =~ /spec\/functional/
|
9
|
+
end
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.before(:each) do
|
13
|
+
Modis.with_connection do |redis|
|
14
|
+
redis.keys('rpush:*').each { |key| redis.del(key) }
|
15
|
+
end
|
16
|
+
|
17
|
+
if functional_example?(example)
|
18
|
+
Rails.stub(root: File.expand_path(File.join(File.dirname(__FILE__), '..', 'tmp')))
|
19
|
+
Rpush.config.logger = ::Logger.new(STDOUT)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
config.after(:each) do
|
24
|
+
DatabaseCleaner.clean if functional_example?(example)
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# describe "Rpush" do
|
2
|
+
|
3
|
+
# before :all do
|
4
|
+
# `vagrant up`
|
5
|
+
# # TODO: Upload current directory.
|
6
|
+
# # TODO: Use Net::SSH
|
7
|
+
# `vagrant ssh 'cd rpush; git fetch origin; git reset --hard origin/master; sh tools/run_docker.sh'`
|
8
|
+
# end
|
9
|
+
|
10
|
+
# it 'can be installed and successfully delivers a notification' do
|
11
|
+
# # Can now SSH to the Docker instance with; ssh -i docker_key root@localhost -p 2100
|
12
|
+
# end
|
13
|
+
# end
|
@@ -0,0 +1 @@
|
|
1
|
+
{"results":[{"message_id": "123"}]}
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
ENV['RAILS_ENV'] = 'test'
|
2
|
+
client = (ENV['CLIENT'] || :active_record).to_sym
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
Bundler.require(:default)
|
6
|
+
|
7
|
+
unless ENV['TRAVIS'] && ENV['QUALITY'] == 'false'
|
8
|
+
begin
|
9
|
+
require './spec/support/simplecov_helper'
|
10
|
+
include SimpleCovHelper
|
11
|
+
start_simple_cov("rpush-#{client}-#{RUBY_VERSION}")
|
12
|
+
rescue LoadError
|
13
|
+
puts "Coverage disabled."
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'rpush'
|
18
|
+
require 'rpush/daemon'
|
19
|
+
require 'rpush/client/redis'
|
20
|
+
require 'rpush/client/active_record'
|
21
|
+
require 'rpush/daemon/store/active_record'
|
22
|
+
require 'rpush/daemon/store/redis'
|
23
|
+
|
24
|
+
require 'support/active_record_setup'
|
25
|
+
|
26
|
+
RAILS_ROOT = '/tmp/rails_root'
|
27
|
+
|
28
|
+
Rpush.configure do |config|
|
29
|
+
config.client = client
|
30
|
+
config.log_dir = RAILS_ROOT
|
31
|
+
end
|
32
|
+
|
33
|
+
RPUSH_CLIENT = Rpush.config.client
|
34
|
+
|
35
|
+
def active_record?
|
36
|
+
Rpush.config.client == :active_record
|
37
|
+
end
|
38
|
+
|
39
|
+
path = File.join(File.dirname(__FILE__), 'support')
|
40
|
+
TEST_CERT = File.read(File.join(path, 'cert_without_password.pem'))
|
41
|
+
TEST_CERT_WITH_PASSWORD = File.read(File.join(path, 'cert_with_password.pem'))
|
42
|
+
|
43
|
+
def after_example_cleanup
|
44
|
+
Rpush.logger = nil
|
45
|
+
Rpush::Daemon.store = nil
|
46
|
+
Rpush::Deprecation.muted do
|
47
|
+
Rpush.config.set_defaults if Rpush.config.is_a?(Rpush::Configuration)
|
48
|
+
Rpush.config.client = RPUSH_CLIENT
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
RSpec.configure do |config|
|
53
|
+
config.before(:each) do
|
54
|
+
Rails.stub(root: RAILS_ROOT)
|
55
|
+
end
|
56
|
+
|
57
|
+
config.after(:each) do
|
58
|
+
after_example_cleanup
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
jruby = defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
|
4
|
+
|
5
|
+
SPEC_ADAPTER = ENV['ADAPTER'] || 'postgresql'
|
6
|
+
SPEC_ADAPTER = 'jdbc' + SPEC_ADAPTER if jruby
|
7
|
+
|
8
|
+
require 'yaml'
|
9
|
+
db_config = YAML.load_file(File.expand_path("config/database.yml", File.dirname(__FILE__)))
|
10
|
+
|
11
|
+
if db_config[SPEC_ADAPTER].nil?
|
12
|
+
puts "No such adapter '#{SPEC_ADAPTER}'. Valid adapters are #{db_config.keys.join(', ')}."
|
13
|
+
exit 1
|
14
|
+
end
|
15
|
+
|
16
|
+
if ENV['TRAVIS']
|
17
|
+
db_config[SPEC_ADAPTER]['username'] = 'postgres'
|
18
|
+
else
|
19
|
+
require 'etc'
|
20
|
+
username = SPEC_ADAPTER =~ /mysql/ ? 'root' : Etc.getlogin
|
21
|
+
db_config[SPEC_ADAPTER]['username'] = username
|
22
|
+
end
|
23
|
+
|
24
|
+
puts "Using #{SPEC_ADAPTER} adapter."
|
25
|
+
|
26
|
+
ActiveRecord::Base.configurations = { "test" => db_config[SPEC_ADAPTER] }
|
27
|
+
ActiveRecord::Base.establish_connection(db_config[SPEC_ADAPTER])
|
28
|
+
|
29
|
+
require 'generators/templates/add_rpush'
|
30
|
+
require 'generators/templates/rpush_2_0_0_updates'
|
31
|
+
|
32
|
+
migrations = [AddRpush, Rpush200Updates]
|
33
|
+
|
34
|
+
unless ENV['TRAVIS']
|
35
|
+
migrations.reverse.each do |m|
|
36
|
+
begin
|
37
|
+
m.down
|
38
|
+
rescue ActiveRecord::StatementInvalid => e
|
39
|
+
p e
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
migrations.each(&:up)
|
45
|
+
|
46
|
+
Rpush::Client::ActiveRecord::Notification.reset_column_information
|
47
|
+
Rpush::Client::ActiveRecord::App.reset_column_information
|
48
|
+
Rpush::Client::ActiveRecord::Apns::Feedback.reset_column_information
|
File without changes
|
data/spec/support/install.sh
CHANGED
@@ -1,20 +1,33 @@
|
|
1
|
+
set -ev
|
1
2
|
cp -R /mnt/rpush /rpush
|
2
|
-
gem install --no-ri --no-rdoc rails
|
3
3
|
cd /tmp
|
4
4
|
export HOME=/
|
5
5
|
export RAILS_NAME=rpush_`date +"%Y%m%d%H%M%S"`
|
6
|
+
mysqladmin create `echo $RAILS_NAME`_development
|
7
|
+
gem install --no-ri --no-rdoc rails bundler
|
6
8
|
rails new $RAILS_NAME -BJTS -d mysql
|
7
9
|
cd $RAILS_NAME
|
8
10
|
for gem in sdoc coffee-rails uglifier sass-rails jquery-rails jbuilder turbolinks
|
9
11
|
do
|
10
|
-
sed -i.bak -e "s/^gem '$gem'/\# gem '$gem'/g" Gemfile
|
12
|
+
sed -i.bak -e "s/^[ \t]*gem '$gem'/\# gem '$gem'/g" Gemfile
|
11
13
|
done
|
14
|
+
|
12
15
|
echo 'gem "rpush", path: "/rpush"' >> Gemfile
|
13
16
|
bundle
|
14
|
-
/etc/init.d/mysql start
|
15
|
-
mysqladmin create `echo $RAILS_NAME`_development
|
16
17
|
rails g rpush
|
17
18
|
rake db:migrate
|
19
|
+
|
20
|
+
cat > gcm_server.rb <<EOF
|
21
|
+
require 'webrick'
|
22
|
+
server = WEBrick::HTTPServer.new(:Port => 80)
|
23
|
+
server.mount_proc '/' do |req, res|
|
24
|
+
res["Content-Type"] = 'application/json'
|
25
|
+
res.body = File.read('/rpush/spec/integration/support/gcm_success_response.json')
|
26
|
+
end
|
27
|
+
server.start
|
28
|
+
EOF
|
29
|
+
rails runner gcm_server.rb &
|
30
|
+
|
18
31
|
cat > create_app.rb <<EOF
|
19
32
|
app = Rpush::Gcm::App.new
|
20
33
|
app.name = "android_app"
|
@@ -26,7 +39,30 @@ n.app = app
|
|
26
39
|
n.registration_ids = ["abc"]
|
27
40
|
n.data = {:message => "hi mom!"}
|
28
41
|
n.save!
|
42
|
+
puts n.id
|
43
|
+
EOF
|
44
|
+
|
45
|
+
export NOTIFICATION_ID=`rails runner create_app.rb`
|
46
|
+
export RPUSH_GCM_HOST='http://localhost'
|
47
|
+
rpush development
|
48
|
+
|
49
|
+
cat > check_notification_status.rb <<EOF
|
50
|
+
n = Rpush::Gcm::Notification.find(ENV["NOTIFICATION_ID"])
|
51
|
+
|
52
|
+
while true do
|
53
|
+
if n.failed
|
54
|
+
puts "FAILED"
|
55
|
+
break
|
56
|
+
elsif n.delivered
|
57
|
+
puts "DELIVERED"
|
58
|
+
break
|
59
|
+
else
|
60
|
+
STDOUT.write(".")
|
61
|
+
STDOUT.flush
|
62
|
+
end
|
63
|
+
|
64
|
+
sleep 0.2
|
65
|
+
n.reload
|
66
|
+
end
|
29
67
|
EOF
|
30
|
-
rails runner
|
31
|
-
export RPUSH_GCM_HOST=http://`/sbin/ip route | awk '/default/ { print $3 }'`
|
32
|
-
rpush development -f
|
68
|
+
rails runner check_notification_status.rb
|
@@ -8,13 +8,17 @@ module SimpleCovHelper
|
|
8
8
|
add_filter '/lib/generators'
|
9
9
|
command_name name
|
10
10
|
|
11
|
+
formatters = [SimpleCov::Formatter::QualityFormatter]
|
12
|
+
|
11
13
|
if ENV['TRAVIS']
|
12
|
-
require '
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
require 'codeclimate-test-reporter'
|
15
|
+
|
16
|
+
if CodeClimate::TestReporter.run?
|
17
|
+
formatters << CodeClimate::TestReporter::Formatter
|
18
|
+
end
|
17
19
|
end
|
20
|
+
|
21
|
+
formatter SimpleCov::Formatter::MultiFormatter[*formatters]
|
18
22
|
end
|
19
23
|
end
|
20
24
|
end
|
@@ -1,8 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module SimpleCov
|
2
|
+
module Formatter
|
3
|
+
class QualityFormatter
|
4
|
+
def format(result)
|
5
|
+
SimpleCov::Formatter::HTMLFormatter.new.format(result)
|
6
|
+
File.open("coverage/covered_percent", "w") do |f|
|
7
|
+
f.puts result.source_files.covered_percent.to_f
|
8
|
+
end
|
9
|
+
end
|
6
10
|
end
|
7
11
|
end
|
8
|
-
end
|
12
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'unit_spec_helper'
|
2
2
|
|
3
3
|
describe Rpush, 'apns_feedback' do
|
4
|
-
let!(:app) { Rpush::Apns::App.create!(:
|
5
|
-
let(:receiver) { double(:
|
4
|
+
let!(:app) { Rpush::Apns::App.create!(name: 'test', environment: 'production', certificate: TEST_CERT) }
|
5
|
+
let(:receiver) { double(check_for_feedback: nil) }
|
6
6
|
|
7
7
|
before do
|
8
|
-
Rpush::Daemon::Apns::FeedbackReceiver.stub(:
|
8
|
+
Rpush::Daemon::Apns::FeedbackReceiver.stub(new: receiver)
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'initializes the store' do
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'unit_spec_helper'
|
2
2
|
|
3
|
-
describe Rpush::Adm::App do
|
4
|
-
subject { Rpush::Adm::App.new(:
|
5
|
-
let(:existing_app) { Rpush::Adm::App.create!(:
|
3
|
+
describe Rpush::Client::ActiveRecord::Adm::App do
|
4
|
+
subject { Rpush::Client::ActiveRecord::Adm::App.new(name: 'test', environment: 'development', client_id: 'CLIENT_ID', client_secret: 'CLIENT_SECRET') }
|
5
|
+
let(:existing_app) { Rpush::Client::ActiveRecord::Adm::App.create!(name: 'existing', environment: 'development', client_id: 'CLIENT_ID', client_secret: 'CLIENT_SECRET') }
|
6
6
|
|
7
7
|
it 'should be valid if properly instantiated' do
|
8
8
|
subject.should be_valid
|
@@ -1,23 +1,21 @@
|
|
1
1
|
require 'unit_spec_helper'
|
2
2
|
require 'unit/notification_shared.rb'
|
3
3
|
|
4
|
-
describe Rpush::Adm::Notification do
|
4
|
+
describe Rpush::Client::ActiveRecord::Adm::Notification do
|
5
5
|
it_should_behave_like 'an Notification subclass'
|
6
6
|
|
7
|
-
let(:app) { Rpush::Adm::App.create!(:
|
8
|
-
let(:notification_class) { Rpush::Adm::Notification }
|
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
9
|
let(:notification) { notification_class.new }
|
10
|
-
let(:data_setter) { 'data=' }
|
11
|
-
let(:data_getter) { 'data' }
|
12
10
|
|
13
11
|
it "has a 'data' payload limit of 6144 bytes" do
|
14
|
-
notification.data = { :
|
12
|
+
notification.data = { key: "a" * 6144 }
|
15
13
|
notification.valid?.should be_false
|
16
14
|
notification.errors[:base].should eq ["Notification payload data cannot be larger than 6144 bytes."]
|
17
15
|
end
|
18
16
|
|
19
17
|
it 'limits the number of registration ids to 100' do
|
20
|
-
notification.registration_ids = ['a']*(100+1)
|
18
|
+
notification.registration_ids = ['a'] * (100 + 1)
|
21
19
|
notification.valid?.should be_false
|
22
20
|
notification.errors[:base].should eq ["Number of registration_ids cannot be larger than 100."]
|
23
21
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'unit_spec_helper'
|
2
|
+
|
3
|
+
describe Rpush::Client::ActiveRecord::App do
|
4
|
+
it 'does not validate an app with an invalid certificate' do
|
5
|
+
app = Rpush::Client::ActiveRecord::Apns::App.new(name: 'test', environment: 'development', certificate: 'foo')
|
6
|
+
app.valid?
|
7
|
+
app.errors[:certificate].should eq ['Certificate 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
|
+
app.errors[:certificate].should 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
|
+
app.errors[:certificate].should 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
|
+
app.errors[:certificate].should eq ["Certificate value must contain a certificate and a private key."]
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'unit_spec_helper'
|
2
|
+
|
3
|
+
describe Rpush::Client::ActiveRecord::Apns::Feedback do
|
4
|
+
it 'validates the format of the device_token' do
|
5
|
+
notification = Rpush::Client::ActiveRecord::Apns::Feedback.new(device_token: "{$%^&*()}")
|
6
|
+
notification.valid?.should be_false
|
7
|
+
notification.errors[:device_token].include?("is invalid").should be_true
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,231 @@
|
|
1
|
+
# encoding: US-ASCII
|
2
|
+
|
3
|
+
require "unit_spec_helper"
|
4
|
+
require 'unit/notification_shared.rb'
|
5
|
+
|
6
|
+
describe Rpush::Client::ActiveRecord::Apns::Notification do
|
7
|
+
it_should_behave_like 'an Notification subclass'
|
8
|
+
|
9
|
+
let(:app) { Rpush::Client::ActiveRecord::Apns::App.create!(name: 'my_app', environment: 'development', certificate: TEST_CERT) }
|
10
|
+
let(:notification_class) { Rpush::Client::ActiveRecord::Apns::Notification }
|
11
|
+
let(:notification) { notification_class.new }
|
12
|
+
|
13
|
+
it "should validate the format of the device_token" do
|
14
|
+
notification = Rpush::Client::ActiveRecord::Apns::Notification.new(device_token: "{$%^&*()}")
|
15
|
+
notification.valid?.should be_false
|
16
|
+
notification.errors[:device_token].include?("is invalid").should be_true
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should validate the length of the binary conversion of the notification" do
|
20
|
+
notification.device_token = "a" * 64
|
21
|
+
notification.alert = "way too long!" * 100
|
22
|
+
notification.valid?.should be_false
|
23
|
+
notification.errors[:base].include?("APN notification cannot be larger than 256 bytes. Try condensing your alert and device attributes.").should be_true
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should default the sound to 'default'" do
|
27
|
+
notification.sound.should eq('default')
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should default the expiry to 1 day" do
|
31
|
+
notification.expiry.should eq 1.day.to_i
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe Rpush::Client::ActiveRecord::Apns::Notification, "when assigning the device token" do
|
36
|
+
it "should strip spaces from the given string" do
|
37
|
+
notification = Rpush::Client::ActiveRecord::Apns::Notification.new(device_token: "o m g")
|
38
|
+
notification.device_token.should eq "omg"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should strip chevrons from the given string" do
|
42
|
+
notification = Rpush::Client::ActiveRecord::Apns::Notification.new(device_token: "<omg>")
|
43
|
+
notification.device_token.should eq "omg"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe Rpush::Client::ActiveRecord::Apns::Notification, "as_json" do
|
48
|
+
it "should include the alert if present" do
|
49
|
+
notification = Rpush::Client::ActiveRecord::Apns::Notification.new(alert: "hi mom")
|
50
|
+
notification.as_json["aps"]["alert"].should eq "hi mom"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should not include the alert key if the alert is not present" do
|
54
|
+
notification = Rpush::Client::ActiveRecord::Apns::Notification.new(alert: nil)
|
55
|
+
notification.as_json["aps"].key?("alert").should be_false
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should encode the alert as JSON if it is a Hash" do
|
59
|
+
notification = Rpush::Client::ActiveRecord::Apns::Notification.new(alert: { 'body' => "hi mom", 'alert-loc-key' => "View" })
|
60
|
+
notification.as_json["aps"]["alert"].should eq('body' => "hi mom", 'alert-loc-key' => "View")
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should include the badge if present" do
|
64
|
+
notification = Rpush::Client::ActiveRecord::Apns::Notification.new(badge: 6)
|
65
|
+
notification.as_json["aps"]["badge"].should eq 6
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should not include the badge key if the badge is not present" do
|
69
|
+
notification = Rpush::Client::ActiveRecord::Apns::Notification.new(badge: nil)
|
70
|
+
notification.as_json["aps"].key?("badge").should be_false
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should include the sound if present" do
|
74
|
+
notification = Rpush::Client::ActiveRecord::Apns::Notification.new(alert: "my_sound.aiff")
|
75
|
+
notification.as_json["aps"]["alert"].should eq "my_sound.aiff"
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should not include the sound key if the sound is not present" do
|
79
|
+
notification = Rpush::Client::ActiveRecord::Apns::Notification.new(sound: false)
|
80
|
+
notification.as_json["aps"].key?("sound").should be_false
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should include attributes for the device" do
|
84
|
+
notification = Rpush::Client::ActiveRecord::Apns::Notification.new
|
85
|
+
notification.data = { omg: :lol, wtf: :dunno }
|
86
|
+
notification.as_json["omg"].should eq "lol"
|
87
|
+
notification.as_json["wtf"].should eq "dunno"
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should allow attributes to include a hash" do
|
91
|
+
notification = Rpush::Client::ActiveRecord::Apns::Notification.new
|
92
|
+
notification.data = { omg: { ilike: :hashes } }
|
93
|
+
notification.as_json["omg"]["ilike"].should eq "hashes"
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
describe Rpush::Client::ActiveRecord::Apns::Notification, 'MDM' do
|
99
|
+
let(:magic) { 'abc123' }
|
100
|
+
let(:notification) { Rpush::Client::ActiveRecord::Apns::Notification.new }
|
101
|
+
|
102
|
+
it 'includes the mdm magic in the payload' do
|
103
|
+
notification.mdm = magic
|
104
|
+
notification.as_json.should eq('mdm' => magic)
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'does not include aps attribute' do
|
108
|
+
notification.alert = "i'm doomed"
|
109
|
+
notification.mdm = magic
|
110
|
+
notification.as_json.key?('aps').should be_false
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe Rpush::Client::ActiveRecord::Apns::Notification, 'content-available' do
|
115
|
+
let(:notification) { Rpush::Client::ActiveRecord::Apns::Notification.new }
|
116
|
+
|
117
|
+
it 'includes content-available in the payload' do
|
118
|
+
notification.content_available = true
|
119
|
+
notification.as_json['aps']['content-available'].should eq 1
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'does not include content-available in the payload if not set' do
|
123
|
+
notification.as_json['aps'].key?('content-available').should be_false
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'does not include content-available as a non-aps attribute' do
|
127
|
+
notification.content_available = true
|
128
|
+
notification.as_json.key?('content-available').should be_false
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'does not overwrite existing attributes for the device' do
|
132
|
+
notification.data = { hi: :mom }
|
133
|
+
notification.content_available = true
|
134
|
+
notification.as_json['aps']['content-available'].should eq 1
|
135
|
+
notification.as_json['hi'].should eq 'mom'
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'does not overwrite the content-available flag when setting attributes for the device' do
|
139
|
+
notification.content_available = true
|
140
|
+
notification.data = { hi: :mom }
|
141
|
+
notification.as_json['aps']['content-available'].should eq 1
|
142
|
+
notification.as_json['hi'].should eq 'mom'
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe Rpush::Client::ActiveRecord::Apns::Notification, 'to_binary' do
|
147
|
+
let(:notification) { Rpush::Client::ActiveRecord::Apns::Notification.new }
|
148
|
+
|
149
|
+
before do
|
150
|
+
notification.device_token = "a" * 64
|
151
|
+
notification.id = 1234
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'uses APNS_PRIORITY_CONSERVE_POWER if content-available is the only key' do
|
155
|
+
notification.alert = nil
|
156
|
+
notification.badge = nil
|
157
|
+
notification.sound = nil
|
158
|
+
notification.content_available = true
|
159
|
+
bytes = notification.to_binary.bytes.to_a[-4..-1]
|
160
|
+
bytes.first.should eq 5 # priority item ID
|
161
|
+
bytes.last.should eq Rpush::Client::ActiveRecord::Apns::Notification::APNS_PRIORITY_CONSERVE_POWER
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'uses APNS_PRIORITY_IMMEDIATE if content-available is not the only key' do
|
165
|
+
notification.alert = "New stuff!"
|
166
|
+
notification.badge = nil
|
167
|
+
notification.sound = nil
|
168
|
+
notification.content_available = true
|
169
|
+
bytes = notification.to_binary.bytes.to_a[-4..-1]
|
170
|
+
bytes.first.should eq 5 # priority item ID
|
171
|
+
bytes.last.should eq Rpush::Client::ActiveRecord::Apns::Notification::APNS_PRIORITY_IMMEDIATE
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should correctly convert the notification to binary" do
|
175
|
+
notification.sound = "1.aiff"
|
176
|
+
notification.badge = 3
|
177
|
+
notification.alert = "Don't panic Mr Mainwaring, don't panic!"
|
178
|
+
notification.data = { hi: :mom }
|
179
|
+
notification.expiry = 86_400 # 1 day, \x00\x01Q\x80
|
180
|
+
notification.priority = Rpush::Client::ActiveRecord::Apns::Notification::APNS_PRIORITY_IMMEDIATE
|
181
|
+
notification.app = Rpush::Client::ActiveRecord::Apns::App.new(name: 'my_app', environment: 'development', certificate: TEST_CERT)
|
182
|
+
notification.to_binary.should eq "\x02\x00\x00\x00\x99\x01\x00 \xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\x02\x00a{\"aps\":{\"alert\":\"Don't panic Mr Mainwaring, don't panic!\",\"badge\":3,\"sound\":\"1.aiff\"},\"hi\":\"mom\"}\x03\x00\x04\x00\x00\x04\xD2\x04\x00\x04\x00\x01Q\x80\x05\x00\x01\n"
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
describe Rpush::Client::ActiveRecord::Apns::Notification, "bug #31" do
|
187
|
+
it 'does not confuse a JSON looking string as JSON' do
|
188
|
+
notification = Rpush::Client::ActiveRecord::Apns::Notification.new
|
189
|
+
notification.alert = "{\"one\":2}"
|
190
|
+
notification.alert.should eq "{\"one\":2}"
|
191
|
+
end
|
192
|
+
|
193
|
+
it 'does confuse a JSON looking string as JSON if the alert_is_json attribute is not present' do
|
194
|
+
notification = Rpush::Client::ActiveRecord::Apns::Notification.new
|
195
|
+
notification.stub(:has_attribute? => false)
|
196
|
+
notification.alert = "{\"one\":2}"
|
197
|
+
notification.alert.should eq('one' => 2)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
describe Rpush::Client::ActiveRecord::Apns::Notification, "bug #35" do
|
202
|
+
it "should limit payload size to 256 bytes but not the entire packet" do
|
203
|
+
notification = Rpush::Client::ActiveRecord::Apns::Notification.new do |n|
|
204
|
+
n.device_token = "a" * 64
|
205
|
+
n.alert = "a" * 210
|
206
|
+
n.app = Rpush::Client::ActiveRecord::Apns::App.create!(name: 'my_app', environment: 'development', certificate: TEST_CERT)
|
207
|
+
end
|
208
|
+
|
209
|
+
notification.to_binary(for_validation: true).bytesize.should be > 256
|
210
|
+
notification.payload_size.should be < 256
|
211
|
+
notification.should be_valid
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
describe Rpush::Client::ActiveRecord::Apns::Notification, "multi_json usage" do
|
216
|
+
describe Rpush::Client::ActiveRecord::Apns::Notification, "alert" do
|
217
|
+
it "should call MultiJson.load when multi_json version is 1.3.0" do
|
218
|
+
notification = Rpush::Client::ActiveRecord::Apns::Notification.new(alert: { a: 1 }, alert_is_json: true)
|
219
|
+
Gem.stub(:loaded_specs).and_return('multi_json' => Gem::Specification.new('multi_json', '1.3.0'))
|
220
|
+
MultiJson.should_receive(:load).with(any_args)
|
221
|
+
notification.alert
|
222
|
+
end
|
223
|
+
|
224
|
+
it "should call MultiJson.decode when multi_json version is 1.2.9" do
|
225
|
+
notification = Rpush::Client::ActiveRecord::Apns::Notification.new(alert: { a: 1 }, alert_is_json: true)
|
226
|
+
Gem.stub(:loaded_specs).and_return('multi_json' => Gem::Specification.new('multi_json', '1.2.9'))
|
227
|
+
MultiJson.should_receive(:decode).with(any_args)
|
228
|
+
notification.alert
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'unit_spec_helper'
|
2
|
+
|
3
|
+
describe Rpush::Client::ActiveRecord::App do
|
4
|
+
it 'validates the uniqueness of name within type and environment' do
|
5
|
+
Rpush::Client::ActiveRecord::Apns::App.create!(name: 'test', environment: 'production', certificate: TEST_CERT)
|
6
|
+
app = Rpush::Client::ActiveRecord::Apns::App.new(name: 'test', environment: 'production', certificate: TEST_CERT)
|
7
|
+
app.valid?.should be_false
|
8
|
+
app.errors[:name].should eq ['has already been taken']
|
9
|
+
|
10
|
+
app = Rpush::Client::ActiveRecord::Apns::App.new(name: 'test', environment: 'development', certificate: TEST_CERT)
|
11
|
+
app.valid?.should be_true
|
12
|
+
|
13
|
+
app = Rpush::Client::ActiveRecord::Gcm::App.new(name: 'test', environment: 'production', auth_key: TEST_CERT)
|
14
|
+
app.valid?.should be_true
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'validating certificates' do
|
18
|
+
it 'rescues from certificate error' do
|
19
|
+
app = Rpush::Client::ActiveRecord::Apns::App.new(name: 'test', environment: 'development', certificate: 'bad')
|
20
|
+
expect { app.valid? }.not_to raise_error
|
21
|
+
expect(app.valid?).to be_false
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'raises other errors' do
|
25
|
+
app = Rpush::Client::ActiveRecord::Apns::App.new(name: 'test', environment: 'development', certificate: 'bad')
|
26
|
+
OpenSSL::X509::Certificate.stub(:new).and_raise(NameError, 'simulating no openssl')
|
27
|
+
expect { app.valid? }.to raise_error(NameError)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|