diff --git a/workbench/.cypress/integration/ui.spec.js b/workbench/.cypress/integration/ui.spec.js index aa32ab1824..abb5ce1bdb 100644 --- a/workbench/.cypress/integration/ui.spec.js +++ b/workbench/.cypress/integration/ui.spec.js @@ -26,9 +26,32 @@ /// -import { edit } from "brace"; -import { delay, testQueries, verifyDownloadData, files } from "../utils/constants"; +import { edit } from 'brace'; +import { delay, files, testDataSet, testQueries, verifyDownloadData } from '../utils/constants'; +describe('Dump test data', () => { + it('Indexes test data for SQL and PPL', () => { + const dumpDataSet = (url, index) => + cy.request(url).then((response) => { + cy.request({ + method: 'POST', + form: true, + url: 'api/console/proxy', + headers: { + 'content-type': 'application/json;charset=UTF-8', + 'osd-xsrf': true, + }, + qs: { + path: `${index}/_bulk`, + method: 'POST', + }, + body: response.body, + }); + }); + + testDataSet.forEach(({url, index}) => dumpDataSet(url, index)); + }); +}); describe('Test PPL UI', () => { beforeEach(() => { @@ -183,13 +206,12 @@ describe('Test and verify SQL downloads', () => { 'osd-xsrf': true, }, body: { - 'query': 'select * from accounts where balance > 49500' - } + query: 'select * from accounts where balance > 49500', + }, }).then((response) => { if (title === 'Download and verify CSV' || title === 'Download and verify Text') { expect(response.body.data.body).to.have.string(files[file]); - } - else { + } else { expect(response.body.data.resp).to.have.string(files[file]); } }); diff --git a/workbench/.cypress/support/commands.js b/workbench/.cypress/support/commands.js index e4d90a3918..ab472854d4 100644 --- a/workbench/.cypress/support/commands.js +++ b/workbench/.cypress/support/commands.js @@ -49,3 +49,44 @@ // // -- This will overwrite an existing command -- // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) + +import { ADMIN_AUTH } from '../utils/constants'; + +Cypress.Commands.overwrite('visit', (originalFn, url, options) => { + // Add the basic auth header when security enabled in the OpenSearch cluster + // https://github.com/cypress-io/cypress/issues/1288 + if (Cypress.env('security_enabled')) { + if (options) { + options.auth = ADMIN_AUTH; + } else { + options = { auth: ADMIN_AUTH }; + } + // Add query parameters - select the default OpenSearch Dashboards tenant + options.qs = { security_tenant: 'private' }; + return originalFn(url, options); + } else { + return originalFn(url, options); + } +}); + +// Be able to add default options to cy.request(), https://github.com/cypress-io/cypress/issues/726 +Cypress.Commands.overwrite('request', (originalFn, ...args) => { + let defaults = {}; + // Add the basic authentication header when security enabled in the OpenSearch cluster + if (Cypress.env('security_enabled')) { + defaults.auth = ADMIN_AUTH; + } + + let options = {}; + if (typeof args[0] === 'object' && args[0] !== null) { + options = Object.assign({}, args[0]); + } else if (args.length === 1) { + [options.url] = args; + } else if (args.length === 2) { + [options.method, options.url] = args; + } else if (args.length === 3) { + [options.method, options.url, options.body] = args; + } + + return originalFn(Object.assign({}, defaults, options)); +}); diff --git a/workbench/.cypress/support/constants.js b/workbench/.cypress/support/constants.js new file mode 100644 index 0000000000..48ee4ff9ff --- /dev/null +++ b/workbench/.cypress/support/constants.js @@ -0,0 +1,15 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +export const ADMIN_AUTH = { + username: 'admin', + password: 'admin', +}; diff --git a/workbench/.cypress/support/index.js b/workbench/.cypress/support/index.js index a7af4e66b9..a3ce8c563c 100644 --- a/workbench/.cypress/support/index.js +++ b/workbench/.cypress/support/index.js @@ -44,3 +44,8 @@ import './commands'; // Alternatively you can use CommonJS syntax: // require('./commands') + +// Switch the base URL of OpenSearch when security enabled in the cluster +if (Cypress.env('security_enabled')) { + Cypress.env('opensearch', 'https://localhost:9200'); +} diff --git a/workbench/.cypress/utils/constants.js b/workbench/.cypress/utils/constants.js index cc5211a444..b83e780572 100644 --- a/workbench/.cypress/utils/constants.js +++ b/workbench/.cypress/utils/constants.js @@ -26,6 +26,17 @@ export const delay = 1000; +export const testDataSet = [ + { + url: 'https://raw.githubusercontent.com/opensearch-project/sql/main/integ-test/src/test/resources/accounts.json', + index: 'accounts', + }, + { + url: 'https://raw.githubusercontent.com/opensearch-project/sql/main/integ-test/src/test/resources/employee_nested.json', + index: 'employee_nested' + } +] + export const verifyDownloadData = [ { title: 'Download and verify JSON', diff --git a/workbench/cypress.json b/workbench/cypress.json index e5441904ad..53c4ba96d8 100644 --- a/workbench/cypress.json +++ b/workbench/cypress.json @@ -9,5 +9,10 @@ "videosFolder": ".cypress/videos", "requestTimeout": 60000, "responseTimeout": 60000, - "defaultCommandTimeout": 60000 + "defaultCommandTimeout": 60000, + "env": { + "opensearch": "localhost:9200", + "opensearchDashboards": "localhost:5601", + "security_enabled": true + } }