Skip to content

Commit

Permalink
Merge branch 'enhance/use-bfetch-in-search' of github.com:lizozom/kib…
Browse files Browse the repository at this point in the history
…ana into enhance/use-bfetch-in-search
  • Loading branch information
Liza K committed Nov 24, 2020
2 parents 42ec042 + 55629da commit 6e8cc8d
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 37 deletions.
1 change: 1 addition & 0 deletions x-pack/plugins/security_solution/cypress/cypress.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"baseUrl": "http://localhost:5601",
"defaultCommandTimeout": 120000,
"experimentalNetworkStubbing": true,
"retries": {
"runMode": 2
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"filebeatZeek": 71129,
"packetbeatDNS": 1090,
"packetbeatFlow": 722153,
"packetbeatTLS": 340,
"__typename": "OverviewNetworkData"
"packetbeatTLS": 340
},
"overviewHost": {
"auditbeatAuditd": 123,
Expand All @@ -27,7 +26,6 @@
"endgameSecurity": 397,
"filebeatSystemModule": 890,
"winlogbeatSecurity": 70,
"winlogbeatMWSysmonOperational": 30,
"__typename": "OverviewHostData"
"winlogbeatMWSysmonOperational": 30
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
markInProgressFirstAlert,
goToInProgressAlerts,
} from '../tasks/alerts';
import { esArchiverLoad } from '../tasks/es_archiver';
import { esArchiverLoad, esArchiverUnload } from '../tasks/es_archiver';
import { loginAndWaitForPage } from '../tasks/login';

import { DETECTIONS_URL } from '../urls/navigation';
Expand All @@ -37,6 +37,10 @@ describe('Alerts', () => {
loginAndWaitForPage(DETECTIONS_URL);
});

afterEach(() => {
esArchiverUnload('alerts');
});

