rhoconnect 5.5.18 → 7.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +18 -11
- data/Gemfile.lock +178 -100
- data/README.md +2 -0
- data/Rakefile +4 -3
- data/commands/dtach/dtach_install.rb +29 -24
- data/commands/rhoconnect/start.rb +5 -4
- data/generators/templates/application/rcgemfile +1 -1
- data/lib/rhoconnect/model/helpers/find_duplicates_on_update.rb +1 -1
- data/lib/rhoconnect/ping/fcm.rb +74 -0
- data/lib/rhoconnect/ping.rb +1 -1
- data/lib/rhoconnect/store.rb +3 -3
- data/lib/rhoconnect/version.rb +1 -1
- data/rhoconnect.gemspec +15 -11
- data/spec/api/client/get_client_params_spec.rb +4 -0
- data/spec/apps/rhotestapp/models/ruby/sample_adapter.rb +1 -1
- data/spec/client_sync_spec.rb +7 -7
- data/spec/dynamic_adapter_spec.rb +13 -13
- data/spec/generator/generator_spec.rb +7 -7
- data/spec/jobs/ping_job_spec.rb +229 -105
- data/spec/perf/perf_spec_helper.rb +5 -5
- data/spec/ping/apple_spec.rb +24 -26
- data/spec/ping/fcm_spec.rb +116 -0
- data/spec/ping/gcm_spec.rb +27 -29
- data/spec/ping/rhoconnect_push_spec.rb +13 -13
- data/spec/rhoconnect_spec.rb +2 -2
- data/spec/server/cors_spec.rb +22 -22
- data/spec/server/server_spec.rb +308 -310
- data/spec/server/stats_spec.rb +7 -7
- data/spec/server/x_domain_session_wrapper_spec.rb +40 -40
- data/spec/source_adapter_spec.rb +2 -2
- data/spec/source_sync_spec.rb +4 -4
- data/spec/spec_helper.rb +8 -8
- data/spec/stats/record_spec.rb +7 -7
- data/spec/store_orm_spec.rb +97 -94
- data/spec/store_spec.rb +23 -23
- data/spec/user_spec.rb +3 -3
- metadata +98 -27
data/spec/jobs/ping_job_spec.rb
CHANGED
@@ -1,189 +1,313 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__),'..','spec_helper')
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
2
|
|
3
|
-
describe
|
4
|
-
include_examples
|
3
|
+
describe 'PingJob' do
|
4
|
+
include_examples 'SharedRhoconnectHelper', :rhoconnect_data => true
|
5
5
|
|
6
6
|
before(:each) do
|
7
7
|
@u1_fields = {:login => 'testuser1'}
|
8
8
|
@u1 = User.create(@u1_fields)
|
9
9
|
@u1.password = 'testpass1'
|
10
10
|
@c1_fields = {
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
:device_type => 'Apple',
|
12
|
+
:device_pin => 'abcde',
|
13
|
+
:device_port => '3333',
|
14
|
+
:user_id => @u1.id,
|
15
|
+
:app_id => @a.id
|
16
16
|
}
|
17
|
-
@c1 = Client.create(@c1_fields,{:source_name => @s_fields[:name]})
|
17
|
+
@c1 = Client.create(@c1_fields, {:source_name => @s_fields[:name]})
|
18
18
|
@a.users << @u1.id
|
19
19
|
end
|
20
20
|
|
21
|
-
it
|
22
|
-
params = {
|
23
|
-
|
24
|
-
|
21
|
+
it 'should perform apple ping with integer parameters' do
|
22
|
+
params = {'user_id' => @u.id,
|
23
|
+
'api_token' => @api_token,
|
24
|
+
'sources' => [@s.name],
|
25
|
+
'message' => 'hello world',
|
26
|
+
'vibrate' => 5,
|
27
|
+
'badge' => '5',
|
28
|
+
'sound' => 'hello.mp3',
|
29
|
+
'phone_id' => nil,
|
30
|
+
'device_app_id' => nil,
|
31
|
+
'device_app_version' => nil, }
|
25
32
|
|
26
33
|
scrubbed_params = params.dup
|
27
34
|
scrubbed_params['vibrate'] = '5'
|
28
35
|
|
29
|
-
Apple.
|
30
|
-
|
36
|
+
expect(Apple).to receive(:ping).once.with({
|
37
|
+
'device_pin' => @c.device_pin,
|
38
|
+
'device_port' => @c.device_port
|
39
|
+
}.merge!(scrubbed_params))
|
31
40
|
PingJob.perform(params)
|
32
41
|
end
|
33
42
|
|
34
|
-
it
|
35
|
-
params = {
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
43
|
+
it 'should perform apple ping' do
|
44
|
+
params = {'user_id' => @u.id,
|
45
|
+
'api_token' => @api_token,
|
46
|
+
'sources' => [@s.name],
|
47
|
+
'message' => 'hello world',
|
48
|
+
'vibrate' => '5',
|
49
|
+
'badge' => '5',
|
50
|
+
'sound' => 'hello.mp3',
|
51
|
+
'phone_id' => nil,
|
52
|
+
'device_app_id' => nil,
|
53
|
+
'device_app_version' => nil}
|
54
|
+
expect(Apple).to receive(:ping).once.with({'device_pin' => @c.device_pin,
|
55
|
+
'device_port' => @c.device_port}.merge!(params))
|
40
56
|
PingJob.perform(params)
|
41
57
|
end
|
42
58
|
|
43
|
-
it
|
44
|
-
params = {
|
45
|
-
|
46
|
-
|
59
|
+
it 'should skip ping for the unknown platform' do
|
60
|
+
params = {'user_id' => @u.id,
|
61
|
+
'api_token' => @api_token,
|
62
|
+
'sources' => [@s.name],
|
63
|
+
'message' => 'hello world',
|
64
|
+
'vibrate' => '5',
|
65
|
+
'badge' => '5',
|
66
|
+
'sound' => 'hello.mp3',
|
67
|
+
'phone_id' => nil,
|
68
|
+
'device_app_id' => nil,
|
69
|
+
'device_app_version' => nil}
|
47
70
|
@c.device_type = 'unknown_device_type'
|
48
|
-
PingJob.
|
71
|
+
expect(PingJob).to receive(:log).once.with("Dropping ping request for unsupported platform '#{@c.device_type}'")
|
49
72
|
PingJob.perform(params)
|
50
73
|
end
|
51
74
|
|
52
|
-
it
|
53
|
-
params = {
|
54
|
-
|
55
|
-
|
75
|
+
it 'should skip ping for empty device_type' do
|
76
|
+
params = {'user_id' => @u.id,
|
77
|
+
'api_token' => @api_token,
|
78
|
+
'sources' => [@s.name],
|
79
|
+
'message' => 'hello world',
|
80
|
+
'vibrate' => '5',
|
81
|
+
'badge' => '5',
|
82
|
+
'sound' => 'hello.mp3',
|
83
|
+
'device_app_id' => nil,
|
84
|
+
'device_app_version' => nil}
|
56
85
|
@c.device_type = nil
|
57
|
-
PingJob.
|
58
|
-
|
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
|
59
88
|
end
|
60
89
|
|
61
|
-
it
|
62
|
-
params = {
|
63
|
-
|
64
|
-
|
90
|
+
it 'should skip ping for empty device_pin' do
|
91
|
+
params = {'user_id' => @u.id,
|
92
|
+
'api_token' => @api_token,
|
93
|
+
'sources' => [@s.name],
|
94
|
+
'message' => 'hello world',
|
95
|
+
'vibrate' => '5',
|
96
|
+
'badge' => '5',
|
97
|
+
'sound' => 'hello.mp3',
|
98
|
+
'device_app_id' => nil,
|
99
|
+
'device_app_version' => nil, }
|
65
100
|
@c.device_type = 'Android'
|
66
101
|
@c.device_pin = nil
|
67
|
-
PingJob.
|
68
|
-
|
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
|
69
104
|
end
|
70
105
|
|
71
|
-
it
|
72
|
-
params = {
|
73
|
-
|
74
|
-
|
106
|
+
it 'should drop ping if it\'s already in user\'s device pin list' do
|
107
|
+
params = {'user_id' => @u.id,
|
108
|
+
'api_token' => @api_token,
|
109
|
+
'sources' => [@s.name],
|
110
|
+
'message' => 'hello world',
|
111
|
+
'vibrate' => '5',
|
112
|
+
'badge' => '5',
|
113
|
+
'sound' => 'hello.mp3',
|
114
|
+
'phone_id' => nil,
|
115
|
+
'device_app_id' => nil,
|
116
|
+
'device_app_version' => nil}
|
75
117
|
# another client with the same device pin ...
|
76
118
|
@c_fields.delete(:id)
|
77
|
-
@c1 = Client.create(@c_fields,{:source_name => @s_fields[:name]})
|
119
|
+
@c1 = Client.create(@c_fields, {:source_name => @s_fields[:name]})
|
78
120
|
# and yet another one ...
|
79
121
|
@c_fields.delete(:id)
|
80
|
-
@c2 = Client.create(@c_fields,{:source_name => @s_fields[:name]})
|
122
|
+
@c2 = Client.create(@c_fields, {:source_name => @s_fields[:name]})
|
81
123
|
|
82
|
-
Apple.
|
83
|
-
PingJob.
|
84
|
-
|
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
|
85
127
|
end
|
86
128
|
|
87
|
-
it
|
88
|
-
params = {
|
89
|
-
|
90
|
-
|
129
|
+
it 'should drop ping if it\'s already in user\'s phone id list and device pin is different' do
|
130
|
+
params = {'user_id' => @u.id,
|
131
|
+
'api_token' => @api_token,
|
132
|
+
'sources' => [@s.name],
|
133
|
+
'message' => 'hello world',
|
134
|
+
'vibrate' => '5',
|
135
|
+
'badge' => '5',
|
136
|
+
'sound' => 'hello.mp3',
|
137
|
+
'device_app_id' => nil,
|
138
|
+
'device_app_version' => nil, }
|
91
139
|
@c.phone_id = '3'
|
92
140
|
@c_fields.merge!(:phone_id => '3')
|
93
141
|
# another client with the same phone id..
|
94
142
|
@c_fields.delete(:id)
|
95
|
-
@c1 = Client.create(@c_fields,{:source_name => @s_fields[:name]})
|
143
|
+
@c1 = Client.create(@c_fields, {:source_name => @s_fields[:name]})
|
96
144
|
# yet another...
|
97
145
|
@c_fields.delete(:id)
|
98
|
-
@c2 = Client.create(@c_fields,{:source_name => @s_fields[:name]})
|
146
|
+
@c2 = Client.create(@c_fields, {:source_name => @s_fields[:name]})
|
99
147
|
|
100
|
-
Apple.
|
101
|
-
PingJob.
|
102
|
-
|
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
|
103
151
|
end
|
104
152
|
|
105
|
-
|
106
|
-
params = {
|
107
|
-
|
108
|
-
|
153
|
+
xit 'should ping two different users from two different devices - Apple and GCM' do
|
154
|
+
params = {'user_id' => [@u.id, @u1.id],
|
155
|
+
'api_token' => @api_token,
|
156
|
+
'sources' => [@s.name],
|
157
|
+
'message' => 'hello world',
|
158
|
+
'vibrate' => '5',
|
159
|
+
'badge' => '5',
|
160
|
+
'sound' => 'hello.mp3',
|
161
|
+
'phone_id' => nil,
|
162
|
+
'device_app_id' => nil,
|
163
|
+
'device_app_version' => nil, }
|
109
164
|
@c.phone_id = '3'
|
110
165
|
|
111
166
|
scrubbed_params = params.dup
|
112
167
|
scrubbed_params['vibrate'] = '5'
|
113
168
|
@c1.device_push_type = 'Gcm'
|
114
169
|
|
115
|
-
Apple.
|
116
|
-
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))
|
117
172
|
PingJob.perform(params)
|
118
173
|
end
|
119
174
|
|
120
|
-
it
|
121
|
-
params = {
|
122
|
-
|
123
|
-
|
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))
|
194
|
+
PingJob.perform(params)
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'should drop ping with two different users from the same device' do
|
198
|
+
params = {'user_id' => [@u.id, @u1.id],
|
199
|
+
'api_token' => @api_token,
|
200
|
+
'sources' => [@s.name],
|
201
|
+
'message' => 'hello world',
|
202
|
+
'vibrate' => '5',
|
203
|
+
'badge' => '5',
|
204
|
+
'sound' => 'hello.mp3',
|
205
|
+
'device_app_id' => nil,
|
206
|
+
'device_app_version' => nil, }
|
124
207
|
@c.phone_id = '3'
|
125
208
|
@c1.phone_id = '3'
|
126
209
|
|
127
|
-
Apple.
|
128
|
-
PingJob.
|
129
|
-
|
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
|
130
213
|
end
|
131
214
|
|
132
|
-
it
|
133
|
-
params = {
|
134
|
-
|
135
|
-
|
215
|
+
it 'should drop ping with two different users with the same pin' do
|
216
|
+
params = {'user_id' => [@u.id, @u1.id],
|
217
|
+
'api_token' => @api_token,
|
218
|
+
'sources' => [@s.name],
|
219
|
+
'message' => 'hello world',
|
220
|
+
'phone_id' => nil,
|
221
|
+
'vibrate' => '5',
|
222
|
+
'badge' => '5',
|
223
|
+
'sound' => 'hello.mp3',
|
224
|
+
'device_app_id' => nil,
|
225
|
+
'device_app_version' => nil, }
|
136
226
|
@c1.device_pin = @c.device_pin
|
137
227
|
|
138
|
-
Apple.
|
139
|
-
PingJob.
|
140
|
-
|
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
|
141
231
|
end
|
142
232
|
|
143
|
-
|
144
|
-
params = {
|
145
|
-
|
146
|
-
|
233
|
+
xit 'should process all pings even if some of them are failing' do
|
234
|
+
params = {'user_id' => [@u.id, @u1.id],
|
235
|
+
'api_token' => @api_token,
|
236
|
+
'sources' => [@s.name],
|
237
|
+
'message' => 'hello world',
|
238
|
+
'vibrate' => '5',
|
239
|
+
'badge' => '5',
|
240
|
+
'sound' => 'hello.mp3',
|
241
|
+
'phone_id' => nil,
|
242
|
+
'device_app_id' => nil,
|
243
|
+
'device_app_version' => nil, }
|
147
244
|
@c.phone_id = '3'
|
148
245
|
|
149
246
|
scrubbed_params = params.dup
|
150
247
|
scrubbed_params['vibrate'] = '5'
|
151
248
|
@c1.device_push_type = 'Gcm'
|
152
249
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
250
|
+
params.merge!({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port})
|
251
|
+
allow(Apple).to receive(:ping).with(params).and_raise(SocketError.new("Socket failure"))
|
252
|
+
allow(Gcm).to receive(:ping).with({'device_pin' => @c1.device_pin, 'device_port' => @c1.device_port}.merge!(scrubbed_params))
|
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
|
277
|
+
end
|
278
|
+
|
279
|
+
it 'should skip ping for unknown user or user with no clients' do
|
280
|
+
params = {'user_id' => ['fake_user'],
|
281
|
+
'api_token' => @api_token,
|
282
|
+
'sources' => [@s.name],
|
283
|
+
'message' => 'hello world',
|
284
|
+
'vibrate' => '5',
|
285
|
+
'badge' => '5',
|
286
|
+
'sound' => 'hello.mp3',
|
287
|
+
'phone_id' => nil,
|
288
|
+
'device_app_id' => nil,
|
289
|
+
'device_app_version' => nil, }
|
290
|
+
expect(PingJob).to receive(:log).once.with(/Skipping ping for unknown user 'fake_user' or 'fake_user' has no registered clients.../)
|
169
291
|
PingJob.perform(params)
|
170
292
|
end
|
171
293
|
|
172
|
-
it
|
294
|
+
it 'should process ping for device_push_type if available' do
|
173
295
|
@c.device_push_type = 'rhoconnect_push'
|
174
296
|
@c.device_port = nil
|
175
297
|
params = {
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
298
|
+
'user_id' => @u.id,
|
299
|
+
'message' => 'hello world',
|
300
|
+
'device_port' => '',
|
301
|
+
'vibrate' => '',
|
302
|
+
'phone_id' => nil,
|
303
|
+
'device_app_id' => nil,
|
304
|
+
'device_app_version' => nil,
|
181
305
|
}
|
182
306
|
scrubbed_params = params.dup
|
183
307
|
|
184
|
-
RhoconnectPush.
|
185
|
-
|
308
|
+
expect(RhoconnectPush).to receive(:ping).once.with(
|
309
|
+
{'device_pin' => @c.device_pin}.merge!(scrubbed_params)
|
186
310
|
)
|
187
311
|
PingJob.perform(params)
|
188
312
|
end
|
189
|
-
end
|
313
|
+
end
|
@@ -41,12 +41,12 @@ def generate_fake_data(num=1000,unique=false)
|
|
41
41
|
unique_prefix = "#{n}-#{Time.now.to_s}"
|
42
42
|
end
|
43
43
|
res[n.to_s] = {
|
44
|
-
"FirstName" =>
|
45
|
-
"LastName" =>
|
46
|
-
"Email" =>
|
47
|
-
"Company" =>
|
44
|
+
"FirstName" => FFaker::Name.first_name + unique_prefix,
|
45
|
+
"LastName" => FFaker::Name.last_name + unique_prefix,
|
46
|
+
"Email" => FFaker::Internet.free_email + unique_prefix,
|
47
|
+
"Company" => FFaker::Company.name + unique_prefix,
|
48
48
|
"JobTitle" => title + unique_prefix,
|
49
|
-
"Phone1" =>
|
49
|
+
"Phone1" => FFaker::PhoneNumber.phone_number + unique_prefix
|
50
50
|
}
|
51
51
|
end
|
52
52
|
res
|
data/spec/ping/apple_spec.rb
CHANGED
@@ -9,22 +9,22 @@ describe "Ping Apple" do
|
|
9
9
|
"vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3',
|
10
10
|
"device_pin" => @c.device_pin, "device_port" => @c.device_port}
|
11
11
|
ssl_ctx = double("ssl_ctx")
|
12
|
-
ssl_ctx.
|
13
|
-
ssl_ctx.
|
14
|
-
OpenSSL::SSL::SSLContext.
|
15
|
-
OpenSSL::PKey::RSA.
|
16
|
-
OpenSSL::X509::Certificate.
|
12
|
+
allow(ssl_ctx).to receive(:key=).and_return('key')
|
13
|
+
allow(ssl_ctx).to receive(:cert=).and_return('cert')
|
14
|
+
allow(OpenSSL::SSL::SSLContext).to receive(:new).and_return(ssl_ctx)
|
15
|
+
allow(OpenSSL::PKey::RSA).to receive(:new)
|
16
|
+
allow(OpenSSL::X509::Certificate).to receive(:new)
|
17
17
|
|
18
18
|
tcp_socket = double("tcp_socket")
|
19
|
-
tcp_socket.
|
20
|
-
TCPSocket.
|
19
|
+
allow(tcp_socket).to receive(:close)
|
20
|
+
allow(TCPSocket).to receive(:new).and_return(tcp_socket)
|
21
21
|
|
22
22
|
@ssl_socket = double("ssl_socket")
|
23
|
-
@ssl_socket.
|
24
|
-
@ssl_socket.
|
25
|
-
@ssl_socket.
|
26
|
-
@ssl_socket.
|
27
|
-
OpenSSL::SSL::SSLSocket.
|
23
|
+
allow(@ssl_socket).to receive(:sync=)
|
24
|
+
allow(@ssl_socket).to receive(:connect)
|
25
|
+
allow(@ssl_socket).to receive(:write)
|
26
|
+
allow(@ssl_socket).to receive(:close)
|
27
|
+
allow(OpenSSL::SSL::SSLSocket).to receive(:new).and_return(@ssl_socket)
|
28
28
|
end
|
29
29
|
|
30
30
|
# TODO: This should really test SSLSocket.write
|
@@ -33,9 +33,7 @@ describe "Ping Apple" do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should log deprecation on iphone ping" do
|
36
|
-
Iphone.
|
37
|
-
:log
|
38
|
-
).once.with("DEPRECATION WARNING: 'iphone' is a deprecated device_type, use 'apple' instead")
|
36
|
+
expect(Iphone).to receive(:log).once.with("DEPRECATION WARNING: 'iphone' is a deprecated device_type, use 'apple' instead")
|
39
37
|
Iphone.ping(@params)
|
40
38
|
end
|
41
39
|
|
@@ -45,8 +43,8 @@ describe "Ping Apple" do
|
|
45
43
|
"do_sync"=>["SampleAdapter"]
|
46
44
|
}
|
47
45
|
apn_message = Apple.apn_message(@params)
|
48
|
-
apn_message[0, 7].inspect.gsub("\"", "").
|
49
|
-
JSON.parse(apn_message[7, apn_message.length]).
|
46
|
+
expect(apn_message[0, 7].inspect.gsub("\"", "")).to eq("\\x00\\x00 \\xAB\\xCD\\x00g")
|
47
|
+
expect(JSON.parse(apn_message[7, apn_message.length])).to eq(expected_hash)
|
50
48
|
end
|
51
49
|
|
52
50
|
it "should compute apn_message with source array" do
|
@@ -56,21 +54,21 @@ describe "Ping Apple" do
|
|
56
54
|
"do_sync"=>["SampleAdapter", "SimpleAdapter"]
|
57
55
|
}
|
58
56
|
apn_message = Apple.apn_message(@params)
|
59
|
-
apn_message[0, 7].inspect.gsub("\"", "").
|
60
|
-
JSON.parse(apn_message[7, apn_message.length]).
|
57
|
+
expect(apn_message[0, 7].inspect.gsub("\"", "")).to eq("\\x00\\x00 \\xAB\\xCD\\x00w")
|
58
|
+
expect(JSON.parse(apn_message[7, apn_message.length])).to eq(expected_hash)
|
61
59
|
end
|
62
60
|
|
63
61
|
it "should raise SocketError if socket fails" do
|
64
62
|
error = 'socket error'
|
65
|
-
@ssl_socket.
|
66
|
-
Apple.
|
67
|
-
lambda { Apple.ping(@params) }.
|
63
|
+
allow(@ssl_socket).to receive(:write).and_raise(SocketError.new(error))
|
64
|
+
expect(Apple).to receive(:log).once.with("Error while sending ping: #{error}")
|
65
|
+
expect(lambda { Apple.ping(@params) }).to raise_error(SocketError, error)
|
68
66
|
end
|
69
67
|
|
70
68
|
it "should do nothing if no cert or host or port" do
|
71
|
-
Rhoconnect::Apple.
|
72
|
-
Rhoconnect::Apple.
|
73
|
-
OpenSSL::SSL::SSLContext.
|
69
|
+
allow(Rhoconnect::Apple).to receive(:get_config).and_return({:test => {:iphonecertfile=>"none"}})
|
70
|
+
expect(Rhoconnect::Apple).to receive(:get_config).once
|
71
|
+
expect(OpenSSL::SSL::SSLContext).to receive(:new).exactly(0).times
|
74
72
|
Apple.ping(@params)
|
75
73
|
end
|
76
|
-
end
|
74
|
+
end
|