Skip to content

Commit

Permalink
add security enable support for gantt charts (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcui1225 authored Mar 24, 2021
1 parent 23b9124 commit 2cf95b1
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 6 deletions.
8 changes: 4 additions & 4 deletions gantt-chart/.cypress/integration/ui.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { delay, GANTT_VIS_NAME, Y_LABEL, X_LABEL, DEFAULT_SIZE } from '../utils/

describe('Save a gantt chart', () => {
beforeEach(() => {
cy.visit('app/visualize#');
cy.visit(`${Cypress.env('kibana')}/app/visualize#`);
cy.wait(delay * 5);
});

Expand All @@ -45,7 +45,7 @@ describe('Save a gantt chart', () => {

describe('Render and configure a gantt chart', () => {
beforeEach(() => {
cy.visit('app/visualize#');
cy.visit(`${Cypress.env('kibana')}/app/visualize#`);
cy.wait(delay * 5);
cy.get('button').contains(GANTT_VIS_NAME).click({ force: true });
cy.wait(delay * 5);
Expand Down Expand Up @@ -88,7 +88,7 @@ describe('Render and configure a gantt chart', () => {

describe('Configure panel settings', () => {
beforeEach(() => {
cy.visit('app/visualize#');
cy.visit(`${Cypress.env('kibana')}/app/visualize#`);
cy.wait(delay * 5);
cy.get('button').contains(GANTT_VIS_NAME).click({ force: true });
cy.wait(delay * 5);
Expand Down Expand Up @@ -176,7 +176,7 @@ describe('Configure panel settings', () => {

describe('Add gantt chart to dashboard', () => {
it('Adds gantt chart to dashboard', () => {
cy.visit('app/dashboards#/create');
cy.visit(`${Cypress.env('kibana')}/app/dashboards#/create`);
cy.wait(delay * 5);

cy.get('.euiLink').contains('Add an existing').click({ force: true });
Expand Down
41 changes: 41 additions & 0 deletions gantt-chart/.cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* permissions and limitations under the License.
*/

const { ADMIN_AUTH } = require('./constants');

// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
Expand All @@ -38,3 +40,42 @@
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })

Cypress.Commands.overwrite('visit', (originalFn, url, options) => {
// Add the basic auth header when security enabled in the Elasticsearch 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 Kibana 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 Elasticsearch 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));
});
19 changes: 19 additions & 0 deletions gantt-chart/.cypress/support/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

export const ADMIN_AUTH = {
username: 'admin',
password: 'admin',
};
5 changes: 5 additions & 0 deletions gantt-chart/.cypress/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')

// Switch the base URL of Elasticsearch when security enabled in the cluster
if (Cypress.env('security_enabled')) {
Cypress.env('elasticsearch', 'https://localhost:9200');
}
8 changes: 6 additions & 2 deletions gantt-chart/cypress.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"baseUrl": "http://localhost:5601",
"video": true,
"fixturesFolder": ".cypress/fixtures",
"integrationFolder": ".cypress/integration",
Expand All @@ -11,5 +10,10 @@
"viewportHeight": 1600,
"requestTimeout": 60000,
"responseTimeout": 60000,
"defaultCommandTimeout": 60000
"defaultCommandTimeout": 60000,
"env": {
"elasticsearch": "localhost:9200",
"kibana": "localhost:5601",
"security_enabled": true
}
}

0 comments on commit 2cf95b1

Please sign in to comment.