From e25e8af1e47d8e7ff0952569e5b4c081d787c2e2 Mon Sep 17 00:00:00 2001 From: Nate Weller Date: Sat, 8 Mar 2025 14:06:27 -0700 Subject: [PATCH] testing --- .../waf/src/class-rest-controller.php | 31 ++++++++++--------- .../protect/tests/e2e/specs/start.test.js | 18 ++++++----- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/projects/packages/waf/src/class-rest-controller.php b/projects/packages/waf/src/class-rest-controller.php index 9ddd542fec999..d5c759686e5d7 100644 --- a/projects/packages/waf/src/class-rest-controller.php +++ b/projects/packages/waf/src/class-rest-controller.php @@ -110,13 +110,6 @@ public static function waf() { */ public static function update_waf( $request ) { - return rest_ensure_response( - array( - 'success' => true, - 'message' => 'Test', - ) - ); - // Automatic Rules Enabled if ( isset( $request[ Waf_Rules_Manager::AUTOMATIC_RULES_ENABLED_OPTION_NAME ] ) ) { update_option( Waf_Rules_Manager::AUTOMATIC_RULES_ENABLED_OPTION_NAME, $request->get_param( Waf_Rules_Manager::AUTOMATIC_RULES_ENABLED_OPTION_NAME ) ? '1' : '' ); @@ -189,16 +182,24 @@ public static function update_waf( $request ) { } } - // Only attempt to update the WAF if the module is supported - if ( Waf_Runner::is_supported_environment() ) { - try { - Waf_Runner::update_waf(); - } catch ( Waf_Exception $e ) { - return $e->get_wp_error(); + try { + // Only attempt to update the WAF if the module is supported + if ( Waf_Runner::is_supported_environment() ) { + try { + Waf_Runner::update_waf(); + } catch ( Waf_Exception $e ) { + return $e->get_wp_error(); + } } - } - return self::waf(); + return self::waf(); + } catch ( Waf_Exception $e ) { + return new WP_Error( + 'test_waf_failed', + $e->getMessage(), + array( 'status' => 500 ) + ); + } } /** diff --git a/projects/plugins/protect/tests/e2e/specs/start.test.js b/projects/plugins/protect/tests/e2e/specs/start.test.js index 29d7bdc317e9e..40cf9b56a40ad 100644 --- a/projects/plugins/protect/tests/e2e/specs/start.test.js +++ b/projects/plugins/protect/tests/e2e/specs/start.test.js @@ -1,3 +1,4 @@ +import { Plans } from '_jetpack-e2e-commons/env/index.js'; import { prerequisitesBuilder } from '_jetpack-e2e-commons/env/prerequisites.js'; import { expect, test } from '_jetpack-e2e-commons/fixtures/base-test.js'; import logger from '_jetpack-e2e-commons/logger.js'; @@ -40,10 +41,13 @@ test.describe( 'Jetpack Protect plugin - Post-Connection', () => { test.beforeEach( async ( { page } ) => { await prerequisitesBuilder( page ) .withCleanEnv() - .withActivePlugins( [ 'protect' ] ) - .withInactivePlugins( [ 'e2e-waf-data-interceptor' ] ) + .withActivePlugins( [ 'protect', 'jetpack' ] ) + .withActiveModules( [ 'waf', 'protect' ] ) + // .withInactivePlugins( [ 'e2e-waf-data-interceptor' ] ) .withLoggedIn( true ) .withConnection( true ) + .withWpComLoggedIn( true ) + .withPlan( Plans.Complete ) .build(); } ); @@ -53,11 +57,11 @@ test.describe( 'Jetpack Protect plugin - Post-Connection', () => { await expect( page.getByText( 'Firewall is on' ) ).toBeVisible(); } ); - await test.step( 'Test the automatic firewall setting is disabled for free plans', async () => { - const automaticFirewallToggle = page.locator( '#inspector-toggle-control-0' ); - await expect( automaticFirewallToggle ).toBeDisabled(); - await expect( automaticFirewallToggle ).not.toBeChecked(); - } ); + // await test.step( 'Test the automatic firewall setting is disabled for free plans', async () => { + // const automaticFirewallToggle = page.locator( '#inspector-toggle-control-0' ); + // await expect( automaticFirewallToggle ).toBeDisabled(); + // await expect( automaticFirewallToggle ).not.toBeChecked(); + // } ); await test.step( 'Test the brute force protection setting', async () => { const bruteForceToggle = page.locator( '#inspector-toggle-control-1' );