installed plugin WPScan version 1.15.1

This commit is contained in:
2021-05-13 11:27:50 +00:00
committed by Gitium
parent 2b403ab680
commit e0e2392c3c
193 changed files with 30878 additions and 0 deletions

View File

@ -0,0 +1,145 @@
<?php
use Action_Scheduler\Migration\ActionMigrator;
use Action_Scheduler\Migration\LogMigrator;
/**
* Class ActionMigrator_Test
* @group migration
*/
class ActionMigrator_Test extends ActionScheduler_UnitTestCase {
public function setUp() {
parent::setUp();
if ( ! taxonomy_exists( ActionScheduler_wpPostStore::GROUP_TAXONOMY ) ) {
// register the post type and taxonomy necessary for the store to work
$store = new ActionScheduler_wpPostStore();
$store->init();
}
}
public function test_migrate_from_wpPost_to_db() {
$source = new ActionScheduler_wpPostStore();
$destination = new ActionScheduler_DBStore();
$migrator = new ActionMigrator( $source, $destination, $this->get_log_migrator() );
$time = as_get_datetime_object();
$schedule = new ActionScheduler_SimpleSchedule( $time );
$action = new ActionScheduler_Action( 'my_hook', [], $schedule, 'my_group' );
$action_id = $source->save_action( $action );
$new_id = $migrator->migrate( $action_id );
// ensure we get the same record out of the new store as we stored in the old
$retrieved = $destination->fetch_action( $new_id );
$this->assertEquals( $action->get_hook(), $retrieved->get_hook() );
$this->assertEqualSets( $action->get_args(), $retrieved->get_args() );
$this->assertEquals( $action->get_schedule()->get_date()->format( 'U' ), $retrieved->get_schedule()->get_date()->format( 'U' ) );
$this->assertEquals( $action->get_group(), $retrieved->get_group() );
$this->assertEquals( \ActionScheduler_Store::STATUS_PENDING, $destination->get_status( $new_id ) );
// ensure that the record in the old store does not exist
$old_action = $source->fetch_action( $action_id );
$this->assertInstanceOf( 'ActionScheduler_NullAction', $old_action );
}
public function test_does_not_migrate_missing_action_from_wpPost_to_db() {
$source = new ActionScheduler_wpPostStore();
$destination = new ActionScheduler_DBStore();
$migrator = new ActionMigrator( $source, $destination, $this->get_log_migrator() );
$action_id = rand( 100, 100000 );
$new_id = $migrator->migrate( $action_id );
$this->assertEquals( 0, $new_id );
// ensure we get the same record out of the new store as we stored in the old
$retrieved = $destination->fetch_action( $new_id );
$this->assertInstanceOf( 'ActionScheduler_NullAction', $retrieved );
}
public function test_migrate_completed_action_from_wpPost_to_db() {
$source = new ActionScheduler_wpPostStore();
$destination = new ActionScheduler_DBStore();
$migrator = new ActionMigrator( $source, $destination, $this->get_log_migrator() );
$time = as_get_datetime_object();
$schedule = new ActionScheduler_SimpleSchedule( $time );
$action = new ActionScheduler_Action( 'my_hook', [], $schedule, 'my_group' );
$action_id = $source->save_action( $action );
$source->mark_complete( $action_id );
$new_id = $migrator->migrate( $action_id );
// ensure we get the same record out of the new store as we stored in the old
$retrieved = $destination->fetch_action( $new_id );
$this->assertEquals( $action->get_hook(), $retrieved->get_hook() );
$this->assertEqualSets( $action->get_args(), $retrieved->get_args() );
$this->assertEquals( $action->get_schedule()->get_date()->format( 'U' ), $retrieved->get_schedule()->get_date()->format( 'U' ) );
$this->assertEquals( $action->get_group(), $retrieved->get_group() );
$this->assertTrue( $retrieved->is_finished() );
$this->assertEquals( \ActionScheduler_Store::STATUS_COMPLETE, $destination->get_status( $new_id ) );
// ensure that the record in the old store does not exist
$old_action = $source->fetch_action( $action_id );
$this->assertInstanceOf( 'ActionScheduler_NullAction', $old_action );
}
public function test_migrate_failed_action_from_wpPost_to_db() {
$source = new ActionScheduler_wpPostStore();
$destination = new ActionScheduler_DBStore();
$migrator = new ActionMigrator( $source, $destination, $this->get_log_migrator() );
$time = as_get_datetime_object();
$schedule = new ActionScheduler_SimpleSchedule( $time );
$action = new ActionScheduler_Action( 'my_hook', [], $schedule, 'my_group' );
$action_id = $source->save_action( $action );
$source->mark_failure( $action_id );
$new_id = $migrator->migrate( $action_id );
// ensure we get the same record out of the new store as we stored in the old
$retrieved = $destination->fetch_action( $new_id );
$this->assertEquals( $action->get_hook(), $retrieved->get_hook() );
$this->assertEqualSets( $action->get_args(), $retrieved->get_args() );
$this->assertEquals( $action->get_schedule()->get_date()->format( 'U' ), $retrieved->get_schedule()->get_date()->format( 'U' ) );
$this->assertEquals( $action->get_group(), $retrieved->get_group() );
$this->assertTrue( $retrieved->is_finished() );
$this->assertEquals( \ActionScheduler_Store::STATUS_FAILED, $destination->get_status( $new_id ) );
// ensure that the record in the old store does not exist
$old_action = $source->fetch_action( $action_id );
$this->assertInstanceOf( 'ActionScheduler_NullAction', $old_action );
}
public function test_migrate_canceled_action_from_wpPost_to_db() {
$source = new ActionScheduler_wpPostStore();
$destination = new ActionScheduler_DBStore();
$migrator = new ActionMigrator( $source, $destination, $this->get_log_migrator() );
$time = as_get_datetime_object();
$schedule = new ActionScheduler_SimpleSchedule( $time );
$action = new ActionScheduler_Action( 'my_hook', [], $schedule, 'my_group' );
$action_id = $source->save_action( $action );
$source->cancel_action( $action_id );
$new_id = $migrator->migrate( $action_id );
// ensure we get the same record out of the new store as we stored in the old
$retrieved = $destination->fetch_action( $new_id );
$this->assertEquals( $action->get_hook(), $retrieved->get_hook() );
$this->assertEqualSets( $action->get_args(), $retrieved->get_args() );
$this->assertEquals( $action->get_schedule()->get_date()->format( 'U' ), $retrieved->get_schedule()->get_date()->format( 'U' ) );
$this->assertEquals( $action->get_group(), $retrieved->get_group() );
$this->assertTrue( $retrieved->is_finished() );
$this->assertEquals( \ActionScheduler_Store::STATUS_CANCELED, $destination->get_status( $new_id ) );
// ensure that the record in the old store does not exist
$old_action = $source->fetch_action( $action_id );
$this->assertInstanceOf( 'ActionScheduler_NullAction', $old_action );
}
private function get_log_migrator() {
return new LogMigrator( \ActionScheduler::logger(), new ActionScheduler_DBLogger() );
}
}

