Skip to content

Commit 4987843

Browse files
committed
testing
1 parent 98b1a26 commit 4987843

File tree

4 files changed

+73
-62
lines changed

4 files changed

+73
-62
lines changed

projects/packages/waf/src/class-rest-controller.php

+20-15
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,6 @@ public static function waf() {
110110
*/
111111
public static function update_waf( $request ) {
112112

113-
return rest_ensure_response(
114-
array(
115-
'success' => true,
116-
'message' => 'Test',
117-
)
118-
);
119-
120113
// Automatic Rules Enabled
121114
if ( isset( $request[ Waf_Rules_Manager::AUTOMATIC_RULES_ENABLED_OPTION_NAME ] ) ) {
122115
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,28 @@ public static function update_waf( $request ) {
189182
}
190183
}
191184

192-
// Only attempt to update the WAF if the module is supported
193-
if ( Waf_Runner::is_supported_environment() ) {
194-
try {
195-
Waf_Runner::update_waf();
196-
} catch ( Waf_Exception $e ) {
197-
return $e->get_wp_error();
185+
try {
186+
// Only attempt to update the WAF if the module is supported
187+
if ( Waf_Runner::is_supported_environment() ) {
188+
try {
189+
Waf_Runner::update_waf();
190+
} catch ( Waf_Exception $e ) {
191+
return new WP_Error(
192+
'test_waf_failed_2',
193+
$e->getMessage(),
194+
array( 'status' => 500 )
195+
);
196+
}
198197
}
199-
}
200198

201-
return self::waf();
199+
return self::waf();
200+
} catch ( Waf_Exception $e ) {
201+
return new WP_Error(
202+
'test_waf_failed',
203+
$e->getMessage(),
204+
array( 'status' => 500 )
205+
);
206+
}
202207
}
203208

204209
/**

projects/plugins/protect/src/js/data/waf/use-waf-mutation.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,9 @@ export default function useWafMutation(): UseMutationResult<
6767
// Reset the WAF config to its previous state.
6868
queryClient.setQueryData( [ QUERY_WAF_KEY ], context.initialValue );
6969

70-
console.error( error );
71-
console.error( variables );
72-
console.error( context );
70+
console.log( error );
71+
console.log( error.data );
7372
throw error;
74-
75-
// showErrorNotice( getCustomErrorMessage( error ) );
7673
},
7774
} );
7875
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { expect } from '_jetpack-e2e-commons/fixtures/base-test.js';
2+
import logger from '_jetpack-e2e-commons/logger.js';
3+
// import { AuthorizePage } from '_jetpack-e2e-commons/pages/wpcom/index.js';
4+
5+
/**
6+
* Connect Jetpack Protect
7+
* @param {page} page - Playwright page object
8+
* @param {admin} admin - Playwright admin object
9+
* @param {boolean} premium - Whether to connect with a Premium plan
10+
*/
11+
export async function connect( page, admin, premium = false ) {
12+
logger.step( 'Connect Jetpack Protect' );
13+
14+
await admin.visitAdminPage( 'admin.php', 'page=jetpack-protect' );
15+
16+
logger.action( 'Checking for button "Get Jetpack Protect"' );
17+
const getJetpackProtectButton = page.getByRole( 'button', { name: 'Get Jetpack Protect' } );
18+
await expect( getJetpackProtectButton ).toBeVisible();
19+
await expect( getJetpackProtectButton ).toBeEnabled();
20+
21+
logger.action( 'Checking for button "Start for free"' );
22+
const startForFreeButton = page.getByRole( 'button', { name: 'Start for free' } );
23+
await expect( startForFreeButton ).toBeVisible();
24+
await expect( startForFreeButton ).toBeEnabled();
25+
26+
logger.action( 'Click the start for free button' );
27+
await startForFreeButton.click();
28+
29+
await expect(
30+
page.getByText( 'vulnerabilities found' ).or( page.getByText( 'ready soon' ) )
31+
).toBeVisible( {
32+
timeout: 30_000,
33+
} );
34+
35+
if ( premium ) {
36+
// todo add purchase steps
37+
}
38+
}

projects/plugins/protect/tests/e2e/specs/start.test.js

+13-42
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { prerequisitesBuilder } from '_jetpack-e2e-commons/env/prerequisites.js';
22
import { expect, test } from '_jetpack-e2e-commons/fixtures/base-test.js';
3-
import logger from '_jetpack-e2e-commons/logger.js';
3+
import { connect } from '../flows/connection';
44

55
test.describe( 'Jetpack Protect plugin - Pre-Connection', () => {
66
test.beforeEach( async ( { page } ) => {
@@ -11,53 +11,22 @@ test.describe( 'Jetpack Protect plugin - Pre-Connection', () => {
1111
.build();
1212
} );
1313

14-
test( 'Jetpack Protect admin page', async ( { page, admin } ) => {
15-
logger.action( 'Visit the Jetpack Protect admin page and start for free' );
16-
17-
await admin.visitAdminPage( 'admin.php', 'page=jetpack-protect' );
18-
19-
logger.action( 'Checking for button "Get Jetpack Protect"' );
20-
const getJetpackProtectButton = page.getByRole( 'button', { name: 'Get Jetpack Protect' } );
21-
await expect( getJetpackProtectButton ).toBeVisible();
22-
await expect( getJetpackProtectButton ).toBeEnabled();
23-
24-
logger.action( 'Checking for button "Start for free"' );
25-
const startForFreeButton = page.getByRole( 'button', { name: 'Start for free' } );
26-
await expect( startForFreeButton ).toBeVisible();
27-
await expect( startForFreeButton ).toBeEnabled();
28-
29-
logger.action( 'Click the start for free button' );
30-
await startForFreeButton.click();
31-
32-
logger.action( 'Checking for heading "Stay one step ahead of threats"' );
33-
await expect(
34-
page.getByRole( 'heading', { name: 'Stay one step ahead of threats' } )
35-
).toBeVisible();
36-
} );
37-
} );
14+
test( 'Jetpack Protect firewall page', async ( { page, admin } ) => {
15+
await connect( page, admin );
3816

39-
test.describe( 'Jetpack Protect plugin - Post-Connection', () => {
40-
test.beforeEach( async ( { page } ) => {
41-
await prerequisitesBuilder( page )
42-
.withCleanEnv()
43-
.withActivePlugins( [ 'protect' ] )
44-
.withInactivePlugins( [ 'e2e-waf-data-interceptor' ] )
45-
.withLoggedIn( true )
46-
.withConnection( true )
47-
.build();
48-
} );
17+
// to do: should not need to manually reload the page here to ensure the waf module is available
18+
await page.reload();
4919

50-
test( 'Jetpack Protect firewall page', async ( { page, admin } ) => {
5120
await test.step( 'Navigate to firewall page', async () => {
5221
await admin.visitAdminPage( 'admin.php', 'page=jetpack-protect#/firewall' );
5322
await expect( page.getByText( 'Firewall is on' ) ).toBeVisible();
5423
} );
5524

56-
await test.step( 'Test the automatic firewall setting is disabled for free plans', async () => {
57-
const automaticFirewallToggle = page.locator( '#inspector-toggle-control-0' );
58-
await expect( automaticFirewallToggle ).toBeDisabled();
59-
await expect( automaticFirewallToggle ).not.toBeChecked();
60-
} );
25+
// await test.step( 'Test the automatic firewall setting is disabled for free plans', async () => {
26+
// const automaticFirewallToggle = page.locator( '#inspector-toggle-control-0' );
27+
// await expect( automaticFirewallToggle ).toBeDisabled();
28+
// await expect( automaticFirewallToggle ).not.toBeChecked();
29+
// } );
6130

6231
await test.step( 'Test the brute force protection setting', async () => {
6332
const bruteForceToggle = page.locator( '#inspector-toggle-control-1' );
@@ -67,7 +36,9 @@ test.describe( 'Jetpack Protect plugin - Post-Connection', () => {
6736

6837
// Test turning brute force off and then on again
6938
await bruteForceToggle.click();
70-
await expect( page.getByText( 'Changes saved' ) ).toBeVisible();
39+
await expect( page.getByText( 'Changes saved' ) ).toBeVisible( {
40+
timeout: 15_000,
41+
} );
7142
await expect( bruteForceToggle ).toBeEnabled();
7243
await expect( bruteForceToggle ).not.toBeChecked();
7344
await bruteForceToggle.click();

0 commit comments

Comments
 (0)