From 63d4b1217216f3d04894090026ed3f01aba9b385 Mon Sep 17 00:00:00 2001 From: thomascube Date: Mon, 2 Mar 2009 14:46:12 +0000 Subject: Create some basic unit tests based in simpletest.org --- tests/mailfunc.php | 110 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/modcss.php | 45 ++++++++++++++++++++ tests/runtests.sh | 53 +++++++++++++++++++++++ tests/src/BID-26800.txt | 52 +++++++++++++++++++++++ tests/src/htmlbody.txt | 50 ++++++++++++++++++++++ tests/src/htmlxss.txt | 22 ++++++++++ tests/src/plainbody.txt | 37 ++++++++++++++++ tests/src/valid.css | 30 +++++++++++++ 8 files changed, 399 insertions(+) create mode 100644 tests/mailfunc.php create mode 100644 tests/modcss.php create mode 100755 tests/runtests.sh create mode 100644 tests/src/BID-26800.txt create mode 100644 tests/src/htmlbody.txt create mode 100644 tests/src/htmlxss.txt create mode 100644 tests/src/plainbody.txt create mode 100644 tests/src/valid.css diff --git a/tests/mailfunc.php b/tests/mailfunc.php new file mode 100644 index 000000000..bf9163b7d --- /dev/null +++ b/tests/mailfunc.php @@ -0,0 +1,110 @@ +UnitTestCase('Mail body rendering tests'); + + // simulate environment to successfully include func.inc + $GLOBALS['RCMAIL'] = $RCMAIL = rcmail::get_instance(); + $GLOBALS['OUTPUT'] = $OUTPUT = $RCMAIL->load_gui(); + $RCMAIL->action = 'spell'; + $IMAP = $RCMAIL->imap; + + require_once 'steps/mail/func.inc'; + } + + /** + * Helper method to create a HTML message part object + */ + function get_html_part($body) + { + $part = new rcube_message_part; + $part->ctype_primary = 'text'; + $part->ctype_secondary = 'html'; + $part->body = file_get_contents(TESTS_DIR . $body); + $part->replaces = array(); + return $part; + } + + /** + * Test sanitization of a "normal" html message + */ + function test_html() + { + $part = $this->get_html_part('src/htmlbody.txt'); + $part->replaces = array('ex1.jpg' => 'part_1.2.jpg', 'ex2.jpg' => 'part_1.2.jpg'); + + // render HTML in normal mode + $html = rcmail_print_body($part, array('safe' => false)); + + $this->assertPattern('/src="'.$part->replaces['ex1.jpg'].'"/', $html, "Replace reference to inline image"); + $this->assertPattern('#background="./program/blocked.gif"#', $html, "Replace external background image"); + $this->assertNoPattern('/ex3.jpg/', $html, "No references to external images"); + $this->assertNoPattern('/]+>/', $html, "No meta tags allowed"); + $this->assertNoPattern('/ + + +

2 test

+

<div> block

+
valid css
+
+
+ +

3 test

+

Inject comment text

+
+
+ +

4 test

+

Using reverse solid to directe the codepoint

+
+
+ +

5 test

+

Character entity references

+

Character entity references is acceptable in "inline styles"

+
+
+
+
+
+ +
+
+
+
+
+ +
+
+
+
+
+
+ + + + diff --git a/tests/src/htmlbody.txt b/tests/src/htmlbody.txt new file mode 100644 index 000000000..5cdd7579e --- /dev/null +++ b/tests/src/htmlbody.txt @@ -0,0 +1,50 @@ + + + + +RoundCube Test Message + + + + + + + + +
+ +

This is a HTML message

+ +

See nice pictures like the following:

+ +
+ Example 1 + Example 2 + Example 3 +
+ +
+

Subscription form

+ + E-Mail:
+ + +
+ +

To unsubscribe click here or + send a mail to unsubscribe@evilsite.net

+ +
+ + + \ No newline at end of file diff --git a/tests/src/htmlxss.txt b/tests/src/htmlxss.txt new file mode 100644 index 000000000..60ceb944e --- /dev/null +++ b/tests/src/htmlxss.txt @@ -0,0 +1,22 @@ + + + +

+ +

mail me! +roundcube.net +roundcube.net (2) + +

+ +
Brilliant!
+ +
BBBBBB
+ +

+Have a nice Christmas time.
+Thomas +

+ + + diff --git a/tests/src/plainbody.txt b/tests/src/plainbody.txt new file mode 100644 index 000000000..7ebfe429b --- /dev/null +++ b/tests/src/plainbody.txt @@ -0,0 +1,37 @@ +From: iPhone Developer Program +To: nobody@roundcube.net + +*iPhone Developer Program* + +----------------------------------- +iPhone SDK 2.2.1 is now available +https://daw.apple.com/cgi-bin/WebObjects/DSAuthWeb.woa/wa/login?appIdKey=3D= +D635F5C417E087A3B9864DAC5D25920C4E9442C9339FA9277951628F0291F620&path=3D//i= +phone/login.action + +Log in to the iPhone Dev Center to download iPhone SDK for iPhone OS 2.2.1.= + Installation of iPhone SDK 2.2.1 is required for development with devices = +updated to iPhone OS 2.2.1. Please view the Read Me before installing the n= +ew version of the iPhone SDK. + +Log in now +https://daw.apple.com/cgi-bin/WebObjects/DSAuthWeb.woa/wa/login?appIdKey=3D= +D635F5C417E087A3B9864DAC5D25920C4E9442C9339FA9277951628F0291F620&path=3D//i= +phone/login.action + +----------------------------------- +Copyright (c) 2009 Apple Inc. 1 Infinite Loop, MS 303-3DM, Cupertino, CA 95= +014. + +All Rights Reserved +http://www.apple.com/legal/default.html + +Keep Informed +http://www.apple.com/enews/subscribe/ + +Privacy Policy +http://www.apple.com/legal/privacy/ + +My Info +https://myinfo.apple.com/cgi-bin/WebObjects/MyInfo + diff --git a/tests/src/valid.css b/tests/src/valid.css new file mode 100644 index 000000000..340fa9a87 --- /dev/null +++ b/tests/src/valid.css @@ -0,0 +1,30 @@ +/** Master style definitions **/ + +body, p, div, h1, h2, h3, textarea { + font-family: "Lucida Grande", Helvetica, sans-serif; + font-size: 8.8pt; + color: #333; +} + +body { + background-color: white; + margin: 0; +} + +h1 { + color: #1F519A; + font-size: 1.7em; + font-weight: normal; + margin-top: 0; + margin-bottom: 1em; +} + +.noscript { + display: none; +} + +.hint, .username { + color: #999; +} + + -- cgit v1.2.3