Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workbench: auto dump cypress test data, support security #199

Merged
merged 2 commits into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions workbench/.cypress/integration/ui.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,32 @@

/// <reference types="cypress" />

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(() => {
Expand Down Expand Up @@ -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]);
}
});
Expand Down
41 changes: 41 additions & 0 deletions workbench/.cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
15 changes: 15 additions & 0 deletions workbench/.cypress/support/constants.js
Original file line number Diff line number Diff line change
@@ -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',
};
5 changes: 5 additions & 0 deletions workbench/.cypress/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
11 changes: 11 additions & 0 deletions workbench/.cypress/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
7 changes: 6 additions & 1 deletion workbench/cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}