File: real_world_spec.rb

package info (click to toggle)
ruby-open-graph-reader 0.7.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 9,976 kB
  • sloc: ruby: 1,525; xml: 22; makefile: 2
file content (507 lines) | stat: -rw-r--r-- 22,927 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
require "spec_helper"

RSpec.describe "real world examples" do
  describe "mixed_case_properties" do
    it "parses" do
      expect {
        OpenGraphReader.parse! fixture_html "real_world/mixed_case_properties"
      }.to_not raise_error
    end

    it "assigns the right attributes" do
      object = OpenGraphReader.parse fixture_html "real_world/mixed_case_properties"

      expect(object.og.title).to eq "Eine Million Unterschriften gegen TTIP"
      expect(object.og.type).to eq "website"
      expect(object.og.locale.to_s).to eq "de_DE"
      expect(object.og.url).to eq "http://www.heise.de/tp/artikel/43/43516/"
      expect(object.og.site_name).to eq "Telepolis"
      expect(object.og.image.url).to eq "http://www.heise.de/tp/artikel/43/43516/43516_1.jpg"
      expect(object.og.description).to eq(
        "Ungenehmigte Bürgerinitiative will das Paket EU-Kommissionschef Juncker zum Geburtstag "\
        "schenken"
      )
    end
  end

  describe "missing_image" do
    it "does not parse" do
      expect {
        OpenGraphReader.parse! fixture_html "real_world/missing_image"
      }.to raise_error OpenGraphReader::InvalidObjectError, /Missing required/
    end
  end

  describe "mixed_case_type" do
    it "parses" do
      expect {
        OpenGraphReader.parse! fixture_html "real_world/mixed_case_type"
      }.to_not raise_error
    end
  end

  describe "not_a_reference" do
    it "does not parse" do
      expect {
        OpenGraphReader.parse! fixture_html "real_world/not_a_reference"
      }.to raise_error OpenGraphReader::InvalidObjectError, /does not start with/
    end

    it "parses with reference validation turned of" do
      OpenGraphReader.config.validate_references = false
      object = OpenGraphReader.parse! fixture_html "real_world/not_a_reference"

      expect(object.og.title).to eq "Emergency call system for all new cars by 2018"
      expect(object.og.type).to eq "article"
      expect(object.og.description).to eq(
        "The European Parliament and EU member states have agreed that new cars must be fitted"\
        " with an automated system to alert emergency services in event of a crash."
      )
      expect(object.og.site_name).to eq "BBC News"
      expect(object.og.url).to eq "http://www.bbc.co.uk/news/technology-30337272"
      expect(object.og.image.url).to eq(
        "http://news.bbcimg.co.uk/media/images/79520000/jpg/_79520623_79519885.jpg"
      )
      expect(object.article.author.to_s).to eq "BBC News"
      expect(object.article.section).to eq "Technology"
    end
  end

  describe "unknown_type" do
    it "parses" do
      object = OpenGraphReader.parse! fixture_html "real_world/unknown_type"

      expect(object.og.url).to eq "http://www.instructables.com/id/Building-the-Open-Knit-machine/"
      expect(object.og.title).to eq "Building the OpenKnit machine"
      expect(object.og.image.url).to eq(
        "http://cdn.instructables.com/FI2/D7XW/I2XTQWFE/FI2D7XWI2XTQWFE.RECTANGLE1.jpg"
      )
      expect(object.og.description).to eq(
        "The OpenKnit machine is an open-source, low cost, digital fabrication tool developed by "\
        "Gerard Rubio.  The machine affords the user the opportunity to..."
      )
    end

    it "does not parse in strict mode" do
      OpenGraphReader.config.strict = true

      expect {
        OpenGraphReader.parse! fixture_html "real_world/unknown_type"
      }.to raise_error OpenGraphReader::InvalidObjectError, /Undefined type/
    end
  end

  describe "undefined_property" do
    it "parses (1)" do
      object = OpenGraphReader.parse! fixture_html "real_world/undefined_property"

      expect(object.og.locale.to_s).to eq "es_ES"
      expect(object.og.type).to eq "article"
      expect(object.og.title).to eq "Profesores y campesinos amarran a infiltrados en marcha"
      expect(object.og.description).to eq(
        "Regeneración, 6 de diciembre de 2014.-Durante la marcha que realizan profesores y "\
        "organizaciones campesinas sobre avenida Paseo de la Reforma, maestros de la Coordinadora "\
        "Estatal de Trabajadores de la Educación en Guerrero (CETEG) ubicaron a 12 jóvenes como "\
        "“infiltrados”, a quienes amarraron de las manos en una cadena humana para evitar que "\
        "marchen con ellos, informó El …"
      )
      expect(object.og.url).to eq(
        "http://regeneracion.mx/sociedad/profesores-y-campesinos-amarran-a-infiltrados-en-marcha/"
      )
      expect(object.og.site_name).to eq "Regeneración"
      expect(object.og.image.url).to eq(
        "http://regeneracion.mx/wp-content/uploads/2014/12/Infiltrados.jpg"
      )
    end

    it "does not parse in strict mode (1)" do
      OpenGraphReader.config.strict = true

      expect {
        OpenGraphReader.parse! fixture_html "real_world/undefined_property"
      }.to raise_error OpenGraphReader::InvalidObjectError, /Undefined property/
    end

    it "parses (2)" do
      object = OpenGraphReader.parse! fixture_html "real_world/undefined_property_2"

      expect(object.og.title).to eq "Emergency call system for all new cars by 2018"
      expect(object.og.type).to eq "article"
      expect(object.og.description).to eq(
        "The European Parliament and EU member states have agreed that new cars must be fitted with"\
        " an automated system to alert emergency services in event of a crash."
      )
      expect(object.og.site_name).to eq "BBC News"
      expect(object.og.url).to eq "http://www.bbc.co.uk/news/technology-30337272"
      expect(object.og.image.url).to eq(
        "http://news.bbcimg.co.uk/media/images/79520000/jpg/_79520623_79519885.jpg"
      )
    end

    it "does not parse in strict mode (2)" do
      OpenGraphReader.config.strict = true

      expect {
        OpenGraphReader.parse! fixture_html "real_world/undefined_property_2"
      }.to raise_error OpenGraphReader::InvalidObjectError, /Undefined property/
    end
  end

  describe "unknown_namespace" do
    it "parses" do
      object = OpenGraphReader.parse! fixture_html "real_world/unknown_namespace"

      expect(object.og.url).to eq "http://www.instructables.com/id/Building-the-Open-Knit-machine/"
      expect(object.og.title).to eq "Building the OpenKnit machine"
      expect(object.og.image.url).to eq(
        "http://cdn.instructables.com/FI2/D7XW/I2XTQWFE/FI2D7XWI2XTQWFE.RECTANGLE1.jpg"
      )
      expect(object.og.description).to eq(
        "The OpenKnit machine is an open-source, low cost, digital fabrication tool developed by "\
        "Gerard Rubio.  The machine affords the user the opportunity to..."
      )
    end

    it "does not parse in strict mode" do
      OpenGraphReader.config.strict = true

      expect {
        OpenGraphReader.parse! fixture_html "real_world/unknown_namespace"
      }.to raise_error OpenGraphReader::InvalidObjectError, /is not a registered namespace/
    end
  end

  describe "missing_title" do
    it "does not parse" do
      expect {
        OpenGraphReader.parse! fixture_html "real_world/missing_title"
      }.to raise_error OpenGraphReader::InvalidObjectError, /Missing required/
    end

    it "does parse when synthesizing titles" do
      OpenGraphReader.config.synthesize_title = true

      object = OpenGraphReader.parse! fixture_html "real_world/missing_title"

      expect(object.og.type).to eq "website"
      expect(object.og.title).to eq(
        "Ultra Conservative Christian Lady Goes To Museum, Tries To Debunk Evolution, Fails Beyond"\
        " Miserably | Geekologie"
      )
      expect(object.og.image.url).to eq(
        "http://geekologie.com/assets_c/2014/11/crazy-lady-goes-to-the"\
        "-museum-thumb-640x389-29314.jpg"
      )
    end
  end

  describe "image_path" do
    it "does not parse" do
      expect {
        OpenGraphReader.parse! fixture_html "real_world/image_path"
      }.to raise_error OpenGraphReader::InvalidObjectError, /does not start with/
    end

    it "parses with image paths turned on" do
      OpenGraphReader.config.synthesize_image_url = true

      object = OpenGraphReader.parse!(
        fixture_html("real_world/image_path"),
        "http://fritzing.org/download/"
      )

      expect(object.og.title).to eq "Fritzing"
      expect(object.og.type).to eq "website"
      expect(object.og.image.url).to eq "http://fritzing.org/static/img/fritzing.png"
      expect(object.og.url).to eq "http://fritzing.org/"
    end
  end

  describe "image_path_2" do
    it "does not parse" do
      expect {
        OpenGraphReader.parse! fixture_html "real_world/image_path_2"
      }.to raise_error OpenGraphReader::InvalidObjectError, /does not start with/
    end

    it "parses with image paths turned on" do
      OpenGraphReader.config.synthesize_image_url = true

      object = OpenGraphReader.parse!(
        fixture_html("real_world/image_path_2"),
        "http://motherboard.vice.com/de/read/forscher-kreieren-ein-material-das-fast-so-dunkel-ist"\
        "-wie-ein-schwarzes-loch?trk_source=popular"
      )

      expect(object.og.type).to eq "article"
      expect(object.og.title).to eq(
        "Forscher kreieren ein Material, das fast so dunkel ist wie ein schwarzes Loch"
      )
      expect(object.og.site_name).to eq "Motherboard"
      expect(object.og.image.url).to eq(
        "https://motherboard-images.vice.com/content-images/article/13701/1405417621515809.JPG?cro"\
        "p=0.75xw:1xh;*,*&resize=500:*&output-format=jpeg&output-quality=90"
      )
      expect(object.og.url).to eq(
        "http://motherboard.vice.com/de/read/forscher-kreieren-ein-material-das-fast-so-dunkel-ist"\
        "-wie-ein-schwarzes-loch"
      )
    end
  end

  describe "invalid_article_author" do
    it "does not parse" do
      expect {
        OpenGraphReader.parse! fixture_html "real_world/invalid_article_author"
      }.to raise_error OpenGraphReader::InvalidObjectError, /does not start with/
    end

    it "ignores the attribute with discarding invalid optional attributes enabled" do
      OpenGraphReader.config.discard_invalid_optional_properties = true

      object = OpenGraphReader.parse! fixture_html "real_world/invalid_article_author"

      expect(object.article.author).to be_nil
      expect(object.article.section).to eq "blog/engineering"
      expect(object.article.published_time).to eq DateTime.iso8601 "2014-12-18T21:16:27+00:00"
      expect(object.og.site_name).to eq "GitHub"
      expect(object.og.type).to eq "article"
      expect(object.og.image.url).to eq "https://github.com/apple-touch-icon-144.png"
      expect(object.og.title).to eq "Vulnerability announced: update your Git clients"
      expect(object.og.url).to eq(
        "https://github.com/blog/1938-vulnerability-announced-update-your-git-clients"
      )
      expect(object.og.description).to eq <<-DESCRIPTION.chomp
