From 3ffeabe37e5028612b4fd1b51356a690551d5419 Mon Sep 17 00:00:00 2001 From: Joshua Date: Mon, 7 Dec 2020 23:46:42 +0000 Subject: [PATCH] Fix workbench bugs from plugin platform upgrade (#886) * Fix download json api path * Fix cypress tests * Fix response tab margin * Update cypress tests * Fix server log message * Fix asScoped call for security plugin * Update cypress tests * Fix unique keys problem * Remove console log --- workbench/.cypress/integration/ui.spec.js | 132 +++++++++++------- workbench/.cypress/utils/constants.js | 12 +- workbench/public/components/Main/main.tsx | 12 +- .../components/QueryResults/QueryResults.tsx | 2 +- .../QueryResults/QueryResultsBody.tsx | 16 +-- .../__snapshots__/QueryResults.test.tsx.snap | 4 + workbench/server/plugin.ts | 4 +- workbench/server/routes/query.ts | 33 ++--- workbench/server/routes/translate.ts | 7 +- workbench/server/services/QueryService.ts | 20 +-- workbench/server/services/TranslateService.ts | 8 +- workbench/server/services/utils/constants.ts | 9 -- 12 files changed, 133 insertions(+), 126 deletions(-) diff --git a/workbench/.cypress/integration/ui.spec.js b/workbench/.cypress/integration/ui.spec.js index 6b141ce0ca..a61b1f2ef9 100644 --- a/workbench/.cypress/integration/ui.spec.js +++ b/workbench/.cypress/integration/ui.spec.js @@ -23,41 +23,49 @@ describe('Test PPL UI', () => { beforeEach(() => { cy.visit('app/opendistro-query-workbench'); cy.wait(delay); - cy.get('.euiToggle__input[title=PPL]').click(); + cy.get('.euiToggle__input[title=PPL]').click({ force: true }); cy.wait(delay); }); it('Confirm results are empty', () => { - cy.get('.euiTextAlign').contains('Enter a query in the query editor above to see results.').should('have.length', 1); + cy.get('.euiTextAlign') + .contains('Enter a query in the query editor above to see results.') + .should('have.length', 1); }); it('Test Run button', () => { cy.get('textarea.ace_text-input').eq(0).focus().type('source=accounts', { force: true }); cy.wait(delay); - cy.get('.euiButton__text').contains('Run').click(); + cy.get('.euiButton__text').contains('Run').click({ force: true }); cy.wait(delay); - cy.get('.euiTab__content').contains('Events').click(); + cy.get('.euiTab__content').contains('Events').click({ force: true }); - cy.get('span.euiTableCellContent__text').eq(21).should((employer) => { - expect(employer).to.contain('Pyrami'); - }); + cy.get('span.euiTableCellContent__text') + .eq(19) + .should((employer) => { + expect(employer).to.contain('Pyrami'); + }); }); it('Test Clear button', () => { cy.get('textarea.ace_text-input').eq(0).focus().type('source=accounts', { force: true }); cy.wait(delay); - cy.get('.euiButton__text').contains('Run').click(); + cy.get('.euiButton__text').contains('Run').click({ force: true }); cy.wait(delay); - cy.get('.euiTab__content').contains('Events').click(); + cy.get('.euiTab__content').contains('Events').click({ force: true }); cy.wait(delay); - cy.get('.euiButton__text').contains('Clear').click(); + cy.get('.euiButton__text').contains('Clear').click({ force: true }); cy.wait(delay); - cy.get('.euiTextAlign').contains('Enter a query in the query editor above to see results.').should('have.length', 1); - cy.get('.ace_content').eq(0).then((queryEditor) => { - const editor = edit(queryEditor[0]); - expect(editor.getValue()).to.equal(''); - }); + cy.get('.euiTextAlign') + .contains('Enter a query in the query editor above to see results.') + .should('have.length', 1); + cy.get('.ace_content') + .eq(0) + .then((queryEditor) => { + const editor = edit(queryEditor[0]); + expect(editor.getValue()).to.equal(''); + }); }); it('Test full screen view', () => { @@ -66,13 +74,13 @@ describe('Test PPL UI', () => { cy.get('textarea.ace_text-input').eq(0).focus().type('source=accounts', { force: true }); cy.wait(delay); - cy.get('.euiButton__text').contains('Run').click(); + cy.get('.euiButton__text').contains('Run').click({ force: true }); cy.wait(delay); - cy.get('.euiButton__text').contains('Full screen view').click(); + cy.get('.euiButton__text').contains('Full screen view').click({ force: true }); cy.get('.euiTitle').should('not.exist'); - cy.get('button#exit-fullscreen-button').click(); + cy.get('button#exit-fullscreen-button').click({ force: true }); cy.wait(delay); cy.get('.euiButton__text').contains('Full screen view').should('exist'); cy.get('.euiTitle').contains('Query Workbench').should('exist'); @@ -83,33 +91,45 @@ describe('Test SQL UI', () => { beforeEach(() => { cy.visit('app/opendistro-query-workbench'); cy.wait(delay); - cy.get('.euiToggle__input[title=SQL]').click(); + cy.get('.euiToggle__input[title=SQL]').click({ force: true }); cy.wait(delay); }); it('Confirm results are empty', () => { - cy.get('.euiTextAlign').contains('Enter a query in the query editor above to see results.').should('have.length', 1); + cy.get('.euiTextAlign') + .contains('Enter a query in the query editor above to see results.') + .should('have.length', 1); }); it('Test Run button and field search', () => { - cy.get('textarea.ace_text-input').eq(0).focus().type('{enter}select * from accounts where balance > 49500;', { force: true }); + cy.get('textarea.ace_text-input') + .eq(0) + .focus() + .type('{enter}select * from accounts where balance > 49500;', { force: true }); cy.wait(delay); - cy.get('.euiButton__text').contains('Run').click(); + cy.get('.euiButton__text').contains('Run').click({ force: true }); cy.wait(delay); - cy.get('.euiTab__content').contains('accounts').click(); + cy.get('.euiTab__content').contains('accounts').click({ force: true }); cy.get('input.euiFieldSearch').type('marissa'); - cy.get('span.euiTableCellContent__text').eq(15).should((account_number) => { - expect(account_number).to.contain('803'); - }); + cy.get('span.euiTableCellContent__text') + .eq(13) + .should((account_number) => { + expect(account_number).to.contain('803'); + }); }); it('Test Translate button', () => { cy.get('textarea.ace_text-input').eq(0).focus().type('{selectall}{backspace}', { force: true }); cy.wait(delay); - cy.get('textarea.ace_text-input').eq(0).focus().type('{selectall}{backspace}select log(balance) from accounts where abs(age) > 20;', { force: true }); + cy.get('textarea.ace_text-input') + .eq(0) + .focus() + .type('{selectall}{backspace}select log(balance) from accounts where abs(age) > 20;', { + force: true, + }); cy.wait(delay); - cy.get('.euiButton__text').contains('Explain').click(); + cy.get('.euiButton__text').contains('Explain').click({ force: true }); cy.wait(delay); // hard to get euiCodeBlock content, check length instead @@ -117,22 +137,24 @@ describe('Test SQL UI', () => { }); it('Test Clear button', () => { - cy.get('.euiButton__text').contains('Clear').click(); + cy.get('.euiButton__text').contains('Clear').click({ force: true }); cy.wait(delay); - cy.get('.ace_content').eq(0).then((queryEditor) => { - const editor = edit(queryEditor[0]); - expect(editor.getValue()).to.equal(''); - }); + cy.get('.ace_content') + .eq(0) + .then((queryEditor) => { + const editor = edit(queryEditor[0]); + expect(editor.getValue()).to.equal(''); + }); }); it('Test full screen view', () => { cy.get('.euiButton__text').contains('Full screen view').should('not.exist'); cy.get('.euiTitle').contains('Query Workbench').should('exist'); - cy.get('.euiButton__text').contains('Run').click(); + cy.get('.euiButton__text').contains('Run').click({ force: true }); cy.wait(delay); - cy.get('.euiButton__text').contains('Full screen view').click(); + cy.get('.euiButton__text').contains('Full screen view').click({ force: true }); cy.get('.euiTitle').should('not.exist'); }); @@ -147,13 +169,13 @@ describe('Test and verify SQL downloads', () => { url: url, headers: { 'content-type': 'application/json;charset=UTF-8', - 'kbn-version': '7.9.1', + 'kbn-version': '7.10.0', }, body: { 'query': 'select * from accounts where balance > 49500' } - }).then(response => { - expect(response.body.resp).to.have.string(files[file]); + }).then((response) => { + expect(response.body.data.resp).to.have.string(files[file]); }); }); }); @@ -163,7 +185,7 @@ describe('Test table display', () => { beforeEach(() => { cy.visit('app/opendistro-query-workbench'); cy.wait(delay); - cy.get('.euiToggle__input[title=SQL]').click(); + cy.get('.euiToggle__input[title=SQL]').click({ force: true }); cy.wait(delay); cy.get('textarea.ace_text-input').eq(0).focus().type('{selectall}{backspace}', { force: true }); cy.wait(delay); @@ -171,27 +193,37 @@ describe('Test table display', () => { testQueries.map(({ title, query, cell_idx, expected_string }) => { it(title, () => { - cy.get('textarea.ace_text-input').eq(0).focus().type(`{selectall}{backspace}${query}`, { force: true }); + cy.get('textarea.ace_text-input') + .eq(0) + .focus() + .type(`{selectall}{backspace}${query}`, { force: true }); cy.wait(delay); - cy.get('.euiButton__text').contains('Run').click(); + cy.get('.euiButton__text').contains('Run').click({ force: true }); cy.wait(delay); - cy.get('span.euiTableCellContent__text').eq(cell_idx).should((cell) => { - expect(cell).to.contain(expected_string); - }); + cy.get('span.euiTableCellContent__text') + .eq(cell_idx) + .should((cell) => { + expect(cell).to.contain(expected_string); + }); }); }); it('Test nested fields display', () => { - cy.get('textarea.ace_text-input').eq(0).focus().type(`{selectall}{backspace}select * from employee_nested;`, { force: true }); + cy.get('textarea.ace_text-input') + .eq(0) + .focus() + .type(`{selectall}{backspace}select * from employee_nested;`, { force: true }); cy.wait(delay); - cy.get('.euiButton__text').contains('Run').click(); + cy.get('.euiButton__text').contains('Run').click({ force: true }); cy.wait(delay); - cy.get('span.euiTableCellContent__text').eq(21).click(); + cy.get('button.euiLink').eq(2).click({ force: true }); cy.wait(delay); - cy.get('span.euiTableCellContent__text').eq(27).should((cell) => { - expect(cell).to.contain('2018-06-23'); - }); + cy.get('span.euiTableCellContent__text') + .eq(24) + .should((cell) => { + expect(cell).to.contain('2018-06-23'); + }); }); }); diff --git a/workbench/.cypress/utils/constants.js b/workbench/.cypress/utils/constants.js index ace19d6aaf..9f696d0244 100644 --- a/workbench/.cypress/utils/constants.js +++ b/workbench/.cypress/utils/constants.js @@ -42,32 +42,32 @@ export const testQueries = [ { title: 'Test GROUP BY', query: 'select count(*) from accounts group by gender;', - cell_idx: 5, + cell_idx: 3, expected_string: '507' }, { title: 'Test GROUP BY with aliases and scalar function', query: 'SELECT ABS(age) AS a FROM accounts GROUP BY ABS(age);', cell_idx: 17, - expected_string: '35.0' + expected_string: '28.0' }, { title: 'Test GROUP BY and HAVING', query: 'SELECT age, MAX(balance) FROM accounts GROUP BY age HAVING MIN(balance) > 3000;', - cell_idx: 15, - expected_string: '49339' + cell_idx: 5, + expected_string: '47257' }, { title: 'Test ORDER BY', query: 'SELECT account_number FROM accounts ORDER BY account_number DESC;', cell_idx: 5, - expected_string: '999' + expected_string: '998' }, { title: 'Test JOIN', query: 'select a.account_number, a.firstname, a.lastname, e.id, e.name from accounts a join employee_nested e order by a.account_number;', cell_idx: 45, - expected_string: 'Amber' + expected_string: 'Duke' }, ]; diff --git a/workbench/public/components/Main/main.tsx b/workbench/public/components/Main/main.tsx index 38dfaec974..16da354dfa 100644 --- a/workbench/public/components/Main/main.tsx +++ b/workbench/public/components/Main/main.tsx @@ -325,7 +325,7 @@ export class Main extends React.Component { let endpoint = '../api/sql_console/' + (_.isEqual(language, 'SQL') ? 'sqlquery' : 'pplquery'); const responsePromise = Promise.all( queries.map((query: string) => - this.httpClient.post(endpoint, { query }).catch((error: any) => { + this.httpClient.post(endpoint, { body: `{ "query": "${query}" }` }).catch((error: any) => { this.setState({ messages: [ { @@ -372,7 +372,7 @@ export class Main extends React.Component { '../api/sql_console/' + (_.isEqual(language, 'SQL') ? 'translatesql' : 'translateppl'); const translationPromise = Promise.all( queries.map((query: string) => - this.httpClient.post(endpoint, { query }).catch((error: any) => { + this.httpClient.post(endpoint, { body: `{ "query": "${query}" }` }).catch((error: any) => { this.setState({ messages: [ { @@ -416,7 +416,7 @@ export class Main extends React.Component { if (queries.length > 0) { Promise.all( queries.map((query: string) => - this.httpClient.post('../api/sql_console/queryjson', { query }).catch((error: any) => { + this.httpClient.post('../api/sql_console/sqljson', { body: `{ "query": "${query}" }` }).catch((error: any) => { this.setState({ messages: [ { @@ -448,7 +448,7 @@ export class Main extends React.Component { let endpoint = '../api/sql_console/' + (_.isEqual(language, 'SQL') ? 'sqlquery' : 'pplquery'); Promise.all( queries.map((query: string) => - this.httpClient.post(endpoint, { query }).catch((error: any) => { + this.httpClient.post(endpoint, { body: `{ "query": "${query}" }` }).catch((error: any) => { this.setState({ messages: [ { @@ -480,7 +480,7 @@ export class Main extends React.Component { let endpoint = '../api/sql_console/' + (_.isEqual(language, 'SQL') ? 'sqlcsv' : 'pplcsv'); Promise.all( queries.map((query: string) => - this.httpClient.post(endpoint, { query }).catch((error: any) => { + this.httpClient.post(endpoint, { body: `{ "query": "${query}" }` }).catch((error: any) => { this.setState({ messages: [ { @@ -512,7 +512,7 @@ export class Main extends React.Component { let endpoint = '../api/sql_console/' + (_.isEqual(language, 'SQL') ? 'sqltext' : 'ppltext'); Promise.all( queries.map((query: string) => - this.httpClient.post(endpoint, { query }).catch((error: any) => { + this.httpClient.post(endpoint, { body: `{ "query": "${query}" }` }).catch((error: any) => { this.setState({ messages: [ { diff --git a/workbench/public/components/QueryResults/QueryResults.tsx b/workbench/public/components/QueryResults/QueryResults.tsx index 910d647b73..d6736ae744 100644 --- a/workbench/public/components/QueryResults/QueryResults.tsx +++ b/workbench/public/components/QueryResults/QueryResults.tsx @@ -347,7 +347,7 @@ class QueryResults extends React.Component style={{ marginTop: "8px" }} grow={false} > - {tabsButtons} + {tabsButtons} diff --git a/workbench/public/components/QueryResults/QueryResultsBody.tsx b/workbench/public/components/QueryResults/QueryResultsBody.tsx index 073fa59138..33df6214b9 100644 --- a/workbench/public/components/QueryResults/QueryResultsBody.tsx +++ b/workbench/public/components/QueryResults/QueryResultsBody.tsx @@ -683,7 +683,7 @@ class QueryResultsBody extends React.Component @@ -695,7 +695,7 @@ class QueryResultsBody extends React.Component + {expandingNode} ); @@ -704,26 +704,26 @@ class QueryResultsBody extends React.Component + {fieldObj.value} ); } - const tableRow = {tableCells}; - let row = {tableRow}; + const tableRow = {tableCells}; + let row = {tableRow}; if (expandedRowMap[rowId] && expandedRowMap[rowId].expandedRow) { const tableRow = ( - + {tableCells}{" "} ); const expandedRow = ( - {expandedRowMap[rowId].expandedRow} + {expandedRowMap[rowId].expandedRow} ); row = ( - + {tableRow} {expandedRow} diff --git a/workbench/public/components/QueryResults/__snapshots__/QueryResults.test.tsx.snap b/workbench/public/components/QueryResults/__snapshots__/QueryResults.test.tsx.snap index 77df8ef7ad..1d09d78f7d 100644 --- a/workbench/public/components/QueryResults/__snapshots__/QueryResults.test.tsx.snap +++ b/workbench/public/components/QueryResults/__snapshots__/QueryResults.test.tsx.snap @@ -62,6 +62,7 @@ exports[` spec renders the component to test tabs down