View File

@ -0,0 +1,76 @@
<?php
use Action_Scheduler\Migration\BatchFetcher;
use ActionScheduler_wpPostStore as PostStore;
/**
* Class BatchFetcher_Test
* @group migration
*/
class BatchFetcher_Test extends ActionScheduler_UnitTestCase {
public function setUp() {
parent::setUp();
if ( ! taxonomy_exists( PostStore::GROUP_TAXONOMY ) ) {
// register the post type and taxonomy necessary for the store to work
$store = new PostStore();
$store->init();
}
}
public function test_nothing_to_migrate() {
$store = new PostStore();
$batch_fetcher = new BatchFetcher( $store );
$actions = $batch_fetcher->fetch();
$this->assertEmpty( $actions );
}
public function test_get_due_before_future() {
$store = new PostStore();
$due = [];
$future = [];
for ( $i = 0; $i < 5; $i ++ ) {
$time = as_get_datetime_object( $i + 1 . ' minutes' );
$schedule = new ActionScheduler_SimpleSchedule( $time );
$action = new ActionScheduler_Action( 'my_hook', [], $schedule );
$future[] = $store->save_action( $action );
$time = as_get_datetime_object( $i + 1 . ' minutes ago' );
$schedule = new ActionScheduler_SimpleSchedule( $time );
$action = new ActionScheduler_Action( 'my_hook', [], $schedule );
$due[] = $store->save_action( $action );
}
$batch_fetcher = new BatchFetcher( $store );
$actions = $batch_fetcher->fetch();
$this->assertEqualSets( $due, $actions );
}
public function test_get_future_before_complete() {
$store = new PostStore();
$future = [];
$complete = [];
for ( $i = 0; $i < 5; $i ++ ) {
$time = as_get_datetime_object( $i + 1 . ' minutes' );
$schedule = new ActionScheduler_SimpleSchedule( $time );
$action = new ActionScheduler_Action( 'my_hook', [], $schedule );
$future[] = $store->save_action( $action );
$time = as_get_datetime_object( $i + 1 . ' minutes ago' );
$schedule = new ActionScheduler_SimpleSchedule( $time );
$action = new ActionScheduler_FinishedAction( 'my_hook', [], $schedule );
$complete[] = $store->save_action( $action );
}
$batch_fetcher = new BatchFetcher( $store );
$actions = $batch_fetcher->fetch();
$this->assertEqualSets( $future, $actions );
}
}

