Skip to content

Commit

Permalink
[MD]Update cypress tests for sigV4 & serverless support (#669)
Browse files Browse the repository at this point in the history
Signed-off-by: Su <[email protected]>
(cherry picked from commit 9ebded5)
  • Loading branch information
zhongnansu authored and github-actions[bot] committed May 26, 2023
1 parent 8e9a58a commit 5824f7c
Show file tree
Hide file tree
Showing 4 changed files with 303 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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(() => {
Expand All @@ -40,20 +48,35 @@ 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'
);
});

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(
Expand All @@ -65,71 +88,93 @@ 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'
);
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',
'app/management/opensearch-dashboards/dataSources'
);
});

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',
Expand Down Expand Up @@ -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);
});

Expand Down Expand Up @@ -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'
);
});
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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',
},
Expand Down
Loading

0 comments on commit 5824f7c

Please sign in to comment.