rhoconnect 6.2.0 → 7.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 867ce0e17fb3e61305afe8736a2f06d913abb0b2
4
- data.tar.gz: 20f31ff7fefe36ae3fd1020ef541fa77062f6583
2
+ SHA256:
3
+ metadata.gz: 83766b251f604a4cd12879f43b25f2c362a02c024854c1939b4308fc910c9407
4
+ data.tar.gz: ab266ed612312bc3d41c96d6f528a2497426b3ee81fd7ce6f4aa087385fabb00
5
5
  SHA512:
6
- metadata.gz: a96a0176b31ca6e2539b18b4cd82235077817ed20a7bedd809878a851cb584fd08747fda22fffcb41d5226f16dbeb8aacca80e10825ad270a6d891277dcbd361
7
- data.tar.gz: a425f98cb21806eaf9058bb44f378173c2daed1f2204d1ec0b9d1f1a1dc1de51bca308478b2d84d0354290e6530454e2a89b0f8feed38b948821894c695e590d
6
+ metadata.gz: 60645c4807398d6e817a47d5d22a76c1280080cfc68920ddea55bc788e986d386ddd5a8e1affeec29de64a2df8295c5afd471560e50dacc48edda684cf49e683
7
+ data.tar.gz: f8b55854160a7efaf803209cf2e796323189613e0d377de39dede5041fc9c46f5bb41e89c213d5bbec240b48e4ecaef74d1aabf49321c2f9cbdbd7914bc3b244
data/Gemfile CHANGED
@@ -29,7 +29,7 @@ group :development do
29
29
  # gem 'debugger'
30
30
  gem 'aws-s3', '>= 0.6.3', :require => 'aws/s3'
31
31
  gem 'sqlite3', ">= 1.4.0", :platforms => [:ruby, :mswin, :mingw]
32
- gem "excon", "~> 0.62.0"
32
+ gem "excon", "~> 0.72.0"
33
33
  gem "net-ssh", "~> 5.2.0"
34
34
  gem "fog-aws", "~> 3.4.0"
35
35
  gem 'ffaker', '~> 2.10.0'
@@ -48,3 +48,7 @@ end
48
48
  group :build do
49
49
  gem 'fpm', '>= 1.11.00'
50
50
  end
51
+
52
+ gem 'signet', '~> 0.7'
53
+ gem 'google-api-client', '~> 0.31.0'
54
+ gem 'google-api-fcm', '~> 0.1.7'
data/Gemfile.lock CHANGED
@@ -8,32 +8,36 @@ GIT
8
8
  PATH
9
9
  remote: .
10
10
  specs:
11
- rhoconnect (7.0.0)
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)
20
+ redis-namespace (~> 1.6.0)
18
21
  resque (>= 2.0.0)
19
22
  rest-client (~> 2.0.2)
20
- rubyzip (~> 1.2.2)
23
+ rubyzip (>= 1.2.2, < 2.1.0)
24
+ signet (~> 0.11.0)
21
25
  sinatra (~> 2.0.5)
22
26
  thor (~> 0.20.3)
23
27
 
24
28
  GEM
25
29
  remote: https://rubygems.org/
26
30
  specs:
27
- addressable (2.6.0)
28
- public_suffix (>= 2.0.2, < 4.0)
31
+ addressable (2.7.0)
32
+ public_suffix (>= 2.0.2, < 5.0)
29
33
  arr-pm (0.0.10)
30
34
  cabin (> 0)
31
35
  aws-s3 (0.6.3)
32
36
  builder
33
37
  mime-types
34
38
  xml-simple
35
- backports (3.13.0)
36
- builder (3.2.3)
39
+ backports (3.16.1)
40
+ builder (3.2.4)
37
41
  cabin (0.9.0)
38
42
  childprocess (0.9.0)
39
43
  ffi (~> 1.0, >= 1.0.11)
@@ -42,23 +46,27 @@ GEM
42
46
  crack (0.4.3)
43
47
  safe_yaml (~> 1.0.0)
44
48
  daemons (1.3.1)
49
+ declarative (0.0.10)
50
+ declarative-option (0.1.0)
45
51
  diff-lcs (1.3)
46
- docile (1.3.1)
47
- domain_name (0.5.20180417)
52
+ docile (1.3.2)
53
+ domain_name (0.5.20190701)
48
54
  unf (>= 0.0.5, < 1.0.0)