A critical Git security vulnerability has been announced today, affecting all versions of the \
official Git client and all related software that interacts with Git repositories, including \
GitHub for Windows and GitHub for Mac. Because this is a client-side only vulnerability, \
github.com and GitHub Enterprise are not directly affected.

The vulnerability concerns Git and Git-compatible clients that access Git repositories in a \
case-insensitive or case-normalizing filesystem. An attacker can craft a malicious Git tree that \
will cause Git to overwrite its own .git/config file when cloning or checking out a repository, \
leading to arbitrary command execution in the client machine. Git clients running on OS X (HFS+) \
or any version of Microsoft Windows (NTFS, FAT) are exploitable through this vulnerability. Linux \
clients are not affected if they run in a case-sensitive filesystem.

We strongly encourage all users of GitHub and GitHub Enterprise to update their Git clients as \
soon as possible, and to be particularly careful when cloning or accessing Git repositories hosted \
on unsafe or untrusted hosts.

Repositories hosted on github.com cannot contain any of the malicious trees that trigger the \
vulnerability because we now verify and block these trees on push. We have also completed an \
automated scan of all existing content on github.com to look for malicious content that might have \
been pushed to our site before this vulnerability was discovered. This work is an extension of the \
data-quality checks we have always performed on repositories pushed to our servers to protect our \
users against malformed or malicious Git data.

