Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Travis Builds #40

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ cache:
- vendor
- $HOME/phpunit-bin

services:
- mysql
- memcached

addons:
apt:
packages:
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
},
"require-dev": {
"brainmaestro/composer-git-hooks": "^2.6.0",
"dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
"firebase/php-jwt": "^5.0",
"phpcompatibility/phpcompatibility-wp": "*",
"php-coveralls/php-coveralls": "^2.1",
"php-coveralls/php-coveralls": "^2.4.2",
"slowprog/composer-copy-file": "0.2.1",
"wp-coding-standards/wpcs": "*",
"xwp/wp-dev-lib": "^1.1.1"
"xwp/wp-dev-lib": "^1.6.5"
},
"scripts": {
"phpcs": [
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
convertWarningsToExceptions="true"
>
<testsuites>
<testsuite>
<testsuite name="jwt-auth">
<directory prefix="class-test-" suffix=".php">./tests/</directory>
<directory prefix="test-" suffix=".php">./tests/</directory>
</testsuite>
Expand Down
4 changes: 2 additions & 2 deletions wp-admin/includes/class-wp-key-pair-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ protected function column_default( $item, $column_name ) {
if ( empty( $item['created'] ) ) {
return '&mdash;';
}
return date( 'F j, Y g:i a', $item['created'] );
return gmdate( 'F j, Y g:i a', $item['created'] );
case 'last_used':
if ( empty( $item['last_used'] ) ) {
return '&mdash;';
}
return date( 'F j, Y g:i a', $item['last_used'] );
return gmdate( 'F j, Y g:i a', $item['last_used'] );
case 'last_ip':
if ( empty( $item['last_ip'] ) ) {
return '&mdash;';
Expand Down
25 changes: 14 additions & 11 deletions wp-includes/rest-api/auth/class-wp-rest-key-pair.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ public static function get_rest_uri() {
*/
public function register_routes() {
$args = array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => array( $this, 'generate_key_pair' ),
'args' => array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => array( $this, 'generate_key_pair' ),
'permission_callback' => '__return_true',
'args' => array(
'name' => array(
'description' => esc_html__( 'The name of the key-pair.', 'jwt-auth' ),
'type' => 'string',
Expand All @@ -110,14 +111,15 @@ public function register_routes() {
'validate_callback' => 'rest_validate_request_arg',
),
),
'schema' => array( $this, 'get_item_schema' ),
'schema' => array( $this, 'get_item_schema' ),
);
register_rest_route( self::_NAMESPACE_, '/' . self::_REST_BASE_ . '/(?P<user_id>[\d]+)', $args );

$args = array(
'methods' => WP_REST_Server::DELETABLE,
'callback' => array( $this, 'delete_all_key_pairs' ),
'args' => array(
'methods' => WP_REST_Server::DELETABLE,
'callback' => array( $this, 'delete_all_key_pairs' ),
'permission_callback' => '__return_true',
'args' => array(
'user_id' => array(
'description' => esc_html__( 'The ID of the user.', 'jwt-auth' ),
'type' => 'integer',
Expand All @@ -130,9 +132,10 @@ public function register_routes() {
register_rest_route( self::_NAMESPACE_, '/' . self::_REST_BASE_ . '/(?P<user_id>[\d]+)/revoke-all', $args );

$args = array(
'methods' => WP_REST_Server::DELETABLE,
'callback' => array( $this, 'delete_key_pair' ),
'args' => array(
'methods' => WP_REST_Server::DELETABLE,
'callback' => array( $this, 'delete_key_pair' ),
'permission_callback' => '__return_true',
'args' => array(
'user_id' => array(
'description' => esc_html__( 'The ID of the user.', 'jwt-auth' ),
'type' => 'integer',
Expand Down Expand Up @@ -514,7 +517,7 @@ public function generate_key_pair( WP_REST_Request $request ) {
$keypairs[] = $new_item;
$this->set_user_key_pairs( $user_id, $keypairs );

$new_item['created'] = date( 'F j, Y g:i a', $new_item['created'] );
$new_item['created'] = gmdate( 'F j, Y g:i a', $new_item['created'] );
$new_item['last_used'] = '—';
$new_item['last_ip'] = '—';

Expand Down
22 changes: 12 additions & 10 deletions wp-includes/rest-api/auth/class-wp-rest-token.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,17 @@ public static function get_rest_uri() {
*/
public function register_routes() {
$args = array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'validate' ),
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'validate' ),
'permission_callback' => '__return_true',
);
register_rest_route( self::_NAMESPACE_, '/' . self::_REST_BASE_ . '/validate', $args );

$args = array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => array( $this, 'generate_token' ),
'args' => array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => array( $this, 'generate_token' ),
'permission_callback' => '__return_true',
'args' => array(
'api_key' => array(
'description' => __( 'The API key of the user; requires also setting the api_secret.', 'jwt-auth' ),
'type' => 'string',
Expand All @@ -120,7 +122,7 @@ public function register_routes() {
'validate_callback' => 'rest_validate_request_arg',
),
),
'schema' => array( $this, 'get_item_schema' ),
'schema' => array( $this, 'get_item_schema' ),
);
register_rest_route( self::_NAMESPACE_, '/' . self::_REST_BASE_, $args );
}
Expand Down Expand Up @@ -380,8 +382,8 @@ public function authenticate_refresh_token( $user, WP_REST_Request $request ) {
*/
public function require_token() {
$require_token = true;
$request_uri = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( $_SERVER['REQUEST_URI'] ) : false;
$request_method = isset( $_SERVER['REQUEST_METHOD'] ) ? sanitize_text_field( $_SERVER['REQUEST_METHOD'] ) : false;
$request_uri = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : false;
$request_method = isset( $_SERVER['REQUEST_METHOD'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_METHOD'] ) ) : false;

// User is already authenticated.
$user = wp_get_current_user();
Expand Down Expand Up @@ -775,11 +777,11 @@ public function validate_token() {
public function get_auth_header() {

// Get HTTP Authorization Header.
$header = isset( $_SERVER['HTTP_AUTHORIZATION'] ) ? sanitize_text_field( $_SERVER['HTTP_AUTHORIZATION'] ) : false;
$header = isset( $_SERVER['HTTP_AUTHORIZATION'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_AUTHORIZATION'] ) ) : false;

// Check for alternative header.
if ( ! $header && isset( $_SERVER['REDIRECT_HTTP_AUTHORIZATION'] ) ) {
$header = sanitize_text_field( $_SERVER['REDIRECT_HTTP_AUTHORIZATION'] );
$header = sanitize_text_field( wp_unslash( $_SERVER['REDIRECT_HTTP_AUTHORIZATION'] ) );
}

// The HTTP Authorization Header is missing, return an error.
Expand Down