49
- dotenv (2.7.2)
55
+ dotenv (2.7.5)
50
56
  eventmachine (1.0.9.1)
51
- excon (0.62.0)
57
+ excon (0.72.0)
58
+ faraday (0.17.3)
59
+ multipart-post (>= 1.2, < 3)
52
60
  ffaker (2.10.0)
53
- ffi (1.10.0)
61
+ ffi (1.12.2)
54
62
  fog-aws (3.4.0)
55
63
  fog-core (~> 2.1)
56
64
  fog-json (~> 1.1)
57
65
  fog-xml (~> 0.1)
58
66
  ipaddress (~> 0.8)
59
- fog-core (2.1.2)
67
+ fog-core (2.2.0)
60
68
  builder
61
- excon (~> 0.58)
69
+ excon (~> 0.71)
62
70
  formatador (~> 0.2)
63
71
  mime-types
64
72
  fog-json (1.2.0)
@@ -79,25 +87,49 @@ GEM
79
87
  pleaserun (~> 0.0.29)
80
88
  ruby-xz (~> 0.2.3)
81
89
  stud
82
- hashdiff (0.3.8)
90
+ google-api-client (0.31.0)
91
+ addressable (~> 2.5, >= 2.5.1)
92
+ googleauth (>= 0.5, < 0.10.0)
93
+ httpclient (>= 2.8.1, < 3.0)
94
+ mini_mime (~> 1.0)
95
+ representable (~> 3.0)
96
+ retriable (>= 2.0, < 4.0)
97
+ signet (~> 0.10)
98
+ google-api-fcm (0.1.7)
99
+ google-api-client (~> 0.17)
100
+ googleauth (0.9.0)
101
+ faraday (~> 0.12)
102
+ jwt (>= 1.4, < 3.0)
103
+ memoist (~> 0.16)
104
+ multi_json (~> 1.11)
105
+ os (>= 0.9, < 2.0)
106
+ signet (~> 0.7)
107
+ hashdiff (1.0.0)
83
108
  http-cookie (1.0.3)
84
109
  domain_name (~> 0.5)
110
+ httpclient (2.8.3)
85
111
  insist (1.0.0)
86
- io-like (0.3.0)
112
+ io-like (0.3.1)
87
113
  ipaddress (0.8.3)
88
114
  json (1.8.6)
89
- mime-types (3.2.2)
115
+ jwt (2.2.1)
116
+ memoist (0.16.2)
117
+ mime-types (3.3.1)
90
118
  mime-types-data (~> 3.2015)
91
- mime-types-data (3.2019.0331)
119
+ mime-types-data (3.2019.1009)
120
+ mini_mime (1.0.2)
92
121
  mini_portile2 (2.4.0)
93
122
  mono_logger (1.1.0)
94
- multi_json (1.13.1)
123
+ multi_json (1.14.1)
124
+ multipart-post (2.1.1)
95
125
  mustache (0.99.8)
96
- mustermann (1.0.3)
126
+ mustermann (1.1.1)
127
+ ruby2_keywords (~> 0.0.1)
97
128
  net-ssh (5.2.0)
98
129
  netrc (0.11.0)
99
- nokogiri (1.10.2)
130
+ nokogiri (1.10.8)
100
131
  mini_portile2 (~> 2.4.0)
132
+ os (1.0.1)
101
133
  pleaserun (0.0.30)
102
134
  cabin (> 0)
103
135
  clamp
@@ -105,17 +137,21 @@ GEM
105
137
  insist
106
138
  mustache (= 0.99.8)
107
139
  stud
108
- public_suffix (3.0.3)
109
- rack (2.0.7)
140
+ public_suffix (4.0.3)
141
+ rack (2.0.9)
110
142
  rack-fiber_pool (0.9.3)
111
- rack-protection (2.0.5)
143
+ rack-protection (2.0.8.1)
112
144
  rack
113
145
  rack-test (1.1.0)
114
146
  rack (>= 1.0, < 3)
115
- rake (12.3.2)
116
- redis (4.1.0)
147
+ rake (12.3.3)
148
+ redis (4.1.3)
117
149
  redis-namespace (1.6.0)
118
150
  redis (>= 3.0.4)
151
+ representable (3.0.4)
152
+ declarative (< 0.1.0)
153
+ declarative-option (< 0.2.0)
154
+ uber (< 0.2.0)
119
155
  resque (2.0.0)