View File

@ -0,0 +1,33 @@
<?php
use Action_Scheduler\Migration\Config;
/**
* Class Config_Test
* @group migration
*/
class Config_Test extends ActionScheduler_UnitTestCase {
public function test_source_store_required() {
$config = new Config();
$this->expectException( \RuntimeException::class );
$config->get_source_store();
}
public function test_source_logger_required() {
$config = new Config();
$this->expectException( \RuntimeException::class );
$config->get_source_logger();
}
public function test_destination_store_required() {
$config = new Config();
$this->expectException( \RuntimeException::class );
$config->get_destination_store();
}
public function test_destination_logger_required() {
$config = new Config();
$this->expectException( \RuntimeException::class );
$config->get_destination_logger();
}
}

View File

@ -0,0 +1,44 @@
<?php
use Action_Scheduler\Migration\LogMigrator;
/**
* Class LogMigrator_Test
* @group migration
*/
class LogMigrator_Test extends ActionScheduler_UnitTestCase {
function setUp() {
parent::setUp();
if ( ! taxonomy_exists( ActionScheduler_wpPostStore::GROUP_TAXONOMY ) ) {
// register the post type and taxonomy necessary for the store to work
$store = new ActionScheduler_wpPostStore();
$store->init();
}
}
public function test_migrate_from_wpComment_to_db() {
$source = new ActionScheduler_wpCommentLogger();
$destination = new ActionScheduler_DBLogger();
$migrator = new LogMigrator( $source, $destination );
$source_action_id = rand( 10, 10000 );
$destination_action_id = rand( 10, 10000 );
$logs = [];
for ( $i = 0 ; $i < 3 ; $i++ ) {
for ( $j = 0 ; $j < 5 ; $j++ ) {
$logs[ $i ][ $j ] = md5(rand());
if ( $i == 1 ) {
$source->log( $source_action_id, $logs[ $i ][ $j ] );
}
}
}
$migrator->migrate( $source_action_id, $destination_action_id );
$migrated = $destination->get_logs( $destination_action_id );
$this->assertEqualSets( $logs[ 1 ], array_map( function( $log ) { return $log->get_message(); }, $migrated ) );
// no API for deleting logs, so we leave them for manual cleanup later
$this->assertCount( 5, $source->get_logs( $source_action_id ) );
}
}

