From 8507efc4273aa87e32090bcabb31b7bc5b98ec35 Mon Sep 17 00:00:00 2001 From: Martial Saunois Date: Tue, 28 Jan 2014 21:08:27 +0100 Subject: Unit tests added for the new Freebox user agent. --- tests/lib/request.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests/lib') diff --git a/tests/lib/request.php b/tests/lib/request.php index c6401a57144..3cb58674d3e 100644 --- a/tests/lib/request.php +++ b/tests/lib/request.php @@ -118,6 +118,16 @@ class Test_Request extends PHPUnit_Framework_TestCase { ), true ), + array( + 'Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Firefox/24.0', + OC_Request::USER_AGENT_FREEBOX, + false + ), + array( + 'Mozilla/5.0', + OC_Request::USER_AGENT_FREEBOX, + true + ), ); } } -- cgit v1.2.3 From 0f1c587e6baaa201f01683b6adac8cc907c4f3e3 Mon Sep 17 00:00:00 2001 From: Martial Saunois Date: Wed, 29 Jan 2014 10:58:34 +0100 Subject: The regexp of the Freebox user agent is now more strict. A new unit test has been added in consequence. --- lib/private/request.php | 2 +- tests/lib/request.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'tests/lib') diff --git a/lib/private/request.php b/lib/private/request.php index 855148ac25a..2c5b907846e 100755 --- a/lib/private/request.php +++ b/lib/private/request.php @@ -11,7 +11,7 @@ class OC_Request { const USER_AGENT_IE = '/MSIE/'; // Android Chrome user agent: https://developers.google.com/chrome/mobile/docs/user-agent const USER_AGENT_ANDROID_MOBILE_CHROME = '#Android.*Chrome/[.0-9]*#'; - const USER_AGENT_FREEBOX = '#Mozilla/5\.0$#'; + const USER_AGENT_FREEBOX = '#^Mozilla/5\.0$#'; /** * @brief Check overwrite condition diff --git a/tests/lib/request.php b/tests/lib/request.php index 3cb58674d3e..1d77acc70ae 100644 --- a/tests/lib/request.php +++ b/tests/lib/request.php @@ -128,6 +128,11 @@ class Test_Request extends PHPUnit_Framework_TestCase { OC_Request::USER_AGENT_FREEBOX, true ), + array( + 'Fake Mozilla/5.0', + OC_Request::USER_AGENT_FREEBOX, + false + ), ); } } -- cgit v1.2.3 From 36838b2837168b69aba82f88f110c174db25e6d7 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 4 Feb 2014 11:11:24 +0100 Subject: add test for password remove method --- lib/private/log/errorhandler.php | 2 +- tests/lib/errorHandler.php | 62 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 tests/lib/errorHandler.php (limited to 'tests/lib') diff --git a/lib/private/log/errorhandler.php b/lib/private/log/errorhandler.php index f6c96ef8218..1dde6b507fc 100644 --- a/lib/private/log/errorhandler.php +++ b/lib/private/log/errorhandler.php @@ -19,7 +19,7 @@ class ErrorHandler { * @param string $msg * @return string */ - private static function removePassword($msg) { + protected static function removePassword($msg) { return preg_replace('/\/\/(.*):(.*)@/', '//xxx:xxx@', $msg); } diff --git a/tests/lib/errorHandler.php b/tests/lib/errorHandler.php new file mode 100644 index 00000000000..68b87deccb6 --- /dev/null +++ b/tests/lib/errorHandler.php @@ -0,0 +1,62 @@ + + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see . + * + */ + +class Test_ErrorHandler extends \PHPUnit_Framework_TestCase { + + /** + * @brief provide username, password combinations for testRemovePassword + * @return array + */ + function passwordProvider() { + return array( + array('user', 'password'), + array('user@owncloud.org', 'password'), + array('user', 'pass@word'), + array('us:er', 'password'), + array('user', 'pass:word'), + ); + + } + + /** + * @dataProvider passwordProvider + * @param string $username + * @param string $password + */ + function testRemovePassword($username, $password) { + $url = 'http://'.$username.':'.$password.'@owncloud.org'; + $expectedResult = 'http://xxx:xxx@owncloud.org'; + $result = TestableErrorHandler::testRemovePassword($url); + + $this->assertEquals($expectedResult, $result); + } + +} + +/** + * @brief dummy class to access protected methods of \OC\Log\ErrorHandler + */ +class TestableErrorHandler extends \OC\Log\ErrorHandler { + public static function testRemovePassword($msg) { + return self::removePassword($msg); + } +} -- cgit v1.2.3