Updated versions of GitHub for Windows and GitHub for Mac are available for immediate download, and \
both contain the security fix on the Desktop application itself and on the bundled version of the \
Git command-line client.

In addition, the following updated versions of Git address this vulnerability:


The Git core team has announced maintenance releases for all current versions of Git (v1.8.5.6, \
v1.9.5, v2.0.5, v2.1.4, and v2.2.1).
Git for Windows (also known as MSysGit) has released maintenance version 1.9.5.
The two major Git libraries, libgit2 and JGit, have released maintenance versions with the fix. \
Third party software using these libraries is strongly encouraged to update.


More details on the vulnerability can be found in the official Git mailing list announcement and on \
the git-blame blog.
DESCRIPTION
    end
  end

  describe "invalid_datetime" do
    it "does not parse" do
      expect {
        OpenGraphReader.parse! fixture_html "real_world/invalid_datetime"
      }.to raise_error OpenGraphReader::InvalidObjectError, /ISO8601 datetime expected/
    end

    it "ignores the attribute with discarding invalid optional attributes enabled" do
      OpenGraphReader.config.discard_invalid_optional_properties = true

      object = OpenGraphReader.parse! fixture_html "real_world/invalid_datetime"

      expect(object.article.section).to eq "blog/engineering"
      expect(object.article.published_time).to be_nil
      expect(object.og.site_name).to eq "GitHub"
      expect(object.og.type).to eq "article"
      expect(object.og.image.url).to eq "https://github.com/apple-touch-icon-144.png"
      expect(object.og.title).to eq "Vulnerability announced: update your Git clients"
      expect(object.og.url).to eq(
        "https://github.com/blog/1938-vulnerability-announced-update-your-git-clients"
      )
      expect(object.og.description).to eq <<-DESCRIPTION.chomp