120
156
  mono_logger (~> 1.0)
121
157
  multi_json (~> 1.0)
@@ -126,47 +162,54 @@ GEM
126
162
  http-cookie (>= 1.0.2, < 2.0)
127
163
  mime-types (>= 1.16, < 4.0)
128
164
  netrc (~> 0.8)
165
+ retriable (3.1.2)
129
166
  rspec (3.8.0)
130
167
  rspec-core (~> 3.8.0)
131
168
  rspec-expectations (~> 3.8.0)
132
169
  rspec-mocks (~> 3.8.0)
133
- rspec-core (3.8.0)
170
+ rspec-core (3.8.2)
134
171
  rspec-support (~> 3.8.0)
135
- rspec-expectations (3.8.2)
172
+ rspec-expectations (3.8.6)
136
173
  diff-lcs (>= 1.2.0, < 2.0)
137
174
  rspec-support (~> 3.8.0)
138
- rspec-mocks (3.8.0)
175
+ rspec-mocks (3.8.2)
139
176
  diff-lcs (>= 1.2.0, < 2.0)
140
177
  rspec-support (~> 3.8.0)
141
- rspec-support (3.8.0)
178
+ rspec-support (3.8.3)
142
179
  ruby-xz (0.2.3)
143
180
  ffi (~> 1.9)
144
181
  io-like (~> 0.3)
145
- rubyzip (1.2.2)
182
+ ruby2_keywords (0.0.2)
183
+ rubyzip (2.0.0)
146
184
  safe_yaml (1.0.5)
147
- simplecov (0.16.1)
185
+ signet (0.11.0)
186
+ addressable (~> 2.3)
187
+ faraday (~> 0.9)
188
+ jwt (>= 1.5, < 3.0)
189
+ multi_json (~> 1.10)
190
+ simplecov (0.18.2)
148
191
  docile (~> 1.1)
149
- json (>= 1.8, < 3)
150
- simplecov-html (~> 0.10.0)
151
- simplecov-html (0.10.2)
192
+ simplecov-html (~> 0.11)
193
+ simplecov-html (0.12.0)
152
194
  simplecov-rcov (0.2.3)
153
195
  simplecov (>= 0.4.1)
154
- sinatra (2.0.5)
196
+ sinatra (2.0.8.1)
155
197
  mustermann (~> 1.0)
156
198
  rack (~> 2.0)
157
- rack-protection (= 2.0.5)
199
+ rack-protection (= 2.0.8.1)
158
200
  tilt (~> 2.0)
159
- sqlite3 (1.4.0)
201
+ sqlite3 (1.4.2)
160
202
  stud (0.0.23)
161
203
  thin (1.7.2)
162
204
  daemons (~> 1.0, >= 1.0.9)
163
205
  eventmachine (~> 1.0, >= 1.0.4)
164
206
  rack (>= 1, < 3)
165
207
  thor (0.20.3)
166
- tilt (2.0.9)
208
+ tilt (2.0.10)
209
+ uber (0.1.0)
167
210
  unf (0.1.4)
168
211
  unf_ext
169
- unf_ext (0.0.7.5)
212
+ unf_ext (0.0.7.6)
170
213
  vegas (0.1.11)
171
214
  rack (>= 1.0.0)
172
215
  webmock (3.5.1)
@@ -184,10 +227,12 @@ DEPENDENCIES
184
227
  dbd-jdbc (>= 0.1.4)
185
228
  dbi (>= 0.4.5)
186
229
  eventmachine (~> 1.0.5)
187
- excon (~> 0.62.0)
230
+ excon (~> 0.72.0)
188
231
  ffaker (~> 2.10.0)
189
232
  fog-aws (~> 3.4.0)
190
233
  fpm (>= 1.11.00)
234
+ google-api-client (~> 0.31.0)
235
+ google-api-fcm (~> 0.1.7)
191
236
  jdbc-sqlite3 (>= 3.7.2)
192
237
  jruby-openssl (>= 0.7.4)
193
238
  net-ssh (~> 5.2.0)
@@ -196,6 +241,7 @@ DEPENDENCIES
196
241
  rack-test (~> 1.1.0)
197
242
  rhoconnect!
198
243
  rspec (~> 3.8.0)
244
+ signet (~> 0.7)
199
245
  simplecov (>= 0.16.1)