it('Closes and opens alerts', () => {
waitForAlertsPanelToBeLoaded();
waitForAlertsToBeLoaded();
Expand Down Expand Up @@ -165,6 +169,10 @@ describe('Alerts', () => {
loginAndWaitForPage(DETECTIONS_URL);
});

afterEach(() => {
esArchiverUnload('closed_alerts');
});

it('Open one alert when more than one closed alerts are selected', () => {
waitForAlerts();
goToClosedAlerts();
Expand Down Expand Up @@ -212,6 +220,10 @@ describe('Alerts', () => {
loginAndWaitForPage(DETECTIONS_URL);
});

afterEach(() => {
esArchiverUnload('alerts');
});

it('Mark one alert in progress when more than one open alerts are selected', () => {
waitForAlerts();
waitForAlertsToBeLoaded();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ describe('Alerts detection rules', () => {
});
});

it('Auto refreshes rules', () => {
// FIXME: UI hangs on loading
it.skip('Auto refreshes rules', () => {
cy.clock(Date.now());

loginAndWaitForPageWithoutDateRange(DETECTIONS_URL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,7 @@ describe('Custom detection rules creation', () => {
});
});

// FLAKY: https://github.com/elastic/kibana/issues/83772
describe.skip('Custom detection rules deletion and edition', () => {
describe('Custom detection rules deletion and edition', () => {
beforeEach(() => {
esArchiverLoad('custom_rules');
loginAndWaitForPageWithoutDateRange(DETECTIONS_URL);
Expand All @@ -225,7 +224,7 @@ describe.skip('Custom detection rules deletion and edition', () => {
goToManageAlertsDetectionRules();
});

after(() => {
afterEach(() => {
esArchiverUnload('custom_rules');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import { DETECTIONS_URL } from '../urls/navigation';

const EXPECTED_EXPORTED_RULE_FILE_PATH = 'cypress/test_files/expected_rules_export.ndjson';

// FLAKY: https://github.com/elastic/kibana/issues/69849
describe.skip('Export rules', () => {
describe('Export rules', () => {
before(() => {
esArchiverLoad('export_rule');
cy.server();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ import { loginAndWaitForPage } from '../tasks/login';

import { OVERVIEW_URL } from '../urls/navigation';

import overviewFixture from '../fixtures/overview_search_strategy.json';
import emptyInstance from '../fixtures/empty_instance.json';

describe('Overview Page', () => {
it('Host stats render with correct values', () => {
cy.stubSearchStrategyApi('overview_search_strategy');
cy.stubSearchStrategyApi(overviewFixture, 'overviewHost');
loginAndWaitForPage(OVERVIEW_URL);
expandHostStats();

Expand All @@ -23,7 +26,7 @@ describe('Overview Page', () => {
});

it('Network stats render with correct values', () => {
cy.stubSearchStrategyApi('overview_search_strategy');
cy.stubSearchStrategyApi(overviewFixture, 'overviewNetwork');
loginAndWaitForPage(OVERVIEW_URL);
expandNetworkStats();

Expand All @@ -33,14 +36,8 @@ describe('Overview Page', () => {
});

describe('with no data', () => {
before(() => {
cy.server();
cy.fixture('empty_instance').as('emptyInstance');
loginAndWaitForPage(OVERVIEW_URL);
cy.route('POST', '**/internal/search/securitySolutionIndexFields', '@emptyInstance');
});

it('Splash screen should be here', () => {
cy.stubSearchStrategyApi(emptyInstance, undefined, 'securitySolutionIndexFields');
cy.get(OVERVIEW_EMPTY_PAGE).should('be.visible');
});
});
Expand Down
70 changes: 56 additions & 14 deletions x-pack/plugins/security_solution/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,66 @@
// -- This is will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })

Cypress.Commands.add('stubSecurityApi', function (dataFileName) {
cy.on('window:before:load', (win) => {
win.fetch = null;
});
cy.server();
cy.fixture(dataFileName).as(`${dataFileName}JSON`);
cy.route('POST', 'api/solutions/security/graphql', `@${dataFileName}JSON`);
});
import { findIndex } from 'lodash/fp';

const getFindRequestConfig = (searchStrategyName, factoryQueryType) => {
if (!factoryQueryType) {
return {
options: { strategy: searchStrategyName },
};
}

return {
options: { strategy: searchStrategyName },
request: { factoryQueryType },
};
};

Cypress.Commands.add(
'stubSearchStrategyApi',
function (dataFileName, searchStrategyName = 'securitySolutionSearchStrategy') {
cy.on('window:before:load', (win) => {
win.fetch = null;
function (stubObject, factoryQueryType, searchStrategyName = 'securitySolutionSearchStrategy') {
cy.route2('POST', '/internal/bsearch', (req) => {
const bodyObj = JSON.parse(req.body);
const findRequestConfig = getFindRequestConfig(searchStrategyName, factoryQueryType);

const requestIndex = findIndex(findRequestConfig, bodyObj.batch);

if (requestIndex > -1) {
return req.reply((res) => {
const responseObjectsArray = res.body.split('\n').map((responseString) => {
try {
return JSON.parse(responseString);
} catch {
return responseString;
}
});
const responseIndex = findIndex({ id: requestIndex }, responseObjectsArray);

const stubbedResponseObjectsArray = [...responseObjectsArray];
stubbedResponseObjectsArray[responseIndex] = {
...stubbedResponseObjectsArray[responseIndex],
result: {
...stubbedResponseObjectsArray[responseIndex].result,
...stubObject,
},
};

const stubbedResponse = stubbedResponseObjectsArray
.map((object) => {
try {
return JSON.stringify(object);
} catch {
return object;
}
})
.join('\n');

res.send(stubbedResponse);
});
}

req.reply();
});
cy.server();
cy.fixture(dataFileName).as(`${dataFileName}JSON`);
cy.route('POST', `internal/search/${searchStrategyName}`, `@${dataFileName}JSON`);
}
);

Expand Down
7 changes: 5 additions & 2 deletions x-pack/plugins/security_solution/cypress/support/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
declare namespace Cypress {
interface Chainable<Subject> {
promisify(): Promise<Subject>;
stubSecurityApi(dataFileName: string): Chainable<Subject>;
stubSearchStrategyApi(dataFileName: string, searchStrategyName?: string): Chainable<Subject>;
stubSearchStrategyApi(
stubObject: Record<string, unknown>,
factoryQueryType?: string,
searchStrategyName?: string
): Chainable<Subject>;
attachFile(fileName: string, fileType?: string): Chainable<JQuery>;
waitUntil(
fn: (subject: Subject) => boolean | Chainable<boolean>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@
"throttle": {
"type": "keyword"
},
"updatedAt": {
"type": "date"
},
"updatedBy": {
"type": "keyword"
}
Expand Down Expand Up @@ -9060,4 +9063,4 @@
}
}
}
}
}

0 comments on commit 6e8cc8d

Please sign in to comment.