From 66182361ee7cafc2dc579549705567ff1a5e70bf Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 17 Nov 2023 15:02:33 +0000 Subject: [PATCH 01/12] initial skeleton Signed-off-by: Sam --- .../integration/plugins/security/auth_spec.js | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/cypress/integration/plugins/security/auth_spec.js b/cypress/integration/plugins/security/auth_spec.js index ffe9ceedd..ce124286b 100644 --- a/cypress/integration/plugins/security/auth_spec.js +++ b/cypress/integration/plugins/security/auth_spec.js @@ -9,6 +9,47 @@ import { } from '../../../utils/constants'; if (Cypress.env('SECURITY_ENABLED')) { + + describe('OpenSearch Dashboards Security Plugin - User Creation', () => { + const username = 'newuser'; + const password = 'newpassword'; + + beforeEach(() => { + // Visit the OpenSearch Dashboards login page + cy.visit('/'); + + // Login as admin + cy.get('input[name="username"]').type(Cypress.env('username')); + cy.get('input[name="password"]').type(Cypress.env('password'), { log: false }); + cy.get('button[type="submit"]').click(); + + // Wait for the OpenSearch Dashboards home page to load + cy.contains('Welcome to OpenSearch Dashboards', { timeout: 60000 }).should('be.visible'); + }); + + it('should create a new internal user', () => { + // Navigate to Security/Internal User Database section + cy.visit('/app/security-dashboards#/users'); + + // Click on 'Add internal user' button + cy.get('button').contains('Add internal user').click(); + + // Provide username and password for the new user + cy.get('input[data-test-subj="user-name"]').type(username); + cy.get('input[data-test-subj="password"]').type(password); + cy.get('input[data-test-subj="password-confirmation"]').type(password); + + // Optionally add backend role and user attribute + // Skipping as per the instruction [No backend role] + + // Submit the form to create the user + cy.get('button').contains('Submit').click(); + + // Verify that the user is created + cy.contains(username).should('exist'); + }); + }); + describe('Authc and Authz page', () => { // start a server so that server responses can be mocked via fixtures // in all of the below test cases From 03187b808e6c6e53f820653ff28c94c74edbe3ea Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 21 Nov 2023 13:52:13 +0000 Subject: [PATCH 02/12] first two sections Signed-off-by: Sam --- .../integration/plugins/security/auth_spec.js | 212 +++++++++++++----- 1 file changed, 150 insertions(+), 62 deletions(-) diff --git a/cypress/integration/plugins/security/auth_spec.js b/cypress/integration/plugins/security/auth_spec.js index ce124286b..96bd0143a 100644 --- a/cypress/integration/plugins/security/auth_spec.js +++ b/cypress/integration/plugins/security/auth_spec.js @@ -6,83 +6,171 @@ import { SEC_UI_AUTH_PATH, SEC_FIXTURES_BASE_PATH, + BASE_PATH, } from '../../../utils/constants'; -if (Cypress.env('SECURITY_ENABLED')) { +import '../../../utils/commands'; +import '../../../utils/dashboards/commands'; +import '../../../utils/dashboards/datasource-management-dashboards-plugin/commands'; +import '../../../utils/plugins/index-management-dashboards-plugin/commands'; +import '../../../utils/plugins/anomaly-detection-dashboards-plugin/commands'; +import '../../../utils/plugins/security/commands'; +import '../../../utils/plugins/security-dashboards-plugin/commands'; +import '../../../utils/plugins/alerting-dashboards-plugin/commands'; +import '../../../utils/plugins/ml-commons-dashboards/commands'; +import '../../../utils/plugins/security-analytics-dashboards-plugin/commands'; +import '../../../utils/plugins/notifications-dashboards/commands'; + +import 'cypress-real-events'; - describe('OpenSearch Dashboards Security Plugin - User Creation', () => { +if (Cypress.env('SECURITY_ENABLED')) { + describe('OpenSearch Dashboards Security Plugin - Enhanced Sanity Tests', () => { const username = 'newuser'; - const password = 'newpassword'; + const password = 'ew4q56a4d6as51!*asSS'; beforeEach(() => { // Visit the OpenSearch Dashboards login page - cy.visit('/'); - + // cy.visit(SEC_UI_AUTH_PATH); // Login as admin - cy.get('input[name="username"]').type(Cypress.env('username')); - cy.get('input[name="password"]').type(Cypress.env('password'), { log: false }); - cy.get('button[type="submit"]').click(); - + // cy.get('input[name="username"]').type(Cypress.env('username')); + // cy.get('input[name="password"]').type(Cypress.env('password'), { log: false }); + // cy.get('button[type="submit"]').click(); // Wait for the OpenSearch Dashboards home page to load - cy.contains('Welcome to OpenSearch Dashboards', { timeout: 60000 }).should('be.visible'); + // cy.contains('Welcome to OpenSearch Dashboards', { timeout: 12000 }).should('be.visible'); }); - it('should create a new internal user', () => { - // Navigate to Security/Internal User Database section - cy.visit('/app/security-dashboards#/users'); - - // Click on 'Add internal user' button - cy.get('button').contains('Add internal user').click(); - - // Provide username and password for the new user - cy.get('input[data-test-subj="user-name"]').type(username); - cy.get('input[data-test-subj="password"]').type(password); - cy.get('input[data-test-subj="password-confirmation"]').type(password); - - // Optionally add backend role and user attribute - // Skipping as per the instruction [No backend role] - - // Submit the form to create the user - cy.get('button').contains('Submit').click(); - - // Verify that the user is created - cy.contains(username).should('exist'); - }); - }); - - describe('Authc and Authz page', () => { - // start a server so that server responses can be mocked via fixtures - // in all of the below test cases - before(() => { - cy.server(); - }); - - it('authentication and authorization section should exist', () => { - cy.mockAuthAction(SEC_FIXTURES_BASE_PATH + '/auth_response.json', () => { - cy.visit(SEC_UI_AUTH_PATH); + // it.skip('should create a new internal user', () => { + // // Navigate to Security/Internal User Database section + // cy.visit('/app/security-dashboards-plugin#/users'); + // + // // Click on 'Add internal user' button + // // cy.get('button').contains('Create internal user').click(); + // cy.get('a[href="#/users/create"]').click({ + // force: true, + // }); + // // Provide username and password for the new user + // cy.get('input[data-test-subj="name-text"]').type(username); + // cy.get('input[data-test-subj="password"]').type(password); + // cy.get('input[data-test-subj="re-enter-password"]').type(password); + // + // // Optionally add backend role and user attribute + // // Skipping as per the instruction [No backend role] + // + // // Submit the form to create the user + // cy.get('button').contains('Create').click(); + // + // // Verify that the user is created + // cy.contains(username).should('exist'); + // }); + // it('should create a new role with specific permissions', () => { + + it('should create a new role with specific permissions', () => { + // Add sample data if it hasn't been added yet + cy.visit(`${BASE_PATH}/app/home#/tutorial_directory/sampleData`, { + retryOnStatusCodeFailure: true, }); - cy.contains('h3', 'Authentication sequences'); - cy.contains('span', 'kerberos_auth_domain'); - - cy.contains('h3', 'Authorization'); - cy.contains('span', 'roles_from_another_ldap'); - }); - - it('View Expression Modal should display and close correctly', () => { - cy.mockAuthAction(SEC_FIXTURES_BASE_PATH + '/auth_response.json', () => { - cy.visit(SEC_UI_AUTH_PATH); + cy.get('body').then(($body) => { + if ( + $body.find('[data-test-subj="addSampleDataSetflights"]').length > 0 + ) { + // If the element exists, click on it + cy.get('[data-test-subj="addSampleDataSetflights"]').click(); + } else { + // The element does not exist, you can log a message or take other actions + cy.get('[data-test-subj="launchSampleDataSetecommerce"]').click(); + } }); - cy.get('.euiModal').should('not.exist'); - - cy.get('[data-test-subj=view-expression]').first().click({ force: true }); - - cy.get('.euiModal').should('be.visible'); - - cy.get('.euiModal__closeIcon').click({ force: true }); - - cy.get('.euiModal').should('not.exist'); + // if(cy.find('[data-test-subj="addSampleDataSetflights"]').then(($el) => { + // if ($el.length()) { + // cy.get('[data-test-subj="addSampleDataSetflights"]').click(); + // } else { + // cy.get('[data-test-subj="launchSampleDataSetecommerce"]').click(); + // } + // }); + + // //[data-test-subj="addSampleDataSetflights"').click(); + // cy.get('div[data-test-subj="sampleDataSetCardflights"]', { + // timeout: 90000, + // }) + // .contains(/Add data/) + // .click(); + // // cy.wait(60000); + + // Navigate to Security/Roles section + cy.visit('/app/security-dashboards-plugin#/roles/create'); + + // Click on 'Add new role' button + // Set role name + const roleName = 'newRole'; + cy.get('input[data-test-subj="name-text"]').type(roleName); + + // Add Cluster Permissions + cy.get('input[data-test-subj="comboBoxSearchInput"]') + .eq(0) + .type('indices:data/read/msearch') + .type('{downArrow}{enter}'); + + cy.get('#index-input-box').type( + 'opensearch_dashboards_sample_data_flights*' + ); + + // Set Document Level Security Query + cy.get('textarea').type('{{}"match": {{}"FlightDelay": true}}'); + + // Anonymize fields + cy.get('input[data-test-subj="comboBoxSearchInput"][role="textbox"]') + .eq(4) + .type('FlightNum'); + + // Add Tenant Permissions + const tenantName = 'yourTenantName'; // Replace with your tenant name + cy.get('input[id="roles-tenant-permission-box"]') + .type(tenantName) + .type('{enter}'); + + // Save Role Definition + cy.get('button').contains('Create').click(); + + // Verify that the role is created + cy.contains(roleName).should('exist'); }); }); + + // describe.skip('Authc and Authz page', () => { + // // start a server so that server responses can be mocked via fixtures + // // in all of the below test cases + // before(() => { + // cy.server(); + // }); + // + // it.skip('authentication and authorization section should exist', () => { + // cy.mockAuthAction(SEC_FIXTURES_BASE_PATH + '/auth_response.json', () => { + // cy.visit(SEC_UI_AUTH_PATH); + // }); + // + // cy.contains('h3', 'Authentication sequences'); + // cy.contains('span', 'kerberos_auth_domain'); + // + // cy.contains('h3', 'Authorization'); + // cy.contains('span', 'roles_from_another_ldap'); + // }); + // + // it.skip('View Expression Modal should display and close correctly', () => { + // cy.mockAuthAction(SEC_FIXTURES_BASE_PATH + '/auth_response.json', () => { + // cy.visit(SEC_UI_AUTH_PATH); + // }); + // + // cy.get('.euiModal').should('not.exist'); + // + // cy.get('[data-test-subj=view-expression]').first().click({ force: true }); + // + // cy.get('.euiModal').should('be.visible'); + // + // cy.get('.euiModal__closeIcon').click({ force: true }); + // + // cy.get('.euiModal').should('not.exist'); + // }); + // }); } From 801906fc1bd612cb4419b9d97fc9f75e0a97e7fd Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 23 Nov 2023 01:04:26 +0000 Subject: [PATCH 03/12] first two sections Signed-off-by: Sam --- .../integration/plugins/security/auth_spec.js | 91 +++++++++++++++---- 1 file changed, 72 insertions(+), 19 deletions(-) diff --git a/cypress/integration/plugins/security/auth_spec.js b/cypress/integration/plugins/security/auth_spec.js index 96bd0143a..56af881ea 100644 --- a/cypress/integration/plugins/security/auth_spec.js +++ b/cypress/integration/plugins/security/auth_spec.js @@ -27,6 +27,8 @@ if (Cypress.env('SECURITY_ENABLED')) { describe('OpenSearch Dashboards Security Plugin - Enhanced Sanity Tests', () => { const username = 'newuser'; const password = 'ew4q56a4d6as51!*asSS'; + const roleName = 'newRole'; + const tenantName = 'yourTenantName'; // Replace with your tenant name beforeEach(() => { // Visit the OpenSearch Dashboards login page @@ -78,32 +80,15 @@ if (Cypress.env('SECURITY_ENABLED')) { cy.get('[data-test-subj="addSampleDataSetflights"]').click(); } else { // The element does not exist, you can log a message or take other actions - cy.get('[data-test-subj="launchSampleDataSetecommerce"]').click(); + cy.get('[data-test-subj="launchSampleDataSetflights"]').click(); } }); - // if(cy.find('[data-test-subj="addSampleDataSetflights"]').then(($el) => { - // if ($el.length()) { - // cy.get('[data-test-subj="addSampleDataSetflights"]').click(); - // } else { - // cy.get('[data-test-subj="launchSampleDataSetecommerce"]').click(); - // } - // }); - - // //[data-test-subj="addSampleDataSetflights"').click(); - // cy.get('div[data-test-subj="sampleDataSetCardflights"]', { - // timeout: 90000, - // }) - // .contains(/Add data/) - // .click(); - // // cy.wait(60000); - // Navigate to Security/Roles section cy.visit('/app/security-dashboards-plugin#/roles/create'); // Click on 'Add new role' button // Set role name - const roleName = 'newRole'; cy.get('input[data-test-subj="name-text"]').type(roleName); // Add Cluster Permissions @@ -125,7 +110,6 @@ if (Cypress.env('SECURITY_ENABLED')) { .type('FlightNum'); // Add Tenant Permissions - const tenantName = 'yourTenantName'; // Replace with your tenant name cy.get('input[id="roles-tenant-permission-box"]') .type(tenantName) .type('{enter}'); @@ -135,6 +119,75 @@ if (Cypress.env('SECURITY_ENABLED')) { // Verify that the role is created cy.contains(roleName).should('exist'); + + //TODO checkTenantText exist + //TODO checkClusterPermisio exist + //TODO checkIndexPermissionText exist + }); + + it('should add a new role mapping', () => { + // Navigate to Role Mappings + cy.visit( + 'http://localhost:5601/app/security-dashboards-plugin#/users/edit/' + + username + ); + + // Choose the role you created earlier + cy.get('[placeholder="Type in backend role"]').type(roleName); //Not iDeal use placeholder + + // Submit the role mapping + cy.get('button[id="submit"]').click(); + + // Optional: Verify that the role mapping was added + // This can include checking for a success message or verifying the list of role mappings + }); + + it.only('should create a new index pattern', () => { + cy.visit('/'); + // Step 1: Change tenant to the newly created tenant user-icon-btn + cy.get('[id="user-icon-btn"]').click({ force: true }); + + cy.get('body').then(($body) => { + if ($body.find('[data-test-subj="tenant-switch-modal"]').length == 0) { + cy.get('[id="user-icon-btn"]').click({ force: true }); + cy.get('button[data-test-subj="switch-tenants"]').click(); + + // If the element exists, click on it + cy.get('[data-test-subj="addSampleDataSetflights"]').click(); + } else { + // The element does not exist, you can log a message or take other actions + cy.log('POTATO'); + } + }); + + cy.get('button[data-test-subj="switch-tenants"]').click(); + cy.get('button[title="${tenantName}"]').click(); + cy.get('button[data-test-subj="confirm"]').click(); + // Step 2: Add sample flight data if it's not already present + + cy.visit('/app/home#/tutorial_directory/sampleData'); + cy.get('button').contains('Add data').click(); // Adjust if the button text or selectors differ + + // Step 3: Navigate to Manage data to add an index pattern + cy.visit('/app/home'); + cy.get('button').contains('Manage data').click(); // Adjust the selector as needed + + // Step 4: Add the index pattern + cy.contains('Index patterns').click(); + cy.contains('Add an index pattern').click(); + cy.get('input[type="text"]').type( + 'opensearch_dashboards_sample_data_flights' + ); + cy.contains('Next step').click(); + + // Assuming a timestamp field needs to be selected + cy.get('yourTimestampFieldSelector').click(); // Replace with actual selector + + // Step 5: Create index pattern + cy.contains('Create index pattern').click(); + + // Step 6: Additional verification if needed + // Navigate to verify if necessary, or perform checks to ensure index pattern creation }); }); From a21675366d587d371d3ff9ec768b784b81421c37 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 24 Nov 2023 01:27:38 +0000 Subject: [PATCH 04/12] index pattern creation Signed-off-by: Sam --- .../integration/plugins/security/auth_spec.js | 184 ++++++++++-------- 1 file changed, 100 insertions(+), 84 deletions(-) diff --git a/cypress/integration/plugins/security/auth_spec.js b/cypress/integration/plugins/security/auth_spec.js index 56af881ea..b2f45998f 100644 --- a/cypress/integration/plugins/security/auth_spec.js +++ b/cypress/integration/plugins/security/auth_spec.js @@ -22,6 +22,7 @@ import '../../../utils/plugins/security-analytics-dashboards-plugin/commands'; import '../../../utils/plugins/notifications-dashboards/commands'; import 'cypress-real-events'; +import { switchTenantTo } from '../security-dashboards-plugin/switch_tenant'; if (Cypress.env('SECURITY_ENABLED')) { describe('OpenSearch Dashboards Security Plugin - Enhanced Sanity Tests', () => { @@ -41,29 +42,29 @@ if (Cypress.env('SECURITY_ENABLED')) { // cy.contains('Welcome to OpenSearch Dashboards', { timeout: 12000 }).should('be.visible'); }); - // it.skip('should create a new internal user', () => { - // // Navigate to Security/Internal User Database section - // cy.visit('/app/security-dashboards-plugin#/users'); - // - // // Click on 'Add internal user' button - // // cy.get('button').contains('Create internal user').click(); - // cy.get('a[href="#/users/create"]').click({ - // force: true, - // }); - // // Provide username and password for the new user - // cy.get('input[data-test-subj="name-text"]').type(username); - // cy.get('input[data-test-subj="password"]').type(password); - // cy.get('input[data-test-subj="re-enter-password"]').type(password); - // - // // Optionally add backend role and user attribute - // // Skipping as per the instruction [No backend role] - // - // // Submit the form to create the user - // cy.get('button').contains('Create').click(); - // - // // Verify that the user is created - // cy.contains(username).should('exist'); - // }); + it('should create a new internal user', () => { + // Navigate to Security/Internal User Database section + cy.visit('/app/security-dashboards-plugin#/users'); + + // Click on 'Add internal user' button + // cy.get('button').contains('Create internal user').click(); + cy.get('a[href="#/users/create"]').click({ + force: true, + }); + // Provide username and password for the new user + cy.get('input[data-test-subj="name-text"]').type(username); + cy.get('input[data-test-subj="password"]').type(password); + cy.get('input[data-test-subj="re-enter-password"]').type(password); + + // Optionally add backend role and user attribute + // Skipping as per the instruction [No backend role] + + // Submit the form to create the user + cy.get('button').contains('Create').click(); + + // Verify that the user is created + cy.contains(username).should('exist'); + }); // it('should create a new role with specific permissions', () => { it('should create a new role with specific permissions', () => { @@ -143,87 +144,102 @@ if (Cypress.env('SECURITY_ENABLED')) { }); it.only('should create a new index pattern', () => { - cy.visit('/'); + cy.visit('http://localhost:5601/app/home?security_tenant=' + tenantName); // Step 1: Change tenant to the newly created tenant user-icon-btn - cy.get('[id="user-icon-btn"]').click({ force: true }); - cy.get('body').then(($body) => { - if ($body.find('[data-test-subj="tenant-switch-modal"]').length == 0) { - cy.get('[id="user-icon-btn"]').click({ force: true }); - cy.get('button[data-test-subj="switch-tenants"]').click(); + // cy.get('body').then(($body) => { + // if ($body.find('[data-test-subj="tenant-switch-modal"]').length == 0) { + // cy.get('[id="user-icon-btn"]').click({ force: true }); + // cy.get('button[data-test-subj="switch-tenants"]').click(); + // + // // If the element exists, click on it + // cy.get('[data-test-subj="addSampleDataSetflights"]').click(); + // } else { + // // The element does not exist, you can log a message or take other actions + // cy.log('POTATO'); + // } + // }); + + // cy.get('button[data-test-subj="switch-tenants"]').click(); + // cy.get('button[title="${tenantName}"]').click(); + // cy.get('button[data-test-subj="confirm"]').click(); + + cy.visit(`${BASE_PATH}/app/home#/tutorial_directory/sampleData`, { + retryOnStatusCodeFailure: true, + }); + cy.get('body').then(($body) => { + if ( + $body.find('[data-test-subj="addSampleDataSetflights"]').length > 0 + ) { // If the element exists, click on it cy.get('[data-test-subj="addSampleDataSetflights"]').click(); } else { // The element does not exist, you can log a message or take other actions - cy.log('POTATO'); + cy.get('[data-test-subj="launchSampleDataSetflights"]').click(); } }); - cy.get('button[data-test-subj="switch-tenants"]').click(); - cy.get('button[title="${tenantName}"]').click(); - cy.get('button[data-test-subj="confirm"]').click(); - // Step 2: Add sample flight data if it's not already present - - cy.visit('/app/home#/tutorial_directory/sampleData'); - cy.get('button').contains('Add data').click(); // Adjust if the button text or selectors differ - // Step 3: Navigate to Manage data to add an index pattern cy.visit('/app/home'); - cy.get('button').contains('Manage data').click(); // Adjust the selector as needed + cy.get('button[aria-label="Closes this modal window"]').click(); + cy.get('a').contains('Manage').click(); // Adjust the selector as needed // Step 4: Add the index pattern - cy.contains('Index patterns').click(); - cy.contains('Add an index pattern').click(); - cy.get('input[type="text"]').type( - 'opensearch_dashboards_sample_data_flights' + cy.get('[data-test-subj="indexPatterns"]').click(); + cy.get('[data-test-subj="createIndexPatternButton"]').click(); + cy.get('input[data-test-subj="createIndexPatternNameInput"]').type( + 'opensearch_dashboards_sample_data_flights*' ); - cy.contains('Next step').click(); + cy.get( + 'button[data-test-subj="createIndexPatternGoToStep2Button"]' + ).click(); // Assuming a timestamp field needs to be selected - cy.get('yourTimestampFieldSelector').click(); // Replace with actual selector + cy.get( + 'select[data-test-subj="createIndexPatternTimeFieldSelect"]' + ).select('timestamp'); - // Step 5: Create index pattern - cy.contains('Create index pattern').click(); + cy.get('option[value="timestamp"]'); + cy.get('button[data-test-subj="createIndexPatternButton"]').click(); - // Step 6: Additional verification if needed - // Navigate to verify if necessary, or perform checks to ensure index pattern creation + // Additional verification if needed }); }); - // describe.skip('Authc and Authz page', () => { - // // start a server so that server responses can be mocked via fixtures - // // in all of the below test cases - // before(() => { - // cy.server(); - // }); - // - // it.skip('authentication and authorization section should exist', () => { - // cy.mockAuthAction(SEC_FIXTURES_BASE_PATH + '/auth_response.json', () => { - // cy.visit(SEC_UI_AUTH_PATH); - // }); - // - // cy.contains('h3', 'Authentication sequences'); - // cy.contains('span', 'kerberos_auth_domain'); - // - // cy.contains('h3', 'Authorization'); - // cy.contains('span', 'roles_from_another_ldap'); - // }); - // - // it.skip('View Expression Modal should display and close correctly', () => { - // cy.mockAuthAction(SEC_FIXTURES_BASE_PATH + '/auth_response.json', () => { - // cy.visit(SEC_UI_AUTH_PATH); - // }); - // - // cy.get('.euiModal').should('not.exist'); - // - // cy.get('[data-test-subj=view-expression]').first().click({ force: true }); - // - // cy.get('.euiModal').should('be.visible'); - // - // cy.get('.euiModal__closeIcon').click({ force: true }); - // - // cy.get('.euiModal').should('not.exist'); - // }); - // }); + describe('Authc and Authz page', () => { + // start a server so that server responses can be mocked via fixtures + // in all of the below test cases + before(() => { + cy.server(); + }); + + it('authentication and authorization section should exist', () => { + cy.mockAuthAction(SEC_FIXTURES_BASE_PATH + '/auth_response.json', () => { + cy.visit(SEC_UI_AUTH_PATH); + }); + + cy.contains('h3', 'Authentication sequences'); + cy.contains('span', 'kerberos_auth_domain'); + + cy.contains('h3', 'Authorization'); + cy.contains('span', 'roles_from_another_ldap'); + }); + + it('View Expression Modal should display and close correctly', () => { + cy.mockAuthAction(SEC_FIXTURES_BASE_PATH + '/auth_response.json', () => { + cy.visit(SEC_UI_AUTH_PATH); + }); + + cy.get('.euiModal').should('not.exist'); + + cy.get('[data-test-subj=view-expression]').first().click({ force: true }); + + cy.get('.euiModal').should('be.visible'); + + cy.get('.euiModal__closeIcon').click({ force: true }); + + cy.get('.euiModal').should('not.exist'); + }); + }); } From 171c3c8540a5024086221a60579b82deb92182f2 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 30 Nov 2023 00:08:40 +0000 Subject: [PATCH 05/12] index pattern creation Signed-off-by: Sam --- .../sanity_tests.spec.js | 209 ++++++++++++++++++ .../integration/plugins/security/auth_spec.js | 198 ----------------- 2 files changed, 209 insertions(+), 198 deletions(-) create mode 100644 cypress/integration/plugins/security-dashboards-plugin/sanity_tests.spec.js diff --git a/cypress/integration/plugins/security-dashboards-plugin/sanity_tests.spec.js b/cypress/integration/plugins/security-dashboards-plugin/sanity_tests.spec.js new file mode 100644 index 000000000..de0c1c43a --- /dev/null +++ b/cypress/integration/plugins/security-dashboards-plugin/sanity_tests.spec.js @@ -0,0 +1,209 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { + SEC_UI_AUTH_PATH, + SEC_FIXTURES_BASE_PATH, + BASE_PATH, +} from '../../../utils/constants'; + +import '../../../utils/commands'; +import '../../../utils/dashboards/commands'; +import '../../../utils/dashboards/datasource-management-dashboards-plugin/commands'; +import '../../../utils/plugins/index-management-dashboards-plugin/commands'; +import '../../../utils/plugins/anomaly-detection-dashboards-plugin/commands'; +import '../../../utils/plugins/security/commands'; +import '../../../utils/plugins/security-dashboards-plugin/commands'; +import '../../../utils/plugins/alerting-dashboards-plugin/commands'; +import '../../../utils/plugins/ml-commons-dashboards/commands'; +import '../../../utils/plugins/security-analytics-dashboards-plugin/commands'; +import '../../../utils/plugins/notifications-dashboards/commands'; + +import 'cypress-real-events'; +import { switchTenantTo } from '../security-dashboards-plugin/switch_tenant'; + +if (Cypress.env('SECURITY_ENABLED')) { + describe('OpenSearch Dashboards Security Plugin - Enhanced Sanity Tests', () => { + const username = 'newuser'; + const password = 'ew4q56a4d6as51!*asSS'; + const roleName = 'newRole'; + const tenantName = 'yourTenantName'; // Replace with your tenant name + + beforeEach(() => { + // Visit the OpenSearch Dashboards login page + // cy.visit(SEC_UI_AUTH_PATH); + // Login as admin + // cy.get('input[name="username"]').type(Cypress.env('username')); + // cy.get('input[name="password"]').type(Cypress.env('password'), { log: false }); + // cy.get('button[type="submit"]').click(); + // Wait for the OpenSearch Dashboards home page to load + // cy.contains('Welcome to OpenSearch Dashboards', { timeout: 12000 }).should('be.visible'); + }); + + it('should create a new internal user', () => { + // Navigate to Security/Internal User Database section + cy.visit('/app/security-dashboards-plugin#/users'); + + // Click on 'Add internal user' button + // cy.get('button').contains('Create internal user').click(); + cy.get('a[href="#/users/create"]').click({ + force: true, + }); + // Provide username and password for the new user + cy.get('input[data-test-subj="name-text"]').type(username); + cy.get('input[data-test-subj="password"]').type(password); + cy.get('input[data-test-subj="re-enter-password"]').type(password); + + // Optionally add backend role and user attribute + // Skipping as per the instruction [No backend role] + + // Submit the form to create the user + cy.get('button').contains('Create').click(); + + // Verify that the user is created + cy.contains(username).should('exist'); + }); + // it('should create a new role with specific permissions', () => { + + it('should create a new role with specific permissions', () => { + // Add sample data if it hasn't been added yet + cy.visit(`${BASE_PATH}/app/home#/tutorial_directory/sampleData`, { + retryOnStatusCodeFailure: true, + }); + + cy.get('body').then(($body) => { + if ( + $body.find('[data-test-subj="addSampleDataSetflights"]').length > 0 + ) { + // If the element exists, click on it + cy.get('[data-test-subj="addSampleDataSetflights"]').click(); + } else { + // The element does not exist, you can log a message or take other actions + cy.get('[data-test-subj="launchSampleDataSetflights"]').click(); + } + }); + + // Navigate to Security/Roles section + cy.visit('/app/security-dashboards-plugin#/roles/create'); + + // Click on 'Add new role' button + // Set role name + cy.get('input[data-test-subj="name-text"]').type(roleName); + + // Add Cluster Permissions + cy.get('input[data-test-subj="comboBoxSearchInput"]') + .eq(0) + .type('indices:data/read/msearch') + .type('{downArrow}{enter}'); + + cy.get('#index-input-box').type( + 'opensearch_dashboards_sample_data_flights*' + ); + + // Set Document Level Security Query + cy.get('textarea').type('{{}"match": {{}"FlightDelay": true}}'); + + // Anonymize fields + cy.get('input[data-test-subj="comboBoxSearchInput"][role="textbox"]') + .eq(4) + .type('FlightNum'); + + // Add Tenant Permissions + cy.get('input[id="roles-tenant-permission-box"]') + .type(tenantName) + .type('{enter}'); + + // Save Role Definition + cy.get('button').contains('Create').click(); + + // Verify that the role is created + cy.contains(roleName).should('exist'); + + //TODO checkTenantText exist + //TODO checkClusterPermisio exist + //TODO checkIndexPermissionText exist + }); + + it('should add a new role mapping', () => { + // Navigate to Role Mappings + cy.visit( + 'http://localhost:5601/app/security-dashboards-plugin#/users/edit/' + + username + ); + + // Choose the role you created earlier + cy.get('[placeholder="Type in backend role"]').type(roleName); //Not iDeal use placeholder + + // Submit the role mapping + cy.get('button[id="submit"]').click(); + + // Optional: Verify that the role mapping was added + // This can include checking for a success message or verifying the list of role mappings + }); + + it.only('should create a new index pattern', () => { + cy.visit('http://localhost:5601/app/home?security_tenant=' + tenantName); + // Step 1: Change tenant to the newly created tenant user-icon-btn + + // cy.get('body').then(($body) => { + // if ($body.find('[data-test-subj="tenant-switch-modal"]').length == 0) { + // cy.get('[id="user-icon-btn"]').click({ force: true }); + // cy.get('button[data-test-subj="switch-tenants"]').click(); + // + // // If the element exists, click on it + // cy.get('[data-test-subj="addSampleDataSetflights"]').click(); + // } else { + // // The element does not exist, you can log a message or take other actions + // cy.log('POTATO'); + // } + // }); + + // cy.get('button[data-test-subj="switch-tenants"]').click(); + // cy.get('button[title="${tenantName}"]').click(); + // cy.get('button[data-test-subj="confirm"]').click(); + + cy.visit(`${BASE_PATH}/app/home#/tutorial_directory/sampleData`, { + retryOnStatusCodeFailure: true, + }); + + cy.get('body').then(($body) => { + if ( + $body.find('[data-test-subj="addSampleDataSetflights"]').length > 0 + ) { + // If the element exists, click on it + cy.get('[data-test-subj="addSampleDataSetflights"]').click(); + } else { + // The element does not exist, you can log a message or take other actions + cy.get('[data-test-subj="launchSampleDataSetflights"]').click(); + } + }); + + // Step 3: Navigate to Manage data to add an index pattern + cy.visit('/app/home'); + cy.get('button[aria-label="Closes this modal window"]').click(); + cy.get('a').contains('Manage').click(); // Adjust the selector as needed + + // Step 4: Add the index pattern + cy.get('[data-test-subj="indexPatterns"]').click(); + cy.get('[data-test-subj="createIndexPatternButton"]').click(); + cy.get('input[data-test-subj="createIndexPatternNameInput"]').type( + 'opensearch_dashboards_sample_data_flights*' + ); + cy.get( + 'button[data-test-subj="createIndexPatternGoToStep2Button"]' + ).click(); + + // Assuming a timestamp field needs to be selected + cy.get( + 'select[data-test-subj="createIndexPatternTimeFieldSelect"]' + ).select('timestamp'); + + cy.get('option[value="timestamp"]'); + cy.get('button[data-test-subj="createIndexPatternButton"]').click(); + + // Additional verification if needed + }); + }); +} diff --git a/cypress/integration/plugins/security/auth_spec.js b/cypress/integration/plugins/security/auth_spec.js index b2f45998f..ffe9ceedd 100644 --- a/cypress/integration/plugins/security/auth_spec.js +++ b/cypress/integration/plugins/security/auth_spec.js @@ -6,207 +6,9 @@ import { SEC_UI_AUTH_PATH, SEC_FIXTURES_BASE_PATH, - BASE_PATH, } from '../../../utils/constants'; -import '../../../utils/commands'; -import '../../../utils/dashboards/commands'; -import '../../../utils/dashboards/datasource-management-dashboards-plugin/commands'; -import '../../../utils/plugins/index-management-dashboards-plugin/commands'; -import '../../../utils/plugins/anomaly-detection-dashboards-plugin/commands'; -import '../../../utils/plugins/security/commands'; -import '../../../utils/plugins/security-dashboards-plugin/commands'; -import '../../../utils/plugins/alerting-dashboards-plugin/commands'; -import '../../../utils/plugins/ml-commons-dashboards/commands'; -import '../../../utils/plugins/security-analytics-dashboards-plugin/commands'; -import '../../../utils/plugins/notifications-dashboards/commands'; - -import 'cypress-real-events'; -import { switchTenantTo } from '../security-dashboards-plugin/switch_tenant'; - if (Cypress.env('SECURITY_ENABLED')) { - describe('OpenSearch Dashboards Security Plugin - Enhanced Sanity Tests', () => { - const username = 'newuser'; - const password = 'ew4q56a4d6as51!*asSS'; - const roleName = 'newRole'; - const tenantName = 'yourTenantName'; // Replace with your tenant name - - beforeEach(() => { - // Visit the OpenSearch Dashboards login page - // cy.visit(SEC_UI_AUTH_PATH); - // Login as admin - // cy.get('input[name="username"]').type(Cypress.env('username')); - // cy.get('input[name="password"]').type(Cypress.env('password'), { log: false }); - // cy.get('button[type="submit"]').click(); - // Wait for the OpenSearch Dashboards home page to load - // cy.contains('Welcome to OpenSearch Dashboards', { timeout: 12000 }).should('be.visible'); - }); - - it('should create a new internal user', () => { - // Navigate to Security/Internal User Database section - cy.visit('/app/security-dashboards-plugin#/users'); - - // Click on 'Add internal user' button - // cy.get('button').contains('Create internal user').click(); - cy.get('a[href="#/users/create"]').click({ - force: true, - }); - // Provide username and password for the new user - cy.get('input[data-test-subj="name-text"]').type(username); - cy.get('input[data-test-subj="password"]').type(password); - cy.get('input[data-test-subj="re-enter-password"]').type(password); - - // Optionally add backend role and user attribute - // Skipping as per the instruction [No backend role] - - // Submit the form to create the user - cy.get('button').contains('Create').click(); - - // Verify that the user is created - cy.contains(username).should('exist'); - }); - // it('should create a new role with specific permissions', () => { - - it('should create a new role with specific permissions', () => { - // Add sample data if it hasn't been added yet - cy.visit(`${BASE_PATH}/app/home#/tutorial_directory/sampleData`, { - retryOnStatusCodeFailure: true, - }); - - cy.get('body').then(($body) => { - if ( - $body.find('[data-test-subj="addSampleDataSetflights"]').length > 0 - ) { - // If the element exists, click on it - cy.get('[data-test-subj="addSampleDataSetflights"]').click(); - } else { - // The element does not exist, you can log a message or take other actions - cy.get('[data-test-subj="launchSampleDataSetflights"]').click(); - } - }); - - // Navigate to Security/Roles section - cy.visit('/app/security-dashboards-plugin#/roles/create'); - - // Click on 'Add new role' button - // Set role name - cy.get('input[data-test-subj="name-text"]').type(roleName); - - // Add Cluster Permissions - cy.get('input[data-test-subj="comboBoxSearchInput"]') - .eq(0) - .type('indices:data/read/msearch') - .type('{downArrow}{enter}'); - - cy.get('#index-input-box').type( - 'opensearch_dashboards_sample_data_flights*' - ); - - // Set Document Level Security Query - cy.get('textarea').type('{{}"match": {{}"FlightDelay": true}}'); - - // Anonymize fields - cy.get('input[data-test-subj="comboBoxSearchInput"][role="textbox"]') - .eq(4) - .type('FlightNum'); - - // Add Tenant Permissions - cy.get('input[id="roles-tenant-permission-box"]') - .type(tenantName) - .type('{enter}'); - - // Save Role Definition - cy.get('button').contains('Create').click(); - - // Verify that the role is created - cy.contains(roleName).should('exist'); - - //TODO checkTenantText exist - //TODO checkClusterPermisio exist - //TODO checkIndexPermissionText exist - }); - - it('should add a new role mapping', () => { - // Navigate to Role Mappings - cy.visit( - 'http://localhost:5601/app/security-dashboards-plugin#/users/edit/' + - username - ); - - // Choose the role you created earlier - cy.get('[placeholder="Type in backend role"]').type(roleName); //Not iDeal use placeholder - - // Submit the role mapping - cy.get('button[id="submit"]').click(); - - // Optional: Verify that the role mapping was added - // This can include checking for a success message or verifying the list of role mappings - }); - - it.only('should create a new index pattern', () => { - cy.visit('http://localhost:5601/app/home?security_tenant=' + tenantName); - // Step 1: Change tenant to the newly created tenant user-icon-btn - - // cy.get('body').then(($body) => { - // if ($body.find('[data-test-subj="tenant-switch-modal"]').length == 0) { - // cy.get('[id="user-icon-btn"]').click({ force: true }); - // cy.get('button[data-test-subj="switch-tenants"]').click(); - // - // // If the element exists, click on it - // cy.get('[data-test-subj="addSampleDataSetflights"]').click(); - // } else { - // // The element does not exist, you can log a message or take other actions - // cy.log('POTATO'); - // } - // }); - - // cy.get('button[data-test-subj="switch-tenants"]').click(); - // cy.get('button[title="${tenantName}"]').click(); - // cy.get('button[data-test-subj="confirm"]').click(); - - cy.visit(`${BASE_PATH}/app/home#/tutorial_directory/sampleData`, { - retryOnStatusCodeFailure: true, - }); - - cy.get('body').then(($body) => { - if ( - $body.find('[data-test-subj="addSampleDataSetflights"]').length > 0 - ) { - // If the element exists, click on it - cy.get('[data-test-subj="addSampleDataSetflights"]').click(); - } else { - // The element does not exist, you can log a message or take other actions - cy.get('[data-test-subj="launchSampleDataSetflights"]').click(); - } - }); - - // Step 3: Navigate to Manage data to add an index pattern - cy.visit('/app/home'); - cy.get('button[aria-label="Closes this modal window"]').click(); - cy.get('a').contains('Manage').click(); // Adjust the selector as needed - - // Step 4: Add the index pattern - cy.get('[data-test-subj="indexPatterns"]').click(); - cy.get('[data-test-subj="createIndexPatternButton"]').click(); - cy.get('input[data-test-subj="createIndexPatternNameInput"]').type( - 'opensearch_dashboards_sample_data_flights*' - ); - cy.get( - 'button[data-test-subj="createIndexPatternGoToStep2Button"]' - ).click(); - - // Assuming a timestamp field needs to be selected - cy.get( - 'select[data-test-subj="createIndexPatternTimeFieldSelect"]' - ).select('timestamp'); - - cy.get('option[value="timestamp"]'); - cy.get('button[data-test-subj="createIndexPatternButton"]').click(); - - // Additional verification if needed - }); - }); - describe('Authc and Authz page', () => { // start a server so that server responses can be mocked via fixtures // in all of the below test cases From 5299062b5206884ef42df694b681285102e4f6a2 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 30 Nov 2023 01:57:44 +0000 Subject: [PATCH 06/12] Bug Fixes Signed-off-by: Sam --- .../sanity_tests.spec.js | 115 +++++++++++------- 1 file changed, 69 insertions(+), 46 deletions(-) diff --git a/cypress/integration/plugins/security-dashboards-plugin/sanity_tests.spec.js b/cypress/integration/plugins/security-dashboards-plugin/sanity_tests.spec.js index de0c1c43a..5b61f2462 100644 --- a/cypress/integration/plugins/security-dashboards-plugin/sanity_tests.spec.js +++ b/cypress/integration/plugins/security-dashboards-plugin/sanity_tests.spec.js @@ -4,9 +4,9 @@ */ import { - SEC_UI_AUTH_PATH, - SEC_FIXTURES_BASE_PATH, BASE_PATH, + SEC_UI_TENANTS_PATH, + SEC_TENANTS_FIXTURES_PATH, } from '../../../utils/constants'; import '../../../utils/commands'; @@ -22,24 +22,59 @@ import '../../../utils/plugins/security-analytics-dashboards-plugin/commands'; import '../../../utils/plugins/notifications-dashboards/commands'; import 'cypress-real-events'; -import { switchTenantTo } from '../security-dashboards-plugin/switch_tenant'; if (Cypress.env('SECURITY_ENABLED')) { describe('OpenSearch Dashboards Security Plugin - Enhanced Sanity Tests', () => { - const username = 'newuser'; + const username = 'newuser7'; const password = 'ew4q56a4d6as51!*asSS'; - const roleName = 'newRole'; - const tenantName = 'yourTenantName'; // Replace with your tenant name - - beforeEach(() => { - // Visit the OpenSearch Dashboards login page - // cy.visit(SEC_UI_AUTH_PATH); - // Login as admin - // cy.get('input[name="username"]').type(Cypress.env('username')); - // cy.get('input[name="password"]').type(Cypress.env('password'), { log: false }); - // cy.get('button[type="submit"]').click(); - // Wait for the OpenSearch Dashboards home page to load - // cy.contains('Welcome to OpenSearch Dashboards', { timeout: 12000 }).should('be.visible'); + const roleName = 'newRole7'; + const tenantName = 'yourTenantName7'; // Replace with your tenant name + const tenantDescription = 'Test description'; + + const indexPattern = 'opensearch_dashboards_sample_data_flight'; + const documentLevelSecurityQuery = '{{}"match": {{}"FlightDelay": true}}'; + + it('should create new tenant successfully by selecting `Create tenant`', () => { + cy.visit(SEC_UI_TENANTS_PATH); + + cy.get('button[id="createTenant"]').first().click({ force: true }); + + cy.contains('button', 'Create'); + cy.contains('button', 'Cancel'); + cy.contains('.euiModalHeader__title', 'Create tenant'); + + cy.get('input[data-test-subj="name-text"]').type(tenantName, { + force: true, + }); + cy.get('input[data-test-subj="name-text"]').should( + 'have.value', + tenantName + ); + + cy.get('textarea[data-test-subj="tenant-description"]').type( + tenantDescription, + { force: true } + ); + cy.get('textarea[data-test-subj="tenant-description"]').should( + 'have.value', + tenantDescription + ); + + cy.mockTenantsAction( + SEC_TENANTS_FIXTURES_PATH + '/tenants_post_creation_response.json', + () => { + cy.get('button[id="submit"]').first().click({ force: true }); + } + ); + + cy.url().should((url) => { + expect(url).to.contain('/tenants'); + }); + + cy.contains('h3', 'Tenants'); + // should contain the new tenant that was just created + cy.contains('.euiTableCellContent', tenantName); + cy.contains('span', tenantDescription); }); it('should create a new internal user', () => { @@ -98,12 +133,17 @@ if (Cypress.env('SECURITY_ENABLED')) { .type('indices:data/read/msearch') .type('{downArrow}{enter}'); + cy.get('input[data-test-subj="comboBoxSearchInput"]') + .eq(2) + .type('indices:data/read/search*') + .type('{downArrow}{enter}'); + cy.get('#index-input-box').type( 'opensearch_dashboards_sample_data_flights*' ); // Set Document Level Security Query - cy.get('textarea').type('{{}"match": {{}"FlightDelay": true}}'); + cy.get('textarea').type(documentLevelSecurityQuery); // Anonymize fields cy.get('input[data-test-subj="comboBoxSearchInput"][role="textbox"]') @@ -129,41 +169,26 @@ if (Cypress.env('SECURITY_ENABLED')) { it('should add a new role mapping', () => { // Navigate to Role Mappings cy.visit( - 'http://localhost:5601/app/security-dashboards-plugin#/users/edit/' + - username + 'http://localhost:5601/app/security-dashboards-plugin#/roles/edit/' + + roleName + + '/mapuser' ); - // Choose the role you created earlier - cy.get('[placeholder="Type in backend role"]').type(roleName); //Not iDeal use placeholder + cy.get('div[data-test-subj="comboBoxInput"]').type(username); + cy.get('button[id="map"]').click(); - // Submit the role mapping - cy.get('button[id="submit"]').click(); + // Choose the role you created earlier + // cy.get('[placeholder="Type in backend role"]').type(roleName); //Not iDeal use placeholder + // + // // Submit the role mapping + // cy.get('button[id="submit"]').click(); // Optional: Verify that the role mapping was added // This can include checking for a success message or verifying the list of role mappings }); - it.only('should create a new index pattern', () => { + it.skip('should create a new index pattern', () => { cy.visit('http://localhost:5601/app/home?security_tenant=' + tenantName); - // Step 1: Change tenant to the newly created tenant user-icon-btn - - // cy.get('body').then(($body) => { - // if ($body.find('[data-test-subj="tenant-switch-modal"]').length == 0) { - // cy.get('[id="user-icon-btn"]').click({ force: true }); - // cy.get('button[data-test-subj="switch-tenants"]').click(); - // - // // If the element exists, click on it - // cy.get('[data-test-subj="addSampleDataSetflights"]').click(); - // } else { - // // The element does not exist, you can log a message or take other actions - // cy.log('POTATO'); - // } - // }); - - // cy.get('button[data-test-subj="switch-tenants"]').click(); - // cy.get('button[title="${tenantName}"]').click(); - // cy.get('button[data-test-subj="confirm"]').click(); - cy.visit(`${BASE_PATH}/app/home#/tutorial_directory/sampleData`, { retryOnStatusCodeFailure: true, }); @@ -189,7 +214,7 @@ if (Cypress.env('SECURITY_ENABLED')) { cy.get('[data-test-subj="indexPatterns"]').click(); cy.get('[data-test-subj="createIndexPatternButton"]').click(); cy.get('input[data-test-subj="createIndexPatternNameInput"]').type( - 'opensearch_dashboards_sample_data_flights*' + indexPattern ); cy.get( 'button[data-test-subj="createIndexPatternGoToStep2Button"]' @@ -202,8 +227,6 @@ if (Cypress.env('SECURITY_ENABLED')) { cy.get('option[value="timestamp"]'); cy.get('button[data-test-subj="createIndexPatternButton"]').click(); - - // Additional verification if needed }); }); } From 0f0e9449ea9b8022e78b57d3a54f1f3ae0a0e649 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 30 Nov 2023 15:43:14 +0000 Subject: [PATCH 07/12] Cleanup Signed-off-by: Sam --- .../sanity_tests.spec.js | 31 ++----------------- 1 file changed, 3 insertions(+), 28 deletions(-) diff --git a/cypress/integration/plugins/security-dashboards-plugin/sanity_tests.spec.js b/cypress/integration/plugins/security-dashboards-plugin/sanity_tests.spec.js index 5b61f2462..ab8bce00c 100644 --- a/cypress/integration/plugins/security-dashboards-plugin/sanity_tests.spec.js +++ b/cypress/integration/plugins/security-dashboards-plugin/sanity_tests.spec.js @@ -9,26 +9,14 @@ import { SEC_TENANTS_FIXTURES_PATH, } from '../../../utils/constants'; -import '../../../utils/commands'; -import '../../../utils/dashboards/commands'; -import '../../../utils/dashboards/datasource-management-dashboards-plugin/commands'; -import '../../../utils/plugins/index-management-dashboards-plugin/commands'; -import '../../../utils/plugins/anomaly-detection-dashboards-plugin/commands'; -import '../../../utils/plugins/security/commands'; -import '../../../utils/plugins/security-dashboards-plugin/commands'; -import '../../../utils/plugins/alerting-dashboards-plugin/commands'; -import '../../../utils/plugins/ml-commons-dashboards/commands'; -import '../../../utils/plugins/security-analytics-dashboards-plugin/commands'; -import '../../../utils/plugins/notifications-dashboards/commands'; - import 'cypress-real-events'; if (Cypress.env('SECURITY_ENABLED')) { describe('OpenSearch Dashboards Security Plugin - Enhanced Sanity Tests', () => { - const username = 'newuser7'; + const username = 'newuser'; const password = 'ew4q56a4d6as51!*asSS'; - const roleName = 'newRole7'; - const tenantName = 'yourTenantName7'; // Replace with your tenant name + const roleName = 'newRole'; + const tenantName = 'yourTenantName'; // Replace with your tenant name const tenantDescription = 'Test description'; const indexPattern = 'opensearch_dashboards_sample_data_flight'; @@ -160,10 +148,6 @@ if (Cypress.env('SECURITY_ENABLED')) { // Verify that the role is created cy.contains(roleName).should('exist'); - - //TODO checkTenantText exist - //TODO checkClusterPermisio exist - //TODO checkIndexPermissionText exist }); it('should add a new role mapping', () => { @@ -176,15 +160,6 @@ if (Cypress.env('SECURITY_ENABLED')) { cy.get('div[data-test-subj="comboBoxInput"]').type(username); cy.get('button[id="map"]').click(); - - // Choose the role you created earlier - // cy.get('[placeholder="Type in backend role"]').type(roleName); //Not iDeal use placeholder - // - // // Submit the role mapping - // cy.get('button[id="submit"]').click(); - - // Optional: Verify that the role mapping was added - // This can include checking for a success message or verifying the list of role mappings }); it.skip('should create a new index pattern', () => { From b1d4517c8774e2c2350c5b837bbd719cbe0d1483 Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 2 Dec 2023 01:55:51 +0000 Subject: [PATCH 08/12] Cleanup Signed-off-by: Sam --- .../sanity_tests.spec.js | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/cypress/integration/plugins/security-dashboards-plugin/sanity_tests.spec.js b/cypress/integration/plugins/security-dashboards-plugin/sanity_tests.spec.js index ab8bce00c..232db5a30 100644 --- a/cypress/integration/plugins/security-dashboards-plugin/sanity_tests.spec.js +++ b/cypress/integration/plugins/security-dashboards-plugin/sanity_tests.spec.js @@ -7,9 +7,12 @@ import { BASE_PATH, SEC_UI_TENANTS_PATH, SEC_TENANTS_FIXTURES_PATH, + SEC_INTERNALUSERS_FIXTURES_PATH, + SEC_UI_INTERNAL_USERS_PATH, } from '../../../utils/constants'; import 'cypress-real-events'; +import cypress from 'cypress'; if (Cypress.env('SECURITY_ENABLED')) { describe('OpenSearch Dashboards Security Plugin - Enhanced Sanity Tests', () => { @@ -22,6 +25,10 @@ if (Cypress.env('SECURITY_ENABLED')) { const indexPattern = 'opensearch_dashboards_sample_data_flight'; const documentLevelSecurityQuery = '{{}"match": {{}"FlightDelay": true}}'; + before(() => { + cy.server(); + }); + it('should create new tenant successfully by selecting `Create tenant`', () => { cy.visit(SEC_UI_TENANTS_PATH); @@ -66,6 +73,13 @@ if (Cypress.env('SECURITY_ENABLED')) { }); it('should create a new internal user', () => { + cy.mockInternalUsersAction( + SEC_INTERNALUSERS_FIXTURES_PATH + '/internalusers_info_response.json', + () => { + cy.visit(SEC_UI_INTERNAL_USERS_PATH); + } + ); + // Navigate to Security/Internal User Database section cy.visit('/app/security-dashboards-plugin#/users'); @@ -103,7 +117,6 @@ if (Cypress.env('SECURITY_ENABLED')) { // If the element exists, click on it cy.get('[data-test-subj="addSampleDataSetflights"]').click(); } else { - // The element does not exist, you can log a message or take other actions cy.get('[data-test-subj="launchSampleDataSetflights"]').click(); } }); @@ -153,7 +166,7 @@ if (Cypress.env('SECURITY_ENABLED')) { it('should add a new role mapping', () => { // Navigate to Role Mappings cy.visit( - 'http://localhost:5601/app/security-dashboards-plugin#/roles/edit/' + + '${BASE_PATH}/app/security-dashboards-plugin#/roles/edit/' + roleName + '/mapuser' ); @@ -162,8 +175,8 @@ if (Cypress.env('SECURITY_ENABLED')) { cy.get('button[id="map"]').click(); }); - it.skip('should create a new index pattern', () => { - cy.visit('http://localhost:5601/app/home?security_tenant=' + tenantName); + it('should create a new index pattern', () => { + cy.visit('${BASE_PATH}/app/home?security_tenant=' + tenantName); cy.visit(`${BASE_PATH}/app/home#/tutorial_directory/sampleData`, { retryOnStatusCodeFailure: true, }); @@ -172,10 +185,8 @@ if (Cypress.env('SECURITY_ENABLED')) { if ( $body.find('[data-test-subj="addSampleDataSetflights"]').length > 0 ) { - // If the element exists, click on it cy.get('[data-test-subj="addSampleDataSetflights"]').click(); } else { - // The element does not exist, you can log a message or take other actions cy.get('[data-test-subj="launchSampleDataSetflights"]').click(); } }); @@ -195,7 +206,6 @@ if (Cypress.env('SECURITY_ENABLED')) { 'button[data-test-subj="createIndexPatternGoToStep2Button"]' ).click(); - // Assuming a timestamp field needs to be selected cy.get( 'select[data-test-subj="createIndexPatternTimeFieldSelect"]' ).select('timestamp'); From f28dba4784891ad3ba7b0c33577700dc7e18e8fa Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 2 Dec 2023 01:55:51 +0000 Subject: [PATCH 09/12] Cleanup Signed-off-by: Sam --- .../sanity_tests.spec.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/cypress/integration/plugins/security-dashboards-plugin/sanity_tests.spec.js b/cypress/integration/plugins/security-dashboards-plugin/sanity_tests.spec.js index ab8bce00c..65b527d4f 100644 --- a/cypress/integration/plugins/security-dashboards-plugin/sanity_tests.spec.js +++ b/cypress/integration/plugins/security-dashboards-plugin/sanity_tests.spec.js @@ -9,8 +9,6 @@ import { SEC_TENANTS_FIXTURES_PATH, } from '../../../utils/constants'; -import 'cypress-real-events'; - if (Cypress.env('SECURITY_ENABLED')) { describe('OpenSearch Dashboards Security Plugin - Enhanced Sanity Tests', () => { const username = 'newuser'; @@ -67,7 +65,7 @@ if (Cypress.env('SECURITY_ENABLED')) { it('should create a new internal user', () => { // Navigate to Security/Internal User Database section - cy.visit('/app/security-dashboards-plugin#/users'); + cy.visit(`${BASE_PATH}/app/security-dashboards-plugin#/users`); // Click on 'Add internal user' button // cy.get('button').contains('Create internal user').click(); @@ -109,7 +107,7 @@ if (Cypress.env('SECURITY_ENABLED')) { }); // Navigate to Security/Roles section - cy.visit('/app/security-dashboards-plugin#/roles/create'); + cy.visit(`${BASE_PATH}/app/security-dashboards-plugin#/roles/create`); // Click on 'Add new role' button // Set role name @@ -153,9 +151,7 @@ if (Cypress.env('SECURITY_ENABLED')) { it('should add a new role mapping', () => { // Navigate to Role Mappings cy.visit( - 'http://localhost:5601/app/security-dashboards-plugin#/roles/edit/' + - roleName + - '/mapuser' + `${BASE_PATH}/app/security-dashboards-plugin#/roles/edit/${roleName}/mapuser` ); cy.get('div[data-test-subj="comboBoxInput"]').type(username); @@ -163,7 +159,7 @@ if (Cypress.env('SECURITY_ENABLED')) { }); it.skip('should create a new index pattern', () => { - cy.visit('http://localhost:5601/app/home?security_tenant=' + tenantName); + cy.visit(`${BASE_PATH}/app/home?security_tenant=${tenantName}`); cy.visit(`${BASE_PATH}/app/home#/tutorial_directory/sampleData`, { retryOnStatusCodeFailure: true, }); @@ -181,7 +177,7 @@ if (Cypress.env('SECURITY_ENABLED')) { }); // Step 3: Navigate to Manage data to add an index pattern - cy.visit('/app/home'); + cy.visit(`${BASE_PATH}/app/home`); cy.get('button[aria-label="Closes this modal window"]').click(); cy.get('a').contains('Manage').click(); // Adjust the selector as needed From 664bdc3b167b429d87dd35afa6aecba50651b5e4 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 5 Dec 2023 15:41:05 +0000 Subject: [PATCH 10/12] Refactor Signed-off-by: Sam --- .../sanity_tests.spec.js | 39 +++++++------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/cypress/integration/plugins/security-dashboards-plugin/sanity_tests.spec.js b/cypress/integration/plugins/security-dashboards-plugin/sanity_tests.spec.js index 29b3506d4..7a1a808fc 100644 --- a/cypress/integration/plugins/security-dashboards-plugin/sanity_tests.spec.js +++ b/cypress/integration/plugins/security-dashboards-plugin/sanity_tests.spec.js @@ -103,17 +103,7 @@ if (Cypress.env('SECURITY_ENABLED')) { retryOnStatusCodeFailure: true, }); - cy.get('body').then(($body) => { - if ( - $body.find('[data-test-subj="addSampleDataSetflights"]').length > 0 - ) { - // If the element exists, click on it - cy.get('[data-test-subj="addSampleDataSetflights"]').click(); - } else { - // The element does not exist, you can log a message or take other actions - cy.get('[data-test-subj="launchSampleDataSetflights"]').click(); - } - }); + createSampleFlightDataIfDoesntExist(); // Navigate to Security/Roles section cy.visit(`${BASE_PATH}/app/security-dashboards-plugin#/roles/create`); @@ -167,24 +157,13 @@ if (Cypress.env('SECURITY_ENABLED')) { cy.get('button[id="map"]').click(); }); - it.skip('should create a new index pattern', () => { + it('should create a new index pattern', () => { cy.visit(`${BASE_PATH}/app/home?security_tenant=${tenantName}`); cy.visit(`${BASE_PATH}/app/home#/tutorial_directory/sampleData`, { retryOnStatusCodeFailure: true, }); - cy.get('body').then(($body) => { - if ( - $body.find('[data-test-subj="addSampleDataSetflights"]').length > 0 - ) { - // If the element exists, click on it - cy.get('[data-test-subj="addSampleDataSetflights"]').click(); - } else { - // The element does not exist, you can log a message or take other actions - cy.get('[data-test-subj="launchSampleDataSetflights"]').click(); - } - }); - + createSampleFlightDataIfDoesntExist(); // Step 3: Navigate to Manage data to add an index pattern cy.visit(`${BASE_PATH}/app/home`); cy.get('button[aria-label="Closes this modal window"]').click(); @@ -210,3 +189,15 @@ if (Cypress.env('SECURITY_ENABLED')) { }); }); } + +function createSampleFlightDataIfDoesntExist() { + cy.get('body').then(($body) => { + if ($body.find('[data-test-subj="addSampleDataSetflights"]').length > 0) { + // If the element exists, click on it + cy.get('[data-test-subj="addSampleDataSetflights"]').click(); + } else { + // The element does not exist, you can log a message or take other actions + cy.get('[data-test-subj="launchSampleDataSetflights"]').click(); + } + }); +} From 7ac9120e2baceae20e0b196dd22803a57806418e Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 9 Jan 2024 12:24:23 +0000 Subject: [PATCH 11/12] Comment/ Extra line removal Signed-off-by: Sam --- .../plugins/security-dashboards-plugin/sanity_tests.spec.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/cypress/integration/plugins/security-dashboards-plugin/sanity_tests.spec.js b/cypress/integration/plugins/security-dashboards-plugin/sanity_tests.spec.js index 7a1a808fc..dada727f3 100644 --- a/cypress/integration/plugins/security-dashboards-plugin/sanity_tests.spec.js +++ b/cypress/integration/plugins/security-dashboards-plugin/sanity_tests.spec.js @@ -74,9 +74,6 @@ if (Cypress.env('SECURITY_ENABLED')) { SEC_INTERNALUSERS_FIXTURES_PATH + '/internalusers_info_response.json', }).as('listUserResponse'); cy.wait('@listUserResponse'); - - // Click on 'Add internal user' button - // cy.get('button').contains('Create internal user').click(); cy.get('a[href="#/users/create"]').click({ force: true, }); @@ -95,7 +92,6 @@ if (Cypress.env('SECURITY_ENABLED')) { }).as('createUserResponse'); cy.contains(username).should('exist'); }); - // it('should create a new role with specific permissions', () => { it('should create a new role with specific permissions', () => { // Add sample data if it hasn't been added yet From ff90f9df9b0684bb8af6bd4b653fa5951b44be3e Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 6 Mar 2024 19:05:22 +0100 Subject: [PATCH 12/12] Using loadSampleData command instead of custom method. Check if pattern was acually created Signed-off-by: Sam --- .../sanity_tests.spec.js | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/cypress/integration/plugins/security-dashboards-plugin/sanity_tests.spec.js b/cypress/integration/plugins/security-dashboards-plugin/sanity_tests.spec.js index dada727f3..0508665aa 100644 --- a/cypress/integration/plugins/security-dashboards-plugin/sanity_tests.spec.js +++ b/cypress/integration/plugins/security-dashboards-plugin/sanity_tests.spec.js @@ -99,8 +99,7 @@ if (Cypress.env('SECURITY_ENABLED')) { retryOnStatusCodeFailure: true, }); - createSampleFlightDataIfDoesntExist(); - + cy.loadSampleData('flights'); // Navigate to Security/Roles section cy.visit(`${BASE_PATH}/app/security-dashboards-plugin#/roles/create`); @@ -158,8 +157,7 @@ if (Cypress.env('SECURITY_ENABLED')) { cy.visit(`${BASE_PATH}/app/home#/tutorial_directory/sampleData`, { retryOnStatusCodeFailure: true, }); - - createSampleFlightDataIfDoesntExist(); + cy.loadSampleData('flights'); // Step 3: Navigate to Manage data to add an index pattern cy.visit(`${BASE_PATH}/app/home`); cy.get('button[aria-label="Closes this modal window"]').click(); @@ -182,18 +180,10 @@ if (Cypress.env('SECURITY_ENABLED')) { cy.get('option[value="timestamp"]'); cy.get('button[data-test-subj="createIndexPatternButton"]').click(); + cy.visit( + `${BASE_PATH}/app/management/opensearch-dashboards/indexPatterns/patterns` + ); + cy.contains(indexPattern); }); }); } - -function createSampleFlightDataIfDoesntExist() { - cy.get('body').then(($body) => { - if ($body.find('[data-test-subj="addSampleDataSetflights"]').length > 0) { - // If the element exists, click on it - cy.get('[data-test-subj="addSampleDataSetflights"]').click(); - } else { - // The element does not exist, you can log a message or take other actions - cy.get('[data-test-subj="launchSampleDataSetflights"]').click(); - } - }); -}