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

[7.x] [Uptime] Add TLS alert functional test (#65303) #65571

Merged
merged 2 commits into from
May 7, 2020
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
8 changes: 6 additions & 2 deletions x-pack/test/functional/services/uptime/alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ export function UptimeAlertsProvider({ getService }: FtrProviderContext) {
const browser = getService('browser');

return {
async openFlyout() {
async openFlyout(alertType: 'monitorStatus' | 'tls') {
await testSubjects.click('xpack.uptime.alertsPopover.toggleButton', 5000);
await testSubjects.click('xpack.uptime.openAlertContextPanel', 5000);
await testSubjects.click('xpack.uptime.toggleAlertFlyout', 5000);
if (alertType === 'monitorStatus') {
await testSubjects.click('xpack.uptime.toggleAlertFlyout', 5000);
} else if (alertType === 'tls') {
await testSubjects.click('xpack.uptime.toggleTlsAlertFlyout');
}
},
async openMonitorStatusAlertType(alertType: string) {
return testSubjects.click(`xpack.uptime.alerts.${alertType}-SelectOption`, 5000);
Expand Down
283 changes: 184 additions & 99 deletions x-pack/test/functional_with_es_ssl/apps/uptime/alert_flyout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,123 +8,208 @@ import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';

export default ({ getPageObjects, getService }: FtrProviderContext) => {
describe('overview page alert flyout controls', function() {
const DEFAULT_DATE_START = 'Sep 10, 2019 @ 12:40:08.078';
const DEFAULT_DATE_END = 'Sep 11, 2019 @ 19:40:08.078';
describe('uptime alerts', () => {
const pageObjects = getPageObjects(['common', 'uptime']);
const supertest = getService('supertest');
const retry = getService('retry');
let alerts: any;

before(async () => {
alerts = getService('uptime').alerts;
});
describe('overview page alert flyout controls', function() {
const DEFAULT_DATE_START = 'Sep 10, 2019 @ 12:40:08.078';
const DEFAULT_DATE_END = 'Sep 11, 2019 @ 19:40:08.078';
let alerts: any;

it('can open alert flyout', async () => {
await pageObjects.uptime.goToUptimeOverviewAndLoadData(DEFAULT_DATE_START, DEFAULT_DATE_END);
await alerts.openFlyout();
});
before(async () => {
alerts = getService('uptime').alerts;
});

it('can set alert name', async () => {
await alerts.setAlertName('uptime-test');
});
it('can open alert flyout', async () => {
await pageObjects.uptime.goToUptimeOverviewAndLoadData(
DEFAULT_DATE_START,
DEFAULT_DATE_END
);
await alerts.openFlyout('monitorStatus');
});

it('can set alert tags', async () => {
await alerts.setAlertTags(['uptime', 'another']);
});
it('can set alert name', async () => {
await alerts.setAlertName('uptime-test');
});

it('can set alert interval', async () => {
await alerts.setAlertInterval('11');
});
it('can set alert tags', async () => {
await alerts.setAlertTags(['uptime', 'another']);
});

it('can set alert throttle interval', async () => {
await alerts.setAlertThrottleInterval('30');
});
it('can set alert interval', async () => {
await alerts.setAlertInterval('11');
});

it('can set alert status number of time', async () => {
await alerts.setAlertStatusNumTimes('3');
});
it('can set alert time range', async () => {
await alerts.setAlertTimerangeSelection('1');
});
it('can set monitor hours', async () => {
await alerts.setMonitorStatusSelectableToHours();
});
it('can set alert throttle interval', async () => {
await alerts.setAlertThrottleInterval('30');
});

it('can set kuery bar filters', async () => {
await pageObjects.uptime.setAlertKueryBarText('monitor.id: "0001-up"');
});
it('can set alert status number of time', async () => {
await alerts.setAlertStatusNumTimes('3');
});

it('can select location filter', async () => {
await alerts.clickAddFilterLocation();
await alerts.clickLocationExpression('mpls');
});
it('can set alert time range', async () => {
await alerts.setAlertTimerangeSelection('1');
});

it('can select port filter', async () => {
await alerts.clickAddFilterPort();
await alerts.clickPortExpression('5678');
});
it('can set monitor hours', async () => {
await alerts.setMonitorStatusSelectableToHours();
});

it('can select type/scheme filter', async () => {
await alerts.clickAddFilterType();
await alerts.clickTypeExpression('http');
});
it('can set kuery bar filters', async () => {
await pageObjects.uptime.setAlertKueryBarText('monitor.id: "0001-up"');
});

it('can select location filter', async () => {
await alerts.clickAddFilterLocation();
await alerts.clickLocationExpression('mpls');
});

it('can select port filter', async () => {
await alerts.clickAddFilterPort();
await alerts.clickPortExpression('5678');
});

it('can select type/scheme filter', async () => {
await alerts.clickAddFilterType();
await alerts.clickTypeExpression('http');
});

it('can save alert', async () => {
await alerts.clickSaveAlertButton();
});

it('can save alert', async () => {
await alerts.clickSaveAlertButton();
it('posts an alert, verifies its presence, and deletes the alert', async () => {
// The creation of the alert could take some time, so the first few times we query after
// the previous line resolves, the API may not be done creating the alert yet, so we
// put the fetch code in a retry block with a timeout.
let alert: any;
await retry.tryForTime(15000, async () => {
const apiResponse = await supertest.get('/api/alert/_find?search=uptime-test');
const alertsFromThisTest = apiResponse.body.data.filter(
({ name }: { name: string }) => name === 'uptime-test'
);
expect(alertsFromThisTest).to.have.length(1);
alert = alertsFromThisTest[0];
});

// Ensure the parameters and other stateful data
// on the alert match up with the values we provided
// for our test helper to input into the flyout.
const {
actions,
alertTypeId,
consumer,
id,
params: { numTimes, timerange, locations, filters },
schedule: { interval },
tags,
} = alert;

try {
// we're not testing the flyout's ability to associate alerts with action connectors
expect(actions).to.eql([]);

expect(alertTypeId).to.eql('xpack.uptime.alerts.monitorStatus');
expect(consumer).to.eql('uptime');
expect(interval).to.eql('11m');
expect(tags).to.eql(['uptime', 'another']);
expect(numTimes).to.be(3);
expect(timerange.from).to.be('now-1h');
expect(timerange.to).to.be('now');
expect(locations).to.eql(['mpls']);
expect(filters).to.eql(
'{"bool":{"filter":[{"bool":{"should":[{"match_phrase":{"monitor.id":"0001-up"}}],' +
'"minimum_should_match":1}},{"bool":{"filter":[{"bool":{"should":[{"match":{"observer.geo.name":"mpls"}}],' +
'"minimum_should_match":1}},{"bool":{"filter":[{"bool":{"should":[{"match":{"url.port":5678}}],' +
'"minimum_should_match":1}},{"bool":{"should":[{"match":{"monitor.type":"http"}}],"minimum_should_match":1}}]}}]}}]}}'
);
} finally {
await supertest
.delete(`/api/alert/${id}`)
.set('kbn-xsrf', 'true')
.expect(204);
}
});
});

it('posts an alert, verifies its presence, and deletes the alert', async () => {
// The creation of the alert could take some time, so the first few times we query after
// the previous line resolves, the API may not be done creating the alert yet, so we
// put the fetch code in a retry block with a timeout.
let alert: any;
await retry.tryForTime(15000, async () => {
const apiResponse = await supertest.get('/api/alert/_find?search=uptime-test');
const alertsFromThisTest = apiResponse.body.data.filter(
({ name }: { name: string }) => name === 'uptime-test'
);
expect(alertsFromThisTest).to.have.length(1);
alert = alertsFromThisTest[0];
});

// Ensure the parameters and other stateful data
// on the alert match up with the values we provided
// for our test helper to input into the flyout.
const {
actions,
alertTypeId,
consumer,
id,
params: { numTimes, timerange, locations, filters },
schedule: { interval },
tags,
} = alert;

try {
// we're not testing the flyout's ability to associate alerts with action connectors
expect(actions).to.eql([]);

expect(alertTypeId).to.eql('xpack.uptime.alerts.monitorStatus');
expect(consumer).to.eql('uptime');
expect(interval).to.eql('11m');
expect(tags).to.eql(['uptime', 'another']);
expect(numTimes).to.be(3);
expect(timerange.from).to.be('now-1h');
expect(timerange.to).to.be('now');
expect(locations).to.eql(['mpls']);
expect(filters).to.eql(
'{"bool":{"filter":[{"bool":{"should":[{"match_phrase":{"monitor.id":"0001-up"}}],' +
'"minimum_should_match":1}},{"bool":{"filter":[{"bool":{"should":[{"match":{"observer.geo.name":"mpls"}}],' +
'"minimum_should_match":1}},{"bool":{"filter":[{"bool":{"should":[{"match":{"url.port":5678}}],' +
'"minimum_should_match":1}},{"bool":{"should":[{"match":{"monitor.type":"http"}}],"minimum_should_match":1}}]}}]}}]}}'
describe('tls alert', function() {
const DEFAULT_DATE_START = 'Sep 10, 2019 @ 12:40:08.078';
const DEFAULT_DATE_END = 'Sep 11, 2019 @ 19:40:08.078';
let alerts: any;
const alertId = 'uptime-tls';

before(async () => {
alerts = getService('uptime').alerts;
});

it('can open alert flyout', async () => {
await pageObjects.uptime.goToUptimeOverviewAndLoadData(
DEFAULT_DATE_START,
DEFAULT_DATE_END
);
} finally {
await supertest
.delete(`/api/alert/${id}`)
.set('kbn-xsrf', 'true')
.expect(204);
}
await alerts.openFlyout('tls');
});

it('can set alert name', async () => {
await alerts.setAlertName(alertId);
});

it('can set alert tags', async () => {
await alerts.setAlertTags(['uptime', 'certs']);
});

it('can set alert interval', async () => {
await alerts.setAlertInterval('11');
});

it('can set alert throttle interval', async () => {
await alerts.setAlertThrottleInterval('30');
});

it('can save alert', async () => {
await alerts.clickSaveAlertButton();
});

it('has created a valid alert with expected parameters', async () => {
let alert: any;
await retry.tryForTime(15000, async () => {
const apiResponse = await supertest.get(`/api/alert/_find?search=${alertId}`);
const alertsFromThisTest = apiResponse.body.data.filter(
({ name }: { name: string }) => name === alertId
);
expect(alertsFromThisTest).to.have.length(1);
alert = alertsFromThisTest[0];
});

// Ensure the parameters and other stateful data
// on the alert match up with the values we provided
// for our test helper to input into the flyout.
const {
actions,
alertTypeId,
consumer,
id,
params,
schedule: { interval },
tags,
} = alert;
try {
expect(actions).to.eql([]);
expect(alertTypeId).to.eql('xpack.uptime.alerts.tls');
expect(consumer).to.eql('uptime');
expect(tags).to.eql(['uptime', 'certs']);
expect(params).to.eql({});
expect(interval).to.eql('11m');
} finally {
await supertest
.delete(`/api/alert/${id}`)
.set('kbn-xsrf', 'true')
.expect(204);
}
});
});
});
};