fix security test for redirect. Also set common server variables to mimick a real...
[phpbb.git] / tests / security / all_tests.php
blobbc482f1f90772fc1bb779b1ea7ac9004974374b8
1 <?php
2 /**
4 * @package testing
5 * @version $Id$
6 * @copyright (c) 2008 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
9 */
11 define('IN_PHPBB', true);
13 if (!defined('PHPUnit_MAIN_METHOD'))
15 define('PHPUnit_MAIN_METHOD', 'phpbb_security_all_tests::main');
18 require_once 'PHPUnit/Framework.php';
19 require_once 'PHPUnit/TextUI/TestRunner.php';
21 require_once 'security/extract_current_page.php';
22 require_once 'security/redirect.php';
24 class phpbb_security_all_tests extends PHPUnit_Framework_TestSuite
26 /**
27 * Set up the required user object and server variables for the suites
29 protected function setUp()
31 global $user;
33 // Put this into a global function being run by every test to init a proper user session
34 $_SERVER['HTTP_HOST'] = 'localhost';
35 $_SERVER['SERVER_NAME'] = 'localhost';
36 $_SERVER['SERVER_ADDR'] = '127.0.0.1';
37 $_SERVER['SERVER_PORT'] = 80;
38 $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
39 $_SERVER['QUERY_STRING'] = '';
40 $_SERVER['REQUEST_URI'] = '/tests/';
41 $_SERVER['SCRIPT_NAME'] = '/tests/index.php';
42 $_SERVER['PHP_SELF'] = '/tests/index.php';
43 $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; de; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14';
44 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
47 [HTTP_ACCEPT_ENCODING] => gzip,deflate
48 [HTTP_ACCEPT_CHARSET] => ISO-8859-1,utf-8;q=0.7,*;q=0.7
49 DOCUMENT_ROOT] => /var/www/
50 [SCRIPT_FILENAME] => /var/www/tests/index.php
53 // Set no user and trick a bit to circumvent errors
54 $user = new user();
55 $user->lang = true;
56 $user->browser = (!empty($_SERVER['HTTP_USER_AGENT'])) ? htmlspecialchars((string) $_SERVER['HTTP_USER_AGENT']) : '';
57 $user->referer = (!empty($_SERVER['HTTP_REFERER'])) ? htmlspecialchars((string) $_SERVER['HTTP_REFERER']) : '';
58 $user->forwarded_for = (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) ? (string) $_SERVER['HTTP_X_FORWARDED_FOR'] : '';
59 $user->host = (!empty($_SERVER['HTTP_HOST'])) ? (string) strtolower($_SERVER['HTTP_HOST']) : ((!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : getenv('SERVER_NAME'));
60 $user->page = session::extract_current_page(PHPBB_ROOT_PATH);
63 protected function tearDown()
65 global $user;
66 $user = NULL;
69 public static function main()
71 PHPUnit_TextUI_TestRunner::run(self::suite());
74 public static function suite()
76 // I bet there is a better method calling this... :)
77 $suite = new phpbb_security_all_tests('phpBB Security Fixes');
79 $suite->addTestSuite('phpbb_security_extract_current_page_test');
80 $suite->addTestSuite('phpbb_security_redirect_test');
82 return $suite;
86 if (PHPUnit_MAIN_METHOD == 'phpbb_security_all_tests::main')
88 phpbb_security_all_tests::main();