A critical Git security vulnerability has been announced today, affecting all versions of the \
official Git client and all related software that interacts with Git repositories, including \
GitHub for Windows and GitHub for Mac. Because this is a client-side only vulnerability, \
github.com and GitHub Enterprise are not directly affected.

The vulnerability concerns Git and Git-compatible clients that access Git repositories in a \
case-insensitive or case-normalizing filesystem. An attacker can craft a malicious Git tree that \
will cause Git to overwrite its own .git/config file when cloning or checking out a repository, \
leading to arbitrary command execution in the client machine. Git clients running on OS X (HFS+) \
or any version of Microsoft Windows (NTFS, FAT) are exploitable through this vulnerability. Linux \
clients are not affected if they run in a case-sensitive filesystem.

We strongly encourage all users of GitHub and GitHub Enterprise to update their Git clients as \
soon as possible, and to be particularly careful when cloning or accessing Git repositories hosted \
on unsafe or untrusted hosts.

Repositories hosted on github.com cannot contain any of the malicious trees that trigger the \
vulnerability because we now verify and block these trees on push. We have also completed an \
automated scan of all existing content on github.com to look for malicious content that might have \
been pushed to our site before this vulnerability was discovered. This work is an extension of the \
data-quality checks we have always performed on repositories pushed to our servers to protect our \
users against malformed or malicious Git data.

Updated versions of GitHub for Windows and GitHub for Mac are available for immediate download, and \
both contain the security fix on the Desktop application itself and on the bundled version of the \
Git command-line client.

In addition, the following updated versions of Git address this vulnerability:


The Git core team has announced maintenance releases for all current versions of Git (v1.8.5.6, \
v1.9.5, v2.0.5, v2.1.4, and v2.2.1).
Git for Windows (also known as MSysGit) has released maintenance version 1.9.5.
The two major Git libraries, libgit2 and JGit, have released maintenance versions with the fix. \
Third party software using these libraries is strongly encouraged to update.


More details on the vulnerability can be found in the official Git mailing list announcement and on \
the git-blame blog.
DESCRIPTION
    end

    it "parses with datetime format parsing turned on" do
      OpenGraphReader.config.guess_datetime_format = true

      object = OpenGraphReader.parse! fixture_html "real_world/invalid_datetime"

      expect(object.article.section).to eq "blog/engineering"
      expect(object.article.published_time).to eq DateTime.iso8601 "2014-12-18T21:16:27+00:00"
      expect(object.og.site_name).to eq "GitHub"
      expect(object.og.type).to eq "article"
      expect(object.og.image.url).to eq "https://github.com/apple-touch-icon-144.png"
      expect(object.og.title).to eq "Vulnerability announced: update your Git clients"
      expect(object.og.url).to eq "https://github.com/blog/1938-vulnerability-announced-update-your-git-clients"
      expect(object.og.description).to eq <<-DESCRIPTION.chomp
A critical Git security vulnerability has been announced today, affecting all versions of the \
official Git client and all related software that interacts with Git repositories, including \
GitHub for Windows and GitHub for Mac. Because this is a client-side only vulnerability, \
github.com and GitHub Enterprise are not directly affected.

