aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--application/ApplicationUtils.php20
-rw-r--r--application/Utils.php20
-rw-r--r--index.php2
-rw-r--r--tests/ApplicationUtilsTest.php31
-rw-r--r--tests/UtilsTest.php31
5 files changed, 52 insertions, 52 deletions
diff --git a/application/ApplicationUtils.php b/application/ApplicationUtils.php
index 6fb07f36..b0e94e24 100644
--- a/application/ApplicationUtils.php
+++ b/application/ApplicationUtils.php
@@ -6,6 +6,26 @@ class ApplicationUtils
6{ 6{
7 7
8 /** 8 /**
9 * Checks the PHP version to ensure Shaarli can run
10 *
11 * @param string $minVersion minimum PHP required version
12 * @param string $curVersion current PHP version (use PHP_VERSION)
13 *
14 * @throws Exception the PHP version is not supported
15 */
16 public static function checkPHPVersion($minVersion, $curVersion)
17 {
18 if (version_compare($curVersion, $minVersion) < 0) {
19 throw new Exception(
20 'Your PHP version is obsolete!'
21 .' Shaarli requires at least PHP '.$minVersion.', and thus cannot run.'
22 .' Your PHP version has known security vulnerabilities and should be'
23 .' updated as soon as possible.'
24 );
25 }
26 }
27
28 /**
9 * Checks Shaarli has the proper access permissions to its resources 29 * Checks Shaarli has the proper access permissions to its resources
10 * 30 *
11 * @param array $globalConfig The $GLOBALS['config'] array 31 * @param array $globalConfig The $GLOBALS['config'] array
diff --git a/application/Utils.php b/application/Utils.php
index 120333c5..b8579b48 100644
--- a/application/Utils.php
+++ b/application/Utils.php
@@ -120,26 +120,6 @@ function generateLocation($referer, $host, $loopTerms = array())
120} 120}
121 121
122/** 122/**
123 * Checks the PHP version to ensure Shaarli can run
124 *
125 * @param string $minVersion minimum PHP required version
126 * @param string $curVersion current PHP version (use PHP_VERSION)
127 *
128 * @throws Exception the PHP version is not supported
129 */
130function checkPHPVersion($minVersion, $curVersion)
131{
132 if (version_compare($curVersion, $minVersion) < 0) {
133 throw new Exception(
134 'Your PHP version is obsolete!'
135 .' Shaarli requires at least PHP '.$minVersion.', and thus cannot run.'
136 .' Your PHP version has known security vulnerabilities and should be'
137 .' updated as soon as possible.'
138 );
139 }
140}
141
142/**
143 * Validate session ID to prevent Full Path Disclosure. 123 * Validate session ID to prevent Full Path Disclosure.
144 * 124 *
145 * See #298. 125 * See #298.
diff --git a/index.php b/index.php
index 654f7f8f..aae477bf 100644
--- a/index.php
+++ b/index.php
@@ -159,7 +159,7 @@ require_once 'application/Router.php';
159 159
160// Ensure the PHP version is supported 160// Ensure the PHP version is supported
161try { 161try {
162 checkPHPVersion('5.3', PHP_VERSION); 162 ApplicationUtils::checkPHPVersion('5.3', PHP_VERSION);
163} catch(Exception $exc) { 163} catch(Exception $exc) {
164 header('Content-Type: text/plain; charset=utf-8'); 164 header('Content-Type: text/plain; charset=utf-8');
165 echo $exc->getMessage(); 165 echo $exc->getMessage();
diff --git a/tests/ApplicationUtilsTest.php b/tests/ApplicationUtilsTest.php
index 9a99c6c6..01301e68 100644
--- a/tests/ApplicationUtilsTest.php
+++ b/tests/ApplicationUtilsTest.php
@@ -12,6 +12,37 @@ require_once 'application/ApplicationUtils.php';
12class ApplicationUtilsTest extends PHPUnit_Framework_TestCase 12class ApplicationUtilsTest extends PHPUnit_Framework_TestCase
13{ 13{
14 /** 14 /**
15 * Check supported PHP versions
16 */
17 public function testCheckSupportedPHPVersion()
18 {
19 $minVersion = '5.3';
20 ApplicationUtils::checkPHPVersion($minVersion, '5.4.32');
21 ApplicationUtils::checkPHPVersion($minVersion, '5.5');
22 ApplicationUtils::checkPHPVersion($minVersion, '5.6.10');
23 }
24
25 /**
26 * Check a unsupported PHP version
27 * @expectedException Exception
28 * @expectedExceptionMessageRegExp /Your PHP version is obsolete/
29 */
30 public function testCheckSupportedPHPVersion51()
31 {
32 ApplicationUtils::checkPHPVersion('5.3', '5.1.0');
33 }
34
35 /**
36 * Check another unsupported PHP version
37 * @expectedException Exception
38 * @expectedExceptionMessageRegExp /Your PHP version is obsolete/
39 */
40 public function testCheckSupportedPHPVersion52()
41 {
42 ApplicationUtils::checkPHPVersion('5.3', '5.2');
43 }
44
45 /**
15 * Checks resource permissions for the current Shaarli installation 46 * Checks resource permissions for the current Shaarli installation
16 */ 47 */
17 public function testCheckCurrentResourcePermissions() 48 public function testCheckCurrentResourcePermissions()
diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php
index 311d4bfb..4847ea94 100644
--- a/tests/UtilsTest.php
+++ b/tests/UtilsTest.php
@@ -139,37 +139,6 @@ class UtilsTest extends PHPUnit_Framework_TestCase
139 } 139 }
140 140
141 /** 141 /**
142 * Check supported PHP versions
143 */
144 public function testCheckSupportedPHPVersion()
145 {
146 $minVersion = '5.3';
147 checkPHPVersion($minVersion, '5.4.32');
148 checkPHPVersion($minVersion, '5.5');
149 checkPHPVersion($minVersion, '5.6.10');
150 }
151
152 /**
153 * Check a unsupported PHP version
154 * @expectedException Exception
155 * @expectedExceptionMessageRegExp /Your PHP version is obsolete/
156 */
157 public function testCheckSupportedPHPVersion51()
158 {
159 checkPHPVersion('5.3', '5.1.0');
160 }
161
162 /**
163 * Check another unsupported PHP version
164 * @expectedException Exception
165 * @expectedExceptionMessageRegExp /Your PHP version is obsolete/
166 */
167 public function testCheckSupportedPHPVersion52()
168 {
169 checkPHPVersion('5.3', '5.2');
170 }
171
172 /**
173 * Test is_session_id_valid with a valid ID - TEST ALL THE HASHES! 142 * Test is_session_id_valid with a valid ID - TEST ALL THE HASHES!
174 * 143 *
175 * This tests extensively covers all hash algorithms / bit representations 144 * This tests extensively covers all hash algorithms / bit representations