Skip to content

Commit e481dc1

Browse files
committed
Merge remote-tracking branch 'upstream/master' into switch-to-core-application-service
2 parents 6f6a695 + 712e917 commit e481dc1

41 files changed

Lines changed: 3159 additions & 46 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/kbn-es/src/utils/native_realm.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ exports.NativeRealm = class NativeRealm {
7676
}
7777

7878
const reservedUsers = await this.getReservedUsers();
79+
if (!reservedUsers || reservedUsers.length < 1) {
80+
throw new Error('no reserved users found, unable to set native realm passwords');
81+
}
82+
7983
await Promise.all(
8084
reservedUsers.map(async user => {
8185
await this.setPassword(user, options[`password.${user}`]);

x-pack/plugins/infra/public/pages/metrics/inventory_view/components/waffle/waffle_time_controls.tsx

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { EuiButtonEmpty, EuiDatePicker, EuiFormControlLayout } from '@elastic/eui';
7+
import { EuiButton, EuiDatePicker, EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
88
import { FormattedMessage } from '@kbn/i18n/react';
99
import moment, { Moment } from 'moment';
1010
import React, { useCallback } from 'react';
11+
import { withTheme, EuiTheme } from '../../../../../../../observability/public';
1112
import { useWaffleTimeContext } from '../../hooks/use_waffle_time';
1213

13-
export const WaffleTimeControls = () => {
14+
interface Props {
15+
theme: EuiTheme;
16+
}
17+
18+
export const WaffleTimeControls = withTheme(({ theme }: Props) => {
1419
const {
1520
currentTime,
1621
isAutoReloading,
@@ -22,19 +27,19 @@ export const WaffleTimeControls = () => {
2227
const currentMoment = moment(currentTime);
2328

2429
const liveStreamingButton = isAutoReloading ? (
25-
<EuiButtonEmpty color="primary" iconSide="left" iconType="pause" onClick={stopAutoReload}>
30+
<EuiButton color="primary" iconSide="left" iconType="pause" onClick={stopAutoReload}>
2631
<FormattedMessage
2732
id="xpack.infra.waffleTime.stopRefreshingButtonLabel"
2833
defaultMessage="Stop refreshing"
2934
/>
30-
</EuiButtonEmpty>
35+
</EuiButton>
3136
) : (
32-
<EuiButtonEmpty iconSide="left" iconType="play" onClick={startAutoReload}>
37+
<EuiButton iconSide="left" iconType="play" onClick={startAutoReload}>
3338
<FormattedMessage
3439
id="xpack.infra.waffleTime.autoRefreshButtonLabel"
3540
defaultMessage="Auto-refresh"
3641
/>
37-
</EuiButtonEmpty>
42+
</EuiButton>
3843
);
3944

4045
const handleChangeDate = useCallback(
@@ -47,20 +52,31 @@ export const WaffleTimeControls = () => {
4752
);
4853

4954
return (
50-
<EuiFormControlLayout append={liveStreamingButton} data-test-subj="waffleDatePicker">
51-
<EuiDatePicker
52-
className="euiFieldText--inGroup"
53-
dateFormat="L LTS"
54-
disabled={isAutoReloading}
55-
injectTimes={currentMoment ? [currentMoment] : []}
56-
isLoading={isAutoReloading}
57-
onChange={handleChangeDate}
58-
popperPlacement="top-end"
59-
selected={currentMoment}
60-
shouldCloseOnSelect
61-
showTimeSelect
62-
timeFormat="LT"
63-
/>
64-
</EuiFormControlLayout>
55+
<EuiFlexGroup alignItems="center" gutterSize="none">
56+
<EuiFlexItem
57+
grow={false}
58+
style={{
59+
border: theme.eui.euiFormInputGroupBorder,
60+
boxShadow: `0px 3px 2px ${theme.eui.euiTableActionsBorderColor}, 0px 1px 1px ${theme.eui.euiTableActionsBorderColor}`,
61+
marginRight: theme.eui.paddingSizes.m,
62+
}}
63+
data-test-subj="waffleDatePicker"
64+
>
65+
<EuiDatePicker
66+
className="euiFieldText--inGroup"
67+
dateFormat="L LTS"
68+
disabled={isAutoReloading}
69+
injectTimes={currentMoment ? [currentMoment] : []}
70+
isLoading={isAutoReloading}
71+
onChange={handleChangeDate}
72+
popperPlacement="top-end"
73+
selected={currentMoment}
74+
shouldCloseOnSelect
75+
showTimeSelect
76+
timeFormat="LT"
77+
/>
78+
</EuiFlexItem>
79+
<EuiFlexItem grow={false}>{liveStreamingButton}</EuiFlexItem>
80+
</EuiFlexGroup>
6581
);
66-
};
82+
});

x-pack/scripts/functional_tests.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const onlyNotInCoverageTests = [
2121
require.resolve('../test/alerting_api_integration/spaces_only/config.ts'),
2222
require.resolve('../test/alerting_api_integration/security_and_spaces/config.ts'),
2323
require.resolve('../test/detection_engine_api_integration/security_and_spaces/config.ts'),
24+
require.resolve('../test/detection_engine_api_integration/basic/config.ts'),
2425
require.resolve('../test/plugin_api_integration/config.ts'),
2526
require.resolve('../test/kerberos_api_integration/config.ts'),
2627
require.resolve('../test/kerberos_api_integration/anonymous_access.config.ts'),
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { createTestConfig } from '../common/config';
8+
9+
// eslint-disable-next-line import/no-default-export
10+
export default createTestConfig('basic', {
11+
disabledPlugins: [],
12+
license: 'basic',
13+
ssl: true,
14+
});
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import expect from '@kbn/expect';
8+
9+
import { DETECTION_ENGINE_PREPACKAGED_URL } from '../../../../plugins/siem/common/constants';
10+
import { FtrProviderContext } from '../../common/ftr_provider_context';
11+
import { createSignalsIndex, deleteAllAlerts, deleteSignalsIndex } from '../../utils';
12+
13+
// eslint-disable-next-line import/no-default-export
14+
export default ({ getService }: FtrProviderContext): void => {
15+
const supertest = getService('supertest');
16+
const es = getService('legacyEs');
17+
18+
describe('add_prepackaged_rules', () => {
19+
describe('validation errors', () => {
20+
it('should give an error that the index must exist first if it does not exist before adding prepackaged rules', async () => {
21+
const { body } = await supertest
22+
.put(DETECTION_ENGINE_PREPACKAGED_URL)
23+
.set('kbn-xsrf', 'true')
24+
.send()
25+
.expect(400);
26+
27+
expect(body).to.eql({
28+
message:
29+
'Pre-packaged rules cannot be installed until the signals index is created: .siem-signals-default',
30+
status_code: 400,
31+
});
32+
});
33+
});
34+
35+
describe('creating prepackaged rules', () => {
36+
beforeEach(async () => {
37+
await createSignalsIndex(supertest);
38+
});
39+
40+
afterEach(async () => {
41+
await deleteSignalsIndex(supertest);
42+
await deleteAllAlerts(es);
43+
});
44+
45+
it('should contain two output keys of rules_installed and rules_updated', async () => {
46+
const { body } = await supertest
47+
.put(DETECTION_ENGINE_PREPACKAGED_URL)
48+
.set('kbn-xsrf', 'true')
49+
.send()
50+
.expect(200);
51+
52+
expect(Object.keys(body)).to.eql(['rules_installed', 'rules_updated']);
53+
});
54+
55+
it('should create the prepackaged rules and return a count greater than zero', async () => {
56+
const { body } = await supertest
57+
.put(DETECTION_ENGINE_PREPACKAGED_URL)
58+
.set('kbn-xsrf', 'true')
59+
.send()
60+
.expect(200);
61+
62+
expect(body.rules_installed).to.be.greaterThan(0);
63+
});
64+
65+
it('should create the prepackaged rules that the rules_updated is of size zero', async () => {
66+
const { body } = await supertest
67+
.put(DETECTION_ENGINE_PREPACKAGED_URL)
68+
.set('kbn-xsrf', 'true')
69+
.send()
70+
.expect(200);
71+
72+
expect(body.rules_updated).to.eql(0);
73+
});
74+
75+
it('should be possible to call the API twice and the second time the number of rules installed should be zero', async () => {
76+
await supertest
77+
.put(DETECTION_ENGINE_PREPACKAGED_URL)
78+
.set('kbn-xsrf', 'true')
79+
.send()
80+
.expect(200);
81+
82+
const { body } = await supertest
83+
.put(DETECTION_ENGINE_PREPACKAGED_URL)
84+
.set('kbn-xsrf', 'true')
85+
.send()
86+
.expect(200);
87+
88+
expect(body.rules_installed).to.eql(0);
89+
});
90+
});
91+
});
92+
};
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import expect from '@kbn/expect';
8+
9+
import { DETECTION_ENGINE_RULES_URL } from '../../../../plugins/siem/common/constants';
10+
import { FtrProviderContext } from '../../common/ftr_provider_context';
11+
import {
12+
createSignalsIndex,
13+
deleteAllAlerts,
14+
deleteSignalsIndex,
15+
getSimpleRule,
16+
getSimpleRuleOutput,
17+
getSimpleRuleOutputWithoutRuleId,
18+
getSimpleRuleWithoutRuleId,
19+
removeServerGeneratedProperties,
20+
removeServerGeneratedPropertiesIncludingRuleId,
21+
getSimpleMlRule,
22+
} from '../../utils';
23+
24+
// eslint-disable-next-line import/no-default-export
25+
export default ({ getService }: FtrProviderContext) => {
26+
const supertest = getService('supertest');
27+
const es = getService('legacyEs');
28+
29+
describe('create_rules', () => {
30+
describe('validation errors', () => {
31+
it('should give an error that the index must exist first if it does not exist before creating a rule', async () => {
32+
const { body } = await supertest
33+
.post(DETECTION_ENGINE_RULES_URL)
34+
.set('kbn-xsrf', 'true')
35+
.send(getSimpleRule())
36+
.expect(400);
37+
38+
expect(body).to.eql({
39+
message:
40+
'To create a rule, the index must exist first. Index .siem-signals-default does not exist',
41+
status_code: 400,
42+
});
43+
});
44+
});
45+
46+
describe('creating rules', () => {
47+
beforeEach(async () => {
48+
await createSignalsIndex(supertest);
49+
});
50+
51+
afterEach(async () => {
52+
await deleteSignalsIndex(supertest);
53+
await deleteAllAlerts(es);
54+
});
55+
56+
it('should create a single rule with a rule_id', async () => {
57+
const { body } = await supertest
58+
.post(DETECTION_ENGINE_RULES_URL)
59+
.set('kbn-xsrf', 'true')
60+
.send(getSimpleRule())
61+
.expect(200);
62+
63+
const bodyToCompare = removeServerGeneratedProperties(body);
64+
expect(bodyToCompare).to.eql(getSimpleRuleOutput());
65+
});
66+
67+
it('should create a single rule without an input index', async () => {
68+
const { index, ...payload } = getSimpleRule();
69+
const { index: _index, ...expected } = getSimpleRuleOutput();
70+
71+
const { body } = await supertest
72+
.post(DETECTION_ENGINE_RULES_URL)
73+
.set('kbn-xsrf', 'true')
74+
.send(payload)
75+
.expect(200);
76+
77+
const bodyToCompare = removeServerGeneratedProperties(body);
78+
expect(bodyToCompare).to.eql(expected);
79+
});
80+
81+
it('should create a single rule without a rule_id', async () => {
82+
const { body } = await supertest
83+
.post(DETECTION_ENGINE_RULES_URL)
84+
.set('kbn-xsrf', 'true')
85+
.send(getSimpleRuleWithoutRuleId())
86+
.expect(200);
87+
88+
const bodyToCompare = removeServerGeneratedPropertiesIncludingRuleId(body);
89+
expect(bodyToCompare).to.eql(getSimpleRuleOutputWithoutRuleId());
90+
});
91+
92+
it('should give a 403 when trying to create a single Machine Learning rule since the license is basic', async () => {
93+
const { body } = await supertest
94+
.post(DETECTION_ENGINE_RULES_URL)
95+
.set('kbn-xsrf', 'true')
96+
.send(getSimpleMlRule())
97+
.expect(403);
98+
99+
const bodyToCompare = removeServerGeneratedProperties(body);
100+
expect(bodyToCompare).to.eql({
101+
message: 'Your license does not support machine learning. Please upgrade your license.',
102+
status_code: 403,
103+
});
104+
});
105+
106+
it('should cause a 409 conflict if we attempt to create the same rule_id twice', async () => {
107+
await supertest
108+
.post(DETECTION_ENGINE_RULES_URL)
109+
.set('kbn-xsrf', 'true')
110+
.send(getSimpleRule())
111+
.expect(200);
112+
113+
const { body } = await supertest
114+
.post(DETECTION_ENGINE_RULES_URL)
115+
.set('kbn-xsrf', 'true')
116+
.send(getSimpleRule())
117+
.expect(409);
118+
119+
expect(body).to.eql({
120+
message: 'rule_id: "rule-1" already exists',
121+
status_code: 409,
122+
});
123+
});
124+
});
125+
});
126+
};

0 commit comments

Comments
 (0)