200
246
  simplecov-rcov (~> 0.2.3)
201
247
  sqlite3 (>= 1.4.0)
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://travis-ci.org/rhomobile/rhoconnect.svg?branch=master)](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
File without changes
@@ -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
@@ -1,3 +1,3 @@
1
1
  require 'rhoconnect/ping/apple'
2
2
  require 'rhoconnect/ping/rhoconnect_push'
3
- require 'rhoconnect/ping/gcm'
3
+ require 'rhoconnect/ping/fcm'
@@ -1,3 +1,3 @@
1
1
  module Rhoconnect
2
- VERSION = '6.2.0'
2
+ VERSION = '7.5.1'
3
3
  end
data/rhoconnect.gemspec CHANGED
@@ -44,10 +44,14 @@ 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', '~> 1.2.2')
47
+ s.add_dependency('rubyzip', '>= 1.2.2', '< 2.1.0')
48
48
  s.add_dependency('connection_pool', '~> 2.2.2')
49
+ s.add_dependency('redis-namespace', '~> 1.6.0')
49
50
  s.add_dependency('redis', '~> 4.1.0')
50
51
  s.add_dependency('resque', '>= 2.0.0')
51
52
  s.add_dependency('rest-client', '~> 2.0.2')
52
53
  s.add_dependency('thor', '~> 0.20.3')
54
+ s.add_dependency('signet', '~> 0.11.0')
55
+ s.add_dependency('google-api-client', '~> 0.31.0')
56
+ s.add_dependency('google-api-fcm', '~> 0.1.7')
53
57
  end
@@ -33,8 +33,10 @@ describe 'PingJob' do
33
33
  scrubbed_params = params.dup
34
34
  scrubbed_params['vibrate'] = '5'
35
35
 
