Skip to content

Commit

Permalink
experiment with seeders to impovise test performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidsector9 committed Oct 23, 2022
1 parent c97420f commit 3d0e0d2
Show file tree
Hide file tree
Showing 10 changed files with 271 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .wp-env.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"core": null,
"plugins": [ "." ],
"plugins": [ ".", "./tests/rsa-seeder" ],
"config": {
"WP_ALLOW_MULTISITE": true
},
Expand Down
1 change: 1 addition & 0 deletions tests/bin/initialize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ npm run env run tests-cli wp rewrite structure '/%postname%/' --hard
npm run env run tests-cli "wp core multisite-convert --title='RSA Multisite'"
npm run env run tests-cli "wp post create --post_type=page --post_title='Accessible page' --post_status='publish'"
npm run env run tests-cli "wp post create --post_type=page --post_title='Page to redirect' --post_status='publish'"
npm run env run tests-cli "wp plugin activate rsa-seeder --network"
npm run env run tests-cli "wp rewrite flush"
3 changes: 3 additions & 0 deletions tests/cypress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ module.exports = defineConfig({
],
supportFile: 'tests/cypress/support/e2e.js'
},
retries: {
runMode: 3,
}
});

/**
Expand Down
5 changes: 3 additions & 2 deletions tests/cypress/e2e/activation-deactivation.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
describe( 'Activation/Deactivation', () => {
before( () => {
cy.resetState();
cy.wpCli( 'plugin deactivate restricted-site-access --network' );
cy.request( {
url: '/wp-json/rsa/v1/seed/activation-deactivation'
} );
cy.login();
} );

Expand Down
6 changes: 5 additions & 1 deletion tests/cypress/e2e/add-invalid-addresses.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
describe( 'Add invalid IPv4, IPv6 addresses', () => {
before( () => {
cy.resetState();
cy.request( {
url: '/wp-json/rsa/v1/seed/add-invalid-addresses'
} ).then( response => {
console.log( response )
} );
cy.login();
cy.visitAdminPage( 'network/settings.php' );
} );
Expand Down
7 changes: 6 additions & 1 deletion tests/cypress/e2e/add-valid-addresses.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
describe( 'Add & save valid IPv4, IPv6 addresses', () => {
before( () => {
cy.resetState();
cy.request( {
url: '/wp-json/rsa/v1/seed/add-valid-addresses'
} ).then( response => {
console.log( response )
} );
cy.login();
cy.visitAdminPage( 'network/settings.php' );
} );
Expand All @@ -27,6 +31,7 @@ describe( 'Add & save valid IPv4, IPv6 addresses', () => {

it( 'Add IPv6 pattern', () => {
cy.addIp( '2001:db8:3333:4444:5555:6666:*:*', 'IPv6 pattern' );
cy.wait(300);
} );

after( () => {
Expand Down
17 changes: 12 additions & 5 deletions tests/cypress/e2e/allow-unrestricted-users.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
describe( 'Handle restricted visitors - Show simple message', () => {
before( () => {
cy.wpCli( `network meta set 1 blog_public 2` );
cy.wpCli( `network meta set 1 rsa_mode enforce` );
cy.request( {
url: '/wp-json/rsa/v1/seed/allow-unrestricted-users'
} )
} );

it( 'Show simple message - Visitor can still access requested page ', () => {
cy.wpCli( `network meta set 1 rsa_options '{"approach":3,"message":"Access to this site is restricted.","redirect_path":0,"head_code":302,"redirect_url":"","page":0,"allowed":["172.13.24.5"],"comment":[""]}' --format=json` );
cy.request( {
url: '/wp-json/rsa/v1/seed/allow-unrestricted-users/show-simple-message'
} )
cy.request( {
url: 'sample-page',
followRedirect: false,
Expand All @@ -18,7 +21,9 @@ describe( 'Handle restricted visitors - Show simple message', () => {
} );

it( 'Redirect to web address - Visitor can still access requested page ', () => {
cy.wpCli( `network meta set 1 rsa_options '{"approach":2,"message":"Access to this site is restricted.","redirect_path":0,"head_code":301,"redirect_url":"http:\/\/localhost:8889\/page-to-redirect\/","page":0,"allowed":["172.13.24.5"],"comment":[]}' --format=json` );
cy.request( {
url: '/wp-json/rsa/v1/seed/allow-unrestricted-users/redirect-to-web-address'
} )
cy.request( {
url: 'sample-page',
followRedirect: false,
Expand All @@ -31,7 +36,9 @@ describe( 'Handle restricted visitors - Show simple message', () => {
} );

it( 'Send to login screen - Visitor can still access requested page ', () => {
cy.wpCli( `network meta set 1 rsa_options '{"approach":2,"message":"Access to this site is restricted.","redirect_path":0,"head_code":301,"redirect_url":"http:\/\/localhost:8889\/page-to-redirect\/","page":0,"allowed":["172.13.24.5"],"comment":[]}' --format=json` );
cy.request( {
url: '/wp-json/rsa/v1/seed/allow-unrestricted-users/send-to-login-screen'
} );
cy.request( {
url: 'sample-page',
followRedirect: false,
Expand Down
28 changes: 15 additions & 13 deletions tests/cypress/e2e/restrict-users.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
describe( 'Handle restricted visitors - Send to login screen', () => {
before( () => {
cy.wpCli( `network meta set 1 blog_public 2` );
cy.wpCli( `network meta set 1 rsa_mode enforce` );
cy.wpCli( `network meta set 1 rsa_options '{"approach":1,"message":"Access to this site is restricted.","redirect_path":0,"head_code":302,"redirect_url":"","page":0,"allowed":["172.13.24.5"],"comment":[""]}' --format=json` );
} );

it( 'Verify - Visitor is redirected to login screen', () => {
cy.request( {
url: '/wp-json/rsa/v1/seed/restrict-users/send-to-login-screen'
} );
cy.visit( `sample-page`, {
failOnStatusCode: false,
} );
Expand All @@ -16,7 +13,9 @@ describe( 'Handle restricted visitors - Send to login screen', () => {

describe( 'Handle restricted visitors - Redirect to web address', () => {
it( 'Verify - Redirection with status code 301', () => {
cy.wpCli( `network meta set 1 rsa_options '{"approach":2,"message":"Access to this site is restricted.","redirect_path":0,"head_code":301,"redirect_url":"http:\/\/localhost:8889\/page-to-redirect\/","page":0,"allowed":["172.13.24.5"],"comment":[]}' --format=json` );
cy.request( {
url: '/wp-json/rsa/v1/seed/restrict-users/redirect-to-web-address/with-301'
} );
cy.request( {
url: 'sample-page',
followRedirect: false,
Expand All @@ -27,7 +26,9 @@ describe( 'Handle restricted visitors - Redirect to web address', () => {
} );

it( 'Verify - Redirection with status code 302', () => {
cy.wpCli( `network meta set 1 rsa_options '{"approach":2,"message":"Access to this site is restricted.","redirect_path":0,"head_code":302,"redirect_url":"http:\/\/localhost:8889\/page-to-redirect\/","page":0,"allowed":["172.13.24.5"],"comment":[]}' --format=json` );
cy.request( {
url: '/wp-json/rsa/v1/seed/restrict-users/redirect-to-web-address/with-302'
} );
cy.request( {
url: 'sample-page',
followRedirect: false,
Expand All @@ -38,7 +39,9 @@ describe( 'Handle restricted visitors - Redirect to web address', () => {
} );

it( 'Verify - Redirection with status code 307', () => {
cy.wpCli( `network meta set 1 rsa_options '{"approach":2,"message":"Access to this site is restricted.","redirect_path":0,"head_code":307,"redirect_url":"http:\/\/localhost:8889\/page-to-redirect\/","page":0,"allowed":["172.13.24.5"],"comment":[]}' --format=json` );
cy.request( {
url: '/wp-json/rsa/v1/seed/restrict-users/redirect-to-web-address/with-307'
} );
cy.request( {
url: 'sample-page',
followRedirect: false,
Expand All @@ -50,11 +53,10 @@ describe( 'Handle restricted visitors - Redirect to web address', () => {
} );

describe( 'Handle restricted visitors - Show simple message', () => {
before( () => {
cy.wpCli( `network meta set 1 rsa_options '{"approach":3,"message":"Access to this site is restricted.","redirect_path":0,"head_code":302,"redirect_url":"","page":0,"allowed":["172.13.24.5"],"comment":[""]}' --format=json` );
} );

it( 'Verify - Show simple message', () => {
cy.request( {
url: '/wp-json/rsa/v1/seed/restrict-users/show-simple-message'
} );
cy.visit( `sample-page`, {
failOnStatusCode: false,
} );
Expand Down
1 change: 0 additions & 1 deletion tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,4 @@ Cypress.Commands.add( 'addIp', ( ip = '', label = '' ) => {
cy.get( '#rsa_add_new_ip_fields input[name="newip"]' ).type( ip );
cy.get( '#rsa_add_new_ip_fields input[name="newipcomment"]' ).type( label );
cy.get( '#addip' ).click();
cy.wait( 600 );
} );
Loading

0 comments on commit 3d0e0d2

Please sign in to comment.