View File

@ -0,0 +1,92 @@
<?php
use Action_Scheduler\Migration\Config;
use Action_Scheduler\Migration\Runner;
use ActionScheduler_wpCommentLogger as CommentLogger;
use ActionScheduler_wpPostStore as PostStore;
/**
* Class Runner_Test
* @group migration
*/
class Runner_Test extends ActionScheduler_UnitTestCase {
public function setUp() {
parent::setUp();
if ( ! taxonomy_exists( PostStore::GROUP_TAXONOMY ) ) {
// register the post type and taxonomy necessary for the store to work
$store = new PostStore();
$store->init();
}
}
public function test_migrate_batches() {
$source_store = new PostStore();
$destination_store = new ActionScheduler_DBStore();
$source_logger = new CommentLogger();
$destination_logger = new ActionScheduler_DBLogger();
$config = new Config();
$config->set_source_store( $source_store );
$config->set_source_logger( $source_logger );
$config->set_destination_store( $destination_store );
$config->set_destination_logger( $destination_logger );
$runner = new Runner( $config );
$due = [];
$future = [];
$complete = [];
for ( $i = 0; $i < 5; $i ++ ) {
$time = as_get_datetime_object( $i + 1 . ' minutes' );
$schedule = new ActionScheduler_SimpleSchedule( $time );
$action = new ActionScheduler_Action( 'my_hook', [], $schedule );
$future[] = $source_store->save_action( $action );
$time = as_get_datetime_object( $i + 1 . ' minutes ago' );
$schedule = new ActionScheduler_SimpleSchedule( $time );
$action = new ActionScheduler_Action( 'my_hook', [], $schedule );
$due[] = $source_store->save_action( $action );
$time = as_get_datetime_object( $i + 1 . ' minutes ago' );
$schedule = new ActionScheduler_SimpleSchedule( $time );
$action = new ActionScheduler_FinishedAction( 'my_hook', [], $schedule );
$complete[] = $source_store->save_action( $action );
}
$created = $source_store->query_actions( [ 'per_page' => 0 ] );
$this->assertCount( 15, $created );
$runner->run( 10 );
// due actions should migrate in the first batch
$migrated = $destination_store->query_actions( [ 'per_page' => 0, 'hook' => 'my_hook' ] );
$this->assertCount( 5, $migrated );
$remaining = $source_store->query_actions( [ 'per_page' => 0, 'hook' => 'my_hook' ] );
$this->assertCount( 10, $remaining );
$runner->run( 10 );
// pending actions should migrate in the second batch
$migrated = $destination_store->query_actions( [ 'per_page' => 0, 'hook' => 'my_hook' ] );
$this->assertCount( 10, $migrated );
$remaining = $source_store->query_actions( [ 'per_page' => 0, 'hook' => 'my_hook' ] );
$this->assertCount( 5, $remaining );
$runner->run( 10 );
// completed actions should migrate in the third batch
$migrated = $destination_store->query_actions( [ 'per_page' => 0, 'hook' => 'my_hook' ] );
$this->assertCount( 15, $migrated );
$remaining = $source_store->query_actions( [ 'per_page' => 0, 'hook' => 'my_hook' ] );
$this->assertCount( 0, $remaining );
}
}

View File