36
- Apple.should_receive(:ping).once.with({'device_pin' => @c.device_pin,
37
- 'device_port' => @c.device_port}.merge!(scrubbed_params))
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.should_receive(:ping).once.with({'device_pin' => @c.device_pin,
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.should_receive(:log).once.with("Dropping ping request for unsupported platform '#{@c.device_type}'")
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.should_receive(:log).once.with("Skipping ping for non-registered client_id '#{@c.id}'...")
85
- lambda {PingJob.perform(params)}.should_not raise_error
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.should_receive(:log).once.with("Skipping ping for non-registered client_id '#{@c.id}'...")
101
- lambda {PingJob.perform(params)}.should_not raise_error
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.should_receive(:ping).with({'device_pin' => @c.device_pin, 'device_port' => @c.device_port}.merge!(params))
123
- PingJob.should_receive(:log).twice.with(/Dropping ping request for client/)
124
- lambda {PingJob.perform(params)}.should_not raise_error
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.should_receive(:ping).with({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port}.merge!(params))
147
- PingJob.should_receive(:log).twice.with(/Dropping ping request for client/)
148
- lambda {PingJob.perform(params)}.should_not raise_error
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
- it 'should ping two different users from two different devices - Apple and GCM' do
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.should_receive(:ping).with(params.merge!({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port}))
169
- Gcm.should_receive(:ping).with({'device_pin' => @c1.device_pin, 'device_port' => @c1.device_port}.merge!(scrubbed_params))
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.should_receive(:ping).with({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port}.merge!(params))
187
- PingJob.should_receive(:log).once.with(/Dropping ping request for client/)
188
- lambda {PingJob.perform(params)}.should_not raise_error
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.should_receive(:ping).with({'device_pin' => @c.device_pin, 'device_port' => @c.device_port}.merge!(params))
205
- PingJob.should_receive(:log).once.with(/Dropping ping request for client/)
206
- lambda {PingJob.perform(params)}.should_not raise_error
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
- it 'should process all pings even if some of them are failing' do
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
- exception_raised = false
230
- begin
231
- PingJob.perform(params)
232
- rescue Exception => e
233
- exception_raised = true
234
- end
235
- exception_raised.should == true
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.should_receive(:log).once.with(/Skipping ping for unknown user 'fake_user' or 'fake_user' has no registered clients.../)
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.should_receive(:ping).once.with(
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
@@ -1,6 +1,6 @@
1
1
  require File.join(File.dirname(__FILE__),'..','spec_helper')
2
2
 
3
- describe "Ping Android GCM" do
3
+ xdescribe "Ping Android GCM" do
4
4
  include_examples "SharedRhoconnectHelper", :rhoconnect_data => false
5
5
 
6
6
  before(:each) do
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: 6.2.0
4
+ version: 7.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rhomobile
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-09 00:00:00.000000000 Z
11
+ date: 2022-07-20 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
@@ -114,6 +120,20 @@ dependencies:
114
120
  - - "~>"
115
121
  - !ruby/object:Gem::Version
116
122
  version: 2.2.2
123
+ - !ruby/object:Gem::Dependency
124
+ name: redis-namespace
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: 1.6.0
130
+ type: :runtime
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - "~>"
135
+ - !ruby/object:Gem::Version
136
+ version: 1.6.0
117
137
  - !ruby/object:Gem::Dependency
118
138
  name: redis
119
139
  requirement: !ruby/object:Gem::Requirement
@@ -170,6 +190,48 @@ dependencies:
170
190
  - - "~>"
171
191
  - !ruby/object:Gem::Version
172
192
  version: 0.20.3
193
+ - !ruby/object:Gem::Dependency
194
+ name: signet
195
+ requirement: !ruby/object:Gem::Requirement
196
+ requirements:
197
+ - - "~>"
198
+ - !ruby/object:Gem::Version
199
+ version: 0.11.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.11.0
207
+ - !ruby/object:Gem::Dependency
208
+ name: google-api-client
209
+ requirement: !ruby/object:Gem::Requirement
210
+ requirements:
211
+ - - "~>"
212
+ - !ruby/object:Gem::Version
213
+ version: 0.31.0
214
+ type: :runtime
215
+ prerelease: false
216
+ version_requirements: !ruby/object:Gem::Requirement
217
+ requirements:
218
+ - - "~>"
219
+ - !ruby/object:Gem::Version
220
+ version: 0.31.0
221
+ - !ruby/object:Gem::Dependency
222
+ name: google-api-fcm
223
+ requirement: !ruby/object:Gem::Requirement
224
+ requirements:
225
+ - - "~>"
226
+ - !ruby/object:Gem::Version
227
+ version: 0.1.7
228
+ type: :runtime
229
+ prerelease: false
230
+ version_requirements: !ruby/object:Gem::Requirement
231
+ requirements:
232
+ - - "~>"
233
+ - !ruby/object:Gem::Version
234
+ version: 0.1.7
173
235
  description: RhoConnect App Integration Server and related command-line utilities
174
236
  email: dev@rhomobile.com
175
237
  executables:
@@ -504,6 +566,7 @@ files:
504
566
  - lib/rhoconnect/model/js_base.rb
505
567
  - lib/rhoconnect/ping.rb
506
568
  - lib/rhoconnect/ping/apple.rb
569
+ - lib/rhoconnect/ping/fcm.rb
507
570
  - lib/rhoconnect/ping/gcm.rb
508
571
  - lib/rhoconnect/ping/rhoconnect_push.rb
509
572
  - lib/rhoconnect/predefined_adapters/bench_adapter.rb
@@ -672,6 +735,7 @@ files:
672
735
  - spec/perf/perf_spec_helper.rb
673
736
  - spec/perf/store_perf_spec.rb
674
737
  - spec/ping/apple_spec.rb
738
+ - spec/ping/fcm_spec.rb
675
739
  - spec/ping/gcm_spec.rb
676
740
  - spec/ping/rhoconnect_push_spec.rb
677
741
  - spec/predefined_adapters/rho_internal_bench_adapter_controller_js_spec.rb
@@ -721,8 +785,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
721
785
  - !ruby/object:Gem::Version
722
786
  version: '0'
723
787
  requirements: []
724
- rubyforge_project:
725
- rubygems_version: 2.4.5.1
788
+ rubygems_version: 3.0.3.1
726
789
  signing_key:
727
790
  specification_version: 4
728
791
  summary: RhoConnect App Integration Server
@@ -831,6 +894,7 @@ test_files:
831
894
  - spec/perf/perf_spec_helper.rb
832
895
  - spec/perf/store_perf_spec.rb
833
896
  - spec/ping/apple_spec.rb
897
+ - spec/ping/fcm_spec.rb
834
898
  - spec/ping/gcm_spec.rb
835
899
  - spec/ping/rhoconnect_push_spec.rb
836
900
  - spec/predefined_adapters/rho_internal_bench_adapter_controller_js_spec.rb