Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into bugs-5879
Browse files Browse the repository at this point in the history
  • Loading branch information
John Spellman committed May 19, 2023
2 parents 4780024 + e10a8a8 commit de5b6b3
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 14 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ jobs:
validate:
name: "Run validation test suite"
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ["7.2", "7.3", "7.4"]

env:
# GITHUB_CONTEXT: ${{ toJson(github) }}
PANTHEON_WPVULNDB_API_TOKEN: ${{ secrets.PANTHEON_WPVULNDB_API_TOKEN }}
Expand Down Expand Up @@ -44,7 +42,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
php-version: 7.4
ini-values: post_max_size=256M, max_execution_time=120

- name: Get Composer Cache Directory
Expand Down
6 changes: 3 additions & 3 deletions features/general.feature
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Feature: General tests of WP Launch Check

Scenario: WordPress has a new minor version but no new major version
Given a WP install
And I run `wp core download --version=6.0 --force`
And I run `wp core download --version=6.1 --force`
And I run `wp theme activate twentytwentytwo`

When I run `wp launchcheck general`
Expand All @@ -71,8 +71,8 @@ Feature: General tests of WP Launch Check

Scenario: WordPress has a new major version but no new minor version
Given a WP install
And I run `wp core download --version=5.9.5 --force`
And I run `wp theme activate twentytwentytwo`
And I run `wp core download --version=5.6.10 --force`
And I run `wp theme activate twentytwenty`

When I run `wp launchcheck general`
Then STDOUT should contain:
Expand Down
1 change: 1 addition & 0 deletions features/objectcache.feature
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Feature: Suggest object cache to be enabled

Scenario: WP Redis is present as the enabled object-cache
Given a WP install
# TODO Remove the version flag.
And I run `wp plugin install wp-redis --activate`
And I run `wp redis enable`

Expand Down
19 changes: 19 additions & 0 deletions php/commands/launchcheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function all($args, $assoc_args) {

// wp-config is going to be loaded again, and we need to avoid notices
@WP_CLI::get_runner()->load_wordpress();
WP_CLI::add_hook( 'before_run_command', [ $this, 'maybe_switch_to_blog' ] );

// WordPress is now loaded, so other checks can run
$searcher = new \Pantheon\Filesearcher( WP_CONTENT_DIR );
Expand All @@ -47,6 +48,24 @@ public function all($args, $assoc_args) {
\Pantheon\Messenger::emit($format);
}

/**
* Switch to BLOG_ID_CURRENT_SITE if we're on a multisite.
*
* This forces the launchcheck command to use the main site's info for all
* the checks.
*/
public function maybe_switch_to_blog() {
// Check for multisite. If we're on multisite, switch to the main site.
if ( is_multisite() ) {
if ( defined( 'BLOG_ID_CURRENT_SITE' ) ) {
switch_to_blog( BLOG_ID_CURRENT_SITE );
} else {
switch_to_blog( 1 );
}
\WP_CLI::log( sprintf( esc_html__( 'Multisite detected. Running checks on %s site.' ), get_bloginfo( 'name' ) ) );
}
}

/**
* Checks for a properly-configured wp-config
*
Expand Down
4 changes: 4 additions & 0 deletions php/pantheon/checks/insecure.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public function run($file) {
if ( $matches ) {
$note = '';
foreach($matches as $match) {
// Don't flag if the file in question is inside wp-redis.
if ( false !== strpos( $file->getPath(), 'wp-redis' ) ) {
continue;
}
$linenum = substr_count(substr($file_contents, 0, $match[1]), "\n") + 1;
$this->alerts[] = array( 'class'=>'warning', 'data'=> array( $file->getRelativePathname(), $linenum, substr($match[0],0,50)));
}
Expand Down
3 changes: 2 additions & 1 deletion php/pantheon/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use \Symfony\Component\Filesystem\Filesystem;
use \Symfony\Component\Finder\Finder;
use \Pantheon\Utils as Pantheon;

class Utils {
static $fs;
Expand Down Expand Up @@ -59,7 +60,7 @@ public static function sanitize_data($data, $sanitizer_function = 'htmlspecialch
array_map('self::sanitize_data', array_values((array)$data))
);
return is_object( $data ) ? (object)$sanitized_data : $sanitized_data;
} elseif ( is_integer( $data ) ) {
} elseif ( is_integer($data) ) {
return (string)$data;
} elseif ( is_string( $data ) ) {
if ( ! empty( $data ) ) {
Expand Down
8 changes: 2 additions & 6 deletions php/pantheon/views/table.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
<?php

use Pantheon\Utils; ?>

<table class='table table-condensed'>
<thead>
<tr>
<?php if(isset($headers)): ?>
<?php foreach ($headers as $header): ?>
<th><?php echo Utils::sanitize_data( $header ); ?></th>
<th><?php echo $header; ?></th>
<?php endforeach; ?>
<?php endif; ?>
</tr>
Expand All @@ -16,7 +12,7 @@
<?php foreach($rows as $row): ?>
<tr class="<?php if(isset($row['class'])) { echo $row['class']; } ?>">
<?php foreach($row['data'] as $values): ?>
<td><?php echo Utils::sanitize_data( $values ); ?></td>
<td><?php echo $values; ?></td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
Expand Down

0 comments on commit de5b6b3

Please sign in to comment.