diff --git api.wordpress.org/public_html/core/serve-happy/1.0/config.php api.wordpress.org/public_html/core/serve-happy/1.0/config.php
index 60c283a..037cfe4 100644
|
|
|
|
| 1 | 1 | <?php |
| 2 | 2 | namespace WordPressdotorg\API\Serve_Happy; |
| 3 | 3 | |
| 4 | | // The latest branch of PHP which is receiving security updates. Should be defined as X.Y |
| 5 | | define( 'PHP_RECEIVING_SECURITY_UPDATES', '5.6' ); |
| | 4 | // The latest branch of PHP which WordPress.org recommends. |
| | 5 | define( 'RECOMMENDED_PHP', '7.2' ); |
| 6 | 6 | |
| 7 | | // The latest branch of PHP which is considered NOT out-of-date. |
| 8 | | define( 'TRIGGER_PHP_VERSION', '5.3' ); |
| | 7 | // The lowest branch of PHP which is actively supported. |
| | 8 | define( 'SUPPORTED_PHP', '7.0' ); |
| 9 | 9 | |
| 10 | | // The latest branch of PHP which WordPress.org recommends. |
| 11 | | define( 'RECOMMENDED_PHP', '7.2' ); |
| 12 | | No newline at end of file |
| | 10 | // The lowest branch of PHP which is receiving security updates. |
| | 11 | define( 'SECURE_PHP', '5.6' ); |
| | 12 | |
| | 13 | // The lowest branch of PHP which is still considered acceptable in WordPress. |
| | 14 | define( 'ACCEPTABLE_PHP', '5.3' ); |
diff --git api.wordpress.org/public_html/core/serve-happy/1.0/include.php api.wordpress.org/public_html/core/serve-happy/1.0/include.php
index 89cba05..3bc36b8 100644
|
|
|
function determine_request( $request = false ) { |
| 18 | 18 | return bail( 'invalid_param', 'Invalid parameter: php_version', 400 ); |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | | // Including the IP address here as an optional parameter incase it's wanted later to return dynamic responses for hosts. |
| 22 | | $ip_adress = false; |
| 23 | | if ( ! empty( $request['ip_address'] ) ) { |
| 24 | | $ip_address = $request['ip_address']; |
| 25 | | |
| 26 | | // Only allow a IP range to be passed. for example: 123.123.123.0 instead of 123.123.123.45 |
| 27 | | if ( '.0' != substr( $ip_address, -2 ) ) { |
| 28 | | return bail( 'invalid_param', 'Invalid parameter: ip_address', 400 ); |
| 29 | | } |
| 30 | | } |
| 31 | | |
| 32 | | return compact( |
| 33 | | 'php_version', |
| 34 | | 'ip_address' |
| 35 | | ); |
| | 21 | return compact( 'php_version' ); |
| 36 | 22 | } |
| 37 | 23 | |
| 38 | 24 | function parse_request( $request ) { |
| 39 | 25 | $php_version = $request['php_version']; |
| 40 | 26 | |
| 41 | | $out_of_date = version_compare( $php_version, TRIGGER_PHP_VERSION, '<' ); |
| 42 | | $receiving_security_updates = version_compare( $php_version, PHP_RECEIVING_SECURITY_UPDATES, '>=' ); |
| 43 | | |
| 44 | | $status = 'ok'; |
| 45 | | if ( $out_of_date ) { |
| 46 | | $status = 'out_of_date'; |
| 47 | | } elseif ( ! $receiving_security_updates ) { |
| 48 | | $status = 'no_security_updates'; |
| 49 | | } |
| 50 | | |
| 51 | | $recommended_php = RECOMMENDED_PHP; |
| 52 | | $secure_php = PHP_RECEIVING_SECURITY_UPDATES; |
| 53 | | $update_url = ''; // Potential future use based on $request['ip_address'] |
| 54 | | |
| 55 | | return compact( |
| 56 | | 'php_version', |
| 57 | | 'recommended_php', |
| 58 | | 'secure_php', |
| 59 | | 'status', |
| 60 | | 'update_url', |
| 61 | | |
| 62 | | // Including for debugging purposes, see https://meta.trac.wordpress.org/ticket/3474 |
| 63 | | 'out_of_date', |
| 64 | | 'receiving_security_updates' |
| | 27 | return array( |
| | 28 | 'recommended_version' => RECOMMENDED_PHP, |
| | 29 | 'is_supported' => version_compare( $php_version, SUPPORTED_PHP, '>=' ), |
| | 30 | 'is_secure' => version_compare( $php_version, SECURE_PHP, '>=' ), |
| | 31 | 'is_acceptable' => version_compare( $php_version, ACCEPTABLE_PHP, '>=' ), |
| 65 | 32 | ); |
| 66 | 33 | } |
| 67 | 34 | |
diff --git api.wordpress.org/public_html/core/serve-happy/1.0/tests/tests.php api.wordpress.org/public_html/core/serve-happy/1.0/tests/tests.php
index cc95cac..b71a207 100644
|
|
|
class Tests_API_Responses extends PHPUnit_Framework_TestCase { |
| 24 | 24 | ], |
| 25 | 25 | [ 'php_version' => '5.3.2' ] |
| 26 | 26 | ], |
| 27 | | [ |
| 28 | | [ |
| 29 | | 'php_version' => '7.0', |
| 30 | | 'ip_address' => '1.2.3.0' |
| 31 | | ], |
| 32 | | [ |
| 33 | | 'php_version' => '7.0', |
| 34 | | 'ip_address' => '1.2.3.0' |
| 35 | | ] |
| 36 | | ], |
| 37 | 27 | ]; |
| 38 | 28 | } |
| 39 | 29 | |
| … |
… |
class Tests_API_Responses extends PHPUnit_Framework_TestCase { |
| 91 | 81 | 'status' => 400 |
| 92 | 82 | ] |
| 93 | 83 | ], |
| 94 | | [ |
| 95 | | [ |
| 96 | | 'php_version' => '7.0', |
| 97 | | 'ip_address' => '1.2.3.4' |
| 98 | | ], |
| 99 | | [ |
| 100 | | 'code' => 'invalid_param', |
| 101 | | 'message' => 'Invalid parameter: ip_address', |
| 102 | | 'status' => 400 |
| 103 | | ] |
| 104 | | ], |
| 105 | 84 | ]; |
| 106 | 85 | } |
| 107 | 86 | |
| … |
… |
class Tests_API_Responses extends PHPUnit_Framework_TestCase { |
| 125 | 104 | } |
| 126 | 105 | |
| 127 | 106 | function dataprovider_parse_request_valid() { |
| 128 | | return [ |
| 129 | | // Testing Valid IP Address format |
| 130 | | [ |
| 131 | | [ |
| 132 | | 'php_version' => RECOMMENDED_PHP, |
| 133 | | 'ip_address' => '1.2.3.0', |
| 134 | | ], |
| 135 | | [ 'status' => 'ok' ] |
| 136 | | ], |
| 137 | | // Testing PHP version logic: |
| | 107 | // Test recommended PHP version is always returned. |
| | 108 | $data = [ |
| 138 | 109 | [ |
| 139 | 110 | [ 'php_version' => RECOMMENDED_PHP ], |
| 140 | | [ 'status' => 'ok' ] |
| 141 | | ], |
| 142 | | [ |
| 143 | | [ 'php_version' => RECOMMENDED_PHP + 0.1 ], |
| 144 | | [ 'status' => 'ok' ] |
| | 111 | [ 'recommended_version' => RECOMMENDED_PHP ] |
| 145 | 112 | ], |
| 146 | 113 | [ |
| 147 | | [ 'php_version' => PHP_RECEIVING_SECURITY_UPDATES ], |
| 148 | | [ 'status' => 'ok' ] |
| 149 | | ], |
| 150 | | [ |
| 151 | | [ 'php_version' => PHP_RECEIVING_SECURITY_UPDATES - 0.1 ], |
| 152 | | [ 'status' => 'no_security_updates' ] |
| 153 | | ], |
| 154 | | [ |
| 155 | | [ 'php_version' => TRIGGER_PHP_VERSION - 0.1 ], |
| 156 | | [ 'status' => 'out_of_date' ] |
| | 114 | [ 'php_version' => '5.2' ], |
| | 115 | [ 'recommended_version' => RECOMMENDED_PHP ] |
| 157 | 116 | ], |
| 158 | 117 | ]; |
| | 118 | |
| | 119 | // Test individual PHP versions. |
| | 120 | $flags = [ |
| | 121 | 'is_supported' => 'SUPPORTED_PHP', |
| | 122 | 'is_secure' => 'SECURE_PHP', |
| | 123 | 'is_acceptable' => 'ACCEPTABLE_PHP' |
| | 124 | ]; |
| | 125 | foreach ( $flags as $flag => $constant_name ) { |
| | 126 | $data[] = [ |
| | 127 | [ 'php_version' => constant( $constant_name ) ], |
| | 128 | [ $flag => true ] |
| | 129 | ]; |
| | 130 | $data[] = [ |
| | 131 | [ 'php_version' => constant( $constant_name ) + 0.1 ], |
| | 132 | [ $flag => true ] |
| | 133 | ]; |
| | 134 | $data[] = [ |
| | 135 | [ 'php_version' => constant( $constant_name ) - 0.1 ], |
| | 136 | [ $flag => false ] |
| | 137 | ]; |
| | 138 | } |
| | 139 | return $data; |
| 159 | 140 | } |
| 160 | 141 | |
| 161 | 142 | /** |