The vulnerability concerns Git and Git-compatible clients that access Git repositories in a \
case-insensitive or case-normalizing filesystem. An attacker can craft a malicious Git tree that \
will cause Git to overwrite its own .git/config file when cloning or checking out a repository, \
leading to arbitrary command execution in the client machine. Git clients running on OS X (HFS+) \
or any version of Microsoft Windows (NTFS, FAT) are exploitable through this vulnerability. Linux \
clients are not affected if they run in a case-sensitive filesystem.

We strongly encourage all users of GitHub and GitHub Enterprise to update their Git clients as \
soon as possible, and to be particularly careful when cloning or accessing Git repositories hosted \
on unsafe or untrusted hosts.

Repositories hosted on github.com cannot contain any of the malicious trees that trigger the \
vulnerability because we now verify and block these trees on push. We have also completed an \
automated scan of all existing content on github.com to look for malicious content that might have \
been pushed to our site before this vulnerability was discovered. This work is an extension of the \
data-quality checks we have always performed on repositories pushed to our servers to protect our \
users against malformed or malicious Git data.

Updated versions of GitHub for Windows and GitHub for Mac are available for immediate download, and \
both contain the security fix on the Desktop application itself and on the bundled version of the \
Git command-line client.

In addition, the following updated versions of Git address this vulnerability:


The Git core team has announced maintenance releases for all current versions of Git (v1.8.5.6, \
v1.9.5, v2.0.5, v2.1.4, and v2.2.1).
Git for Windows (also known as MSysGit) has released maintenance version 1.9.5.
The two major Git libraries, libgit2 and JGit, have released maintenance versions with the fix. \
Third party software using these libraries is strongly encouraged to update.


More details on the vulnerability can be found in the official Git mailing list announcement and on \
the git-blame blog.
DESCRIPTION
    end
  end

  describe "url_path" do
    it "does not parse" do
      expect {
        OpenGraphReader.parse! fixture_html "real_world/url_path"
      }.to raise_error OpenGraphReader::InvalidObjectError, /does not start with/
    end

    it "parses with paths turned on" do
      OpenGraphReader.config.synthesize_full_url = true
      OpenGraphReader.config.synthesize_image_url = true

      object = OpenGraphReader.parse!(
        fixture_html("real_world/url_path"),
        "http://www.nextinpact.com/news/93425-revue-presse-cities-skylines-est-il-simcity-que-on-attendait.htm"
      )

      expect(object.og.title).to eq "Revue de presse : Cities Skylines est-il le SimCity que l'on attendait ?"
      expect(object.og.type).to eq "article"
      expect(object.og.image.url).to eq "https://az664837.vo.msecnd.net/images/bd/wide-linked-media/5920.jpg"
      expect(object.og.url).to eq(
        "http://www.nextinpact.com/news/93425-revue-presse-cities-skylines-est-il-simcity-que-on-attendait.htm"
      )
    end
  end

  describe "missing_url" do
    it "does not parse" do
      expect {
        OpenGraphReader.parse! fixture_html "real_world/missing_url"
      }.to raise_error OpenGraphReader::InvalidObjectError, /Missing required/
    end

    it "parses with url synthesization turned on" do
      OpenGraphReader.config.synthesize_url = true

      object = OpenGraphReader.parse!(
        fixture_html("real_world/missing_url"),
        "http://taz.de/!159273"
      )

      expect(object.og.title).to eq "Wandel im Biohandel: Alnatura weitet Vertrieb im Netz aus"
      expect(object.og.type).to eq "article"
      expect(object.og.image.url).to eq "http://www.taz.de/uploads/images/948/0634n.jpg"
      expect(object.og.url).to eq "http://taz.de/!159273"
    end
  end

  describe "missing_content" do
    it "parses" do
      object = OpenGraphReader.parse! fixture_html "real_world/missing_content"

      expect(object.og.site_name).to eq "Rudaw"
      expect(object.og.type).to eq "article"
      expect(object.og.url).to eq "http://rudaw.net/english/kurdistan/070520155"
      expect(object.og.title).to eq "VIDEO: Scenes from Mahabad riots in Eastern (Iran) Kurdistan"
      expect(object.og.image.url).to eq "http://rudaw.net/ContentFiles/126638Image1.jpg"
      expect(object.og.image.width).to eq 486
      expect(object.og.image.height).to eq 286
      expect(object.og.description).to be_nil
    end
  end

  describe "just_other_prefix" do
    it "parses" do
      expect {
        object = OpenGraphReader.parse! fixture_html "real_world/just_other_prefix"
      }.to raise_error OpenGraphReader::NoOpenGraphDataError
    end
  end
end