diff --git a/.eslintrc.js b/.eslintrc.js index 79beb330d3ba..fd1f136af61e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -756,5 +756,12 @@ module.exports = { ], }, }, + { + files: ['cypress/**/*.js'], + rules: { + 'import/no-unresolved': 'off', + 'no-undef': 'off', + }, + }, ], }; diff --git a/.gitignore b/.gitignore index e595410ae9ac..8f252da0826f 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ trash /built_assets target /build +/bwc_tmp .jruby .idea *.iml diff --git a/TESTING.md b/TESTING.md index c07ced980abf..9bd59c54a3d9 100644 --- a/TESTING.md +++ b/TESTING.md @@ -48,7 +48,20 @@ To debug functional tests: Say that you would want to debug a test in CI group 1, you can run the following command in your environment: `node --debug-brk --inspect scripts/functional_tests.js --config test/functional/config.js --include ciGroup1 --debug` -This will print of an address, to which you could open your chrome browser on your instance and navigate to `chrome://inspect/#devices` and inspect the functional test runner `scripts/functional_tests.js`. +This will print off an address, to which you could open your chrome browser on your instance and navigate to `chrome://inspect/#devices` and inspect the functional test runner `scripts/functional_tests.js`. + +### Backwards Compatibility tests +To run all the backwards compatibility tests on OpenSearch Dashboards without security: + +`yarn test:bwc -o [test path to opensearch.tar.gz] -d [test path to opensearch-dashboards.tar.gz]` + +To run all the backwards compatibility tests on OpenSearch Dashboards with security, pass the security parameter to the test: + +`yarn test:bwc -o [test path to opensearch.tar.gz] -d [test path to opensearch-dashboards.tar.gz] -s true` + +To run specific versions' backwards compatibility tests, pass the versions to the test: + +`yarn test:bwc -o [test path to opensearch.tar.gz] -d [test path to opensearch-dashboards.tar.gz] -v "[test versions]"` ### Additional checks Make sure you run lint checker before submitting a pull request. To run lint checker: diff --git a/bwctest.sh b/bwctest.sh old mode 100644 new mode 100755 index 3bf9b3527fbd..24aae816767a --- a/bwctest.sh +++ b/bwctest.sh @@ -2,6 +2,9 @@ set -e +# TODO: Update to include all known BWC of data +DEFAULT_VERSIONS="osd-1.1.0" + function usage() { echo "" echo "This script is used to run bwc tests on a remote OpenSearch/Dashboards cluster." @@ -9,35 +12,42 @@ function usage() { echo "Usage: $0 [args]" echo "" echo "Required arguments:" - echo "None" + echo -e "-d DASHBOARDS\t, Specify the url of the build/dist of OpenSearch Dashboards" echo "" echo "Optional arguments:" - echo -e "-a BIND_ADDRESS\t, defaults to localhost | 127.0.0.1, can be changed to any IP or domain name for the cluster location." + echo -e "-o OPENSEARCH\t, Specify the url of the build/dist of OpenSearch" + echo -e "-b BIND_ADDRESS\t, defaults to localhost | 127.0.0.1, can be changed to any IP or domain name for the cluster location." echo -e "-p BIND_PORT\t, defaults to 9200 or 5601 depends on OpenSearch or Dashboards, can be changed to any port for the cluster location." - echo -e "-b BUNDLED_OSD\t(true | false), defaults to true. Specify the usage of bundled Dashboards or not." + echo -e "-s SECURITY_ENABLED\t(true | false), defaults to true. Specify the OpenSearch/Dashboards have security enabled or not." echo -e "-c CREDENTIAL\t(usename:password), no defaults, effective when SECURITY_ENABLED=true." echo -e "-h\tPrint this message." echo "--------------------------------------------------------------------------" } -while getopts ":ha:p:b:c:" arg; do +while getopts ":h:b:p:s:c:o:d:" arg; do case $arg in h) usage exit 1 ;; - a) + b) BIND_ADDRESS=$OPTARG ;; p) BIND_PORT=$OPTARG ;; - b) - BUNDLED_OSD=$OPTARG + s) + SECURITY_ENABLED=$OPTARG ;; c) CREDENTIAL=$OPTARG ;; + o) + OPENSEARCH=$OPTARG + ;; + d) + DASHBOARDS=$OPTARG + ;; :) echo "-${OPTARG} requires an argument" usage @@ -50,50 +60,26 @@ while getopts ":ha:p:b:c:" arg; do esac done +[ -z "$BIND_ADDRESS" ] && BIND_ADDRESS="localhost" +[ -z "$BIND_PORT" ] && BIND_PORT="5601" +[ -z "$SECURITY_ENABLED" ] && SECURITY_ENABLED="false" +[ -z "$CREDENTIAL" ] && CREDENTIAL="admin:admin" -if [ -z "$BIND_ADDRESS" ] -then - BIND_ADDRESS="localhost" -fi - -if [ -z "$BIND_PORT" ] -then - BIND_PORT="5601" -fi - -if [ -z "$BUNDLED_OSD" ] -then - BUNDLED_OSD="true" -fi - -if [ -z "$CREDENTIAL" ] -then - CREDENTIAL="admin:admin" - USERNAME=`echo $CREDENTIAL | awk -F ':' '{print $1}'` - PASSWORD=`echo $CREDENTIAL | awk -F ':' '{print $2}'` -fi - -cwd=$(pwd) -dir="bwc-tmp" -if [ -d "$dir" ]; then - rm -rf "$dir" - echo "bwc-tmp exists and needs to be removed" -fi - -mkdir "$dir" -git clone https://github.com/opensearch-project/opensearch-dashboards-functional-test "$dir" -rm -rf "$dir/cypress" -cp -r cypress "$dir" -cd "$dir" - -npm install +# If no OpenSearch build was passed then this constructs the version +if [ -z "$OPENSEARCH" ]; then + IFS='/' read -ra SLASH_ARR <<< "$DASHBOARDS" + # Expected to be opensearch-x.y.z-platform-arch.tar.gz + TARBALL="${SLASH_ARR[12]}" + IFS='-' read -ra DASH_ARR <<< "$TARBALL" + # Expected to be arch.tar.gz + DOTS="${DASH_ARR[4]}" + IFS='.' read -ra DOTS_ARR <<< "$DOTS" + + VERSION="${DASH_ARR[2]}" + PLATFORM="${DASH_ARR[3]}" + ARCH="${DOTS_ARR[0]}" -if [ $BUNDLED_OSD = "true" ] -then - echo "run security enabled tests" - npx cypress run --spec "$cwd/bwc-tmp/cypress/integration/bundled-osd/*.js" -else - npx cypress run --spec "$cwd/bwc-tmp/cypress/integration/osd/*.js" + OPENSEARCH="https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/$VERSION/latest/$PLATFORM/$ARCH/dist/opensearch/opensearch-$VERSION-$PLATFORM-$ARCH.tar.gz" fi -rm -rf "$cwd/$dir" \ No newline at end of file +./scripts/bwctest_osd.sh -b $BIND_ADDRESS -p $BIND_PORT -s $SECURITY_ENABLED -c $CREDENTIAL -o $OPENSEARCH -d $DASHBOARDS -v $DEFAULT_VERSIONS diff --git a/cypress/integration/with-security/check_advanced_settings.js b/cypress/integration/with-security/check_advanced_settings.js new file mode 100644 index 000000000000..502ee150a33f --- /dev/null +++ b/cypress/integration/with-security/check_advanced_settings.js @@ -0,0 +1,41 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { + MiscUtils, + LoginPage, +} from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; + +const miscUtils = new MiscUtils(cy); +const loginPage = new LoginPage(cy); + +describe('verify the advanced settings are saved', () => { + beforeEach(() => { + miscUtils.visitPage('app/management/opensearch-dashboards/settings'); + loginPage.enterUserName('admin'); + loginPage.enterPassword('admin'); + loginPage.submit(); + }); + + it('the dark mode is on', () => { + cy.get('[data-test-subj="advancedSetting-editField-theme:darkMode"]') + .invoke('attr', 'aria-checked') + .should('eq', 'true'); + }); + + it('the Timeline default columns field is set to 4', () => { + cy.get('[data-test-subj="advancedSetting-editField-timeline:default_columns"]').should( + 'have.value', + 4 + ); + }); + + it('the Timeline Maximum buckets field is set to 4', () => { + cy.get('[data-test-subj="advancedSetting-editField-timeline:max_buckets"]').should( + 'have.value', + 4 + ); + }); +}); diff --git a/cypress/integration/with-security/check_default_page.js b/cypress/integration/with-security/check_default_page.js new file mode 100644 index 000000000000..43a1c059ed9b --- /dev/null +++ b/cypress/integration/with-security/check_default_page.js @@ -0,0 +1,25 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { + MiscUtils, + LoginPage, +} from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; + +const miscUtils = new MiscUtils(cy); +const loginPage = new LoginPage(cy); + +describe('verify default landing page work for bwc', () => { + beforeEach(() => { + miscUtils.visitPage(''); + loginPage.enterUserName('admin'); + loginPage.enterPassword('admin'); + loginPage.submit(); + }); + + it('the overview page is set as the default landing page', () => { + cy.url().should('include', '/app/opensearch_dashboards_overview#/'); + }); +}); diff --git a/cypress/integration/with-security/check_filter_and_query.js b/cypress/integration/with-security/check_filter_and_query.js new file mode 100644 index 000000000000..0055e5c078ed --- /dev/null +++ b/cypress/integration/with-security/check_filter_and_query.js @@ -0,0 +1,82 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { + MiscUtils, + CommonUI, + LoginPage, +} from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; + +const miscUtils = new MiscUtils(cy); +const commonUI = new CommonUI(cy); +const loginPage = new LoginPage(cy); + +describe('check dashboards filter and query', () => { + beforeEach(() => { + miscUtils.visitPage('app/dashboards#'); + loginPage.enterUserName('admin'); + loginPage.enterPassword('admin'); + loginPage.submit(); + }); + + afterEach(() => { + cy.clearCookies(); + }); + + it('tenant-switch-modal page should show and be clicked', () => { + cy.get('[data-test-subj="tenant-switch-modal"]'); + cy.get('[data-test-subj="confirm"]').click(); + }); + + describe('osx filter and query should work in [Logs] Web Traffic dashboards', () => { + beforeEach(() => { + cy.get('[data-test-subj="dashboardListingTitleLink-[Logs]-Web-Traffic"]').click(); + cy.get('[data-test-subj="breadcrumb last"]') + .invoke('attr', 'title') + .should('eq', '[Logs] Web Traffic'); + }); + + it('osx filter and query should exist and be named correctly', () => { + cy.get('[data-test-subj="saved-query-management-popover-button"]').click(); + cy.get('[data-test-subj="saved-query-management-popover"]') + .find('[class="osdSavedQueryListItem__labelText"]') + .should('have.text', 'test-query') + .click(); + cy.get('[data-test-subj="queryInput"]').should('have.text', 'resp=200'); + cy.get( + '[data-test-subj="filter filter-enabled filter-key-machine.os filter-value-osx filter-unpinned "]' + ) + .should('have.text', 'osx filter') + .click(); + cy.get('[data-test-subj="editFilter"]').click(); + cy.get('[data-test-subj="filterFieldSuggestionList"]') + .find('[data-test-subj="comboBoxInput"]') + .should('have.text', 'machine.os'); + cy.get('[data-test-subj="filterOperatorList"]') + .find('[data-test-subj="comboBoxInput"]') + .should('have.text', 'is'); + cy.get('[data-test-subj="filterParams"]').find('input').should('have.value', 'osx'); + }); + + it('osx filter and query should function correctly', () => { + cy.get('[data-test-subj="saved-query-management-popover-button"]').click(); + cy.get('[data-test-subj="saved-query-management-popover"]') + .find('[class="osdSavedQueryListItem__labelText"]') + .should('have.text', 'test-query') + .click(); + commonUI.setDateRange('Dec 1, 2021 @ 00:00:00.000', 'Jan 1, 2021 @ 00:00:00.000'); + + //[Logs] vistor chart should show osx 100% + cy.get('[data-title="[Logs] Visitors by OS"]') + .find('[class="label"]') + .should('have.text', 'osx (100%)'); + + //[Logs] Response chart should show 200 label + cy.get('[data-title="[Logs] Response Codes Over Time + Annotations"]') + .find('[title="200"]') + .should('have.text', '200'); + }); + }); +}); diff --git a/cypress/integration/with-security/check_loaded_data.js b/cypress/integration/with-security/check_loaded_data.js new file mode 100644 index 000000000000..cd173e4a90ba --- /dev/null +++ b/cypress/integration/with-security/check_loaded_data.js @@ -0,0 +1,102 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { + MiscUtils, + CommonUI, + LoginPage, +} from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; + +const miscUtils = new MiscUtils(cy); +const commonUI = new CommonUI(cy); +const loginPage = new LoginPage(cy); + +describe('check previously loaded data', () => { + beforeEach(() => { + miscUtils.visitPage('app/dashboards#'); + loginPage.enterUserName('admin'); + loginPage.enterPassword('admin'); + loginPage.submit(); + }); + + afterEach(() => { + cy.clearCookies(); + }); + + it('previous loaded data should exist in dashboards', () => { + const items = cy.get('[data-test-subj="itemsInMemTable"]'); + + items + .get('[data-test-subj="dashboardListingTitleLink-[Flights]-Global-Flight-Dashboard"]') + .should('have.text', '[Flights] Global Flight Dashboard'); + + items + .get('[data-test-subj="dashboardListingTitleLink-[Logs]-Web-Traffic"]') + .should('have.text', '[Logs] Web Traffic'); + + items + .get('[data-test-subj="dashboardListingTitleLink-[eCommerce]-Revenue-Dashboard"]') + .should('have.text', '[eCommerce] Revenue Dashboard'); + }); + + describe('Check Global Flight Dashboard', () => { + beforeEach(() => { + cy.get('[data-test-subj="itemsInMemTable"]') + .get('[data-test-subj="dashboardListingTitleLink-[Flights]-Global-Flight-Dashboard"]') + .click(); + commonUI.removeAllFilters(); + commonUI.setDateRange('Dec 1, 2021 @ 00:00:00.000', 'Nov 1, 2021 @ 00:00:00.000'); + }); + + it('Global Flight Dashboard is loaded and funtions correctly', () => { + cy.get('[data-test-subj="breadcrumb last"]').should( + 'have.text', + '[Flights] Global Flight Dashboard' + ); + cy.get('[data-title="[Flights] Total Flights"]').should('exist'); + cy.get('[data-title="[Flights] Average Ticket Price"]').should('exist'); + + commonUI.addFilterRetrySelection('FlightDelayType', 'is not', 'No Delay'); + const types = cy.get('[data-title="[Flights] Delay Type"]'); + types.find('[data-label="Weather Delay"]').should('exist'); + types.find('[data-label="No Delay"]').should('not.exist'); + commonUI.removeFilter('FlightDelayType'); + + commonUI.addFilterRetrySelection('Carrier', 'is', 'Logstash Airways'); + cy.get('[data-title="[Flights] Airline Carrier"]') + .find('[class="label-text"]') + .should('have.text', 'Logstash Airways (100%)'); + }); + }); + + describe('Check eCommerce Revenue Dashboard', () => { + beforeEach(() => { + cy.get('[data-test-subj="itemsInMemTable"]') + .get('[data-test-subj="dashboardListingTitleLink-[eCommerce]-Revenue-Dashboard"]') + .click(); + commonUI.removeAllFilters(); + commonUI.setDateRange('Nov 1, 2021 @ 00:00:00.000', 'Nov 1, 2016 @ 00:00:00.000'); + }); + + it('eCommerce Revenue Dashboard is loaded and functions correctly', () => { + cy.get('[data-test-subj="breadcrumb last"]').should( + 'have.text', + '[eCommerce] Revenue Dashboard' + ); + cy.get('[data-title="[eCommerce] Average Sales Price"]').should('exist'); + cy.get('[data-title="[eCommerce] Average Sold Quantity"]').should('exist'); + + commonUI.addFilterRetrySelection('customer_gender', 'is', 'FEMALE'); + cy.get('[data-title="[eCommerce] Sales by Gender"]') + .find('[class="label-text"]') + .should('have.text', 'FEMALE (100%)'); + + commonUI.addFilterRetrySelection('category', 'is not', "Women's Clothing"); + const category = cy.get('[data-title="[eCommerce] Sales by Category"]'); + category.find('[data-label="Men\'s Clothing"]').should('exist'); + category.find('[data-label="Women\'s Clothing"]').should('not.exist'); + }); + }); +}); diff --git a/cypress/integration/with-security/check_timeline.js b/cypress/integration/with-security/check_timeline.js new file mode 100644 index 000000000000..2cd6401edc13 --- /dev/null +++ b/cypress/integration/with-security/check_timeline.js @@ -0,0 +1,133 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { + MiscUtils, + LoginPage, +} from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; + +const miscUtils = new MiscUtils(cy); +const loginPage = new LoginPage(cy); + +describe('check timeline visualization', () => { + beforeEach(() => { + miscUtils.visitPage('app/visualize#'); + loginPage.enterUserName('admin'); + loginPage.enterPassword('admin'); + loginPage.submit(); + }); + + afterEach(() => { + cy.clearCookies(); + }); + + it('tenant-switch-modal page should show and be clicked', () => { + cy.get('[data-test-subj="tenant-switch-modal"]'); + cy.get('[data-test-subj="confirm"]').click(); + }); + + it('timeline visualizations should be saved and named correctly', () => { + cy.get('[data-test-subj="visualizationLandingPage"]') + .find('[class="euiFormControlLayout__childrenWrapper"]') + .type('timeline'); + cy.get('[data-test-subj="visListingTitleLink-test-timeline"]') + .should('have.text', 'test-timeline') + .click(); + cy.get('[class="view-line"]').contains('.es(*)'); + }); + + describe('timeline visualizations should work properly', () => { + beforeEach(() => { + cy.get('[data-test-subj="visualizationLandingPage"]') + .find('[data-test-subj="newItemButton"]') + .click(); + cy.get('[data-test-subj="visType-timelion"]').click(); + }); + + it('.es(*, kibana1=true) should report search error', () => { + cy.get('[class="view-line"]').type('{selectall}{backspace}, kibana1=true)'); + cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.get('[data-test-subj="globalToastList"]') + .find('[data-test-subj="errorToastMessage"]') + .contains('Timeline request error: undefined Error: Unknown argument to es: kibana1'); + }); + + it('.es(*, kibana=true) should not report search error', () => { + cy.get('[class="view-line"]').type('{selectall}{backspace}, kibana=true)'); + cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.get('[data-test-subj="globalToastList"]') + .find('[data-test-subj="errorToastMessage"]') + .should('not.exist'); + }); + + it('.es(*, opensearchDashboards=true) should not report search error', () => { + cy.get('[class="view-line"]').type('{selectall}{backspace}, opensearchDashboards=true)'); + cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.get('[data-test-subj="globalToastList"]') + .find('[data-test-subj="errorToastMessage"]') + .should('not.exist'); + }); + + it('.elasticsearch(*, kibana1=true) should report search error', () => { + cy.get('[class="view-line"]').type( + '{selectall}{backspace}{backspace}{backspace}{backspace}{backspace}elasticsearch(*, kibana1=true)' + ); + cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.get('[data-test-subj="globalToastList"]') + .find('[data-test-subj="errorToastMessage"]') + .contains('Timeline request error: undefined Error: Unknown argument to es: kibana1'); + }); + + it('.elasticsearch(*, kibana=true) should not report search error', () => { + cy.get('[class="view-line"]').type( + '{selectall}{backspace}{backspace}{backspace}{backspace}{backspace}elasticsearch(*, kibana=true)' + ); + cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.get('[data-test-subj="globalToastList"]') + .find('[data-test-subj="errorToastMessage"]') + .should('not.exist'); + }); + + it('.elasticsearch(*, opensearchDashboards=true) should not report search error', () => { + cy.get('[class="view-line"]').type( + '{selectall}{backspace}{backspace}{backspace}{backspace}{backspace}elasticsearch(*, opensearchDashboards=true)' + ); + cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.get('[data-test-subj="globalToastList"]') + .find('[data-test-subj="errorToastMessage"]') + .should('not.exist'); + }); + + it('.opensearch(*, kibana1=true) should report search error', () => { + cy.get('[class="view-line"]').type( + '{selectall}{backspace}{backspace}{backspace}{backspace}{backspace}opensearch(*, kibana1=true)' + ); + cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.get('[data-test-subj="globalToastList"]') + .find('[data-test-subj="errorToastMessage"]') + .contains('Timeline request error: undefined Error: Unknown argument to es: kibana1'); + }); + + it('.opensearch(*, kibana=true) should not report search error', () => { + cy.get('[class="view-line"]').type( + '{selectall}{backspace}{backspace}{backspace}{backspace}{backspace}opensearch(*, kibana=true)' + ); + cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.get('[data-test-subj="globalToastList"]') + .find('[data-test-subj="errorToastMessage"]') + .should('not.exist'); + }); + + it('.opensearch(*, opensearchDashboards=true) should not report search error', () => { + cy.get('[class="view-line"]').type( + '{selectall}{backspace}{backspace}{backspace}{backspace}{backspace}opensearch(*, opensearchDashboards=true)' + ); + cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.get('[data-test-subj="globalToastList"]') + .find('[data-test-subj="errorToastMessage"]') + .should('not.exist'); + }); + }); +}); diff --git a/cypress/integration/with-security/plugins/.gitignore b/cypress/integration/with-security/plugins/.gitignore new file mode 100644 index 000000000000..86d0cb2726c6 --- /dev/null +++ b/cypress/integration/with-security/plugins/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore \ No newline at end of file diff --git a/cypress/integration/without-security/check_advanced_settings.js b/cypress/integration/without-security/check_advanced_settings.js new file mode 100644 index 000000000000..474a8178441a --- /dev/null +++ b/cypress/integration/without-security/check_advanced_settings.js @@ -0,0 +1,34 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; + +const miscUtils = new MiscUtils(cy); + +describe('verify the advanced settings are saved', () => { + beforeEach(() => { + miscUtils.visitPage('app/management/opensearch-dashboards/settings'); + }); + + it('the dark mode is on', () => { + cy.get('[data-test-subj="advancedSetting-editField-theme:darkMode"]') + .invoke('attr', 'aria-checked') + .should('eq', 'true'); + }); + + it('the Timeline default columns field is set to 4', () => { + cy.get('[data-test-subj="advancedSetting-editField-timeline:default_columns"]').should( + 'have.value', + 4 + ); + }); + + it('the Timeline Maximum buckets field is set to 4', () => { + cy.get('[data-test-subj="advancedSetting-editField-timeline:max_buckets"]').should( + 'have.value', + 4 + ); + }); +}); diff --git a/cypress/integration/without-security/check_default_page.js b/cypress/integration/without-security/check_default_page.js new file mode 100644 index 000000000000..390628046cc1 --- /dev/null +++ b/cypress/integration/without-security/check_default_page.js @@ -0,0 +1,18 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; + +const miscUtils = new MiscUtils(cy); + +describe('verify default landing page work for bwc', () => { + beforeEach(() => { + miscUtils.visitPage(''); + }); + + it('the overview page is set as the default landing page', () => { + cy.url().should('include', '/app/opensearch_dashboards_overview#/'); + }); +}); diff --git a/cypress/integration/without-security/check_filter_and_query.js b/cypress/integration/without-security/check_filter_and_query.js new file mode 100644 index 000000000000..30911d05ba7e --- /dev/null +++ b/cypress/integration/without-security/check_filter_and_query.js @@ -0,0 +1,72 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { + MiscUtils, + CommonUI, +} from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; + +const miscUtils = new MiscUtils(cy); +const commonUI = new CommonUI(cy); + +describe('check dashboards filter and query', () => { + beforeEach(() => { + miscUtils.visitPage('app/dashboards#'); + }); + + afterEach(() => { + cy.clearCookies(); + }); + + describe('osx filter and query should work in [Logs] Web Traffic dashboards', () => { + beforeEach(() => { + cy.get('[data-test-subj="dashboardListingTitleLink-[Logs]-Web-Traffic"]').click(); + cy.get('[data-test-subj="breadcrumb last"]') + .invoke('attr', 'title') + .should('eq', '[Logs] Web Traffic'); + }); + + it('osx filter and query should exist and be named correctly', () => { + cy.get('[data-test-subj="saved-query-management-popover-button"]').click(); + cy.get('[data-test-subj="saved-query-management-popover"]') + .find('[class="osdSavedQueryListItem__labelText"]') + .should('have.text', 'test-query') + .click(); + cy.get('[data-test-subj="queryInput"]').should('have.text', 'resp=200'); + cy.get( + '[data-test-subj="filter filter-enabled filter-key-machine.os filter-value-osx filter-unpinned "]' + ) + .should('have.text', 'osx filter') + .click(); + cy.get('[data-test-subj="editFilter"]').click(); + cy.get('[data-test-subj="filterFieldSuggestionList"]') + .find('[data-test-subj="comboBoxInput"]') + .should('have.text', 'machine.os'); + cy.get('[data-test-subj="filterOperatorList"]') + .find('[data-test-subj="comboBoxInput"]') + .should('have.text', 'is'); + cy.get('[data-test-subj="filterParams"]').find('input').should('have.value', 'osx'); + }); + + it('osx filter and query should function correctly', () => { + cy.get('[data-test-subj="saved-query-management-popover-button"]').click(); + cy.get('[data-test-subj="saved-query-management-popover"]') + .find('[class="osdSavedQueryListItem__labelText"]') + .should('have.text', 'test-query') + .click(); + commonUI.setDateRange('Dec 1, 2021 @ 00:00:00.000', 'Jan 1, 2021 @ 00:00:00.000'); + + //[Logs] vistor chart should show osx 100% + cy.get('[data-title="[Logs] Visitors by OS"]') + .find('[class="label"]') + .should('have.text', 'osx (100%)'); + + //[Logs] Response chart should show 200 label + cy.get('[data-title="[Logs] Response Codes Over Time + Annotations"]') + .find('[title="200"]') + .should('have.text', '200'); + }); + }); +}); diff --git a/cypress/integration/without-security/check_loaded_data.js b/cypress/integration/without-security/check_loaded_data.js new file mode 100644 index 000000000000..5a738c539ef2 --- /dev/null +++ b/cypress/integration/without-security/check_loaded_data.js @@ -0,0 +1,100 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { + MiscUtils, + CommonUI, +} from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; + +const miscUtils = new MiscUtils(cy); +const commonUI = new CommonUI(cy); + +describe('check previously loaded data', () => { + beforeEach(() => { + miscUtils.visitPage('app/dashboards#'); + }); + + it('previous loaded data should exist in dashboards', () => { + const items = cy.get('[data-test-subj="itemsInMemTable"]'); + + items + .get('[data-test-subj="dashboardListingTitleLink-[Flights]-Global-Flight-Dashboard"]') + .should('have.text', '[Flights] Global Flight Dashboard'); + + items + .get('[data-test-subj="dashboardListingTitleLink-[Logs]-Web-Traffic"]') + .should('have.text', '[Logs] Web Traffic'); + + items + .get('[data-test-subj="dashboardListingTitleLink-[eCommerce]-Revenue-Dashboard"]') + .should('have.text', '[eCommerce] Revenue Dashboard'); + }); + + describe('Global Flight Dashboard should function properly', () => { + beforeEach(() => { + cy.get('[data-test-subj="itemsInMemTable"]') + .get('[data-test-subj="dashboardListingTitleLink-[Flights]-Global-Flight-Dashboard"]') + .click(); + commonUI.removeAllFilters(); + commonUI.setDateRange('Dec 1, 2021 @ 00:00:00.000', 'Nov 1, 2021 @ 00:00:00.000'); + }); + + it('Global Flight Dashboard is loaded when clicked', () => { + cy.get('[data-test-subj="breadcrumb last"]').should( + 'have.text', + '[Flights] Global Flight Dashboard' + ); + cy.get('[data-title="[Flights] Total Flights"]').should('exist'); + cy.get('[data-title="[Flights] Average Ticket Price"]').should('exist'); + }); + + it('If set filter for carrier, [Flights] Airline Carrier should show correct carrier', () => { + commonUI.addFilterRetrySelection('Carrier', 'is', 'Logstash Airways'); + cy.get('[data-title="[Flights] Airline Carrier"]') + .find('[class="label-text"]') + .should('have.text', 'Logstash Airways (100%)'); + }); + + it('If set filter for FlightDelayType, [Flights] Delay Type should filter out selected type', () => { + commonUI.addFilterRetrySelection('FlightDelayType', 'is not', 'No Delay'); + const types = cy.get('[data-title="[Flights] Delay Type"]'); + types.find('[data-label="Weather Delay"]').should('exist'); + types.find('[data-label="No Delay"]').should('not.exist'); + }); + }); + + describe('eCommerce Revenue Dashboard should function properly', () => { + beforeEach(() => { + cy.get('[data-test-subj="itemsInMemTable"]') + .get('[data-test-subj="dashboardListingTitleLink-[eCommerce]-Revenue-Dashboard"]') + .click(); + commonUI.removeAllFilters(); + commonUI.setDateRange('Nov 1, 2021 @ 00:00:00.000', 'Nov 1, 2016 @ 00:00:00.000'); + }); + + it('eCommerce Revenue Dashboard is loaded when clicked', () => { + cy.get('[data-test-subj="breadcrumb last"]').should( + 'have.text', + '[eCommerce] Revenue Dashboard' + ); + cy.get('[data-title="[eCommerce] Average Sales Price"]').should('exist'); + cy.get('[data-title="[eCommerce] Average Sold Quantity"]').should('exist'); + }); + + it('If set filter for gender, [eCommerce] Sales by Gender should show one gender', () => { + commonUI.addFilterRetrySelection('customer_gender', 'is', 'FEMALE'); + cy.get('[data-title="[eCommerce] Sales by Gender"]') + .find('[class="label-text"]') + .should('have.text', 'FEMALE (100%)'); + }); + + it("If filter out Women's Clothing, [eCommerce] Sales by Category should not show this category", () => { + commonUI.addFilterRetrySelection('category', 'is not', "Women's Clothing"); + const category = cy.get('[data-title="[eCommerce] Sales by Category"]'); + category.find('[data-label="Men\'s Clothing"]').should('exist'); + category.find('[data-label="Women\'s Clothing"]').should('not.exist'); + }); + }); +}); diff --git a/cypress/integration/without-security/check_timeline.js b/cypress/integration/without-security/check_timeline.js new file mode 100644 index 000000000000..fe97f6c01c1d --- /dev/null +++ b/cypress/integration/without-security/check_timeline.js @@ -0,0 +1,117 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; + +const miscUtils = new MiscUtils(cy); + +describe('check timeline visualization', () => { + beforeEach(() => { + miscUtils.visitPage('app/visualize#'); + }); + + it('timeline visualizations should be saved and named correctly', () => { + cy.get('[data-test-subj="visualizationLandingPage"]') + .find('[class="euiFormControlLayout__childrenWrapper"]') + .type('timeline'); + cy.get('[data-test-subj="visListingTitleLink-test-timeline"]') + .should('have.text', 'test-timeline') + .click(); + cy.get('[class="view-line"]').contains('.es(*)'); + }); + + describe('timeline visualizations should work properly', () => { + beforeEach(() => { + cy.get('[data-test-subj="visualizationLandingPage"]') + .find('[data-test-subj="newItemButton"]') + .click(); + cy.get('[data-test-subj="visType-timelion"]').click(); + }); + + it('.es(*, kibana1=true) should report search error', () => { + cy.get('[class="view-line"]').type('{selectall}{backspace}, kibana1=true)'); + cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.get('[data-test-subj="globalToastList"]') + .find('[data-test-subj="errorToastMessage"]') + .contains('Timeline request error: undefined Error: Unknown argument to es: kibana1'); + }); + + it('.es(*, kibana=true) should not report search error', () => { + cy.get('[class="view-line"]').type('{selectall}{backspace}, kibana=true)'); + cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.get('[data-test-subj="globalToastList"]') + .find('[data-test-subj="errorToastMessage"]') + .should('not.exist'); + }); + + it('.es(*, opensearchDashboards=true) should not report search error', () => { + cy.get('[class="view-line"]').type('{selectall}{backspace}, opensearchDashboards=true)'); + cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.get('[data-test-subj="globalToastList"]') + .find('[data-test-subj="errorToastMessage"]') + .should('not.exist'); + }); + + it('.elasticsearch(*, kibana1=true) should report search error', () => { + cy.get('[class="view-line"]').type( + '{selectall}{backspace}{backspace}{backspace}{backspace}{backspace}elasticsearch(*, kibana1=true)' + ); + cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.get('[data-test-subj="globalToastList"]') + .find('[data-test-subj="errorToastMessage"]') + .contains('Timeline request error: undefined Error: Unknown argument to es: kibana1'); + }); + + it('.elasticsearch(*, kibana=true) should not report search error', () => { + cy.get('[class="view-line"]').type( + '{selectall}{backspace}{backspace}{backspace}{backspace}{backspace}elasticsearch(*, kibana=true)' + ); + cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.get('[data-test-subj="globalToastList"]') + .find('[data-test-subj="errorToastMessage"]') + .should('not.exist'); + }); + + it('.elasticsearch(*, opensearchDashboards=true) should not report search error', () => { + cy.get('[class="view-line"]').type( + '{selectall}{backspace}{backspace}{backspace}{backspace}{backspace}elasticsearch(*, opensearchDashboards=true)' + ); + cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.get('[data-test-subj="globalToastList"]') + .find('[data-test-subj="errorToastMessage"]') + .should('not.exist'); + }); + + it('.opensearch(*, kibana1=true) should report search error', () => { + cy.get('[class="view-line"]').type( + '{selectall}{backspace}{backspace}{backspace}{backspace}{backspace}opensearch(*, kibana1=true)' + ); + cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.get('[data-test-subj="globalToastList"]') + .find('[data-test-subj="errorToastMessage"]') + .contains('Timeline request error: undefined Error: Unknown argument to es: kibana1'); + }); + + it('.opensearch(*, kibana=true) should not report search error', () => { + cy.get('[class="view-line"]').type( + '{selectall}{backspace}{backspace}{backspace}{backspace}{backspace}opensearch(*, kibana=true)' + ); + cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.get('[data-test-subj="globalToastList"]') + .find('[data-test-subj="errorToastMessage"]') + .should('not.exist'); + }); + + it('.opensearch(*, opensearchDashboards=true) should not report search error', () => { + cy.get('[class="view-line"]').type( + '{selectall}{backspace}{backspace}{backspace}{backspace}{backspace}opensearch(*, opensearchDashboards=true)' + ); + cy.get('[data-test-subj="visualizeEditorRenderButton"]').click(); + cy.get('[data-test-subj="globalToastList"]') + .find('[data-test-subj="errorToastMessage"]') + .should('not.exist'); + }); + }); +}); diff --git a/cypress/integration/without-security/plugins/.gitignore b/cypress/integration/without-security/plugins/.gitignore new file mode 100644 index 000000000000..86d0cb2726c6 --- /dev/null +++ b/cypress/integration/without-security/plugins/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore \ No newline at end of file diff --git a/cypress/test-data/with-security/odfe-0.10.0.tar.gz b/cypress/test-data/with-security/odfe-0.10.0.tar.gz new file mode 100644 index 000000000000..efd1092b3786 Binary files /dev/null and b/cypress/test-data/with-security/odfe-0.10.0.tar.gz differ diff --git a/cypress/test-data/with-security/odfe-1.0.2.tar.gz b/cypress/test-data/with-security/odfe-1.0.2.tar.gz new file mode 100644 index 000000000000..b3ddd6a64c5d Binary files /dev/null and b/cypress/test-data/with-security/odfe-1.0.2.tar.gz differ diff --git a/cypress/test-data/with-security/odfe-1.1.0.tar.gz b/cypress/test-data/with-security/odfe-1.1.0.tar.gz new file mode 100644 index 000000000000..378f5a1824a4 Binary files /dev/null and b/cypress/test-data/with-security/odfe-1.1.0.tar.gz differ diff --git a/cypress/test-data/with-security/odfe-1.11.0.tar.gz b/cypress/test-data/with-security/odfe-1.11.0.tar.gz new file mode 100644 index 000000000000..ea676ef49cf7 Binary files /dev/null and b/cypress/test-data/with-security/odfe-1.11.0.tar.gz differ diff --git a/cypress/test-data/with-security/odfe-1.13.2.tar.gz b/cypress/test-data/with-security/odfe-1.13.2.tar.gz new file mode 100644 index 000000000000..5bab78444404 Binary files /dev/null and b/cypress/test-data/with-security/odfe-1.13.2.tar.gz differ diff --git a/cypress/test-data/with-security/odfe-1.2.1.tar.gz b/cypress/test-data/with-security/odfe-1.2.1.tar.gz new file mode 100644 index 000000000000..dffefe62c71a Binary files /dev/null and b/cypress/test-data/with-security/odfe-1.2.1.tar.gz differ diff --git a/cypress/test-data/with-security/odfe-1.3.0.tar.gz b/cypress/test-data/with-security/odfe-1.3.0.tar.gz new file mode 100644 index 000000000000..6b0a8c3e1c97 Binary files /dev/null and b/cypress/test-data/with-security/odfe-1.3.0.tar.gz differ diff --git a/cypress/test-data/with-security/odfe-1.4.0.tar.gz b/cypress/test-data/with-security/odfe-1.4.0.tar.gz new file mode 100644 index 000000000000..f999e5d7dc74 Binary files /dev/null and b/cypress/test-data/with-security/odfe-1.4.0.tar.gz differ diff --git a/cypress/test-data/with-security/odfe-1.7.0.tar.gz b/cypress/test-data/with-security/odfe-1.7.0.tar.gz new file mode 100644 index 000000000000..da3a9fb56c1e Binary files /dev/null and b/cypress/test-data/with-security/odfe-1.7.0.tar.gz differ diff --git a/cypress/test-data/with-security/odfe-1.8.0.tar.gz b/cypress/test-data/with-security/odfe-1.8.0.tar.gz new file mode 100644 index 000000000000..3c0a9ee82467 Binary files /dev/null and b/cypress/test-data/with-security/odfe-1.8.0.tar.gz differ diff --git a/cypress/test-data/with-security/odfe-1.9.0.tar.gz b/cypress/test-data/with-security/odfe-1.9.0.tar.gz new file mode 100644 index 000000000000..7b6c729593dd Binary files /dev/null and b/cypress/test-data/with-security/odfe-1.9.0.tar.gz differ diff --git a/cypress/test-data/with-security/osd-1.0.0.tar.gz b/cypress/test-data/with-security/osd-1.0.0.tar.gz new file mode 100644 index 000000000000..677657e5b2cb Binary files /dev/null and b/cypress/test-data/with-security/osd-1.0.0.tar.gz differ diff --git a/cypress/test-data/with-security/osd-1.1.0.tar.gz b/cypress/test-data/with-security/osd-1.1.0.tar.gz new file mode 100644 index 000000000000..0136b202b592 Binary files /dev/null and b/cypress/test-data/with-security/osd-1.1.0.tar.gz differ diff --git a/cypress/test-data/without-security/odfe-0.10.0.tar.gz b/cypress/test-data/without-security/odfe-0.10.0.tar.gz new file mode 100644 index 000000000000..e3234e1b5966 Binary files /dev/null and b/cypress/test-data/without-security/odfe-0.10.0.tar.gz differ diff --git a/cypress/test-data/without-security/odfe-1.0.2.tar.gz b/cypress/test-data/without-security/odfe-1.0.2.tar.gz new file mode 100644 index 000000000000..193c8b283060 Binary files /dev/null and b/cypress/test-data/without-security/odfe-1.0.2.tar.gz differ diff --git a/cypress/test-data/without-security/odfe-1.1.0.tar.gz b/cypress/test-data/without-security/odfe-1.1.0.tar.gz new file mode 100644 index 000000000000..c6f6221162de Binary files /dev/null and b/cypress/test-data/without-security/odfe-1.1.0.tar.gz differ diff --git a/cypress/test-data/without-security/odfe-1.11.0.tar.gz b/cypress/test-data/without-security/odfe-1.11.0.tar.gz new file mode 100644 index 000000000000..b8f42a50b52a Binary files /dev/null and b/cypress/test-data/without-security/odfe-1.11.0.tar.gz differ diff --git a/cypress/test-data/without-security/odfe-1.13.2.tar.gz b/cypress/test-data/without-security/odfe-1.13.2.tar.gz new file mode 100644 index 000000000000..e775f58ebcea Binary files /dev/null and b/cypress/test-data/without-security/odfe-1.13.2.tar.gz differ diff --git a/cypress/test-data/without-security/odfe-1.2.1.tar.gz b/cypress/test-data/without-security/odfe-1.2.1.tar.gz new file mode 100644 index 000000000000..193f48f99349 Binary files /dev/null and b/cypress/test-data/without-security/odfe-1.2.1.tar.gz differ diff --git a/cypress/test-data/without-security/odfe-1.3.0.tar.gz b/cypress/test-data/without-security/odfe-1.3.0.tar.gz new file mode 100644 index 000000000000..49e96194e53d Binary files /dev/null and b/cypress/test-data/without-security/odfe-1.3.0.tar.gz differ diff --git a/cypress/test-data/without-security/odfe-1.4.0.tar.gz b/cypress/test-data/without-security/odfe-1.4.0.tar.gz new file mode 100644 index 000000000000..2fd7c085895f Binary files /dev/null and b/cypress/test-data/without-security/odfe-1.4.0.tar.gz differ diff --git a/cypress/test-data/without-security/odfe-1.7.0.tar.gz b/cypress/test-data/without-security/odfe-1.7.0.tar.gz new file mode 100644 index 000000000000..5269d283ea75 Binary files /dev/null and b/cypress/test-data/without-security/odfe-1.7.0.tar.gz differ diff --git a/cypress/test-data/without-security/odfe-1.8.0.tar.gz b/cypress/test-data/without-security/odfe-1.8.0.tar.gz new file mode 100644 index 000000000000..7e47882df3b1 Binary files /dev/null and b/cypress/test-data/without-security/odfe-1.8.0.tar.gz differ diff --git a/cypress/test-data/without-security/odfe-1.9.0.tar.gz b/cypress/test-data/without-security/odfe-1.9.0.tar.gz new file mode 100644 index 000000000000..0eea7a9d3e26 Binary files /dev/null and b/cypress/test-data/without-security/odfe-1.9.0.tar.gz differ diff --git a/cypress/test-data/without-security/osd-1.0.0.tar.gz b/cypress/test-data/without-security/osd-1.0.0.tar.gz new file mode 100644 index 000000000000..1614230b81c3 Binary files /dev/null and b/cypress/test-data/without-security/osd-1.0.0.tar.gz differ diff --git a/cypress/test-data/without-security/osd-1.1.0.tar.gz b/cypress/test-data/without-security/osd-1.1.0.tar.gz new file mode 100644 index 000000000000..01470f4b1462 Binary files /dev/null and b/cypress/test-data/without-security/osd-1.1.0.tar.gz differ diff --git a/package.json b/package.json index 517e7927bc7f..f8acbfb3bf49 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "osd": "node scripts/osd", "opensearch": "node scripts/opensearch", "test": "grunt test", + "test:bwc": "./scripts/bwctest_osd.sh", "test:jest": "node scripts/jest", "test:jest_integration": "node scripts/jest_integration", "test:mocha": "node scripts/mocha", diff --git a/scripts/bwctest_osd.sh b/scripts/bwctest_osd.sh new file mode 100755 index 000000000000..9c131e50fc10 --- /dev/null +++ b/scripts/bwctest_osd.sh @@ -0,0 +1,332 @@ +#!/bin/bash + +# Copyright OpenSearch Contributors +# SPDX-License-Identifier: Apache-2.0 + +set -e + +# For every release, add sample data and new version below: +DEFAULT_VERSIONS=( + "odfe-0.10.0" + "odfe-1.0.2" + "odfe-1.1.0" + "odfe-1.2.1" + "odfe-1.3.0" + "odfe-1.4.0" + "odfe-1.7.0" + "odfe-1.8.0" + "odfe-1.9.0" + "odfe-1.11.0" + "odfe-1.13.2" + "osd-1.0.0" + "osd-1.1.0" +) + +# Define test groups +TEST_GROUP_1="check_loaded_data,check_timeline" +TEST_GROUP_2="$TEST_GROUP_1,check_advanced_settings" +TEST_GROUP_3="$TEST_GROUP_2,check_filter_and_query" +TEST_GROUP_4="$TEST_GROUP_3,check_default_page" +# If not defining test suite for a specific version, it will default to this group of tests +TEST_GROUP_DEFAULT="$TEST_GROUP_4" + +function usage() { + echo "" + echo "This script is used to run backwards compatibility tests for OpenSearch Dashboards" + echo "--------------------------------------------------------------------------" + echo "Usage: $0 [args]" + echo "" + echo "Required arguments:" + echo -e "-o OPENSEARCH\t, Specify the tested OpenSearch." + echo -e "-d DASHBOARDS\t, Specify the tested OpenSearch Dashboards." + echo "" + echo "Optional arguments:" + echo -e "-b BIND_ADDRESS\t, defaults to localhost | 127.0.0.1, can be changed to any IP or domain name for the cluster location." + echo -e "-p BIND_PORT\t, defaults to 5601 depends on OpenSearch or Dashboards, can be changed to any port for the cluster location." + echo -e "-s SECURITY_ENABLED\t(true | false), defaults to true. Specify the OpenSearch/Dashboards have security enabled or not." + echo -e "-c CREDENTIAL\t(usename:password), no defaults, effective when SECURITY_ENABLED=true." + echo -e "-v VERSIONS\t, Specify versions as a CSV to execute tests with data from specific version of OpenSearch Dashboards." + echo -e "-r RELEASES\t, Specify versions as a CSV to execute tests for released versions of OpenSearch." + echo -e "-h\tPrint this message." + echo "--------------------------------------------------------------------------" +} + +while getopts ":h:b:p:s:c:v:r:o:d:" arg; do + case $arg in + h) + usage + exit 1 + ;; + b) + BIND_ADDRESS=$OPTARG + ;; + p) + BIND_PORT=$OPTARG + ;; + s) + SECURITY_ENABLED=$OPTARG + ;; + c) + CREDENTIAL=$OPTARG + ;; + v) + VERSIONS=$OPTARG + ;; + r) + RELEASES=$OPTARG + ;; + o) + OPENSEARCH=$OPTARG + ;; + d) + DASHBOARDS=$OPTARG + ;; + :) + echo "-${OPTARG} requires an argument" + usage + exit 1 + ;; + ?) + echo "Invalid option: -${OPTARG}" + exit 1 + ;; + esac +done + +[ -z "$BIND_ADDRESS" ] && BIND_ADDRESS="localhost" +[ -z "$BIND_PORT" ] && BIND_PORT="5601" +[ -z "$VERSIONS" ] && test_array=("${DEFAULT_VERSIONS[@]}") || IFS=',' read -r -a test_array <<<"$VERSIONS" +[ -z "$SECURITY_ENABLED" ] && SECURITY_ENABLED="false" +[ $SECURITY_ENABLED == "false" ] && dashboards_type="without-security" || dashboards_type="with-security" +[ $SECURITY_ENABLED == "false" ] && releases_array=() || IFS=',' read -r -a releases_array <<<"$RELEASES" +[ -z "$CREDENTIAL" ] && CREDENTIAL="admin:admin" + +# define test path +cwd=$(pwd) +dir="$cwd/bwc_tmp" +test_dir="$dir/test" +opensearch_dir="$dir/opensearch" +dashboards_dir="$dir/opensearch-dashboards" +if [ -d "$dir" ]; then + echo "Temporary directory exists. Removing." + rm -rf "$dir" +fi +mkdir "$dir" +mkdir "$test_dir" +mkdir "$opensearch_dir" +mkdir "$dashboards_dir" + +function open_artifact { + artifact_dir=$1 + artifact=$2 + cd $artifact_dir + + # check if artifact provided is URL or attempt if passing by absolute path + if wget -q --method=HEAD $artifact; then + wget -c $artifact -O - | tar -xz --strip-components=1 + else + tar -xf $artifact --strip-components=1 + fi + +} + +# un-tar OpenSearch and OpenSearch Dashboards +echo "[ unzip OpenSearch and OpenSearch Dashboards ]" +open_artifact $opensearch_dir $OPENSEARCH +open_artifact $dashboards_dir $DASHBOARDS + +# define other paths and tmp files +opensearch_file='opensearch.txt' +dashboards_file='dashboards.txt' +opensearch_path="$dir/$opensearch_file" +dashboards_path="$dir/$dashboards_file" +dashboards_msg="\"state\":\"green\",\"title\":\"Green\",\"nickname\":\"Looking good\",\"icon\":\"success\"" +dashboards_url="http://$BIND_ADDRESS:$BIND_PORT/api/status" +if [ $SECURITY_ENABLED == "false" ]; +then + opensearch_msg="\"status\":\"green\"" + opensearch_url="http://$BIND_ADDRESS:9200/_cluster/health" + opensearch_args="" +else + opensearch_msg="\"status\":\"yellow\"" + opensearch_url="https://$BIND_ADDRESS:9200/_cluster/health" + opensearch_args="-u $CREDENTIAL --insecure" +fi + +# define test groups to test suites +declare -A test_suites +test_suites=( + ["odfe-0.10.0"]=$TEST_GROUP_1 + ["odfe-1.0.2"]=$TEST_GROUP_2 + ["odfe-1.1.0"]=$TEST_GROUP_2 + ["odfe-1.2.1"]=$TEST_GROUP_2 + ["odfe-1.3.0"]=$TEST_GROUP_2 + ["odfe-1.4.0"]=$TEST_GROUP_3 + ["odfe-1.7.0"]=$TEST_GROUP_3 + ["odfe-1.8.0"]=$TEST_GROUP_3 + ["odfe-1.9.0"]=$TEST_GROUP_3 + ["odfe-1.11.0"]=$TEST_GROUP_3 + ["odfe-1.13.2"]=$TEST_GROUP_4 + ["osd-1.0.0"]=$TEST_GROUP_4 + ["osd-1.1.0"]=$TEST_GROUP_4 +) + +# remove the running opensearch process +function clean { + echo "Closing the running OpenSearch" + process=($(ps -ef | grep "Dopensearch" | awk '{print $2}')) + kill ${process[0]} + echo "Closing any usage on port $BIND_PORT" + process=($(lsof -i -P -n | grep $BIND_PORT | awk '{print $2}')) + kill ${process[0]} +} + +# Print out a textfile line by line +function print_txt { + while IFS= read -r line; do + echo "text read from $1: $line" + done < $1 +} + +# this function is used to check the running status of OpenSearch or OpenSearch Dashboards +# $1 is the path to the tmp file which saves the running status +# $2 is the error msg to check +# $3 is the url to curl +# $4 contains arguments that need to be passed to the curl command +function check_status { + while [ ! -f $1 ] || ! grep -q "$2" $1; do + if [ -f $1 ]; then rm $1; fi + curl $3 $4 > $1 || true + done + rm $1 +} + +# this function sets up the cypress env +# it first clones the opensearch-dashboards-functional-test library +# then it removes the tests into the cypress integration folder +# and copies the backwards compatibility tests into the folder +function setup_cypress { + echo "[ Setup the cypress test environment ]" + git clone https://github.com/opensearch-project/opensearch-dashboards-functional-test "$test_dir" + rm -rf "$test_dir/cypress/integration" + cp -r "$cwd/cypress/integration" "$test_dir/cypress" + cd "$test_dir" + npm install + echo "Cypress is ready!" +} + +# this function copies the tested data for the required version to the opensearch data folder +# $1 is the required version +function upload_data { + rm -rf "$opensearch_dir/data" + cd $opensearch_dir + cp "$cwd/cypress/test-data/$dashboards_type/$1.tar.gz" . + tar -xvf "$opensearch_dir/$1.tar.gz" >> /dev/null 2>&1 + rm "$1.tar.gz" + echo "Data has been uploaded and ready to test" +} + +# Starts OpenSearch, if verifying a distribution it will install the certs then start. +function run_opensearch { + echo "[ Attempting to start OpenSearch... ]" + cd "$opensearch_dir" + [ $SECURITY_ENABLED == "false" ] && ./bin/opensearch || ./opensearch-tar-install.sh +} + +# Starts OpenSearch Dashboards +function run_dashboards { + echo "[ Attempting to start OpenSearch Dashboards... ]" + cd "$dashboards_dir" + [ $SECURITY_ENABLED == "false" ] && rm config/opensearch_dashboards.yml && touch config/opensearch_dashboards.yml + ./bin/opensearch-dashboards +} + +# Checks the running status of OpenSearch +# it calls check_status and passes the OpenSearch tmp file path, error msg, url, and arguments +# if success, the while loop in the check_status will end and it prints out "OpenSearch is up!" +function check_opensearch_status { + echo "Checking the status OpenSearch..." + cd "$dir" + check_status $opensearch_path "$opensearch_msg" $opensearch_url "$opensearch_args" >> /dev/null 2>&1 + echo "OpenSearch is up!" +} + +# Checks the running status of OpenSearch Dashboards +# it calls check_status and passes the OpenSearch Dashboards tmp file path, error msg, url, and arguments +# if success, the while loop in the check_status will end and it prints out "OpenSearch Dashboards is up!" +function check_dashboards_status { + echo "Checking the OpenSearch Dashboards..." + cd "$dir" + check_status $dashboards_path "$dashboards_msg" $dashboards_url "" >> /dev/null 2>&1 + echo "OpenSearch Dashboards is up!" +} + +# Runs the backwards compatibility test using cypress for the required version +# $1 is the requested version +function run_bwc { + cd "$test_dir" + [ -z "${test_suites[$1]}" ] && test_suite=$TEST_GROUP_DEFAULT || test_suite="${test_suites[$1]}" + IFS=',' read -r -a tests <<<"$test_suite" + for test in "${tests[@]}" + do + npx cypress run --spec "$test_dir/cypress/integration/$dashboards_type/$test.js" || echo "backwards compatibility tests have issue" + done + # Check if $dashboards_type/plugins has tests in them to execute + if [ "$(ls -A $test_dir/cypress/integration/$dashboards_type/plugins | wc -l)" -gt 1 ]; then + echo "Running tests from plugins" + npx cypress run --spec "$test_dir/cypress/integration/$dashboards_type/plugins/*.js" || echo "backwards compatibility plugins tests have issue" + fi +} + +# Main function +function execute_tests { + # for each required testing version, do the following + # first run opensearch and check the status + # second run dashboards and check the status + # run the backwards compatibility tests + for version in "${test_array[@]}" + do + # copy and un-tar data into the OpenSearch data folder + echo "[ Setting up the OpenSearch environment for $version ]" + upload_data $version + + run_opensearch >> /dev/null 2>&1 & + check_opensearch_status + run_dashboards >> /dev/null 2>&1 & + check_dashboards_status + + echo "[ Run the backwards compatibility tests for $version ]" + run_bwc $version + + # kill the running OpenSearch process + clean + done +} + +# Executes the main function with different versions of OpenSearch downloaded +function execute_mismatch_tests { + PACKAGE_VERSION=$(cat $dashboards_dir/package.json \ + | grep version \ + | head -1 \ + | awk -F: '{ print $2 }' \ + | sed 's/[",]//g' \ + | tr -d [:space:]) + + for release in "${releases_array[@]}" + do + echo "Running tests with OpenSearch Dashboards $PACKAGE_VERSION and OpenSearch $release" + ( + rm -rf $opensearch_dir && mkdir "$opensearch_dir" + # TODO: support multiple platforms and architectures + cd $opensearch_dir && wget -c https://artifacts.opensearch.org/releases/bundle/opensearch/$release/opensearch-$release-linux-x64.tar.gz -O - | tar -xz --strip-components=1 + ) + execute_tests + done +} + +# setup the cypress test env +setup_cypress +execute_tests +(( ${#releases_array[@]} )) && execute_mismatch_tests + +rm -rf "$dir" \ No newline at end of file