forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[security solutions][lists] Adds end to end tests (elastic#74473)
## Summary Adds initial set of end to end tests for lists You can run all of these with the command from kibana root: ```ts node scripts/functional_tests --config x-pack/test/lists_api_integration/security_and_spaces/config.ts ``` Fixes a few minor bugs found such as... * Validation for importing lists was not checking if the indexes were created first * Some wording for the error messages had duplicate words within them ### Checklist - [x] [Unit or functional tests](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility) were updated or added to match the most common scenarios
- Loading branch information
1 parent
f4b44c7
commit ccd228d
Showing
34 changed files
with
1,709 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
x-pack/plugins/lists/common/schemas/request/update_list_schema.mock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { DESCRIPTION, LIST_ID, META, NAME, _VERSION } from '../../constants.mock'; | ||
|
||
import { UpdateListSchema } from './update_list_schema'; | ||
|
||
export const getUpdateListSchemaMock = (): UpdateListSchema => ({ | ||
_version: _VERSION, | ||
description: DESCRIPTION, | ||
id: LIST_ID, | ||
meta: META, | ||
name: NAME, | ||
}); | ||
|
||
/** | ||
* Useful for end to end tests and other mechanisms which want to fill in the values | ||
* after doing a get of the structure. | ||
*/ | ||
export const getUpdateMinimalListSchemaMock = (): UpdateListSchema => ({ | ||
description: DESCRIPTION, | ||
id: LIST_ID, | ||
name: NAME, | ||
}); |
48 changes: 48 additions & 0 deletions
48
x-pack/plugins/lists/common/schemas/request/update_list_schema.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { left } from 'fp-ts/lib/Either'; | ||
import { pipe } from 'fp-ts/lib/pipeable'; | ||
|
||
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports'; | ||
|
||
import { UpdateListSchema, updateListSchema } from './update_list_schema'; | ||
import { getUpdateListSchemaMock } from './update_list_schema.mock'; | ||
|
||
describe('update_list_schema', () => { | ||
test('it should validate a typical list request', () => { | ||
const payload = getUpdateListSchemaMock(); | ||
const decoded = updateListSchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(payload); | ||
}); | ||
|
||
test('it should accept an undefined for "meta" but strip it out', () => { | ||
const payload = getUpdateListSchemaMock(); | ||
const outputPayload = getUpdateListSchemaMock(); | ||
delete payload.meta; | ||
const decoded = updateListSchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
delete outputPayload.meta; | ||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(outputPayload); | ||
}); | ||
|
||
test('it should not allow an extra key to be sent in', () => { | ||
const payload: UpdateListSchema & { | ||
extraKey?: string; | ||
} = getUpdateListSchemaMock(); | ||
payload.extraKey = 'some new value'; | ||
const decoded = updateListSchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
expect(getPaths(left(message.errors))).toEqual(['invalid keys "extraKey"']); | ||
expect(message.schema).toEqual({}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import path from 'path'; | ||
import { CA_CERT_PATH } from '@kbn/dev-utils'; | ||
import { FtrConfigProviderContext } from '@kbn/test/types/ftr'; | ||
import { services } from './services'; | ||
|
||
interface CreateTestConfigOptions { | ||
license: string; | ||
disabledPlugins?: string[]; | ||
ssl?: boolean; | ||
} | ||
|
||
export function createTestConfig(name: string, options: CreateTestConfigOptions) { | ||
const { license = 'trial', disabledPlugins = [], ssl = false } = options; | ||
|
||
return async ({ readConfigFile }: FtrConfigProviderContext) => { | ||
const xPackApiIntegrationTestsConfig = await readConfigFile( | ||
require.resolve('../../api_integration/config.ts') | ||
); | ||
const servers = { | ||
...xPackApiIntegrationTestsConfig.get('servers'), | ||
elasticsearch: { | ||
...xPackApiIntegrationTestsConfig.get('servers.elasticsearch'), | ||
protocol: ssl ? 'https' : 'http', | ||
}, | ||
}; | ||
|
||
return { | ||
testFiles: [require.resolve(`../${name}/tests/`)], | ||
servers, | ||
services, | ||
junit: { | ||
reportName: 'X-Pack Lists Integration Tests', | ||
}, | ||
esArchiver: xPackApiIntegrationTestsConfig.get('esArchiver'), | ||
esTestCluster: { | ||
...xPackApiIntegrationTestsConfig.get('esTestCluster'), | ||
license, | ||
ssl, | ||
serverArgs: [ | ||
`xpack.license.self_generated.type=${license}`, | ||
`xpack.security.enabled=${!disabledPlugins.includes('security')}`, | ||
], | ||
}, | ||
kbnTestServer: { | ||
...xPackApiIntegrationTestsConfig.get('kbnTestServer'), | ||
serverArgs: [ | ||
...xPackApiIntegrationTestsConfig.get('kbnTestServer.serverArgs'), | ||
...disabledPlugins.map((key) => `--xpack.${key}.enabled=false`), | ||
`--plugin-path=${path.join(__dirname, 'fixtures', 'plugins', 'alerts')}`, | ||
`--plugin-path=${path.join(__dirname, 'fixtures', 'plugins', 'actions')}`, | ||
`--plugin-path=${path.join(__dirname, 'fixtures', 'plugins', 'task_manager')}`, | ||
`--plugin-path=${path.join(__dirname, 'fixtures', 'plugins', 'aad')}`, | ||
...(ssl | ||
? [ | ||
`--elasticsearch.hosts=${servers.elasticsearch.protocol}://${servers.elasticsearch.hostname}:${servers.elasticsearch.port}`, | ||
`--elasticsearch.ssl.certificateAuthorities=${CA_CERT_PATH}`, | ||
] | ||
: []), | ||
], | ||
}, | ||
}; | ||
}; | ||
} |
11 changes: 11 additions & 0 deletions
11
x-pack/test/lists_api_integration/common/ftr_provider_context.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { GenericFtrProviderContext } from '@kbn/test/types/ftr'; | ||
|
||
import { services } from './services'; | ||
|
||
export type FtrProviderContext = GenericFtrProviderContext<typeof services, {}>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export { services } from '../../api_integration/services'; |
14 changes: 14 additions & 0 deletions
14
x-pack/test/lists_api_integration/security_and_spaces/config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { createTestConfig } from '../common/config'; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default createTestConfig('security_and_spaces', { | ||
disabledPlugins: [], | ||
license: 'trial', | ||
ssl: true, | ||
}); |
Oops, something went wrong.