Making WordPress.org

Ticket #3474: 3474.2.diff

File 3474.2.diff, 5.8 KB (added by flixos90, 7 years ago)
  • api.wordpress.org/public_html/core/serve-happy/1.0/config.php

    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
     
    11<?php
    22namespace WordPressdotorg\API\Serve_Happy;
    33
    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.
     5define( 'RECOMMENDED_PHP', '7.2' );
    66
    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.
     8define( 'SUPPORTED_PHP', '7.0' );
    99
    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.
     11define( 'SECURE_PHP', '5.6' );
     12
     13// The lowest branch of PHP which is still considered acceptable in WordPress.
     14define( 'ACCEPTABLE_PHP', '5.3' );
  • api.wordpress.org/public_html/core/serve-happy/1.0/include.php

    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 ) { 
    1818                return bail( 'invalid_param', 'Invalid parameter: php_version', 400 );
    1919        }
    2020
    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' );
    3622}
    3723
    3824function parse_request( $request ) {
    3925        $php_version = $request['php_version'];
    4026
    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, '>=' ),
    6532        );
    6633}
    6734
  • api.wordpress.org/public_html/core/serve-happy/1.0/tests/tests.php

    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 { 
    2424                                ],
    2525                                [ 'php_version' => '5.3.2' ]
    2626                        ],
    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                         ],
    3727                ];
    3828        }
    3929
    class Tests_API_Responses extends PHPUnit_Framework_TestCase { 
    9181                                        'status'  => 400
    9282                                ]
    9383                        ],
    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                         ],
    10584                ];
    10685        }
    10786
    class Tests_API_Responses extends PHPUnit_Framework_TestCase { 
    125104        }
    126105
    127106        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 = [
    138109                        [
    139110                                [ 'php_version' => RECOMMENDED_PHP ],
    140                                 [ 'status' => 'ok' ]
    141                         ],
    142                         [
    143                                 [ 'php_version' => RECOMMENDED_PHP + 0.1 ],
    144                                 [ 'status' => 'ok' ]
     111                                [ 'recommended_version' => RECOMMENDED_PHP ]
    145112                        ],
    146113                        [
    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 ]
    157116                        ],
    158117                ];
     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;
    159140        }
    160141
    161142        /**