From f3f83a9aff0a947b9440776deaa3e6b8ecd27ae9 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Fri, 26 May 2023 15:05:23 -0400 Subject: [PATCH] [MD]Update cypress tests for sigV4 & serverless support (#669) (#686) Signed-off-by: Su (cherry picked from commit 9ebded51afec23c43d470f9f43377ce18674f6d3) Co-authored-by: Zhongnan Su Signed-off-by: leanne.laceybyrne@eliatra.com --- .../1_create_datasource.spec.js | 182 ++++++++++++++---- .../2_datasource_table.spec.js | 7 +- .../3_update_datasource.spec.js | 149 ++++++++++++++ .../constants.js | 8 +- 4 files changed, 303 insertions(+), 43 deletions(-) diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/datasource-management-plugin/1_create_datasource.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/datasource-management-plugin/1_create_datasource.spec.js index e0228bf28..16340acb8 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/datasource-management-plugin/1_create_datasource.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/datasource-management-plugin/1_create_datasource.spec.js @@ -6,7 +6,7 @@ import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; import { OSD_TEST_DOMAIN_ENDPOINT_URL, - OSD_INVALID_ENPOINT_URL, + OSD_INVALID_ENDPOINT_URL, } from '../../../../utils/dashboards/datasource-management-dashboards-plugin/constants'; const miscUtils = new MiscUtils(cy); @@ -19,11 +19,19 @@ const SECRET_KEY = 'secretKey'; if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { describe('Create datasources', () => { + before(() => { + // Clean up before creating new data sources for testing + cy.deleteAllDataSources(); + }); beforeEach(() => { // Visit OSD create page miscUtils.visitPage( 'app/management/opensearch-dashboards/dataSources/create' ); + + cy.intercept('POST', '/api/saved_objects/data-source').as( + 'createDataSourceRequest' + ); }); after(() => { @@ -40,13 +48,25 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { describe('Datasource can be created successfully', () => { it('with no auth and all required inputs', () => { + cy.get('[data-test-subj="createDataSourceButton"]').should( + 'be.disabled' + ); cy.get('[name="dataSourceTitle"]').type('test_noauth'); cy.get('[name="endpoint"]').type(OSD_TEST_DOMAIN_ENDPOINT_URL); cy.get('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select( 'no_auth' ); - cy.getElementByTestId('createDataSourceButton').click(); + cy.get('[data-test-subj="createDataSourceButton"]').should( + 'be.enabled' + ); + cy.get('[name="dataSourceDescription"]').type( + 'cypress test no auth data source' + ); + cy.get('[data-test-subj="createDataSourceButton"]').click(); + cy.wait('@createDataSourceRequest').then((interception) => { + expect(interception.response.statusCode).to.equal(200); + }); cy.location('pathname', { timeout: 6000 }).should( 'include', 'app/management/opensearch-dashboards/dataSources' @@ -54,6 +74,9 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { }); it('with basic auth and all required inputs', () => { + cy.get('[data-test-subj="createDataSourceButton"]').should( + 'be.disabled' + ); cy.get('[name="dataSourceTitle"]').type('test_auth'); cy.get('[name="endpoint"]').type(OSD_TEST_DOMAIN_ENDPOINT_URL); cy.get('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select( @@ -65,16 +88,27 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { cy.get('[data-test-subj="createDataSourceFormPasswordField"]').type( password ); - cy.getElementByTestId('createDataSourceButton').click(); - + cy.get('[data-test-subj="createDataSourceButton"]').should( + 'be.enabled' + ); + cy.get('[name="dataSourceDescription"]').type( + 'cypress test basic auth data source' + ); + cy.get('[data-test-subj="createDataSourceButton"]').click(); + cy.wait('@createDataSourceRequest').then((interception) => { + expect(interception.response.statusCode).to.equal(200); + }); cy.location('pathname', { timeout: 6000 }).should( 'include', 'app/management/opensearch-dashboards/dataSources' ); }); - it('with sigV4 and all required inputs', () => { - cy.get('[name="dataSourceTitle"]').type('test_sigv4'); + it('with sigV4 and all required inputs to connect to OpenSearch Service', () => { + cy.get('[data-test-subj="createDataSourceButton"]').should( + 'be.disabled' + ); + cy.get('[name="dataSourceTitle"]').type('test_sigv4_es'); cy.get('[name="endpoint"]').type(OSD_TEST_DOMAIN_ENDPOINT_URL); cy.get('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select( 'sigv4' @@ -82,14 +116,26 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { cy.get('[data-test-subj="createDataSourceFormRegionField"]').type( REGION ); + cy.get( + '[data-test-subj="createDataSourceFormSigV4ServiceTypeSelect"]' + ).select('es'); cy.get('[data-test-subj="createDataSourceFormAccessKeyField"]').type( ACCESS_KEY ); cy.get('[data-test-subj="createDataSourceFormSecretKeyField"]').type( SECRET_KEY ); + cy.get('[data-test-subj="createDataSourceButton"]').should( + 'be.enabled' + ); + cy.get('[name="dataSourceDescription"]').type( + 'cypress test sigV4 data source' + ); - cy.getElementByTestId('createDataSourceButton').click(); + cy.get('[data-test-subj="createDataSourceButton"]').click(); + cy.wait('@createDataSourceRequest').then((interception) => { + expect(interception.response.statusCode).to.equal(200); + }); cy.location('pathname', { timeout: 6000 }).should( 'include', @@ -97,39 +143,38 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { ); }); - it('with no auth and all inputs', () => { - cy.get('[name="dataSourceTitle"]').type('test_noauth_with_all_Inputs'); - cy.get('[name="dataSourceDescription"]').type( - 'test if can create datasource with no auth successfully' + it('with sigV4 and all required inputs to connect to OpenSearch Serverless Service', () => { + cy.get('[data-test-subj="createDataSourceButton"]').should( + 'be.disabled' ); + cy.get('[name="dataSourceTitle"]').type('test_sigv4_aoss'); cy.get('[name="endpoint"]').type(OSD_TEST_DOMAIN_ENDPOINT_URL); cy.get('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select( - 'no_auth' + 'sigv4' ); - cy.getElementByTestId('createDataSourceButton').click(); - - cy.location('pathname', { timeout: 6000 }).should( - 'include', - 'app/management/opensearch-dashboards/dataSources' + cy.get('[data-test-subj="createDataSourceFormRegionField"]').type( + REGION ); - }); - - it('with basic auth and all inputs', () => { - cy.get('[name="dataSourceTitle"]').type('test_auth_with_all_Inputs'); - cy.get('[name="dataSourceDescription"]').type( - 'test if can create datasource with basic auth successfully' + cy.get( + '[data-test-subj="createDataSourceFormSigV4ServiceTypeSelect"]' + ).select('aoss'); + cy.get('[data-test-subj="createDataSourceFormAccessKeyField"]').type( + ACCESS_KEY ); - cy.get('[name="endpoint"]').type(OSD_TEST_DOMAIN_ENDPOINT_URL); - cy.get('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select( - 'username_password' + cy.get('[data-test-subj="createDataSourceFormSecretKeyField"]').type( + SECRET_KEY ); - cy.get('[data-test-subj="createDataSourceFormUsernameField"]').type( - username + cy.get('[data-test-subj="createDataSourceButton"]').should( + 'be.enabled' ); - cy.get('[data-test-subj="createDataSourceFormPasswordField"]').type( - password + cy.get('[name="dataSourceDescription"]').type( + 'cypress test sigV4 data source (Serverless)' ); - cy.getElementByTestId('createDataSourceButton').click(); + + cy.get('[data-test-subj="createDataSourceButton"]').click(); + cy.wait('@createDataSourceRequest').then((interception) => { + expect(interception.response.statusCode).to.equal(200); + }); cy.location('pathname', { timeout: 6000 }).should( 'include', @@ -189,7 +234,7 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { }); it('validate that endpoint field cannot use invalid format of URL', () => { - cy.get('[name="endpoint"]').type(OSD_INVALID_ENPOINT_URL).blur(); + cy.get('[name="endpoint"]').type(OSD_INVALID_ENDPOINT_URL).blur(); cy.get('input[name="endpoint"]:invalid').should('have.length', 1); }); @@ -269,33 +314,92 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { }); }); - describe('Create datasource button', () => { - it('validate if create data source connection button is disabled when first visit this page', () => { + describe('SigV4 AuthType: fields validation', () => { + it('validate that region is a required field', () => { + cy.get('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select( + 'sigv4' + ); + cy.get('[data-test-subj="createDataSourceFormRegionField"]') + .focus() + .blur(); + cy.get( + 'input[data-test-subj="createDataSourceFormRegionField"]:invalid' + ).should('have.length', 1); + }); + + it('validate that accessKey is a required field', () => { + cy.get('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select( + 'sigv4' + ); + cy.get('[data-test-subj="createDataSourceFormAccessKeyField"]') + .focus() + .blur(); + cy.get( + 'input[data-test-subj="createDataSourceFormAccessKeyField"]:invalid' + ).should('have.length', 1); + }); + + it('validate that secretKey is a required field', () => { + cy.get('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select( + 'sigv4' + ); + cy.get('[data-test-subj="createDataSourceFormSecretKeyField"]') + .focus() + .blur(); + cy.get( + 'input[data-test-subj="createDataSourceFormSecretKeyField"]:invalid' + ).should('have.length', 1); + }); + + it('validate that serviceName is a required field, and with default option rendered', () => { + cy.get('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select( + 'sigv4' + ); + cy.get( + '[data-test-subj="createDataSourceFormSigV4ServiceTypeSelect"]' + ).should('have.value', 'es'); + }); + }); + + describe('Cancel button and create data source button', () => { + it('validate if create data source button is disabled when first visit this page', () => { miscUtils.visitPage( 'app/management/opensearch-dashboards/dataSources/create' ); - cy.getElementByTestId('createDataSourceButton').should('be.disabled'); + cy.get('[data-test-subj="createDataSourceButton"]').should( + 'be.disabled' + ); }); - it('validate if create data source connection button is disabled when there is any field error', () => { + it('validate if create data source button is disabled when there is any field error', () => { cy.get('[name="dataSourceTitle"]').focus().blur(); cy.get('input[name="dataSourceTitle"]:invalid').should( 'have.length', 1 ); - cy.getElementByTestId('createDataSourceButton').should('be.disabled'); + cy.get('[data-test-subj="createDataSourceButton"]').should( + 'be.disabled' + ); }); - it('validate if create data source connection button is not disabled only if there is no any field error', () => { + it('validate if create data source button is not disabled only if there is no any field error', () => { cy.get('[name="dataSourceTitle"]').type('test_create_button'); cy.get('[name="endpoint"]').type(OSD_TEST_DOMAIN_ENDPOINT_URL); cy.get('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select( 'no_auth' ); - cy.getElementByTestId('createDataSourceButton').should( + cy.get('[data-test-subj="createDataSourceButton"]').should( 'not.be.disabled' ); }); + + it('cancel button should redirect to datasource listing page', () => { + cy.get('[data-test-subj="cancelCreateDataSourceButton"]').click(); + cy.location('pathname', { timeout: 6000 }).should( + 'include', + 'app/management/opensearch-dashboards/dataSources' + ); + }); }); }); } diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/datasource-management-plugin/2_datasource_table.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/datasource-management-plugin/2_datasource_table.spec.js index aec4e6deb..1ad8ecdcd 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/datasource-management-plugin/2_datasource_table.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/datasource-management-plugin/2_datasource_table.spec.js @@ -3,7 +3,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { TIMEOUT_OPTS } from '../../../../utils/dashboards/datasource-management-dashboards-plugin/constants'; +import { + TIMEOUT_OPTS, + OSD_TEST_DOMAIN_ENDPOINT_URL, +} from '../../../../utils/dashboards/datasource-management-dashboards-plugin/constants'; const searchFieldIdentifier = 'input[type="search"]'; const tableHeadIdentifier = 'thead > tr > th'; @@ -49,7 +52,7 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { attributes: { title: `ds_${char}`, description: `test ds_description_${char}`, - endpoint: `https://dummy${char}`, + endpoint: `${OSD_TEST_DOMAIN_ENDPOINT_URL}/${char}`, auth: { type: i % 2 ? 'username_password' : 'no_auth', }, diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/datasource-management-plugin/3_update_datasource.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/datasource-management-plugin/3_update_datasource.spec.js index d37e6a22f..ba5a84d34 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/datasource-management-plugin/3_update_datasource.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/datasource-management-plugin/3_update_datasource.spec.js @@ -599,6 +599,155 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { }); }); + describe(`Updating current datasource auth type from "no auth" to "SigV4"`, () => { + it('should change credential to "SigV4" & render only related fields', () => { + // verify current auth type is "no auth" + cy.get('[data-test-subj="editDataSourceSelectAuthType"]').should( + 'have.value', + 'no_auth' + ); + cy.get('[data-test-subj="editDataSourceSelectAuthType"]').select( + 'sigv4' + ); + + // username & password fields should be hidden + cy.get('input[name="datasourceUsername"]').should('not.exist'); + cy.get(passwordFieldIdentifier).should('not.exist'); + cy.getElementByTestId('editDatasourceUpdatePasswordBtn').should( + 'not.exist' + ); + + // SigV4 related fields should be visible + cy.getElementByTestId('editDataSourceFormRegionField').should('exist'); + cy.getElementByTestId( + 'editDataSourceFormSigV4ServiceTypeSelect' + ).should('have.value', 'es'); + cy.getElementByTestId('editDataSourceFormAccessKeyField').should( + 'exist' + ); + cy.getElementByTestId('editDataSourceFormSecretKeyField').should( + 'exist' + ); + }); + + it('should make sure that region field is required', () => { + cy.getElementByTestId('editDataSourceFormRegionField').should( + 'not.have.value' + ); + typeInInputFieldAndBlur( + '', + '', + '[data-test-subj="editDataSourceFormRegionField"]' + ); + cy.get( + 'input[data-test-subj="editDataSourceFormRegionField"]:invalid' + ).should('have.length', 1); + cy.getElementByTestId('datasource-edit-saveButton').should( + 'be.disabled' + ); + }); + it('should make sure that access key field is required', () => { + cy.getElementByTestId('editDataSourceFormAccessKeyField').should( + 'not.have.value' + ); + /* Required */ + typeInInputFieldAndBlur( + '', + '', + '[data-test-subj="editDataSourceFormAccessKeyField"]' + ); + cy.get( + 'input[data-test-subj="editDataSourceFormAccessKeyField"]:invalid' + ).should('have.length', 1); + cy.getElementByTestId('datasource-edit-saveButton').should( + 'be.disabled' + ); + }); + it('should make sure that secret key field is required', () => { + cy.getElementByTestId('editDataSourceFormSecretKeyField').should( + 'not.have.value' + ); + /* Required */ + typeInInputFieldAndBlur( + '', + '', + '[data-test-subj="editDataSourceFormSecretKeyField"]' + ); + cy.get( + 'input[data-test-subj="editDataSourceFormSecretKeyField"]:invalid' + ).should('have.length', 1); + cy.getElementByTestId('datasource-edit-saveButton').should( + 'be.disabled' + ); + }); + }); + + describe('bottom bar: Save Changes -> "Change Credential Type to sigv4"', () => { + it('should change credential to "SigV4" & save changes with valid form', () => { + // credential: SigV4 + cy.get('[data-test-subj="editDataSourceSelectAuthType"]').select( + 'sigv4' + ); + // set region + typeInInputFieldAndBlur( + '', + DS_JSON_UNIQUE_VALUES.attributes.auth.credentials.region, + '[data-test-subj="editDataSourceFormRegionField"]' + ); + // set access key + typeInInputFieldAndBlur( + '', + DS_JSON_UNIQUE_VALUES.attributes.auth.credentials.accessKey, + '[data-test-subj="editDataSourceFormAccessKeyField"]' + ); + + // set secret key + typeInInputFieldAndBlur( + '', + DS_JSON_UNIQUE_VALUES.attributes.auth.credentials.secretKey, + '[data-test-subj="editDataSourceFormSecretKeyField"]' + ); + + // set service type + cy.getElementByTestId( + 'editDataSourceFormSigV4ServiceTypeSelect' + ).select(DS_JSON_UNIQUE_VALUES.attributes.auth.credentials.service); + + cy.getElementByTestId('datasource-edit-saveButton') + .should('be.enabled') + .click(); + cy.getElementByTestId( + 'datasource-edit-saveButton', + TIMEOUT_OPTS + ).should('not.exist'); + }); + it('should verify that changes were updated successfully', () => { + cy.get('[data-test-subj="editDataSourceSelectAuthType"]').should( + 'have.value', + 'sigv4' + ); + cy.getElementByTestId('editDataSourceFormRegionField').should( + 'have.value', + DS_JSON_UNIQUE_VALUES.attributes.auth.credentials.region + ); + cy.getElementByTestId( + 'editDataSourceFormSigV4ServiceTypeSelect' + ).should( + 'have.value', + DS_JSON_UNIQUE_VALUES.attributes.auth.credentials.service + ); + cy.getElementByTestId('editDataSourceFormAccessKeyField').should( + 'be.disabled' + ); + cy.getElementByTestId('editDataSourceFormSecretKeyField').should( + 'be.disabled' + ); + cy.getElementByTestId('editDatasourceUpdateAwsCredentialBtn').should( + 'exist' + ); + }); + }); + describe('delete datasource', () => { it('should open delete confirmation modal on click of trash icon', () => { cy.getElementByTestId('editDatasourceDeleteIcon') diff --git a/cypress/utils/dashboards/datasource-management-dashboards-plugin/constants.js b/cypress/utils/dashboards/datasource-management-dashboards-plugin/constants.js index 1c607d0b5..9d13a0a7c 100644 --- a/cypress/utils/dashboards/datasource-management-dashboards-plugin/constants.js +++ b/cypress/utils/dashboards/datasource-management-dashboards-plugin/constants.js @@ -4,8 +4,8 @@ */ export const DS_API_PREFIX = '/api/saved_objects'; -export const OSD_TEST_DOMAIN_ENDPOINT_URL = 'https://test'; -export const OSD_INVALID_ENPOINT_URL = 'test'; +export const OSD_TEST_DOMAIN_ENDPOINT_URL = 'https://opensearch.org'; +export const OSD_INVALID_ENDPOINT_URL = 'test'; export const DS_API = { DATA_SOURCES_LISTING: `${DS_API_PREFIX}/_find?fields=id&fields=description&fields=title&per_page=10000&type=data-source`, CREATE_DATA_SOURCE: `${DS_API_PREFIX}/data-source`, @@ -49,6 +49,10 @@ export const DS_JSON_UNIQUE_VALUES = { credentials: { username: 'a', password: 'a', + region: 'us-east-1', + accessKey: 'a', + secretKey: 'a', + service: 'aoss', }, }, },