From 9b05f19338e209f05386e5b13fe0a704c94062bb Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Mon, 27 Aug 2012 08:45:13 +0200 Subject: Restructured tests --- tests/Framework/Mime.php | 123 ++++++++++++++++++++++++++++++++++ tests/Framework/Shared.php | 161 +++++++++++++++++++++++++++++++++++++++++++++ tests/Framework/Utils.php | 119 +++++++++++++++++++++++++++++++++ tests/Framework/VCard.php | 59 +++++++++++++++++ 4 files changed, 462 insertions(+) create mode 100644 tests/Framework/Mime.php create mode 100644 tests/Framework/Shared.php create mode 100644 tests/Framework/Utils.php create mode 100644 tests/Framework/VCard.php (limited to 'tests/Framework') diff --git a/tests/Framework/Mime.php b/tests/Framework/Mime.php new file mode 100644 index 000000000..dcd55992a --- /dev/null +++ b/tests/Framework/Mime.php @@ -0,0 +1,123 @@ + 'test@domain.tld', + 1 => '', + 2 => 'Test ', + 3 => 'Test Test ', + 4 => 'Test Test', + 5 => '"Test Test" ', + 6 => '"Test Test"', + 7 => '"Test \\" Test" ', + 8 => '"Test', + 9 => '=?ISO-8859-1?B?VGVzdAo=?= ', + 10 => '=?ISO-8859-1?B?VGVzdAo=?=', // #1487068 + // comments in address (#1487673) + 11 => 'Test (comment) ', + 12 => '"Test" (comment) ', + 13 => '"Test (comment)" (comment) ', + 14 => '(comment) ', + 15 => 'Test ', + 16 => 'Test Test ((comment)) ', + 17 => 'test@domain.tld (comment)', + 18 => '"Test,Test" ', + // 1487939 + 19 => 'Test <"test test"@domain.tld>', + 20 => '<"test test"@domain.tld>', + 21 => '"test test"@domain.tld', + ); + + $results = array( + 0 => array(1, '', 'test@domain.tld'), + 1 => array(1, '', 'test@domain.tld'), + 2 => array(1, 'Test', 'test@domain.tld'), + 3 => array(1, 'Test Test', 'test@domain.tld'), + 4 => array(1, 'Test Test', 'test@domain.tld'), + 5 => array(1, 'Test Test', 'test@domain.tld'), + 6 => array(1, 'Test Test', 'test@domain.tld'), + 7 => array(1, 'Test " Test', 'test@domain.tld'), + 8 => array(1, 'Test array(1, 'Test', 'test@domain.tld'), + 10 => array(1, 'Test', 'test@domain.tld'), + 11 => array(1, 'Test', 'test@domain.tld'), + 12 => array(1, 'Test', 'test@domain.tld'), + 13 => array(1, 'Test (comment)', 'test@domain.tld'), + 14 => array(1, '', 'test@domain.tld'), + 15 => array(1, 'Test', 'test@domain.tld'), + 16 => array(1, 'Test Test', 'test@domain.tld'), + 17 => array(1, '', 'test@domain.tld'), + 18 => array(1, 'Test,Test', 'test@domain.tld'), + 19 => array(1, 'Test', '"test test"@domain.tld'), + 20 => array(1, '', '"test test"@domain.tld'), + 21 => array(1, '', '"test test"@domain.tld'), + ); + + foreach ($headers as $idx => $header) { + $res = rcube_mime::decode_address_list($header); + + $this->assertEquals($results[$idx][0], count($res), "Rows number in result for header: " . $header); + $this->assertEquals($results[$idx][1], $res[1]['name'], "Name part decoding for header: " . $header); + $this->assertEquals($results[$idx][2], $res[1]['mailto'], "Email part decoding for header: " . $header); + } + } + + /** + * Test decoding of header values + * Uses rcube_mime::decode_mime_string() + */ + function test_header_decode_qp() + { + $test = array( + // #1488232: invalid character "?" + 'quoted-printable (1)' => array( + 'in' => '=?utf-8?Q?Certifica=C3=A7=C3=A3??=', + 'out' => 'Certifica=C3=A7=C3=A3?', + ), + 'quoted-printable (2)' => array( + 'in' => '=?utf-8?Q?Certifica=?= =?utf-8?Q?C3=A7=C3=A3?=', + 'out' => 'Certifica=C3=A7=C3=A3', + ), + 'quoted-printable (3)' => array( + 'in' => '=?utf-8?Q??= =?utf-8?Q??=', + 'out' => '', + ), + 'quoted-printable (4)' => array( + 'in' => '=?utf-8?Q??= a =?utf-8?Q??=', + 'out' => ' a ', + ), + 'quoted-printable (5)' => array( + 'in' => '=?utf-8?Q?a?= =?utf-8?Q?b?=', + 'out' => 'ab', + ), + 'quoted-printable (6)' => array( + 'in' => '=?utf-8?Q? ?= =?utf-8?Q?a?=', + 'out' => ' a', + ), + 'quoted-printable (7)' => array( + 'in' => '=?utf-8?Q?___?= =?utf-8?Q?a?=', + 'out' => ' a', + ), + ); + + foreach ($test as $idx => $item) { + $res = rcube_mime::decode_mime_string($item['in'], 'UTF-8'); + $res = quoted_printable_encode($res); + + $this->assertEquals($item['out'], $res, "Header decoding for: " . $idx); + } + } +} diff --git a/tests/Framework/Shared.php b/tests/Framework/Shared.php new file mode 100644 index 000000000..d38fb03a3 --- /dev/null +++ b/tests/Framework/Shared.php @@ -0,0 +1,161 @@ +assertTrue($result, $title); + + $result = in_array_nocase($needle, null); + + $this->assertFalse($result, $title); + } + + /** + * rcube_shared.inc: get_boolean() + */ + function test_get_boolean() + { + $input = array( + false, 'false', '0', 'no', 'off', 'nein', 'FALSE', '', null, + ); + + foreach ($input as $idx => $value) { + $this->assertFalse(get_boolean($value), "Invalid result for $idx test item"); + } + + $input = array( + true, 'true', '1', 1, 'yes', 'anything', 1000, + ); + + foreach ($input as $idx => $value) { + $this->assertTrue(get_boolean($value), "Invalid result for $idx test item"); + } + } + + /** + * rcube_shared.inc: parse_bytes() + */ + function test_parse_bytes() + { + $data = array( + '1' => 1, + '1024' => 1024, + '2k' => 2 * 1024, + '2 k' => 2 * 1024, + '2kb' => 2 * 1024, + '2kB' => 2 * 1024, + '2m' => 2 * 1048576, + '2 m' => 2 * 1048576, + '2mb' => 2 * 1048576, + '2mB' => 2 * 1048576, + '2g' => 2 * 1024 * 1048576, + '2 g' => 2 * 1024 * 1048576, + '2gb' => 2 * 1024 * 1048576, + '2gB' => 2 * 1024 * 1048576, + ); + + foreach ($data as $value => $expected) { + $result = parse_bytes($value); + $this->assertEquals($expected, $result, "Invalid parse_bytes() result for $value"); + } + } + + /** + * rcube_shared.inc: slashify() + */ + function test_slashify() + { + $data = array( + 'test' => 'test/', + 'test/' => 'test/', + '' => '/', + "\\" => "\\/", + ); + + foreach ($data as $value => $expected) { + $result = slashify($value); + $this->assertEquals($expected, $result, "Invalid slashify() result for $value"); + } + + } + + /** + * rcube_shared.inc: unslashify() + */ + function test_unslashify() + { + $data = array( + 'test' => 'test', + 'test/' => 'test', + '/' => '', + "\\/" => "\\", + 'test/test' => 'test/test', + 'test//' => 'test', + ); + + foreach ($data as $value => $expected) { + $result = unslashify($value); + $this->assertEquals($expected, $result, "Invalid unslashify() result for $value"); + } + + } + + /** + * rcube_shared.inc: get_offset_sec() + */ + function test_get_offset_sec() + { + $data = array( + '1s' => 1, + '1m' => 1 * 60, + '1h' => 1 * 60 * 60, + '1d' => 1 * 60 * 60 * 24, + '1w' => 1 * 60 * 60 * 24 * 7, + '1y' => (int) '1y', + 100 => 100, + '100' => 100, + ); + + foreach ($data as $value => $expected) { + $result = get_offset_sec($value); + $this->assertEquals($expected, $result, "Invalid get_offset_sec() result for $value"); + } + + } + + /** + * rcube_shared.inc: array_keys_recursive() + */ + function test_array_keys_recursive() + { + $input = array( + 'one' => array( + 'two' => array( + 'three' => array(), + 'four' => 'something', + ), + ), + 'five' => 'test', + ); + + $result = array_keys_recursive($input); + $input_str = 'one,two,three,four,five'; + $result_str = implode(',', $result); + + $this->assertEquals($input_str, $result_str, "Invalid array_keys_recursive() result"); + } +} diff --git a/tests/Framework/Utils.php b/tests/Framework/Utils.php new file mode 100644 index 000000000..b6cc5d577 --- /dev/null +++ b/tests/Framework/Utils.php @@ -0,0 +1,119 @@ +', 'Encoded html within email is invalid'), + array('email.domain.com', 'Missing @'), + array('email@domain@domain.com', 'Two @ sign'), + array('.email@domain.com', 'Leading dot in address is not allowed'), + array('email.@domain.com', 'Trailing dot in address is not allowed'), + array('email..email@domain.com', 'Multiple dots'), + array('あいうえお@domain.com', 'Unicode char as address'), + array('email@domain.com (Joe Smith)', 'Text followed email is not allowed'), + array('email@domain', 'Missing top level domain (.com/.net/.org/etc)'), + array('email@-domain.com', 'Leading dash in front of domain is invalid'), +// array('email@domain.web', '.web is not a valid top level domain'), + array('email@123.123.123.123', 'IP address without brackets'), + array('email@2001:2d12:c4fe:5afe::1', 'IPv6 address without brackets'), + array('email@IPv6:2001:2d12:c4fe:5afe::1', 'IPv6 address without brackets (2)'), + array('email@[111.222.333.44444]', 'Invalid IP format'), + array('email@[111.222.255.257]', 'Invalid IP format (2)'), + array('email@[.222.255.257]', 'Invalid IP format (3)'), + array('email@[::1]', 'Invalid IPv6 format (1)'), + array('email@[IPv6:2001:23x2:1]', 'Invalid IPv6 format (2)'), + array('email@[IPv6:1111:2222:33333::4444:5555]', 'Invalid IPv6 format (3)'), + array('email@[IPv6:1111::3333::4444:5555]', 'Invalid IPv6 format (4)'), + array('email@domain..com', 'Multiple dot in the domain portion is invalid'), + ); + } + + /** + * @dataProvider data_valid_email + */ + function test_valid_email($email, $title) + { + $this->assertTrue(rcube_utils::check_email($email, false), $title); + } + + /** + * @dataProvider data_invalid_email + */ + function test_invalid_email($email, $title) + { + $this->assertFalse(rcube_utils::check_email($email, false), $title); + } + + /** + * rcube_utils::mod_css_styles() + */ + function test_mod_css_styles() + { + $css = file_get_contents(TESTS_DIR . 'src/valid.css'); + $mod = rcube_utils::mod_css_styles($css, 'rcmbody'); + + $this->assertRegExp('/#rcmbody\s+\{/', $mod, "Replace body style definition"); + $this->assertRegExp('/#rcmbody h1\s\{/', $mod, "Prefix tag styles (single)"); + $this->assertRegExp('/#rcmbody h1, #rcmbody h2, #rcmbody h3, #rcmbody textarea\s+\{/', $mod, "Prefix tag styles (multiple)"); + $this->assertRegExp('/#rcmbody \.noscript\s+\{/', $mod, "Prefix class styles"); + } + + /** + * rcube_utils::mod_css_styles() + */ + function test_mod_css_styles_xss() + { + $mod = rcube_utils::mod_css_styles("body.main2cols { background-image: url('../images/leftcol.png'); }", 'rcmbody'); + $this->assertEquals("/* evil! */", $mod, "No url() values allowed"); + + $mod = rcube_utils::mod_css_styles("@import url('http://localhost/somestuff/css/master.css');", 'rcmbody'); + $this->assertEquals("/* evil! */", $mod, "No import statements"); + + $mod = rcube_utils::mod_css_styles("left:expression(document.body.offsetWidth-20)", 'rcmbody'); + $this->assertEquals("/* evil! */", $mod, "No expression properties"); + + $mod = rcube_utils::mod_css_styles("left:exp/* */ression( alert('xss3') )", 'rcmbody'); + $this->assertEquals("/* evil! */", $mod, "Don't allow encoding quirks"); + + $mod = rcube_utils::mod_css_styles("background:\\0075\\0072\\006c( javascript:alert('xss') )", 'rcmbody'); + $this->assertEquals("/* evil! */", $mod, "Don't allow encoding quirks (2)"); + } +} diff --git a/tests/Framework/VCard.php b/tests/Framework/VCard.php new file mode 100644 index 000000000..a830c2cbc --- /dev/null +++ b/tests/Framework/VCard.php @@ -0,0 +1,59 @@ +_srcpath('apple.vcf'))); + + $this->assertTrue($vcard->business, "Identify as business record"); + $this->assertEquals("Apple Computer AG", $vcard->displayname, "FN => displayname"); + $this->assertEquals("", $vcard->firstname, "No person name set"); + } + + function test_parse_two() + { + $vcard = new rcube_vcard(file_get_contents($this->_srcpath('johndoe.vcf')), null); + + $this->assertFalse($vcard->business, "Identify as private record"); + $this->assertEquals("John Doë", $vcard->displayname, "Decode according to charset attribute"); + $this->assertEquals("roundcube.net", $vcard->organization, "Test organization field"); + $this->assertCount(2, $vcard->email, "List two e-mail addresses"); + $this->assertEquals("roundcube@gmail.com", $vcard->email[0], "Use PREF e-mail as primary"); + } + + function test_import() + { + $input = file_get_contents($this->_srcpath('apple.vcf')); + $input .= file_get_contents($this->_srcpath('johndoe.vcf')); + + $vcards = rcube_vcard::import($input); + + $this->assertCount(2, $vcards, "Detected 2 vcards"); + $this->assertEquals("Apple Computer AG", $vcards[0]->displayname, "FN => displayname"); + $this->assertEquals("John Doë", $vcards[1]->displayname, "Displayname with correct charset"); + + // http://trac.roundcube.net/ticket/1485542 + $vcards2 = rcube_vcard::import(file_get_contents($this->_srcpath('thebat.vcf'))); + $this->assertEquals("Iksiñski", $vcards2[0]->surname, "Detect charset in encoded values"); + } + + function test_encodings() + { + $input = file_get_contents($this->_srcpath('utf-16_sample.vcf')); + + $vcards = rcube_vcard::import($input); + $this->assertEquals("Ǽgean ĽdaMonté", $vcards[0]->displayname, "Decoded from UTF-16"); + } +} -- cgit v1.2.3 From 5f8adabb6286fdcb0ff8a0ea5d1d58f40eef51f4 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Mon, 27 Aug 2012 09:28:16 +0200 Subject: Add simple (constructor) tests for Framework classes --- tests/Framework/BaseReplacer.php | 20 ++++++++++++++++++++ tests/Framework/Browser.php | 20 ++++++++++++++++++++ tests/Framework/Cache.php | 20 ++++++++++++++++++++ tests/Framework/Charset.php | 28 ++++++++++++++++++++++++++++ tests/Framework/ContentFilter.php | 20 ++++++++++++++++++++ tests/Framework/Html.php | 20 ++++++++++++++++++++ tests/Framework/Image.php | 20 ++++++++++++++++++++ tests/Framework/Imap.php | 20 ++++++++++++++++++++ tests/Framework/ImapGeneric.php | 20 ++++++++++++++++++++ tests/Framework/MessageHeader.php | 20 ++++++++++++++++++++ tests/Framework/MessagePart.php | 20 ++++++++++++++++++++ tests/Framework/Rcube.php | 20 ++++++++++++++++++++ tests/Framework/ResultIndex.php | 20 ++++++++++++++++++++ tests/Framework/ResultSet.php | 20 ++++++++++++++++++++ tests/Framework/ResultThread.php | 20 ++++++++++++++++++++ tests/Framework/Smtp.php | 20 ++++++++++++++++++++ tests/Framework/Spellchecker.php | 20 ++++++++++++++++++++ tests/Framework/StringReplacer.php | 20 ++++++++++++++++++++ tests/Framework/User.php | 20 ++++++++++++++++++++ tests/phpunit.xml | 19 +++++++++++++++++++ 20 files changed, 407 insertions(+) create mode 100644 tests/Framework/BaseReplacer.php create mode 100644 tests/Framework/Browser.php create mode 100644 tests/Framework/Cache.php create mode 100644 tests/Framework/Charset.php create mode 100644 tests/Framework/ContentFilter.php create mode 100644 tests/Framework/Html.php create mode 100644 tests/Framework/Image.php create mode 100644 tests/Framework/Imap.php create mode 100644 tests/Framework/ImapGeneric.php create mode 100644 tests/Framework/MessageHeader.php create mode 100644 tests/Framework/MessagePart.php create mode 100644 tests/Framework/Rcube.php create mode 100644 tests/Framework/ResultIndex.php create mode 100644 tests/Framework/ResultSet.php create mode 100644 tests/Framework/ResultThread.php create mode 100644 tests/Framework/Smtp.php create mode 100644 tests/Framework/Spellchecker.php create mode 100644 tests/Framework/StringReplacer.php create mode 100644 tests/Framework/User.php (limited to 'tests/Framework') diff --git a/tests/Framework/BaseReplacer.php b/tests/Framework/BaseReplacer.php new file mode 100644 index 000000000..e00b9e5eb --- /dev/null +++ b/tests/Framework/BaseReplacer.php @@ -0,0 +1,20 @@ +assertInstanceOf('rcube_base_replacer', $object, "Class constructor"); + } +} diff --git a/tests/Framework/Browser.php b/tests/Framework/Browser.php new file mode 100644 index 000000000..c3860d8a3 --- /dev/null +++ b/tests/Framework/Browser.php @@ -0,0 +1,20 @@ +assertInstanceOf('rcube_browser', $object, "Class constructor"); + } +} diff --git a/tests/Framework/Cache.php b/tests/Framework/Cache.php new file mode 100644 index 000000000..dc026a634 --- /dev/null +++ b/tests/Framework/Cache.php @@ -0,0 +1,20 @@ +assertInstanceOf('rcube_cache', $object, "Class constructor"); + } +} diff --git a/tests/Framework/Charset.php b/tests/Framework/Charset.php new file mode 100644 index 000000000..9e3fad4d3 --- /dev/null +++ b/tests/Framework/Charset.php @@ -0,0 +1,28 @@ +assertEquals(rcube_charset::clean($input), $output, $title); + } +} diff --git a/tests/Framework/ContentFilter.php b/tests/Framework/ContentFilter.php new file mode 100644 index 000000000..9bee9368b --- /dev/null +++ b/tests/Framework/ContentFilter.php @@ -0,0 +1,20 @@ +assertInstanceOf('rcube_content_filter', $object, "Class constructor"); + } +} diff --git a/tests/Framework/Html.php b/tests/Framework/Html.php new file mode 100644 index 000000000..107f82805 --- /dev/null +++ b/tests/Framework/Html.php @@ -0,0 +1,20 @@ +assertInstanceOf('html', $object, "Class constructor"); + } +} diff --git a/tests/Framework/Image.php b/tests/Framework/Image.php new file mode 100644 index 000000000..31e852042 --- /dev/null +++ b/tests/Framework/Image.php @@ -0,0 +1,20 @@ +assertInstanceOf('rcube_image', $object, "Class constructor"); + } +} diff --git a/tests/Framework/Imap.php b/tests/Framework/Imap.php new file mode 100644 index 000000000..3f52e07be --- /dev/null +++ b/tests/Framework/Imap.php @@ -0,0 +1,20 @@ +assertInstanceOf('rcube_imap', $object, "Class constructor"); + } +} diff --git a/tests/Framework/ImapGeneric.php b/tests/Framework/ImapGeneric.php new file mode 100644 index 000000000..0b2cc3d53 --- /dev/null +++ b/tests/Framework/ImapGeneric.php @@ -0,0 +1,20 @@ +assertInstanceOf('rcube_imap_generic', $object, "Class constructor"); + } +} diff --git a/tests/Framework/MessageHeader.php b/tests/Framework/MessageHeader.php new file mode 100644 index 000000000..e5bc1752f --- /dev/null +++ b/tests/Framework/MessageHeader.php @@ -0,0 +1,20 @@ +assertInstanceOf('rcube_message_header', $object, "Class constructor"); + } +} diff --git a/tests/Framework/MessagePart.php b/tests/Framework/MessagePart.php new file mode 100644 index 000000000..deb426024 --- /dev/null +++ b/tests/Framework/MessagePart.php @@ -0,0 +1,20 @@ +assertInstanceOf('rcube_message_part', $object, "Class constructor"); + } +} diff --git a/tests/Framework/Rcube.php b/tests/Framework/Rcube.php new file mode 100644 index 000000000..637558dc9 --- /dev/null +++ b/tests/Framework/Rcube.php @@ -0,0 +1,20 @@ +assertInstanceOf('rcube', $object, "Class singleton"); + } +} diff --git a/tests/Framework/ResultIndex.php b/tests/Framework/ResultIndex.php new file mode 100644 index 000000000..efbba6da7 --- /dev/null +++ b/tests/Framework/ResultIndex.php @@ -0,0 +1,20 @@ +assertInstanceOf('rcube_result_index', $object, "Class constructor"); + } +} diff --git a/tests/Framework/ResultSet.php b/tests/Framework/ResultSet.php new file mode 100644 index 000000000..2d04e53c0 --- /dev/null +++ b/tests/Framework/ResultSet.php @@ -0,0 +1,20 @@ +assertInstanceOf('rcube_result_set', $object, "Class constructor"); + } +} diff --git a/tests/Framework/ResultThread.php b/tests/Framework/ResultThread.php new file mode 100644 index 000000000..f980845cc --- /dev/null +++ b/tests/Framework/ResultThread.php @@ -0,0 +1,20 @@ +assertInstanceOf('rcube_result_thread', $object, "Class constructor"); + } +} diff --git a/tests/Framework/Smtp.php b/tests/Framework/Smtp.php new file mode 100644 index 000000000..4bd78d097 --- /dev/null +++ b/tests/Framework/Smtp.php @@ -0,0 +1,20 @@ +assertInstanceOf('rcube_smtp', $object, "Class constructor"); + } +} diff --git a/tests/Framework/Spellchecker.php b/tests/Framework/Spellchecker.php new file mode 100644 index 000000000..9c3e92ffd --- /dev/null +++ b/tests/Framework/Spellchecker.php @@ -0,0 +1,20 @@ +assertInstanceOf('rcube_spellchecker', $object, "Class constructor"); + } +} diff --git a/tests/Framework/StringReplacer.php b/tests/Framework/StringReplacer.php new file mode 100644 index 000000000..11210c0da --- /dev/null +++ b/tests/Framework/StringReplacer.php @@ -0,0 +1,20 @@ +assertInstanceOf('rcube_string_replacer', $sr, "Class constructor"); + } +} diff --git a/tests/Framework/User.php b/tests/Framework/User.php new file mode 100644 index 000000000..3b1983c58 --- /dev/null +++ b/tests/Framework/User.php @@ -0,0 +1,20 @@ +assertInstanceOf('rcube_user', $user, "Class constructor"); + } +} diff --git a/tests/phpunit.xml b/tests/phpunit.xml index 1bde91be1..28f7e7420 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -3,8 +3,27 @@ colors="true"> + Framework/BaseReplacer.php + Framework/Browser.php + Framework/Cache.php + Framework/Charset.php + Framework/ContentFilter.php + Framework/Html.php + Framework/Imap.php + Framework/ImapGeneric.php + Framework/Image.php + Framework/MessageHeader.php + Framework/MessagePart.php Framework/Mime.php + Framework/Rcube.php + Framework/ResultIndex.php + Framework/ResultSet.php + Framework/ResultThread.php Framework/Shared.php + Framework/Smtp.php + Framework/Spellchecker.php + Framework/StringReplacer.php + Framework/User.php Framework/Utils.php Framework/VCard.php HtmlToText.php -- cgit v1.2.3 From a65ce5d3b07deb578cc4c4aba5695bcea8c07a87 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Mon, 27 Aug 2012 12:23:30 +0200 Subject: Rename ip_check to check_ip, add IP checking tests --- program/include/rcube_utils.php | 4 ++-- tests/Framework/Utils.php | 47 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) (limited to 'tests/Framework') diff --git a/program/include/rcube_utils.php b/program/include/rcube_utils.php index defb2aed1..aa748dc7f 100644 --- a/program/include/rcube_utils.php +++ b/program/include/rcube_utils.php @@ -94,7 +94,7 @@ class rcube_utils // Validate domain part if (preg_match('/^\[((IPv6:[0-9a-f:.]+)|([0-9.]+))\]$/i', $domain_part, $matches)) { - return self::ip_check(preg_replace('/^IPv6:/i', '', $matches[1])); // valid IPv4 or IPv6 address + return self::check_ip(preg_replace('/^IPv6:/i', '', $matches[1])); // valid IPv4 or IPv6 address } else { // If not an IP address @@ -154,7 +154,7 @@ class rcube_utils * * @return bool True if the address is valid */ - public static function ip_check($ip) + public static function check_ip($ip) { // IPv6, but there's no build-in IPv6 support if (strpos($ip, ':') !== false && !defined('AF_INET6')) { diff --git a/tests/Framework/Utils.php b/tests/Framework/Utils.php index b6cc5d577..503b69a4a 100644 --- a/tests/Framework/Utils.php +++ b/tests/Framework/Utils.php @@ -82,6 +82,53 @@ class Framework_Utils extends PHPUnit_Framework_TestCase $this->assertFalse(rcube_utils::check_email($email, false), $title); } + /** + * Valid IP addresses for test_valid_ip() + */ + function data_valid_ip() + { + return array( + array('0.0.0.0'), + array('123.123.123.123'), + array('::'), + array('::1'), + array('::1.2.3.4'), + array('2001:2d12:c4fe:5afe::1'), + ); + } + + /** + * Valid IP addresses for test_invalid_ip() + */ + function data_invalid_ip() + { + return array( + array(''), + array(0), + array('123.123.123.1234'), + array('1.1.1.1.1'), + array('::1.2.3.260'), + array('::1.0'), + array('2001::c4fe:5afe::1'), + ); + } + + /** + * @dataProvider data_valid_ip + */ + function test_valid_ip($ip) + { + $this->assertTrue(rcube_utils::check_ip($ip)); + } + + /** + * @dataProvider data_invalid_ip + */ + function test_invalid_ip($ip) + { + $this->assertFalse(rcube_utils::check_ip($ip)); + } + /** * rcube_utils::mod_css_styles() */ -- cgit v1.2.3 From 5f8097b9eba09302be561d67ce035275494043e3 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Mon, 27 Aug 2012 12:55:58 +0200 Subject: Added tests for specialchars quoting --- tests/Framework/Html.php | 26 ++++++++++++++++++++++++++ tests/Framework/Utils.php | 30 ++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) (limited to 'tests/Framework') diff --git a/tests/Framework/Html.php b/tests/Framework/Html.php index 107f82805..8a27baca8 100644 --- a/tests/Framework/Html.php +++ b/tests/Framework/Html.php @@ -17,4 +17,30 @@ class Framework_Html extends PHPUnit_Framework_TestCase $this->assertInstanceOf('html', $object, "Class constructor"); } + + /** + * Data for test_quote() + */ + function data_quote() + { + return array( + array('abc', 'abc'), + array('?', '?'), + array('"', '"'), + array('<', '<'), + array('>', '>'), + array('&', '&'), + array('&', '&amp;'), + array('&', '&', true), + ); + } + + /** + * Test for quote() + * @dataProvider data_quote + */ + function test_quote($str, $result, $validate = false) + { + $this->assertEquals(html::quote($str, $validate), $result); + } } diff --git a/tests/Framework/Utils.php b/tests/Framework/Utils.php index 503b69a4a..e58835956 100644 --- a/tests/Framework/Utils.php +++ b/tests/Framework/Utils.php @@ -129,6 +129,36 @@ class Framework_Utils extends PHPUnit_Framework_TestCase $this->assertFalse(rcube_utils::check_ip($ip)); } + /** + * Data for test_rep_specialchars_output() + */ + function data_rep_specialchars_output() + { + return array( + array('', '', 'abc', 'abc'), + array('', '', '?', '?'), + array('', '', '"', '"'), + array('', '', '<', '<'), + array('', '', '>', '>'), + array('', '', '&', '&'), + array('', '', '&', '&amp;'), + array('', '', '', '<a>'), + array('', 'remove', '', ''), + ); + } + + /** + * Test for rep_specialchars_output + * @dataProvider data_rep_specialchars_output + */ + function test_rep_specialchars_output($type, $mode, $str, $res) + { + $result = rcube_utils::rep_specialchars_output( + $str, $type ? $type : 'html', $mode ? $mode : 'strict'); + + $this->assertEquals($result, $res); + } + /** * rcube_utils::mod_css_styles() */ -- cgit v1.2.3 From 528113069db7734cc6a85557291cc9f3c8d8bb91 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Wed, 29 Aug 2012 08:23:26 +0200 Subject: More tests --- tests/Framework/Shared.php | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'tests/Framework') diff --git a/tests/Framework/Shared.php b/tests/Framework/Shared.php index d38fb03a3..99ef829da 100644 --- a/tests/Framework/Shared.php +++ b/tests/Framework/Shared.php @@ -158,4 +158,47 @@ class Framework_Shared extends PHPUnit_Framework_TestCase $this->assertEquals($input_str, $result_str, "Invalid array_keys_recursive() result"); } + + /** + * rcube_shared.inc: format_email() + */ + function test_format_email() + { + $data = array( + '' => '', + 'test' => 'test', + 'test@test.tld' => 'test@test.tld', + 'test@[127.0.0.1]' => 'test@[127.0.0.1]', + 'TEST@TEST.TLD' => 'TEST@test.tld', + ); + + foreach ($data as $value => $expected) { + $result = format_email($value); + $this->assertEquals($expected, $result, "Invalid format_email() result for $value"); + } + + } + + /** + * rcube_shared.inc: format_email_recipient() + */ + function test_format_email_recipient() + { + $data = array( + '' => array(''), + 'test' => array('test'), + 'test@test.tld' => array('test@test.tld'), + 'test@[127.0.0.1]' => array('test@[127.0.0.1]'), + 'TEST@TEST.TLD' => array('TEST@TEST.TLD'), + 'TEST ' => array('test@test.tld', 'TEST'), + '"TEST\"" ' => array('test@test.tld', 'TEST"'), + ); + + foreach ($data as $expected => $value) { + $result = format_email_recipient($value[0], $value[1]); + $this->assertEquals($expected, $result, "Invalid format_email_recipient()"); + } + + } + } -- cgit v1.2.3 From 8f66aa06f58ba2c9f99541a191ee4bcaa98500b3 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Sun, 9 Sep 2012 16:50:14 +0200 Subject: Fix encoding vCard file when contains PHOTO;ENCODING=b (#1488683) --- CHANGELOG | 1 + program/include/rcube_vcard.php | 1 + tests/Framework/VCard.php | 14 +++++++++++++ tests/src/photo.vcf | 45 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+) create mode 100644 tests/src/photo.vcf (limited to 'tests/Framework') diff --git a/CHANGELOG b/CHANGELOG index 0706009c4..bb74cf22e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ CHANGELOG Roundcube Webmail =========================== +- Fix encoding vCard file when contains PHOTO;ENCODING=b (#1488683) - Fix focus issue in IE when selecting message row (#1488620) - Remove (too big) min-width on mail screen - Add full headers view in message preview window (#1488538) diff --git a/program/include/rcube_vcard.php b/program/include/rcube_vcard.php index 2bfd474c6..49b312c5c 100644 --- a/program/include/rcube_vcard.php +++ b/program/include/rcube_vcard.php @@ -555,6 +555,7 @@ class rcube_vcard if ((list($key, $value) = explode('=', $attr)) && $value) { $value = trim($value); if ($key == 'ENCODING') { + $value = strtoupper($value); // add next line(s) to value string if QP line end detected if ($value == 'QUOTED-PRINTABLE') { while (preg_match('/=$/', $lines[$i])) diff --git a/tests/Framework/VCard.php b/tests/Framework/VCard.php index a830c2cbc..56ca9d721 100644 --- a/tests/Framework/VCard.php +++ b/tests/Framework/VCard.php @@ -49,6 +49,20 @@ class Framework_VCard extends PHPUnit_Framework_TestCase $this->assertEquals("Iksiñski", $vcards2[0]->surname, "Detect charset in encoded values"); } + function test_import_photo_encoding() + { + $input = file_get_contents($this->_srcpath('photo.vcf')); + + $vcards = rcube_vcard::import($input); + $vcard = $vcards[0]->get_assoc(); + + $this->assertCount(1, $vcards, "Detected 1 vcard"); + + // ENCODING=b case (#1488683) + $this->assertEquals("/9j/4AAQSkZJRgABAQA", substr(base64_encode($vcard['photo']), 0, 19), "Photo decoding"); + $this->assertEquals("Müller", $vcard['surname'], "Unicode characters"); + } + function test_encodings() { $input = file_get_contents($this->_srcpath('utf-16_sample.vcf')); diff --git a/tests/src/photo.vcf b/tests/src/photo.vcf new file mode 100644 index 000000000..c3a805009 --- /dev/null +++ b/tests/src/photo.vcf @@ -0,0 +1,45 @@ +BEGIN:VCARD +VERSION:3.0 +N:Müller;Jörg;;; +FN:Apple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