rb-net_http-client 1.0.1 → 1.0.2

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.
@@ -1,433 +0,0 @@
1
- require_relative '../../spec_helper'
2
-
3
- describe NetHTTP::Core do
4
- Schema = Dry::Validation.Schema do
5
- required(:required).filled(:type? => String)
6
- end
7
-
8
- # NetHTTP::Core.assign_logger(logger = nil)
9
- it 'assigns logger by default when no logger is provided' do
10
- logger = NetHTTP::Core.assign_logger
11
- expect(logger.class).to eq(Logger)
12
- expect(logger.level).to eq(Logger::INFO)
13
- end
14
-
15
- it 'assigns logger by default when logger is nil' do
16
- logger = nil
17
- logger = NetHTTP::Core.assign_logger(logger)
18
- expect(logger.class).to eq(Logger)
19
- expect(logger.level).to eq(Logger::INFO)
20
- end
21
-
22
- it 'assigns logger by default when logger is empty' do
23
- logger = ''
24
- logger = NetHTTP::Core.assign_logger(logger)
25
- expect(logger.class).to eq(Logger)
26
- expect(logger.level).to eq(Logger::INFO)
27
- end
28
-
29
- it 'returns logger when valid logger is provided' do
30
- logger = Logger.new(STDOUT)
31
- logger.level = Logger::FATAL
32
-
33
- logger = NetHTTP::Core.assign_logger(logger)
34
- expect(logger.class).to eq(Logger)
35
- expect(logger.level).to eq(Logger::FATAL)
36
- end
37
-
38
- # NetHTTP::Core.parse_uri(uri)
39
- it 'should return nil if nil uri is provided' do
40
- uri = nil
41
- uri = NetHTTP::Core.parse_uri(uri)
42
- expect(uri).to eq(nil)
43
- end
44
-
45
- it 'should return nil if empty uri is provided' do
46
- uri = ''
47
- uri = NetHTTP::Core.parse_uri(uri)
48
- expect(uri).to eq(nil)
49
- end
50
-
51
- it 'should return valid URI object if valid uri is provided' do
52
- uri = 'https://esg-qa-oauth2-internal.fmr.com/as/resourceOwner'
53
- uri = NetHTTP::Core.parse_uri(uri)
54
- expect(uri.scheme).to eq('https')
55
- expect(uri.host).to eq('esg-qa-oauth2-internal.fmr.com')
56
- expect(uri.port).to eq(443)
57
- expect(uri.path).to eq('/as/resourceOwner')
58
- end
59
-
60
- it 'should return valid URI object if uri with no scheme is provided' do
61
- uri = 'esg-qa-oauth2-internal.fmr.com:443/as/resourceOwner'
62
- uri = NetHTTP::Core.parse_uri(uri)
63
- expect(uri.scheme).to eq('https')
64
- expect(uri.host).to eq('esg-qa-oauth2-internal.fmr.com')
65
- expect(uri.port).to eq(443)
66
- expect(uri.path).to eq('/as/resourceOwner')
67
- end
68
-
69
- it 'should return valid URI object if uri with no scheme or port is provided' do
70
- uri = 'esg-qa-oauth2-internal.fmr.com/as/resourceOwner'
71
- uri = NetHTTP::Core.parse_uri(uri)
72
- expect(uri.scheme).to eq('https')
73
- expect(uri.host).to eq('esg-qa-oauth2-internal.fmr.com')
74
- expect(uri.port).to eq(443)
75
- expect(uri.path).to eq('/as/resourceOwner')
76
- end
77
-
78
- it 'should return valid URI object if uri is a URI object provided' do
79
- uri = URI('https://esg-qa-oauth2-internal.fmr.com/as/resourceOwner')
80
- uri = NetHTTP::Core.parse_uri(uri)
81
- expect(uri.scheme).to eq('https')
82
- expect(uri.host).to eq('esg-qa-oauth2-internal.fmr.com')
83
- expect(uri.port).to eq(443)
84
- expect(uri.path).to eq('/as/resourceOwner')
85
- end
86
-
87
- it 'should successfully parse the Fidelity proxy uri' do
88
- uri = 'http://http.proxy.fmr.com:8000'
89
- uri = NetHTTP::Core.parse_uri(uri)
90
- expect(uri.scheme).to eq('http')
91
- expect(uri.host).to eq('http.proxy.fmr.com')
92
- expect(uri.port).to eq(8000)
93
- expect(uri.path).to eq('')
94
- end
95
-
96
- # NetHTTP::Core.schema_validation(opts, schema, logger = nil)
97
- it 'should execute schema validation (pass) with no logger provided' do
98
- opts = {}
99
- opts[:required] = 'hello'
100
- NetHTTP::Core.schema_validation(opts, Schema)
101
- end
102
-
103
- it 'should execute schema validation (pass) with logger provided' do
104
- logger = Logger.new(STDOUT)
105
- logger.level = Logger::INFO
106
-
107
- opts = {}
108
- opts[:required] = 'hello'
109
- NetHTTP::Core.schema_validation(opts, Schema, logger)
110
- end
111
-
112
- it 'should execute schema validation (fail) with no logger provided' do
113
- opts = {}
114
- begin
115
- NetHTTP::Core.schema_validation(opts, Schema)
116
- rescue RuntimeError => err
117
- expect(err.message.include?('NetHTTP::Core::Error - schema input validation failed.')).to eq(true)
118
- end
119
- end
120
-
121
- it 'should execute schema validation (fail) with logger provided' do
122
- logger = Logger.new(STDOUT)
123
- logger.level = Logger::DEBUG
124
-
125
- opts = {}
126
- begin
127
- NetHTTP::Core.schema_validation(opts, Schema, logger)
128
- rescue RuntimeError => err
129
- expect(err.message.include?('NetHTTP::Core::Error - schema input validation failed.')).to eq(true)
130
- end
131
- end
132
-
133
- # NetHTTP::Core.valid_json?(string)
134
- it 'should return true for valid json string' do
135
- valid_json_string = '{"key":"value"}'
136
-
137
- expect(NetHTTP::Core.valid_json?(valid_json_string)).to eq(true)
138
- end
139
-
140
- it 'should return true for valid json string passing in logger' do
141
- logger = Logger.new(STDOUT)
142
- logger.level = Logger::DEBUG
143
- valid_json_string = '{"key":"value"}'
144
-
145
- expect(NetHTTP::Core.valid_json?(valid_json_string, logger)).to eq(true)
146
- end
147
-
148
- it 'should return false for invalid json string' do
149
- invalid_json_string = ':'
150
-
151
- expect(NetHTTP::Core.valid_json?(invalid_json_string)).to eq(false)
152
- end
153
-
154
- it 'should return false for invalid json string passing in logger' do
155
- logger = Logger.new(STDOUT)
156
- logger.level = Logger::DEBUG
157
- invalid_json_string = ':'
158
-
159
- expect(NetHTTP::Core.valid_json?(invalid_json_string, logger)).to eq(false)
160
- end
161
-
162
- # NetHTTP::Core.valid_xml?(string)
163
- it 'should return true for valid xml string' do
164
- valid_xml_string = '<key>value</key>'
165
-
166
- expect(NetHTTP::Core.valid_xml?(valid_xml_string)).to eq(true)
167
- end
168
-
169
- it 'should return true for valid xml string passing in logger' do
170
- logger = Logger.new(STDOUT)
171
- logger.level = Logger::DEBUG
172
- valid_xml_string = '<key>value</key>'
173
-
174
- expect(NetHTTP::Core.valid_xml?(valid_xml_string, logger)).to eq(true)
175
- end
176
-
177
- it 'should return false for invalid xml string' do
178
- invalid_xml_string = '<key>value</key'
179
-
180
- expect(NetHTTP::Core.valid_xml?(invalid_xml_string)).to eq(false)
181
- end
182
-
183
- it 'should return false for invalid xml string passing in logger' do
184
- logger = Logger.new(STDOUT)
185
- logger.level = Logger::DEBUG
186
- invalid_xml_string = '<key>value</key'
187
-
188
- expect(NetHTTP::Core.valid_xml?(invalid_xml_string, logger)).to eq(false)
189
- end
190
-
191
- it 'should return false for an invalid xml string (html) but fails strict parsing passing in logger' do
192
- logger = Logger.new(STDOUT)
193
- logger.level = Logger::DEBUG
194
- invalid_xml_string = %(<!DOCTYPE html>
195
- <html>
196
- <head>
197
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
198
- <title>Eel slap!</title>
199
- <meta property="og:title" content="Eel slap!" />
200
- <meta property="og:type" content="website" />
201
- <meta property="og:url" content="http://www.eelslap.com" />
202
- <meta property="og:image" content="http://www.eelslap.com/facebook.png" />
203
- <meta property="og:site_name" content="Eel slap!" />
204
- <meta property="fb:admins" content="543574574" />
205
- <META NAME="keywords" CONTENT="eel slap, eelslap, eel slapping, eelslapping, eel, eal, eal slapping, eal slap, fish slapping, fishslapping, slap this guy with an eel, slap a guy with an eel slap a man with an eel, slap a dude with an eel, slap a guy with eel, slap a man with eel, slap a dude with eel, slap someone with an eel, slap someone with eel, eal slap, ell slap, per hansson, per stenius, fimpen">
206
- <META NAME="description" CONTENT="Ever wanted to slap someone in the face with an eel? Well, today is your lucky day.">
207
- <META NAME="author" CONTENT="Per Stenius - http://www.perstenius.com">
208
- <link rel="SHORTCUT ICON" href="favicon.ico"/>
209
- <script type="text/javascript">
210
- var _gaq = _gaq || [];
211
- _gaq.push(['_setAccount', 'UA-114693-12']);
212
- _gaq.push(['_trackPageview']);
213
-
214
- (function() {
215
- var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
216
- ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
217
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
218
- })();
219
- </script>
220
- <link rel="stylesheet" href="css/normalize.css" type="text/css">
221
- <link rel="stylesheet" type="text/css" href="css/eelslap.css"/>
222
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
223
- <script src="js/eelslap.js"></script>
224
-
225
- </head>
226
- <body>
227
- <div id="eelcontainer" class="eel">
228
- <div id="loader">LOADING...</div>
229
- <div id="introtext">yo</div>
230
- <div id="allimages">
231
- <img class="eelimages" id="eelimage1" src="" width="15360" height="480">
232
- <img class="eelimages" id="eelimage2" src="" width="14720" height="480">
233
- <img class="eelimages" id="eelimage3" src="" width="15360" height="480">
234
- <img class="eelimages" id="eelimage4" src="" width="14720" height="480">
235
- </div>
236
- </div>
237
- <div class="footer">
238
- <a href="https://twitter.com/share" class="twitter-share-button" data-url="http://www.eelslap.com" data-count="vertical">Tweet</a>
239
- <script type="text/javascript" src="http://platform.twitter.com/widgets.js">
240
- </script>
241
- <iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.eelslap.com&amp;send=false&amp;layout=box_count&amp;width=55&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=62" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:55px; height:62px;">
242
- </iframe><br>
243
-
244
- <a href="http://actnormal.co" target="_blank">made by</a>
245
- </div>
246
- </body>
247
- </html>)
248
-
249
- expect(NetHTTP::Core.valid_xml?(invalid_xml_string, logger)).to eq(false)
250
- end
251
-
252
- # NetHTTP::Core.valid_html?(string)
253
- it 'should return true for valid html string' do
254
- valid_html_string = '<!DOCTYPE html>
255
- <html>
256
- <body>
257
- <h1>Heading</h1>
258
- <p>Paragraph.</p>
259
- </body>
260
- </html>'
261
-
262
- expect(NetHTTP::Core.valid_html?(valid_html_string)).to eq(true)
263
- end
264
-
265
- it 'should return true for an invalid html string passing in logger' do
266
- logger = Logger.new(STDOUT)
267
- logger.level = Logger::DEBUG
268
- valid_html_string = '<!DOCTYPE html>
269
- <html>
270
- <body>
271
- <h1>Heading</h1>
272
- <p>Paragraph.</p>
273
- </body>
274
- </html>'
275
-
276
- expect(NetHTTP::Core.valid_html?(valid_html_string, logger)).to eq(true)
277
- end
278
-
279
- it 'should return true for a valid html string which contains javascript but fails strict parsing' do
280
- html_string = %(<!DOCTYPE html>
281
- <html>
282
- <head>
283
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
284
- <title>Eel slap!</title>
285
- <meta property="og:title" content="Eel slap!" />
286
- <meta property="og:type" content="website" />
287
- <meta property="og:url" content="http://www.eelslap.com" />
288
- <meta property="og:image" content="http://www.eelslap.com/facebook.png" />
289
- <meta property="og:site_name" content="Eel slap!" />
290
- <meta property="fb:admins" content="543574574" />
291
- <META NAME="keywords" CONTENT="eel slap, eelslap, eel slapping, eelslapping, eel, eal, eal slapping, eal slap, fish slapping, fishslapping, slap this guy with an eel, slap a guy with an eel slap a man with an eel, slap a dude with an eel, slap a guy with eel, slap a man with eel, slap a dude with eel, slap someone with an eel, slap someone with eel, eal slap, ell slap, per hansson, per stenius, fimpen">
292
- <META NAME="description" CONTENT="Ever wanted to slap someone in the face with an eel? Well, today is your lucky day.">
293
- <META NAME="author" CONTENT="Per Stenius - http://www.perstenius.com">
294
- <link rel="SHORTCUT ICON" href="favicon.ico"/>
295
- <script type="text/javascript">
296
- var _gaq = _gaq || [];
297
- _gaq.push(['_setAccount', 'UA-114693-12']);
298
- _gaq.push(['_trackPageview']);
299
-
300
- (function() {
301
- var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
302
- ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
303
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
304
- })();
305
- </script>
306
- <link rel="stylesheet" href="css/normalize.css" type="text/css">
307
- <link rel="stylesheet" type="text/css" href="css/eelslap.css"/>
308
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
309
- <script src="js/eelslap.js"></script>
310
-
311
- </head>
312
- <body>
313
- <div id="eelcontainer" class="eel">
314
- <div id="loader">LOADING...</div>
315
- <div id="introtext">yo</div>
316
- <div id="allimages">
317
- <img class="eelimages" id="eelimage1" src="" width="15360" height="480">
318
- <img class="eelimages" id="eelimage2" src="" width="14720" height="480">
319
- <img class="eelimages" id="eelimage3" src="" width="15360" height="480">
320
- <img class="eelimages" id="eelimage4" src="" width="14720" height="480">
321
- </div>
322
- </div>
323
- <div class="footer">
324
- <a href="https://twitter.com/share" class="twitter-share-button" data-url="http://www.eelslap.com" data-count="vertical">Tweet</a>
325
- <script type="text/javascript" src="http://platform.twitter.com/widgets.js">
326
- </script>
327
- <iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.eelslap.com&amp;send=false&amp;layout=box_count&amp;width=55&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=62" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:55px; height:62px;">
328
- </iframe><br>
329
-
330
- <a href="http://actnormal.co" target="_blank">made by</a>
331
- </div>
332
- </body>
333
- </html>)
334
-
335
- expect(NetHTTP::Core.valid_html?(html_string)).to eq(true)
336
- end
337
-
338
- it 'should return true for a valid html string which contains javascript but fails strict parsing passing in logger' do
339
- logger = Logger.new(STDOUT)
340
- logger.level = Logger::DEBUG
341
- html_string = %(<!DOCTYPE html>
342
- <html>
343
- <head>
344
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
345
- <title>Eel slap!</title>
346
- <meta property="og:title" content="Eel slap!" />
347
- <meta property="og:type" content="website" />
348
- <meta property="og:url" content="http://www.eelslap.com" />
349
- <meta property="og:image" content="http://www.eelslap.com/facebook.png" />
350
- <meta property="og:site_name" content="Eel slap!" />
351
- <meta property="fb:admins" content="543574574" />
352
- <META NAME="keywords" CONTENT="eel slap, eelslap, eel slapping, eelslapping, eel, eal, eal slapping, eal slap, fish slapping, fishslapping, slap this guy with an eel, slap a guy with an eel slap a man with an eel, slap a dude with an eel, slap a guy with eel, slap a man with eel, slap a dude with eel, slap someone with an eel, slap someone with eel, eal slap, ell slap, per hansson, per stenius, fimpen">
353
- <META NAME="description" CONTENT="Ever wanted to slap someone in the face with an eel? Well, today is your lucky day.">
354
- <META NAME="author" CONTENT="Per Stenius - http://www.perstenius.com">
355
- <link rel="SHORTCUT ICON" href="favicon.ico"/>
356
- <script type="text/javascript">
357
- var _gaq = _gaq || [];
358
- _gaq.push(['_setAccount', 'UA-114693-12']);
359
- _gaq.push(['_trackPageview']);
360
-
361
- (function() {
362
- var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
363
- ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
364
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
365
- })();
366
- </script>
367
- <link rel="stylesheet" href="css/normalize.css" type="text/css">
368
- <link rel="stylesheet" type="text/css" href="css/eelslap.css"/>
369
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
370
- <script src="js/eelslap.js"></script>
371
-
372
- </head>
373
- <body>
374
- <div id="eelcontainer" class="eel">
375
- <div id="loader">LOADING...</div>
376
- <div id="introtext">yo</div>
377
- <div id="allimages">
378
- <img class="eelimages" id="eelimage1" src="" width="15360" height="480">
379
- <img class="eelimages" id="eelimage2" src="" width="14720" height="480">
380
- <img class="eelimages" id="eelimage3" src="" width="15360" height="480">
381
- <img class="eelimages" id="eelimage4" src="" width="14720" height="480">
382
- </div>
383
- </div>
384
- <div class="footer">
385
- <a href="https://twitter.com/share" class="twitter-share-button" data-url="http://www.eelslap.com" data-count="vertical">Tweet</a>
386
- <script type="text/javascript" src="http://platform.twitter.com/widgets.js">
387
- </script>
388
- <iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.eelslap.com&amp;send=false&amp;layout=box_count&amp;width=55&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=62" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:55px; height:62px;">
389
- </iframe><br>
390
-
391
- <a href="http://actnormal.co" target="_blank">made by</a>
392
- </div>
393
- </body>
394
- </html>)
395
-
396
- expect(NetHTTP::Core.valid_html?(html_string, logger)).to eq(true)
397
- end
398
-
399
- it 'should return false for an invalid html string' do
400
- invalid_html_string = '<!DOCTYPE html>
401
- <html>
402
- <body>
403
- <h1>Heading</h1>
404
- <p>Paragraph.</p>
405
- </body'
406
-
407
- expect(NetHTTP::Core.valid_html?(invalid_html_string)).to eq(false)
408
- end
409
-
410
- it 'should return false for an invalid html string passing in logger' do
411
- logger = Logger.new(STDOUT)
412
- logger.level = Logger::DEBUG
413
- invalid_html_string = '<!DOCTYPE html>
414
- <html>
415
- <body>
416
- <h1>Heading</h1>
417
- <p>Paragraph.</p>
418
- </body'
419
-
420
- expect(NetHTTP::Core.valid_html?(invalid_html_string, logger)).to eq(false)
421
- end
422
-
423
- it 'should return false for an invalid html string' do
424
- invalid_html_string = '<!DOCTYPE html>
425
- <html>
426
- <body>
427
- <h1>Heading</h1>
428
- <p>Paragraph.</p>
429
- </body>'
430
-
431
- expect(NetHTTP::Core.valid_html?(invalid_html_string)).to eq(false)
432
- end
433
- end