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 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756
|
require 'test/unit'
require 'feed_tools'
require 'feed_tools/helpers/feed_tools_helper'
class AtomTest < Test::Unit::TestCase
include FeedTools::FeedToolsHelper
def setup
FeedTools.reset_configurations
FeedTools.configurations[:tidy_enabled] = false
FeedTools.configurations[:feed_cache] = "FeedTools::DatabaseFeedCache"
FeedTools::FeedToolsHelper.default_local_path =
File.expand_path(
File.expand_path(File.dirname(__FILE__)) + '/../feeds')
end
def test_iri_feed
if FeedTools::UriHelper.idn_enabled?
with_feed(:from_url =>
'http://www.詹姆斯.com/atomtests/iri/everything.atom') { |feed|
assert_equal(
"http://www.xn--8ws00zhy3a.com/atomtests/iri/everything.atom",
feed.url)
}
end
end
def test_feed_title
with_feed(:from_file => 'wellformed/atom/atom_namespace_1.xml') { |feed|
assert_equal("Example Atom", feed.title)
}
with_feed(:from_file => 'wellformed/atom/atom_namespace_2.xml') { |feed|
assert_equal("Example Atom", feed.title)
}
with_feed(:from_file => 'wellformed/atom/atom_namespace_3.xml') { |feed|
assert_equal("Example Atom", feed.title)
}
with_feed(:from_file => 'wellformed/atom/atom_namespace_4.xml') { |feed|
assert_equal("Example Atom", feed.title)
}
with_feed(:from_file => 'wellformed/atom/atom_namespace_5.xml') { |feed|
assert_equal("Example Atom", feed.title)
}
with_feed(:from_file => 'wellformed/atom/feed_title_base64.xml') { |feed|
assert_equal("Example <b>Atom</b>", feed.title)
}
with_feed(:from_file =>
'wellformed/atom/feed_title_base64_2.xml') { |feed|
assert_equal(
"<p>History of the &lt;blink&gt; tag</p>",
feed.title)
}
end
def test_feed_link
with_feed(:from_data => <<-FEED
<feed version="0.3" xmlns="http://purl.org/atom/ns#">
<link rel="alternate" href="http://www.example.com/" />
<link rel="alternate" href="http://www.example.com/somewhere/" />
</feed>
FEED
) { |feed|
assert_equal("http://www.example.com/", feed.link)
assert_equal(0, feed.images.size)
}
with_feed(:from_data => <<-FEED
<feed version="0.3" xmlns="http://purl.org/atom/ns#">
<link type="text/html" href="http://www.example.com/" />
</feed>
FEED
) { |feed|
assert_equal("http://www.example.com/", feed.link)
assert_equal(0, feed.images.size)
}
with_feed(:from_data => <<-FEED
<feed version="0.3" xmlns="http://purl.org/atom/ns#">
<link type="application/xhtml+xml" href="http://www.example.com/" />
</feed>
FEED
) { |feed|
assert_equal("http://www.example.com/", feed.link)
assert_equal(0, feed.images.size)
}
with_feed(:from_data => <<-FEED
<feed version="0.3" xmlns="http://purl.org/atom/ns#">
<link href="http://www.example.com/" />
</feed>
FEED
) { |feed|
assert_equal("http://www.example.com/", feed.link)
assert_equal(0, feed.images.size)
}
with_feed(:from_data => <<-FEED
<feed version="0.3" xmlns="http://purl.org/atom/ns#">
<link rel="alternate" type="image/jpeg"
href="http://www.example.com/something.jpeg" />
<link rel="alternate" href="http://www.example.com/" />
<link rel="alternate" type="text/html"
href="http://www.example.com/somewhere/" />
<link rel="alternate" type="application/xhtml+xml"
href="http://www.example.com/xhtml/somewhere/" />
</feed>
FEED
) { |feed|
assert_equal("http://www.example.com/xhtml/somewhere/", feed.link)
assert_equal(1, feed.images.size)
assert_equal("http://www.example.com/something.jpeg",
feed.images[0].url)
}
with_feed(:from_data => <<-FEED
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"
xmlns:thr="http://purl.org/syndication/thread/1.0">
<link rel="self" href="http://www.intertwingly.net/blog/index.atom"/>
<id>http://www.intertwingly.net/blog/index.atom</id>
<title>Sam Ruby</title>
<subtitle>It’s just data</subtitle>
<author>
<name>Sam Ruby</name>
<email>rubys@intertwingly.net</email>
<uri>.</uri>
</author>
<updated>2006-07-07T09:45:30-04:00</updated>
<link href="."/>
</feed>
FEED
) { |feed|
assert_equal(2, feed.links.size)
assert_equal("http://www.intertwingly.net/blog/index.atom", feed.href)
assert_equal("http://www.intertwingly.net/blog/", feed.link)
assert_equal("http://www.intertwingly.net/blog/", feed.author.href)
}
with_feed(:from_data => <<-FEED
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"
xmlns:thr="http://purl.org/syndication/thread/1.0">
<link rel="self" href="http://www.intertwingly.net/blog/index.atom"/>
<id>http://www.intertwingly.net/blog/index.atom</id>
<title>Sam Ruby</title>
<subtitle>It’s just data</subtitle>
<author>
<name>Sam Ruby</name>
<email>rubys@intertwingly.net</email>
<uri>.</uri>
</author>
<updated>2006-07-07T09:45:30-04:00</updated>
<link href="."/>
</feed>
FEED
) { |feed|
assert_equal(2, feed.links.size)
assert_equal("http://www.intertwingly.net/blog/", feed.link)
assert_equal("http://www.intertwingly.net/blog/index.atom", feed.href)
assert_equal("http://www.intertwingly.net/blog/", feed.author.href)
}
with_feed(:from_data => <<-FEED
<feed>
<entry xml:base="http://example.com/articles/">
<title>Pain And Suffering</title>
<link href="1.html" type="text/plain" />
<link href="./2.html" type="application/xml" rel="alternate" />
<link href="../3.html" type="text/html" rel="alternate" />
<link href="../4.html" />
<link href="./5.html" type="application/xhtml+xml" />
<link href="6.css" type="text/css" rel="stylesheet" />
<content type="text">
What does your parser come up with for the main link?
What's the right value?
</content>
</entry>
</feed>
FEED
) { |feed|
assert_equal("http://example.com/3.html", feed.entries[0].link)
}
with_feed(:from_data => <<-FEED
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"
xml:base="http://example.org/tests/">
<title>xml:base support tests</title>
<subtitle type="html">
All alternate links should point to
<code>http://example.org/tests/base/result.html</code>;
all links in content should point where their label says.
</subtitle>
<link href="http://example.org/tests/base/result.html"/>
<id>tag:plasmasturm.org,2005:Atom-Tests:xml-base</id>
<updated>2006-01-17T12:35:16+01:00</updated>
<entry>
<title>1: Alternate link: Absolute URL</title>
<link href="http://example.org/tests/base/result.html"/>
<id>tag:plasmasturm.org,2005:Atom-Tests:xml-base:Test1</id>
<updated>2006-01-17T12:35:16+01:00</updated>
</entry>
<entry>
<title>2: Alternate link: Host-relative absolute URL</title>
<link href="/tests/base/result.html"/>
<id>tag:plasmasturm.org,2005:Atom-Tests:xml-base:Test2</id>
<updated>2006-01-17T12:35:15+01:00</updated>
</entry>
<entry>
<title>3: Alternate link: Relative URL</title>
<link href="base/result.html"/>
<id>tag:plasmasturm.org,2005:Atom-Tests:xml-base:Test3</id>
<updated>2006-01-17T12:35:14+01:00</updated>
</entry>
<entry>
<title>
4: Alternate link: Relative URL with parent directory component
</title>
<link href="../tests/base/result.html"/>
<id>tag:plasmasturm.org,2005:Atom-Tests:xml-base:Test4</id>
<updated>2006-01-17T12:35:13+01:00</updated>
</entry>
<entry>
<title>5: Content: Absolute URL</title>
<link href="http://example.org/tests/base/result.html"/>
<id>tag:plasmasturm.org,2005:Atom-Tests:xml-base:Test5</id>
<content type="html">
<a href="http://example.org/tests/base/result.html">
http://example.org/tests/base/result.html
</a>
</content>
<updated>2006-01-17T12:35:12+01:00</updated>
</entry>
<entry>
<title>6: Content: Host-relative URL</title>
<link href="http://example.org/tests/base/result.html"/>
<id>tag:plasmasturm.org,2005:Atom-Tests:xml-base:Test6</id>
<content type="html">
<a href="/tests/base/result.html">
http://example.org/tests/base/result.html
</a>
</content>
<updated>2006-01-17T12:35:11+01:00</updated>
</entry>
<entry>
<title>7: Content: Relative URL</title>
<link href="http://example.org/tests/base/result.html"/>
<id>tag:plasmasturm.org,2005:Atom-Tests:xml-base:Test7</id>
<content type="html">
<a href="base/result.html">
http://example.org/tests/base/result.html
</a>
</content>
<updated>2006-01-17T12:35:10+01:00</updated>
</entry>
<entry>
<title>
8: Content: Relative URL with parent directory component
</title>
<link href="http://example.org/tests/base/result.html"/>
<id>tag:plasmasturm.org,2005:Atom-Tests:xml-base:Test8</id>
<content type="html">
<a href="../tests/base/result.html">
http://example.org/tests/base/result.html
</a>
</content>
<updated>2006-01-17T12:35:9+01:00</updated>
</entry>
<entry xml:base="http://example.org/tests/entrybase/">
<title type="html">
9: Content, <code>&lt;entry></code> has base:
Absolute URL
</title>
<link href="http://example.org/tests/base/result.html"/>
<id>tag:plasmasturm.org,2005:Atom-Tests:xml-base:Test9</id>
<content type="html">
<a href="http://example.org/tests/entrybase/result.html">
http://example.org/tests/entrybase/result.html
</a>
</content>
<updated>2006-01-17T12:35:8+01:00</updated>
</entry>
<entry xml:base="http://example.org/tests/entrybase/">
<title type="html">
10: Content, <code>&lt;entry></code> has base:
Host-relative URL
</title>
<link href="http://example.org/tests/base/result.html"/>
<id>tag:plasmasturm.org,2005:Atom-Tests:xml-base:Test10</id>
<content type="html">
<a href="/tests/entrybase/result.html">
http://example.org/tests/entrybase/result.html
</a>
</content>
<updated>2006-01-17T12:35:7+01:00</updated>
</entry>
<entry xml:base="http://example.org/tests/entrybase/">
<title type="html">
11: Content, <code>&lt;entry></code> has base:
Relative URL
</title>
<link href="http://example.org/tests/base/result.html"/>
<id>tag:plasmasturm.org,2005:Atom-Tests:xml-base:Test11</id>
<content type="html">
<a href="result.html">
http://example.org/tests/entrybase/result.html
</a>
</content>
<updated>2006-01-17T12:35:6+01:00</updated>
</entry>
<entry xml:base="http://example.org/tests/entrybase/">
<title type="html">
12: Content, <code>&lt;entry></code> has base:
Relative URL with parent directory component</title>
<link href="http://example.org/tests/base/result.html"/>
<id>tag:plasmasturm.org,2005:Atom-Tests:xml-base:Test12</id>
<content type="html">
<a href="../entrybase/result.html">
http://example.org/tests/entrybase/result.html
</a>
</content>
<updated>2006-01-17T12:35:5+01:00</updated>
</entry>
<entry>
<title type="html">
13: Content, <code>&lt;content></code> has base:
Absolute URL
</title>
<link href="http://example.org/tests/base/result.html"/>
<id>tag:plasmasturm.org,2005:Atom-Tests:xml-base:Test13</id>
<content type="html"
xml:base="http://example.org/tests/contentbase/">
<a href="http://example.org/tests/contentbase/result.html">
http://example.org/tests/contentbase/result.html
</a>
</content>
<updated>2006-01-17T12:35:4+01:00</updated>
</entry>
<entry>
<title type="html">
14: Content, <code>&lt;content></code> has base:
Host-relative URL
</title>
<link href="http://example.org/tests/base/result.html"/>
<id>tag:plasmasturm.org,2005:Atom-Tests:xml-base:Test14</id>
<content type="html"
xml:base="http://example.org/tests/contentbase/">
<a href="/tests/contentbase/result.html">
http://example.org/tests/contentbase/result.html
</a>
</content>
<updated>2006-01-17T12:35:3+01:00</updated>
</entry>
<entry>
<title type="html">
15: Content, <code>&lt;content></code> has base:
Relative URL
</title>
<link href="http://example.org/tests/base/result.html"/>
<id>tag:plasmasturm.org,2005:Atom-Tests:xml-base:Test15</id>
<content type="html"
xml:base="http://example.org/tests/contentbase/">
<a href="result.html">
http://example.org/tests/contentbase/result.html
</a>
</content>
<updated>2006-01-17T12:35:2+01:00</updated>
</entry>
<entry>
<title type="html">
16: Content, <code>&lt;content></code> has base:
Relative URL with parent directory component
</title>
<link href="http://example.org/tests/base/result.html"/>
<id>tag:plasmasturm.org,2005:Atom-Tests:xml-base:Test16</id>
<content type="html"
xml:base="http://example.org/tests/contentbase/">
<a href="../contentbase/result.html">
http://example.org/tests/contentbase/result.html
</a>
</content>
<updated>2006-01-17T12:35:1+01:00</updated>
</entry>
</feed>
FEED
) { |feed|
for entry in feed.entries
assert_equal("http://example.org/tests/base/result.html", entry.link,
"Broken link for: " + entry.title)
end
assert_equal(2, feed.entries[4].content.scan(
'http://example.org/tests/base/result.html').size,
"Invalid URI resolution:\n#{feed.entries[4].content}")
assert_equal(2, feed.entries[5].content.scan(
'http://example.org/tests/base/result.html').size,
"Invalid URI resolution:\n#{feed.entries[5].content}")
assert_equal(2, feed.entries[6].content.scan(
'http://example.org/tests/base/result.html').size,
"Invalid URI resolution:\n#{feed.entries[6].content}")
assert_equal(2, feed.entries[7].content.scan(
'http://example.org/tests/base/result.html').size,
"Invalid URI resolution:\n#{feed.entries[7].content}")
assert_equal(2, feed.entries[8].content.scan(
'http://example.org/tests/entrybase/result.html').size,
"Invalid URI resolution:\n#{feed.entries[8].content}")
assert_equal(2, feed.entries[9].content.scan(
'http://example.org/tests/entrybase/result.html').size,
"Invalid URI resolution:\n#{feed.entries[9].content}")
assert_equal(2, feed.entries[10].content.scan(
'http://example.org/tests/entrybase/result.html').size,
"Invalid URI resolution:\n#{feed.entries[10].content}")
assert_equal(2, feed.entries[11].content.scan(
'http://example.org/tests/entrybase/result.html').size,
"Invalid URI resolution:\n#{feed.entries[11].content}")
assert_equal(2, feed.entries[12].content.scan(
'http://example.org/tests/contentbase/result.html').size,
"Invalid URI resolution:\n#{feed.entries[12].content}")
assert_equal(2, feed.entries[13].content.scan(
'http://example.org/tests/contentbase/result.html').size,
"Invalid URI resolution:\n#{feed.entries[13].content}")
assert_equal(2, feed.entries[14].content.scan(
'http://example.org/tests/contentbase/result.html').size,
"Invalid URI resolution:\n#{feed.entries[14].content}")
assert_equal(2, feed.entries[15].content.scan(
'http://example.org/tests/contentbase/result.html').size,
"Invalid URI resolution:\n#{feed.entries[15].content}")
}
end
def test_feed_copyright
with_feed(:from_file =>
'wellformed/atom/feed_copyright_base64.xml') { |feed|
assert_equal("Example <b>Atom</b>", feed.copyright)
}
with_feed(:from_file =>
'wellformed/atom/feed_copyright_base64_2.xml') { |feed|
assert_equal(
"<p>History of the &lt;blink&gt; tag</p>",
feed.copyright)
}
end
def test_feed_license
with_feed(:from_data => <<-FEED
<feed xmlns="http://www.w3.org/2005/Atom">
<id>http://www.example.com/myfeed</id>
<title>My Example Feed</title>
<updated>2005-07-28T12:00:00Z</updated>
<link href="http://www.example.com/myfeed" />
<link rel="license" type="application/rdf+xml"
href="http://creativecommons.org/licenses/by-nc/2.5/rdf" />
<rights>
Copyright (c) 2005. Some rights reserved. This feed
is licensed under a Creative Commons Attribute-NonCommercial
Use License. It contains material originally published by
Jane Smith at http://www.example.com/entries/1 under the
Creative Commons Attribute License.
</rights>
<author><name>James</name></author>
<entry>
<id>tag:entries.org,2005:1</id>
<title>Atom Powered Robots Run Amok</title>
<updated>2005-06-28T12:00:00Z</updated>
<link href="http://www.example.org/entries/1" />
<summary>Atom Powered Robots Run Amok</summary>
<author><name>Jane Smith</name></author>
<link rel="license" type="text/html"
href="http://creativecommons.org/licenses/by/2.5/" />
</entry>
</feed>
FEED
) { |feed|
assert_equal(1, feed.entries.size)
assert_equal(
"http://creativecommons.org/licenses/by-nc/2.5/rdf",
feed.license.href
)
assert_equal(
"application/rdf+xml",
feed.license.type
)
assert_equal(
"http://creativecommons.org/licenses/by/2.5/",
feed.entries[0].license.href
)
assert_equal(
"text/html",
feed.entries[0].license.type
)
}
end
def test_feed_item_author
with_feed(:from_data => <<-FEED
<?xml version="1.0" encoding="iso-8859-1"?>
<feed version="0.3" xmlns="http://purl.org/atom/ns#" xml:lang="en">
<entry>
<author>
<name>Cooper Baker</name>
</author>
</entry>
</feed>
FEED
) { |feed|
assert_equal(1, feed.entries.size)
assert_equal("Cooper Baker", feed.entries[0].author.name)
}
end
def test_feed_images
with_feed(:from_data => <<-FEED
<feed version="0.3" xmlns="http://purl.org/atom/ns#">
<link type="image/jpeg" href="http://www.example.com/image.jpeg" />
</feed>
FEED
) { |feed|
assert_equal(1, feed.images.size)
assert_equal("http://www.example.com/image.jpeg", feed.images[0].url)
assert_equal(nil, feed.link)
}
end
def test_feed_item_summary_plus_content
with_feed(:from_data => <<-FEED
<?xml version="1.0" encoding="iso-8859-1"?>
<prefix:feed version="1.0" xmlns:prefix="http://www.w3.org/2005/Atom">
<prefix:entry>
<prefix:summary>Excerpt</prefix:summary>
<prefix:content>Full Content</prefix:content>
</prefix:entry>
</prefix:feed>
FEED
) { |feed|
assert_equal(1, feed.items.size)
assert_equal("Excerpt", feed.items[0].summary)
assert_equal("Full Content", feed.items[0].content)
}
end
# Make sure it knows a title from a hole in the ground
def test_all_feed_titles
with_feed(:from_data => <<-FEED
<?xml version="1.0" encoding="iso-8859-1"?>
<feed version="1.0" xmlns="http://www.w3.org/2005/Atom">
<title><![CDATA[<title>]]></title>
<entry>
<title><![CDATA[<title>]]></title>
</entry>
</feed>
FEED
) { |feed|
assert_equal("&lt;title>",
feed.title, "Text CDATA failed")
assert_equal(1, feed.items.size)
assert_equal("&lt;title>",
feed.items[0].title, "Text CDATA failed")
}
with_feed(:from_data => <<-FEED
<?xml version="1.0" encoding="iso-8859-1"?>
<feed version="1.0" xmlns="http://www.w3.org/2005/Atom">
<title type="html"><![CDATA[<title>]]></title>
<entry>
<title type="html"><![CDATA[<title>]]></title>
</entry>
</feed>
FEED
) { |feed|
assert_equal("<title>",
feed.title, "HTML CDATA failed")
assert_equal(1, feed.items.size)
assert_equal("<title>",
feed.items[0].title, "HTML CDATA failed")
}
with_feed(:from_data => <<-FEED
<?xml version="1.0" encoding="iso-8859-1"?>
<feed version="1.0" xmlns="http://www.w3.org/2005/Atom">
<title type="html">&lt;title></title>
<entry>
<title type="html">&lt;title></title>
</entry>
</feed>
FEED
) { |feed|
assert_equal("<title>",
feed.title, "HTML entity failed")
assert_equal(1, feed.items.size)
assert_equal("<title>",
feed.items[0].title, "HTML entity failed")
}
with_feed(:from_data => <<-FEED
<?xml version="1.0" encoding="iso-8859-1"?>
<feed version="1.0" xmlns="http://www.w3.org/2005/Atom">
<title type="html">&lt;title></title>
<entry>
<title type="html">&lt;title></title>
</entry>
</feed>
FEED
) { |feed|
assert_equal("<title>",
feed.title, "HTML NCR failed")
assert_equal(1, feed.items.size)
assert_equal("<title>",
feed.items[0].title, "HTML NCR failed")
}
with_feed(:from_data => <<-FEED
<?xml version="1.0" encoding="iso-8859-1"?>
<feed version="1.0" xmlns="http://www.w3.org/2005/Atom">
<title type="text"><![CDATA[<title>]]></title>
<entry>
<title type="text"><![CDATA[<title>]]></title>
</entry>
</feed>
FEED
) { |feed|
assert_equal("<title>",
feed.title, "Text CDATA failed")
assert_equal(1, feed.items.size)
assert_equal("<title>",
feed.items[0].title, "Text CDATA failed")
}
with_feed(:from_data => <<-FEED
<?xml version="1.0" encoding="iso-8859-1"?>
<feed version="1.0" xmlns="http://www.w3.org/2005/Atom">
<title type="text"><title></title>
<entry>
<title type="text"><title></title>
</entry>
</feed>
FEED
) { |feed|
assert_equal("<title>",
feed.title, "Text entity failed")
assert_equal(1, feed.items.size)
assert_equal("<title>",
feed.items[0].title, "Text entity failed")
}
with_feed(:from_data => <<-FEED
<?xml version="1.0" encoding="iso-8859-1"?>
<feed version="1.0" xmlns="http://www.w3.org/2005/Atom">
<title type="text"><title></title>
<entry>
<title type="text"><title></title>
</entry>
</feed>
FEED
) { |feed|
assert_equal("<title>",
feed.title, "Text NCR failed")
assert_equal(1, feed.items.size)
assert_equal("<title>",
feed.items[0].title, "Text NCR failed")
}
with_feed(:from_data => <<-FEED
<?xml version="1.0" encoding="iso-8859-1"?>
<feed version="1.0" xmlns="http://www.w3.org/2005/Atom">
<title type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml"><title></div>
</title>
<entry>
<title type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml"><title></div>
</title>
</entry>
</feed>
FEED
) { |feed|
assert_equal(
'<title>',
feed.title, "XHTML entity failed")
assert_equal(1, feed.items.size)
assert_equal(
'<title>',
feed.items[0].title, "XHTML entity failed")
}
with_feed(:from_data => <<-FEED
<?xml version="1.0" encoding="iso-8859-1"?>
<feed version="1.0" xmlns="http://www.w3.org/2005/Atom">
<title type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml"><title></div>
</title>
<entry>
<title type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml"><title></div>
</title>
</entry>
</feed>
FEED
) { |feed|
assert_equal(
'<title>',
feed.title, "XHTML NCR failed")
assert_equal(1, feed.items.size)
assert_equal(
'<title>',
feed.items[0].title, "XHTML NCR failed")
}
with_feed(:from_data => <<-FEED
<?xml version="1.0" encoding="iso-8859-1"?>
<feed version="1.0" xmlns="http://www.w3.org/2005/Atom">
<title type="xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<xhtml:div><title></xhtml:div>
</title>
<entry>
<title type="xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<xhtml:div><title></xhtml:div>
</title>
</entry>
</feed>
FEED
) { |feed|
assert_equal(
'<title>',
feed.title, "XHTML NCR failed")
assert_equal(1, feed.items.size)
assert_equal(
'<title>',
feed.items[0].title, "XHTML NCR failed")
}
end
def test_feed_item_content_sanitization
with_feed(:from_data => <<-FEED
<?xml version="1.0" encoding="iso-8859-1"?>
<feed version="1.0" xmlns="http://www.w3.org/2005/Atom">
<entry>
<content type="xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<xhtml:div>
<xhtml:script>alert('Content Attack Succeeded');</xhtml:script>
</xhtml:div>
</content>
</entry>
</feed>
FEED
) { |feed|
assert_equal(1, feed.items.size)
assert_equal(0,
feed.items[0].content.scan("<xhtml:script>").size,
"Sanitization of content element failed")
assert_equal(0,
feed.items[0].content.scan("<script>").size,
"Sanitization of content element failed")
}
end
end
|