rhoconnect 6.2.0 → 7.1.17
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/Gemfile +4 -0
- data/Gemfile.lock +54 -12
- data/README.md +2 -0
- data/bin/rhoconnect +0 -0
- data/bin/rhoconnect-benchmark +0 -0
- data/lib/rhoconnect/ping.rb +1 -1
- data/lib/rhoconnect/ping/fcm.rb +74 -0
- data/lib/rhoconnect/version.rb +1 -1
- data/rhoconnect.gemspec +4 -1
- data/spec/jobs/ping_job_spec.rb +74 -33
- data/spec/ping/fcm_spec.rb +116 -0
- data/spec/ping/gcm_spec.rb +1 -1
- metadata +55 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 75a2c9f405a47e165d194f4b1f67bac5e852aed3
|
|
4
|
+
data.tar.gz: ab137d204628e7e27ba7bae7950ff78e076c6811
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 792dd2116fd5928c1428c15e1329071e45032c16a25be1853dbfd6c33967eecf12e08762f790dfca9367b50f9eb2125ef53ec5d51097f5f9cdb28cf78d3b5626
|
|
7
|
+
data.tar.gz: bebf30ac060bb73983763b59327972abc6d244499e492be494eab9f003f8e293f097cb23983a37dbab7d76bbf195e69b142e99d9b1350c1f9d19ef1faf48c04f
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -8,16 +8,18 @@ GIT
|
|
|
8
8
|
PATH
|
|
9
9
|
remote: .
|
|
10
10
|
specs:
|
|
11
|
-
rhoconnect (7.
|
|
11
|
+
rhoconnect (7.1.0)
|
|
12
12
|
bundler (~> 1.17.3)
|
|
13
13
|
connection_pool (~> 2.2.2)
|
|
14
|
+
google-api-client (~> 0.31.0)
|
|
15
|
+
google-api-fcm (~> 0.1.7)
|
|
14
16
|
json (>= 1.8, < 2.0)
|
|
15
17
|
rack (~> 2.0.6)
|
|
16
18
|
rake (~> 12.3.2)
|
|
17
19
|
redis (~> 4.1.0)
|
|
18
20
|
resque (>= 2.0.0)
|
|
19
21
|
rest-client (~> 2.0.2)
|
|
20
|
-
rubyzip (
|
|
22
|
+
rubyzip (>= 1.2.2, < 2.1.0)
|
|
21
23
|
sinatra (~> 2.0.5)
|
|
22
24
|
thor (~> 0.20.3)
|
|
23
25
|
|
|
@@ -42,13 +44,17 @@ GEM
|
|
|
42
44
|
crack (0.4.3)
|
|
43
45
|
safe_yaml (~> 1.0.0)
|
|
44
46
|
daemons (1.3.1)
|
|
47
|
+
declarative (0.0.10)
|
|
48
|
+
declarative-option (0.1.0)
|
|
45
49
|
diff-lcs (1.3)
|
|
46
50
|
docile (1.3.1)
|
|
47
|
-
domain_name (0.5.
|
|
51
|
+
domain_name (0.5.20190701)
|
|
48
52
|
unf (>= 0.0.5, < 1.0.0)
|
|
49
53
|
dotenv (2.7.2)
|
|
50
54
|
eventmachine (1.0.9.1)
|
|
51
55
|
excon (0.62.0)
|
|
56
|
+
faraday (0.17.0)
|
|
57
|
+
multipart-post (>= 1.2, < 3)
|
|
52
58
|
ffaker (2.10.0)
|
|
53
59
|
ffi (1.10.0)
|
|
54
60
|
fog-aws (3.4.0)
|
|
@@ -79,25 +85,48 @@ GEM
|
|
|
79
85
|
pleaserun (~> 0.0.29)
|
|
80
86
|
ruby-xz (~> 0.2.3)
|
|
81
87
|
stud
|
|
88
|
+
google-api-client (0.31.0)
|
|
89
|
+
addressable (~> 2.5, >= 2.5.1)
|
|
90
|
+
googleauth (>= 0.5, < 0.10.0)
|
|
91
|
+
httpclient (>= 2.8.1, < 3.0)
|
|
92
|
+
mini_mime (~> 1.0)
|
|
93
|
+
representable (~> 3.0)
|
|
94
|
+
retriable (>= 2.0, < 4.0)
|
|
95
|
+
signet (0.11.0)
|
|
96
|
+
google-api-fcm (0.1.7)
|
|
97
|
+
google-api-client (~> 0.17)
|
|
98
|
+
googleauth (0.9.0)
|
|
99
|
+
faraday (~> 0.12)
|
|
100
|
+
jwt (>= 1.4, < 3.0)
|
|
101
|
+
memoist (~> 0.16)
|
|
102
|
+
multi_json (~> 1.11)
|
|
103
|
+
os (>= 0.9, < 2.0)
|
|
104
|
+
signet (0.11.0)
|
|
82
105
|
hashdiff (0.3.8)
|
|
83
106
|
http-cookie (1.0.3)
|
|
84
107
|
domain_name (~> 0.5)
|
|
108
|
+
httpclient (2.8.3)
|
|
85
109
|
insist (1.0.0)
|
|
86
110
|
io-like (0.3.0)
|
|
87
111
|
ipaddress (0.8.3)
|
|
88
112
|
json (1.8.6)
|
|
113
|
+
jwt (2.2.1)
|
|
114
|
+
memoist (0.16.0)
|
|
89
115
|
mime-types (3.2.2)
|
|
90
116
|
mime-types-data (~> 3.2015)
|
|
91
117
|
mime-types-data (3.2019.0331)
|
|
118
|
+
mini_mime (1.0.2)
|
|
92
119
|
mini_portile2 (2.4.0)
|
|
93
120
|
mono_logger (1.1.0)
|
|
94
121
|
multi_json (1.13.1)
|
|
122
|
+
multipart-post (2.1.1)
|
|
95
123
|
mustache (0.99.8)
|
|
96
124
|
mustermann (1.0.3)
|
|
97
125
|
net-ssh (5.2.0)
|
|
98
126
|
netrc (0.11.0)
|
|
99
|
-
nokogiri (1.10.
|
|
127
|
+
nokogiri (1.10.4)
|
|
100
128
|
mini_portile2 (~> 2.4.0)
|
|
129
|
+
os (1.0.1)
|
|
101
130
|
pleaserun (0.0.30)
|
|
102
131
|
cabin (> 0)
|
|
103
132
|
clamp
|
|
@@ -108,14 +137,18 @@ GEM
|
|
|
108
137
|
public_suffix (3.0.3)
|
|
109
138
|
rack (2.0.7)
|
|
110
139
|
rack-fiber_pool (0.9.3)
|
|
111
|
-
rack-protection (2.0.
|
|
140
|
+
rack-protection (2.0.7)
|
|
112
141
|
rack
|
|
113
142
|
rack-test (1.1.0)
|
|
114
143
|
rack (>= 1.0, < 3)
|
|
115
|
-
rake (12.3.
|
|
116
|
-
redis (4.1.
|
|
144
|
+
rake (12.3.3)
|
|
145
|
+
redis (4.1.3)
|
|
117
146
|
redis-namespace (1.6.0)
|
|
118
147
|
redis (>= 3.0.4)
|
|
148
|
+
representable (3.0.4)
|
|
149
|
+
declarative (< 0.1.0)
|
|
150
|
+
declarative-option (< 0.2.0)
|
|
151
|
+
uber (< 0.2.0)
|
|
119
152
|
resque (2.0.0)
|
|
120
153
|
mono_logger (~> 1.0)
|
|
121
154
|
multi_json (~> 1.0)
|
|
@@ -126,6 +159,7 @@ GEM
|
|
|
126
159
|
http-cookie (>= 1.0.2, < 2.0)
|
|
127
160
|
mime-types (>= 1.16, < 4.0)
|
|
128
161
|
netrc (~> 0.8)
|
|
162
|
+
retriable (3.1.2)
|
|
129
163
|
rspec (3.8.0)
|
|
130
164
|
rspec-core (~> 3.8.0)
|
|
131
165
|
rspec-expectations (~> 3.8.0)
|
|
@@ -142,8 +176,13 @@ GEM
|
|
|
142
176
|
ruby-xz (0.2.3)
|
|
143
177
|
ffi (~> 1.9)
|
|
144
178
|
io-like (~> 0.3)
|
|
145
|
-
rubyzip (
|
|
179
|
+
rubyzip (2.0.0)
|
|
146
180
|
safe_yaml (1.0.5)
|
|
181
|
+
signet (0.11.0)
|
|
182
|
+
addressable (~> 2.3)
|
|
183
|
+
faraday (~> 0.9)
|
|
184
|
+
jwt (>= 1.5, < 3.0)
|
|
185
|
+
multi_json (~> 1.10)
|
|
147
186
|
simplecov (0.16.1)
|
|
148
187
|
docile (~> 1.1)
|
|
149
188
|
json (>= 1.8, < 3)
|
|
@@ -151,10 +190,10 @@ GEM
|
|
|
151
190
|
simplecov-html (0.10.2)
|
|
152
191
|
simplecov-rcov (0.2.3)
|
|
153
192
|
simplecov (>= 0.4.1)
|
|
154
|
-
sinatra (2.0.
|
|
193
|
+
sinatra (2.0.7)
|
|
155
194
|
mustermann (~> 1.0)
|
|
156
195
|
rack (~> 2.0)
|
|
157
|
-
rack-protection (= 2.0.
|
|
196
|
+
rack-protection (= 2.0.7)
|
|
158
197
|
tilt (~> 2.0)
|
|
159
198
|
sqlite3 (1.4.0)
|
|
160
199
|
stud (0.0.23)
|
|
@@ -163,10 +202,11 @@ GEM
|
|
|
163
202
|
eventmachine (~> 1.0, >= 1.0.4)
|
|
164
203
|
rack (>= 1, < 3)
|
|
165
204
|
thor (0.20.3)
|
|
166
|
-
tilt (2.0.
|
|
205
|
+
tilt (2.0.10)
|
|
206
|
+
uber (0.1.0)
|
|
167
207
|
unf (0.1.4)
|
|
168
208
|
unf_ext
|
|
169
|
-
unf_ext (0.0.7.
|
|
209
|
+
unf_ext (0.0.7.6)
|
|
170
210
|
vegas (0.1.11)
|
|
171
211
|
rack (>= 1.0.0)
|
|
172
212
|
webmock (3.5.1)
|
|
@@ -188,6 +228,8 @@ DEPENDENCIES
|
|
|
188
228
|
ffaker (~> 2.10.0)
|
|
189
229
|
fog-aws (~> 3.4.0)
|
|
190
230
|
fpm (>= 1.11.00)
|
|
231
|
+
google-api-client (~> 0.31.0)
|
|
232
|
+
google-api-fcm (~> 0.1.7)
|
|
191
233
|
jdbc-sqlite3 (>= 3.7.2)
|
|
192
234
|
jruby-openssl (>= 0.7.4)
|
|
193
235
|
net-ssh (~> 5.2.0)
|
data/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
[](https://travis-ci.org/rhomobile/rhoconnect)
|
|
2
|
+
|
|
1
3
|
RhoConnect App Integration Server
|
|
2
4
|
-------------------------------------------------------------
|
|
3
5
|
RhoConnect is an app integration server which keeps enterprise data current and available on users’ devices.
|
data/bin/rhoconnect
CHANGED
|
File without changes
|
data/bin/rhoconnect-benchmark
CHANGED
|
File without changes
|
data/lib/rhoconnect/ping.rb
CHANGED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
require 'google/apis/messages'
|
|
2
|
+
|
|
3
|
+
# https://firebase.google.com/docs/cloud-messaging/auth-server
|
|
4
|
+
# https://github.com/oniksfly/google-api-fcm
|
|
5
|
+
|
|
6
|
+
module Rhoconnect
|
|
7
|
+
class Fcm
|
|
8
|
+
class InvalidProjectId < Exception; end
|
|
9
|
+
class InvalidPackageName < Exception; end
|
|
10
|
+
class FCMPingError < Exception; end
|
|
11
|
+
|
|
12
|
+
def self.ping(params)
|
|
13
|
+
begin
|
|
14
|
+
fcm_project_id = Rhoconnect.settings[:fcm_project_id]
|
|
15
|
+
raise InvalidProjectId.new("Missing `:fcm_project_id:` option in settings/settings.yml") unless fcm_project_id
|
|
16
|
+
|
|
17
|
+
package_name = Rhoconnect.settings[:package_name]
|
|
18
|
+
raise InvalidPackageName.new("Missing `:package_name:` option in settings/settings.yml") unless package_name
|
|
19
|
+
|
|
20
|
+
send_ping_to_device(fcm_project_id, package_name, params)
|
|
21
|
+
rescue InvalidProjectId => error
|
|
22
|
+
log error
|
|
23
|
+
log error.backtrace.join("\n")
|
|
24
|
+
raise error
|
|
25
|
+
rescue InvalidPackageName => error
|
|
26
|
+
log error
|
|
27
|
+
log error.backtrace.join("\n")
|
|
28
|
+
raise error
|
|
29
|
+
rescue Exception => error
|
|
30
|
+
log error
|
|
31
|
+
log error.backtrace.join("\n")
|
|
32
|
+
raise error
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def self.send_ping_to_device(project_id,package_name,params)
|
|
37
|
+
|
|
38
|
+
scope = Google::Apis::Messages::AUTH_MESSAGES
|
|
39
|
+
authorization = Google::Auth.get_application_default(scope)
|
|
40
|
+
|
|
41
|
+
service = Google::Apis::Messages::MessagesService.new(project_id: project_id)
|
|
42
|
+
service.authorization = authorization
|
|
43
|
+
|
|
44
|
+
service.notify(fcm_message(package_name,params))
|
|
45
|
+
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def self.fcm_message(package_name,params)
|
|
49
|
+
params.reject! {|k,v| v.nil? || v.length == 0}
|
|
50
|
+
data = {}
|
|
51
|
+
data['do_sync'] = params['sources'] ? params['sources'].join(',') : ''
|
|
52
|
+
data['alert'] = params['message'] if params['message']
|
|
53
|
+
data['vibrate'] = params['vibrate'] if params['vibrate']
|
|
54
|
+
data['sound'] = params['sound'] if params['sound']
|
|
55
|
+
data['phone_id'] = params['phone_id'] if params['phone_id']
|
|
56
|
+
|
|
57
|
+
android = {}
|
|
58
|
+
android['collapse_key'] = (rand * 100000000).to_i.to_s
|
|
59
|
+
android['priority'] = 'high'
|
|
60
|
+
android['restricted_package_name'] = package_name
|
|
61
|
+
android['data'] = data
|
|
62
|
+
android['notification'] = {}
|
|
63
|
+
# android['notification']['title'] = 'Test message'
|
|
64
|
+
android['notification']['body'] = params['message']
|
|
65
|
+
|
|
66
|
+
message = Google::Apis::Messages::Message.new(
|
|
67
|
+
token: params['device_pin'].to_s,
|
|
68
|
+
android: android
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
message
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
data/lib/rhoconnect/version.rb
CHANGED
data/rhoconnect.gemspec
CHANGED
|
@@ -44,10 +44,13 @@ Gem::Specification.new do |s|
|
|
|
44
44
|
s.add_dependency('sinatra', '~> 2.0.5')
|
|
45
45
|
s.add_dependency('rake', '~> 12.3.2')
|
|
46
46
|
s.add_dependency('json', '>= 1.8', '< 2.0')
|
|
47
|
-
s.add_dependency('rubyzip', '
|
|
47
|
+
s.add_dependency('rubyzip', '>= 1.2.2', '< 2.1.0')
|
|
48
48
|
s.add_dependency('connection_pool', '~> 2.2.2')
|
|
49
49
|
s.add_dependency('redis', '~> 4.1.0')
|
|
50
50
|
s.add_dependency('resque', '>= 2.0.0')
|
|
51
51
|
s.add_dependency('rest-client', '~> 2.0.2')
|
|
52
52
|
s.add_dependency('thor', '~> 0.20.3')
|
|
53
|
+
s.add_dependency('signet', '~> 0.11.0')
|
|
54
|
+
s.add_dependency('google-api-client', '~> 0.31.0')
|
|
55
|
+
s.add_dependency('google-api-fcm', '~> 0.1.7')
|
|
53
56
|
end
|
data/spec/jobs/ping_job_spec.rb
CHANGED
|
@@ -33,8 +33,10 @@ describe 'PingJob' do
|
|
|
33
33
|
scrubbed_params = params.dup
|
|
34
34
|
scrubbed_params['vibrate'] = '5'
|
|
35
35
|
|
|
36
|
-
Apple.
|
|
37
|
-
|
|
36
|
+
expect(Apple).to receive(:ping).once.with({
|
|
37
|
+
'device_pin' => @c.device_pin,
|
|
38
|
+
'device_port' => @c.device_port
|
|
39
|
+
}.merge!(scrubbed_params))
|
|
38
40
|
PingJob.perform(params)
|
|
39
41
|
end
|
|
40
42
|
|
|
@@ -49,7 +51,7 @@ describe 'PingJob' do
|
|
|
49
51
|
'phone_id' => nil,
|
|
50
52
|
'device_app_id' => nil,
|
|
51
53
|
'device_app_version' => nil}
|
|
52
|
-
Apple.
|
|
54
|
+
expect(Apple).to receive(:ping).once.with({'device_pin' => @c.device_pin,
|
|
53
55
|
'device_port' => @c.device_port}.merge!(params))
|
|
54
56
|
PingJob.perform(params)
|
|
55
57
|
end
|
|
@@ -66,7 +68,7 @@ describe 'PingJob' do
|
|
|
66
68
|
'device_app_id' => nil,
|
|
67
69
|
'device_app_version' => nil}
|
|
68
70
|
@c.device_type = 'unknown_device_type'
|
|
69
|
-
PingJob.
|
|
71
|
+
expect(PingJob).to receive(:log).once.with("Dropping ping request for unsupported platform '#{@c.device_type}'")
|
|
70
72
|
PingJob.perform(params)
|
|
71
73
|
end
|
|
72
74
|
|
|
@@ -81,8 +83,8 @@ describe 'PingJob' do
|
|
|
81
83
|
'device_app_id' => nil,
|
|
82
84
|
'device_app_version' => nil}
|
|
83
85
|
@c.device_type = nil
|
|
84
|
-
PingJob.
|
|
85
|
-
|
|
86
|
+
expect(PingJob).to receive(:log).once.with("Skipping ping for non-registered client_id '#{@c.id}'...")
|
|
87
|
+
expect {PingJob.perform(params)}.not_to raise_error
|
|
86
88
|
end
|
|
87
89
|
|
|
88
90
|
it 'should skip ping for empty device_pin' do
|
|
@@ -97,8 +99,8 @@ describe 'PingJob' do
|
|
|
97
99
|
'device_app_version' => nil, }
|
|
98
100
|
@c.device_type = 'Android'
|
|
99
101
|
@c.device_pin = nil
|
|
100
|
-
PingJob.
|
|
101
|
-
|
|
102
|
+
expect(PingJob).to receive(:log).once.with("Skipping ping for non-registered client_id '#{@c.id}'...")
|
|
103
|
+
expect {PingJob.perform(params)}.not_to raise_error
|
|
102
104
|
end
|
|
103
105
|
|
|
104
106
|
it 'should drop ping if it\'s already in user\'s device pin list' do
|
|
@@ -119,9 +121,9 @@ describe 'PingJob' do
|
|
|
119
121
|
@c_fields.delete(:id)
|
|
120
122
|
@c2 = Client.create(@c_fields, {:source_name => @s_fields[:name]})
|
|
121
123
|
|
|
122
|
-
Apple.
|
|
123
|
-
PingJob.
|
|
124
|
-
|
|
124
|
+
expect(Apple).to receive(:ping).with({'device_pin' => @c.device_pin, 'device_port' => @c.device_port}.merge!(params))
|
|
125
|
+
expect(PingJob).to receive(:log).twice.with(/Dropping ping request for client/)
|
|
126
|
+
expect {PingJob.perform(params)}.not_to raise_error
|
|
125
127
|
end
|
|
126
128
|
|
|
127
129
|
it 'should drop ping if it\'s already in user\'s phone id list and device pin is different' do
|
|
@@ -143,12 +145,12 @@ describe 'PingJob' do
|
|
|
143
145
|
@c_fields.delete(:id)
|
|
144
146
|
@c2 = Client.create(@c_fields, {:source_name => @s_fields[:name]})
|
|
145
147
|
|
|
146
|
-
Apple.
|
|
147
|
-
PingJob.
|
|
148
|
-
|
|
148
|
+
expect(Apple).to receive(:ping).with({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port}.merge!(params))
|
|
149
|
+
expect(PingJob).to receive(:log).twice.with(/Dropping ping request for client/)
|
|
150
|
+
expect {PingJob.perform(params)}.not_to raise_error
|
|
149
151
|
end
|
|
150
152
|
|
|
151
|
-
|
|
153
|
+
xit 'should ping two different users from two different devices - Apple and GCM' do
|
|
152
154
|
params = {'user_id' => [@u.id, @u1.id],
|
|
153
155
|
'api_token' => @api_token,
|
|
154
156
|
'sources' => [@s.name],
|
|
@@ -165,8 +167,30 @@ describe 'PingJob' do
|
|
|
165
167
|
scrubbed_params['vibrate'] = '5'
|
|
166
168
|
@c1.device_push_type = 'Gcm'
|
|
167
169
|
|
|
168
|
-
Apple.
|
|
169
|
-
Gcm.
|
|
170
|
+
expect(Apple).to receive(:ping).with(params.merge!({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port}))
|
|
171
|
+
expect(Gcm).to receive(:ping).with({'device_pin' => @c1.device_pin, 'device_port' => @c1.device_port}.merge!(scrubbed_params))
|
|
172
|
+
PingJob.perform(params)
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
it 'should ping two different users from two different devices - Apple and FCM' do
|
|
176
|
+
params = {'user_id' => [@u.id, @u1.id],
|
|
177
|
+
'api_token' => @api_token,
|
|
178
|
+
'sources' => [@s.name],
|
|
179
|
+
'message' => 'hello world',
|
|
180
|
+
'vibrate' => '5',
|
|
181
|
+
'badge' => '5',
|
|
182
|
+
'sound' => 'hello.mp3',
|
|
183
|
+
'phone_id' => nil,
|
|
184
|
+
'device_app_id' => nil,
|
|
185
|
+
'device_app_version' => nil, }
|
|
186
|
+
@c.phone_id = '3'
|
|
187
|
+
|
|
188
|
+
scrubbed_params = params.dup
|
|
189
|
+
scrubbed_params['vibrate'] = '5'
|
|
190
|
+
@c1.device_push_type = 'Fcm'
|
|
191
|
+
|
|
192
|
+
expect(Apple).to receive(:ping).with(params.merge!({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port}))
|
|
193
|
+
expect(Fcm).to receive(:ping).with({'device_pin' => @c1.device_pin, 'device_port' => @c1.device_port}.merge!(scrubbed_params))
|
|
170
194
|
PingJob.perform(params)
|
|
171
195
|
end
|
|
172
196
|
|
|
@@ -183,9 +207,9 @@ describe 'PingJob' do
|
|
|
183
207
|
@c.phone_id = '3'
|
|
184
208
|
@c1.phone_id = '3'
|
|
185
209
|
|
|
186
|
-
Apple.
|
|
187
|
-
PingJob.
|
|
188
|
-
|
|
210
|
+
expect(Apple).to receive(:ping).with({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port}.merge!(params))
|
|
211
|
+
expect(PingJob).to receive(:log).once.with(/Dropping ping request for client/)
|
|
212
|
+
expect {PingJob.perform(params)}.not_to raise_error
|
|
189
213
|
end
|
|
190
214
|
|
|
191
215
|
it 'should drop ping with two different users with the same pin' do
|
|
@@ -201,12 +225,12 @@ describe 'PingJob' do
|
|
|
201
225
|
'device_app_version' => nil, }
|
|
202
226
|
@c1.device_pin = @c.device_pin
|
|
203
227
|
|
|
204
|
-
Apple.
|
|
205
|
-
PingJob.
|
|
206
|
-
|
|
228
|
+
expect(Apple).to receive(:ping).with({'device_pin' => @c.device_pin, 'device_port' => @c.device_port}.merge!(params))
|
|
229
|
+
expect(PingJob).to receive(:log).once.with(/Dropping ping request for client/)
|
|
230
|
+
expect {PingJob.perform(params)}.not_to raise_error
|
|
207
231
|
end
|
|
208
232
|
|
|
209
|
-
|
|
233
|
+
xit 'should process all pings even if some of them are failing' do
|
|
210
234
|
params = {'user_id' => [@u.id, @u1.id],
|
|
211
235
|
'api_token' => @api_token,
|
|
212
236
|
'sources' => [@s.name],
|
|
@@ -226,13 +250,30 @@ describe 'PingJob' do
|
|
|
226
250
|
params.merge!({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port})
|
|
227
251
|
allow(Apple).to receive(:ping).with(params).and_raise(SocketError.new("Socket failure"))
|
|
228
252
|
allow(Gcm).to receive(:ping).with({'device_pin' => @c1.device_pin, 'device_port' => @c1.device_port}.merge!(scrubbed_params))
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
253
|
+
expect{ PingJob.perform(params)}.to raise_error
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
it 'should process all pings even if some of them are failing' do
|
|
257
|
+
params = {'user_id' => [@u.id, @u1.id],
|
|
258
|
+
'api_token' => @api_token,
|
|
259
|
+
'sources' => [@s.name],
|
|
260
|
+
'message' => 'hello world',
|
|
261
|
+
'vibrate' => '5',
|
|
262
|
+
'badge' => '5',
|
|
263
|
+
'sound' => 'hello.mp3',
|
|
264
|
+
'phone_id' => nil,
|
|
265
|
+
'device_app_id' => nil,
|
|
266
|
+
'device_app_version' => nil, }
|
|
267
|
+
@c.phone_id = '3'
|
|
268
|
+
|
|
269
|
+
scrubbed_params = params.dup
|
|
270
|
+
scrubbed_params['vibrate'] = '5'
|
|
271
|
+
@c1.device_push_type = 'Fcm'
|
|
272
|
+
|
|
273
|
+
params.merge!({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port})
|
|
274
|
+
allow(Apple).to receive(:ping).with(params).and_raise(SocketError.new("Socket failure"))
|
|
275
|
+
allow(Fcm).to receive(:ping).with({'device_pin' => @c1.device_pin, 'device_port' => @c1.device_port}.merge!(scrubbed_params))
|
|
276
|
+
expect{ PingJob.perform(params)}.to raise_error
|
|
236
277
|
end
|
|
237
278
|
|
|
238
279
|
it 'should skip ping for unknown user or user with no clients' do
|
|
@@ -246,7 +287,7 @@ describe 'PingJob' do
|
|
|
246
287
|
'phone_id' => nil,
|
|
247
288
|
'device_app_id' => nil,
|
|
248
289
|
'device_app_version' => nil, }
|
|
249
|
-
PingJob.
|
|
290
|
+
expect(PingJob).to receive(:log).once.with(/Skipping ping for unknown user 'fake_user' or 'fake_user' has no registered clients.../)
|
|
250
291
|
PingJob.perform(params)
|
|
251
292
|
end
|
|
252
293
|
|
|
@@ -264,7 +305,7 @@ describe 'PingJob' do
|
|
|
264
305
|
}
|
|
265
306
|
scrubbed_params = params.dup
|
|
266
307
|
|
|
267
|
-
RhoconnectPush.
|
|
308
|
+
expect(RhoconnectPush).to receive(:ping).once.with(
|
|
268
309
|
{'device_pin' => @c.device_pin}.merge!(scrubbed_params)
|
|
269
310
|
)
|
|
270
311
|
PingJob.perform(params)
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
|
2
|
+
|
|
3
|
+
describe "Ping Android FCM" do
|
|
4
|
+
include_examples "SharedRhoconnectHelper", :rhoconnect_data => false
|
|
5
|
+
|
|
6
|
+
before(:each) do
|
|
7
|
+
allow( Google::Auth).to receive(:get_application_default)
|
|
8
|
+
@params = {"device_pin" => @c.device_pin,
|
|
9
|
+
"sources" => [@s.name], "message" => 'hello world',
|
|
10
|
+
"vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3'}
|
|
11
|
+
@response = double('response')
|
|
12
|
+
Rhoconnect.settings[:fcm_project_id] = 'valid_project_id'
|
|
13
|
+
Rhoconnect.settings[:package_name] = 'valid_package_name'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "should ping fcm successfully" do
|
|
17
|
+
stub_request(:post, "https://fcm.googleapis.com/v1/projects/valid_project_id/messages:send").with { |request|
|
|
18
|
+
hash = JSON.parse request.body
|
|
19
|
+
valid = hash["message"]["token"] == "abcd"
|
|
20
|
+
valid = valid && hash["message"]["topic"] == nil
|
|
21
|
+
valid = valid && hash["message"]["android"]["restricted_package_name"] == "valid_package_name"
|
|
22
|
+
valid
|
|
23
|
+
}
|
|
24
|
+
Fcm.ping(@params)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "should raise error on missing fcm_project_id setting" do
|
|
28
|
+
key = Rhoconnect.settings[:fcm_project_id.dup]
|
|
29
|
+
Rhoconnect.settings[:fcm_project_id] = nil
|
|
30
|
+
expect(lambda { Fcm.ping(@params) }).to raise_error(Fcm::InvalidProjectId, 'Missing `:fcm_project_id:` option in settings/settings.yml')
|
|
31
|
+
Rhoconnect.settings[:fcm_project_id] = key
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "should raise error on missing package_name setting" do
|
|
35
|
+
key = Rhoconnect.settings[:package_name.dup]
|
|
36
|
+
Rhoconnect.settings[:package_name] = nil
|
|
37
|
+
expect(lambda { Fcm.ping(@params) }).to raise_error(Fcm::InvalidPackageName, 'Missing `:package_name:` option in settings/settings.yml')
|
|
38
|
+
Rhoconnect.settings[:package_name] = key
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "should ping fcm with 503 connection error" do
|
|
42
|
+
stub_request(:post, "https://fcm.googleapis.com/v1/projects/valid_project_id/messages:send").to_raise(RestClient::Exception.new(nil,503))
|
|
43
|
+
expect(lambda { Fcm.ping(@params) }).to raise_error(RestClient::Exception)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
xit "should ping fcm with 200 error message" do
|
|
47
|
+
allow( Google::Auth).to receive(:get_application_default)
|
|
48
|
+
|
|
49
|
+
error = 'error:DeviceMessageRateExceeded'
|
|
50
|
+
allow(@response).to receive(:code).and_return(200)
|
|
51
|
+
allow(@response).to receive(:body).and_return(error)
|
|
52
|
+
allow(@response).to receive(:headers).and_return(nil)
|
|
53
|
+
stub_request(:post, "https://fcm.googleapis.com/v1/projects/valid_project_id/messages:send").to_raise(RestClient::Exception.new(@response,200))
|
|
54
|
+
expect(lambda { Fcm.ping(@params) }).to raise_error(Fcm::FCMPingError, "FCM ping error: DeviceMessageRateExceeded")
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
xit "should fail to ping with bad authentication" do
|
|
58
|
+
error = 'Error=BadAuthentication'
|
|
59
|
+
allow(@response).to receive(:code).and_return(403)
|
|
60
|
+
allow(@response).to receive(:body).and_return(error)
|
|
61
|
+
allow(@response).to receive(:headers).and_return({})
|
|
62
|
+
setup_post_yield(@response)
|
|
63
|
+
expect(Fcm).to receive(:log).twice
|
|
64
|
+
expect(lambda { Fcm.ping(@params) }).to raise_error(
|
|
65
|
+
Fcm::InvalidProjectId, "Invalid FCM project id. Obtain new api key from FCM service."
|
|
66
|
+
)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
xit "should ping fcm with 401 error message" do
|
|
70
|
+
allow(@response).to receive(:code).and_return(401)
|
|
71
|
+
allow(@response).to receive(:body).and_return('')
|
|
72
|
+
setup_post_yield(@response)
|
|
73
|
+
expect(Fcm).to receive(:log).twice
|
|
74
|
+
expect(lambda { Fcm.ping(@params) }).to raise_error(
|
|
75
|
+
Fcm::InvalidProjectId, "Invalid FCM project id. Obtain new api key from FCM service."
|
|
76
|
+
)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "should compute fcm_message" do
|
|
80
|
+
expect(Google::Apis::Messages::Message).to receive(:new) do |options|
|
|
81
|
+
expect(options[:token]).to eq(@c.device_pin)
|
|
82
|
+
expect(options[:android]["priority"]).to eq("high")
|
|
83
|
+
expect(options[:android]["restricted_package_name"]).to eq(Rhoconnect.settings[:package_name])
|
|
84
|
+
expect(options[:android]["data"]["do_sync"]).to eq(@s.name)
|
|
85
|
+
expect(options[:android]["data"]["alert"]).to eq("hello world")
|
|
86
|
+
expect(options[:android]["data"]["vibrate"]).to eq("5")
|
|
87
|
+
expect(options[:android]["data"]["sound"]).to eq("hello.mp3")
|
|
88
|
+
expect(options[:android]["notification"]["body"]).to eq("hello world")
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
Fcm.fcm_message(Rhoconnect.settings[:package_name], @params)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it "should trim empty or nil params from fcm_message" do
|
|
95
|
+
expect(Google::Apis::Messages::Message).to receive(:new) do |options|
|
|
96
|
+
expect(options[:token]).to eq(@c.device_pin)
|
|
97
|
+
expect(options[:android]["priority"]).to eq("high")
|
|
98
|
+
expect(options[:android]["restricted_package_name"]).to eq(Rhoconnect.settings[:package_name])
|
|
99
|
+
expect(options[:android]["data"]["do_sync"]).to eq('')
|
|
100
|
+
expect(options[:android]["data"]["alert"]).to eq(nil)
|
|
101
|
+
expect(options[:android]["data"]["vibrate"]).to eq("5")
|
|
102
|
+
expect(options[:android]["data"]["sound"]).to eq("hello.mp3")
|
|
103
|
+
expect(options[:android]["notification"]["body"]).to eq(nil)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
params = {
|
|
107
|
+
"device_pin" => @c.device_pin,
|
|
108
|
+
"sources" => [],
|
|
109
|
+
"message" => '',
|
|
110
|
+
"vibrate" => '5',
|
|
111
|
+
"sound" => 'hello.mp3'
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
Fcm.fcm_message(Rhoconnect.settings[:package_name], params)
|
|
115
|
+
end
|
|
116
|
+
end
|
data/spec/ping/gcm_spec.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rhoconnect
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 7.1.17
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rhomobile
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-
|
|
11
|
+
date: 2019-11-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -90,16 +90,22 @@ dependencies:
|
|
|
90
90
|
name: rubyzip
|
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
|
92
92
|
requirements:
|
|
93
|
-
- - "
|
|
93
|
+
- - ">="
|
|
94
94
|
- !ruby/object:Gem::Version
|
|
95
95
|
version: 1.2.2
|
|
96
|
+
- - "<"
|
|
97
|
+
- !ruby/object:Gem::Version
|
|
98
|
+
version: 2.1.0
|
|
96
99
|
type: :runtime
|
|
97
100
|
prerelease: false
|
|
98
101
|
version_requirements: !ruby/object:Gem::Requirement
|
|
99
102
|
requirements:
|
|
100
|
-
- - "
|
|
103
|
+
- - ">="
|
|
101
104
|
- !ruby/object:Gem::Version
|
|
102
105
|
version: 1.2.2
|
|
106
|
+
- - "<"
|
|
107
|
+
- !ruby/object:Gem::Version
|
|
108
|
+
version: 2.1.0
|
|
103
109
|
- !ruby/object:Gem::Dependency
|
|
104
110
|
name: connection_pool
|
|
105
111
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -170,6 +176,48 @@ dependencies:
|
|
|
170
176
|
- - "~>"
|
|
171
177
|
- !ruby/object:Gem::Version
|
|
172
178
|
version: 0.20.3
|
|
179
|
+
- !ruby/object:Gem::Dependency
|
|
180
|
+
name: signet
|
|
181
|
+
requirement: !ruby/object:Gem::Requirement
|
|
182
|
+
requirements:
|
|
183
|
+
- - "~>"
|
|
184
|
+
- !ruby/object:Gem::Version
|
|
185
|
+
version: 0.11.0
|
|
186
|
+
type: :runtime
|
|
187
|
+
prerelease: false
|
|
188
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
189
|
+
requirements:
|
|
190
|
+
- - "~>"
|
|
191
|
+
- !ruby/object:Gem::Version
|
|
192
|
+
version: 0.11.0
|
|
193
|
+
- !ruby/object:Gem::Dependency
|
|
194
|
+
name: google-api-client
|
|
195
|
+
requirement: !ruby/object:Gem::Requirement
|
|
196
|
+
requirements:
|
|
197
|
+
- - "~>"
|
|
198
|
+
- !ruby/object:Gem::Version
|
|
199
|
+
version: 0.31.0
|
|
200
|
+
type: :runtime
|
|
201
|
+
prerelease: false
|
|
202
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
203
|
+
requirements:
|
|
204
|
+
- - "~>"
|
|
205
|
+
- !ruby/object:Gem::Version
|
|
206
|
+
version: 0.31.0
|
|
207
|
+
- !ruby/object:Gem::Dependency
|
|
208
|
+
name: google-api-fcm
|
|
209
|
+
requirement: !ruby/object:Gem::Requirement
|
|
210
|
+
requirements:
|
|
211
|
+
- - "~>"
|
|
212
|
+
- !ruby/object:Gem::Version
|
|
213
|
+
version: 0.1.7
|
|
214
|
+
type: :runtime
|
|
215
|
+
prerelease: false
|
|
216
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
217
|
+
requirements:
|
|
218
|
+
- - "~>"
|
|
219
|
+
- !ruby/object:Gem::Version
|
|
220
|
+
version: 0.1.7
|
|
173
221
|
description: RhoConnect App Integration Server and related command-line utilities
|
|
174
222
|
email: dev@rhomobile.com
|
|
175
223
|
executables:
|
|
@@ -504,6 +552,7 @@ files:
|
|
|
504
552
|
- lib/rhoconnect/model/js_base.rb
|
|
505
553
|
- lib/rhoconnect/ping.rb
|
|
506
554
|
- lib/rhoconnect/ping/apple.rb
|
|
555
|
+
- lib/rhoconnect/ping/fcm.rb
|
|
507
556
|
- lib/rhoconnect/ping/gcm.rb
|
|
508
557
|
- lib/rhoconnect/ping/rhoconnect_push.rb
|
|
509
558
|
- lib/rhoconnect/predefined_adapters/bench_adapter.rb
|
|
@@ -672,6 +721,7 @@ files:
|
|
|
672
721
|
- spec/perf/perf_spec_helper.rb
|
|
673
722
|
- spec/perf/store_perf_spec.rb
|
|
674
723
|
- spec/ping/apple_spec.rb
|
|
724
|
+
- spec/ping/fcm_spec.rb
|
|
675
725
|
- spec/ping/gcm_spec.rb
|
|
676
726
|
- spec/ping/rhoconnect_push_spec.rb
|
|
677
727
|
- spec/predefined_adapters/rho_internal_bench_adapter_controller_js_spec.rb
|
|
@@ -831,6 +881,7 @@ test_files:
|
|
|
831
881
|
- spec/perf/perf_spec_helper.rb
|
|
832
882
|
- spec/perf/store_perf_spec.rb
|
|
833
883
|
- spec/ping/apple_spec.rb
|
|
884
|
+
- spec/ping/fcm_spec.rb
|
|
834
885
|
- spec/ping/gcm_spec.rb
|
|
835
886
|
- spec/ping/rhoconnect_push_spec.rb
|
|
836
887
|
- spec/predefined_adapters/rho_internal_bench_adapter_controller_js_spec.rb
|