@ -0,0 +1,130 @@
<?php
use Action_Scheduler\Migration\Scheduler;
use ActionScheduler_wpPostStore as PostStore;
/**
* Class Scheduler_Test
* @group migration
*/
class Scheduler_Test extends ActionScheduler_UnitTestCase {
public function setUp() {
parent::setUp();
if ( ! taxonomy_exists( PostStore::GROUP_TAXONOMY ) ) {
// register the post type and taxonomy necessary for the store to work
$store = new PostStore();
$store->init();
}
}
public function test_migration_is_complete() {
ActionScheduler_DataController::mark_migration_complete();
$this->assertTrue( ActionScheduler_DataController::is_migration_complete() );
}
public function test_migration_is_not_complete() {
$this->assertFalse( ActionScheduler_DataController::is_migration_complete() );
update_option( ActionScheduler_DataController::STATUS_FLAG, 'something_random' );
$this->assertFalse( ActionScheduler_DataController::is_migration_complete() );
}
public function test_migration_is_scheduled() {
// Clear the any existing migration hooks that have already been setup.
as_unschedule_all_actions( Scheduler::HOOK );
$scheduler = new Scheduler();
$this->assertFalse(
$scheduler->is_migration_scheduled(),
'Migration is not automatically scheduled when a new ' . Scheduler::class . ' instance is created.'
);
$scheduler->schedule_migration();
$this->assertTrue(
$scheduler->is_migration_scheduled(),
'Migration is scheduled only after schedule_migration() has been called.'
);
}
public function test_scheduler_runs_migration() {
$source_store = new PostStore();
$destination_store = new ActionScheduler_DBStore();
$return_5 = function () {
return 5;
};
add_filter( 'action_scheduler/migration_batch_size', $return_5 );
// Make sure successive migration actions are delayed so all actions aren't migrated at once on separate hooks
$return_60 = function () {
return 60;
};
add_filter( 'action_scheduler/migration_interval', $return_60 );
for ( $i = 0; $i < 10; $i ++ ) {
$time = as_get_datetime_object( $i + 1 . ' minutes' );
$schedule = new ActionScheduler_SimpleSchedule( $time );
$action = new ActionScheduler_Action( 'my_hook', [], $schedule );
$future[] = $source_store->save_action( $action );
$time = as_get_datetime_object( $i + 1 . ' minutes ago' );
$schedule = new ActionScheduler_SimpleSchedule( $time );
$action = new ActionScheduler_Action( 'my_hook', [], $schedule );
$due[] = $source_store->save_action( $action );
}
$this->assertCount( 20, $source_store->query_actions( [ 'per_page' => 0 ] ) );
$scheduler = new Scheduler();
$scheduler->unschedule_migration();
$scheduler->schedule_migration( time() - 1 );
$queue_runner = ActionScheduler_Mocker::get_queue_runner( $destination_store );
$queue_runner->run();
// 5 actions should have moved from the source store when the queue runner triggered the migration action
$this->assertCount( 15, $source_store->query_actions( [ 'per_page' => 0, 'hook' => 'my_hook' ] ) );
remove_filter( 'action_scheduler/migration_batch_size', $return_5 );
remove_filter( 'action_scheduler/migration_interval', $return_60 );
}
public function test_scheduler_marks_itself_complete() {
$source_store = new PostStore();
$destination_store = new ActionScheduler_DBStore();
for ( $i = 0; $i < 5; $i ++ ) {
$time = as_get_datetime_object( $i + 1 . ' minutes ago' );
$schedule = new ActionScheduler_SimpleSchedule( $time );
$action = new ActionScheduler_Action( 'my_hook', [], $schedule );
$due[] = $source_store->save_action( $action );
}
$this->assertCount( 5, $source_store->query_actions( [ 'per_page' => 0 ] ) );
$scheduler = new Scheduler();
$scheduler->unschedule_migration();
$scheduler->schedule_migration( time() - 1 );
$queue_runner = ActionScheduler_Mocker::get_queue_runner( $destination_store );
$queue_runner->run();
// All actions should have moved from the source store when the queue runner triggered the migration action
$this->assertCount( 0, $source_store->query_actions( [ 'per_page' => 0, 'hook' => 'my_hook' ] ) );
// schedule another so we can get it to run immediately
$scheduler->unschedule_migration();
$scheduler->schedule_migration( time() - 1 );
// run again so it knows that there's nothing left to process
$queue_runner->run();
$scheduler->unhook();
// ensure the flag is set marking migration as complete
$this->assertTrue( ActionScheduler_DataController::is_migration_complete() );
// ensure that another instance has not been scheduled
$this->assertFalse( $scheduler->is_migration_scheduled() );
}
}