Making WordPress.org

Changeset 6806


Ignore:
Timestamp:
02/28/2018 03:27:07 AM (7 years ago)
Author:
dd32
Message:

API: Serve Happy: Update the API to return the final selection of fields.

Props flixos90.
Fixes #3474.

Location:
sites/trunk/api.wordpress.org/public_html/core/serve-happy/1.0
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/api.wordpress.org/public_html/core/serve-happy/1.0/config.php

    r6728 r6806  
    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' );
     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' );
  • sites/trunk/api.wordpress.org/public_html/core/serve-happy/1.0/include.php

    r6728 r6806  
    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
     
    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}
  • sites/trunk/api.wordpress.org/public_html/core/serve-happy/1.0/tests/tests.php

    r6728 r6806  
    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    }
     
    5545
    5646        // Assert that it's a successful response, and not an error.
    57         $this->assertArrayHasKey( 'status', $output );
     47        $this->assertArrayHasKey( 'recommended_version', $output );
     48        $this->assertArrayHasKey( 'is_supported', $output );
     49        $this->assertArrayHasKey( 'is_secure', $output );
     50        $this->assertArrayHasKey( 'is_acceptable', $output );
    5851    }
    5952
     
    9285                ]
    9386            ],
    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             ],
    10587        ];
    10688    }
     
    126108
    127109    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:
     110        // Test recommended PHP version is always returned.
     111        $data = [
    138112            [
    139113                [ 'php_version' => RECOMMENDED_PHP ],
    140                 [ 'status' => 'ok' ]
    141             ],
    142             [
    143                 [ 'php_version' => RECOMMENDED_PHP + 0.1 ],
    144                 [ 'status' => 'ok' ]
    145             ],
    146             [
    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' ]
    157             ],
    158         ];
     114                [ 'recommended_version' => RECOMMENDED_PHP ]
     115            ],
     116            [
     117                [ 'php_version' => '5.2' ],
     118                [ 'recommended_version' => RECOMMENDED_PHP ]
     119            ],
     120        ];
     121
     122        // Test individual PHP versions.
     123        $flags = [
     124            'is_supported'  => 'SUPPORTED_PHP',
     125            'is_secure'     => 'SECURE_PHP',
     126            'is_acceptable' => 'ACCEPTABLE_PHP'
     127        ];
     128        foreach ( $flags as $flag => $constant_name ) {
     129            $data[] = [
     130                [ 'php_version' => constant( $constant_name ) ],
     131                [ $flag => true ]
     132            ];
     133            $data[] = [
     134                [ 'php_version' => constant( $constant_name ) + 0.1 ],
     135                [ $flag => true ]
     136            ];
     137            $data[] = [
     138                [ 'php_version' => constant( $constant_name ) - 0.1 ],
     139                [ $flag => false ]
     140            ];
     141        }
     142        return $data;
    159143    }
    160144
Note: See TracChangeset for help on using the changeset viewer.