-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for exception lists and fixed one flaky test found
- Loading branch information
1 parent
506e953
commit 9180ca1
Showing
13 changed files
with
650 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
77 changes: 77 additions & 0 deletions
77
x-pack/test/lists_api_integration/security_and_spaces/tests/create_exception_lists.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,77 @@ | ||
/* | ||
* 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 expect from '@kbn/expect'; | ||
|
||
import { ExceptionListSchema } from '../../../../plugins/lists/common'; | ||
import { EXCEPTION_LIST_URL } from '../../../../plugins/lists/common/constants'; | ||
import { FtrProviderContext } from '../../common/ftr_provider_context'; | ||
import { getExceptionResponseMockWithoutAutoGeneratedValues } from '../../../../plugins/lists/common/schemas/response/exception_list_schema.mock'; | ||
import { | ||
getCreateExceptionListMinimalSchemaMock, | ||
getCreateExceptionListMinimalSchemaMockWithoutId, | ||
} from '../../../../plugins/lists/common/schemas/request/create_exception_list_schema.mock'; | ||
|
||
import { deleteAllExceptions, removeExceptionListServerGeneratedProperties } from '../../utils'; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default ({ getService }: FtrProviderContext) => { | ||
const supertest = getService('supertest'); | ||
const es = getService('es'); | ||
|
||
describe('create_exception_lists', () => { | ||
describe('creating exception lists', () => { | ||
afterEach(async () => { | ||
await deleteAllExceptions(es); | ||
}); | ||
|
||
it('should create a simple exception list', async () => { | ||
const { body } = await supertest | ||
.post(EXCEPTION_LIST_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send(getCreateExceptionListMinimalSchemaMock()) | ||
.expect(200); | ||
|
||
const bodyToCompare = removeExceptionListServerGeneratedProperties(body); | ||
expect(bodyToCompare).to.eql(getExceptionResponseMockWithoutAutoGeneratedValues()); | ||
}); | ||
|
||
it('should create a simple exception list without a list_id', async () => { | ||
const { body } = await supertest | ||
.post(EXCEPTION_LIST_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send(getCreateExceptionListMinimalSchemaMockWithoutId()) | ||
.expect(200); | ||
|
||
const bodyToCompare = removeExceptionListServerGeneratedProperties(body); | ||
const outputtedList: Partial<ExceptionListSchema> = { | ||
...getExceptionResponseMockWithoutAutoGeneratedValues(), | ||
list_id: bodyToCompare.list_id, | ||
}; | ||
expect(bodyToCompare).to.eql(outputtedList); | ||
}); | ||
|
||
it('should cause a 409 conflict if we attempt to create the same list_id twice', async () => { | ||
await supertest | ||
.post(EXCEPTION_LIST_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send(getCreateExceptionListMinimalSchemaMock()) | ||
.expect(200); | ||
|
||
const { body } = await supertest | ||
.post(EXCEPTION_LIST_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send(getCreateExceptionListMinimalSchemaMock()) | ||
.expect(409); | ||
|
||
expect(body).to.eql({ | ||
message: 'exception list id: "some-list-id" already exists', | ||
status_code: 409, | ||
}); | ||
}); | ||
}); | ||
}); | ||
}; |
90 changes: 90 additions & 0 deletions
90
x-pack/test/lists_api_integration/security_and_spaces/tests/delete_exception_lists.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,90 @@ | ||
/* | ||
* 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 expect from '@kbn/expect'; | ||
|
||
import { getExceptionResponseMockWithoutAutoGeneratedValues } from '../../../../plugins/lists/common/schemas/response/exception_list_schema.mock'; | ||
import { getCreateExceptionListMinimalSchemaMock } from '../../../../plugins/lists/common/schemas/request/create_exception_list_schema.mock'; | ||
import { FtrProviderContext } from '../../common/ftr_provider_context'; | ||
import { EXCEPTION_LIST_URL } from '../../../../plugins/lists/common/constants'; | ||
|
||
import { deleteAllExceptions, removeExceptionListServerGeneratedProperties } from '../../utils'; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default ({ getService }: FtrProviderContext) => { | ||
const supertest = getService('supertest'); | ||
const es = getService('es'); | ||
|
||
describe('delete_exception_lists', () => { | ||
describe('delete exception lists', () => { | ||
afterEach(async () => { | ||
await deleteAllExceptions(es); | ||
}); | ||
|
||
it('should delete a single exception list by its list_id', async () => { | ||
// create an exception list | ||
await supertest | ||
.post(EXCEPTION_LIST_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send(getCreateExceptionListMinimalSchemaMock()) | ||
.expect(200); | ||
|
||
// delete the exception list by its list id | ||
const { body } = await supertest | ||
.delete( | ||
`${EXCEPTION_LIST_URL}?list_id=${getCreateExceptionListMinimalSchemaMock().list_id}` | ||
) | ||
.set('kbn-xsrf', 'true') | ||
.expect(200); | ||
|
||
const bodyToCompare = removeExceptionListServerGeneratedProperties(body); | ||
expect(bodyToCompare).to.eql(getExceptionResponseMockWithoutAutoGeneratedValues()); | ||
}); | ||
|
||
it('should delete a single exception list using an auto generated id', async () => { | ||
// create an exception list | ||
const { body: bodyWithCreatedList } = await supertest | ||
.post(EXCEPTION_LIST_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send(getCreateExceptionListMinimalSchemaMock()) | ||
.expect(200); | ||
|
||
// delete that list by its auto-generated id | ||
const { body } = await supertest | ||
.delete(`${EXCEPTION_LIST_URL}?id=${bodyWithCreatedList.id}`) | ||
.set('kbn-xsrf', 'true') | ||
.expect(200); | ||
|
||
const bodyToCompare = removeExceptionListServerGeneratedProperties(body); | ||
expect(bodyToCompare).to.eql(getExceptionResponseMockWithoutAutoGeneratedValues()); | ||
}); | ||
|
||
it('should return an error if the id does not exist when trying to delete it', async () => { | ||
const { body } = await supertest | ||
.delete(`${EXCEPTION_LIST_URL}?id=c1e1b359-7ac1-4e96-bc81-c683c092436f`) | ||
.set('kbn-xsrf', 'true') | ||
.expect(404); | ||
|
||
expect(body).to.eql({ | ||
message: 'Exception list id: "c1e1b359-7ac1-4e96-bc81-c683c092436f" does not exist', | ||
status_code: 404, | ||
}); | ||
}); | ||
|
||
it('should return an error if the list_id does not exist when trying to delete it', async () => { | ||
const { body } = await supertest | ||
.delete(`${EXCEPTION_LIST_URL}?list_id=c1e1b359-7ac1-4e96-bc81-c683c092436f`) | ||
.set('kbn-xsrf', 'true') | ||
.expect(404); | ||
|
||
expect(body).to.eql({ | ||
message: 'Exception list list_id: "c1e1b359-7ac1-4e96-bc81-c683c092436f" does not exist', | ||
status_code: 404, | ||
}); | ||
}); | ||
}); | ||
}); | ||
}; |
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
67 changes: 67 additions & 0 deletions
67
x-pack/test/lists_api_integration/security_and_spaces/tests/find_exception_lists.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,67 @@ | ||
/* | ||
* 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 expect from '@kbn/expect'; | ||
|
||
import { getExceptionResponseMockWithoutAutoGeneratedValues } from '../../../../plugins/lists/common/schemas/response/exception_list_schema.mock'; | ||
import { getCreateExceptionListMinimalSchemaMock } from '../../../../plugins/lists/common/schemas/request/create_exception_list_schema.mock'; | ||
import { FtrProviderContext } from '../../common/ftr_provider_context'; | ||
import { EXCEPTION_LIST_URL } from '../../../../plugins/lists/common/constants'; | ||
|
||
import { deleteAllExceptions, removeExceptionListServerGeneratedProperties } from '../../utils'; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default ({ getService }: FtrProviderContext): void => { | ||
const supertest = getService('supertest'); | ||
const es = getService('es'); | ||
|
||
describe('find_exception_lists', () => { | ||
describe('find exception lists', () => { | ||
afterEach(async () => { | ||
await deleteAllExceptions(es); | ||
}); | ||
|
||
it('should return an empty find body correctly if no exception lists are loaded', async () => { | ||
const { body } = await supertest | ||
.get(`${EXCEPTION_LIST_URL}/_find`) | ||
.set('kbn-xsrf', 'true') | ||
.send() | ||
.expect(200); | ||
|
||
expect(body).to.eql({ | ||
data: [], | ||
page: 1, | ||
per_page: 20, | ||
total: 0, | ||
}); | ||
}); | ||
|
||
it('should return a single exception list when a single exception list is loaded from a find with defaults added', async () => { | ||
// add a single exception list | ||
await supertest | ||
.post(EXCEPTION_LIST_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send(getCreateExceptionListMinimalSchemaMock()) | ||
.expect(200); | ||
|
||
// query the single exception list from _find | ||
const { body } = await supertest | ||
.get(`${EXCEPTION_LIST_URL}/_find`) | ||
.set('kbn-xsrf', 'true') | ||
.send() | ||
.expect(200); | ||
|
||
body.data = [removeExceptionListServerGeneratedProperties(body.data[0])]; | ||
expect(body).to.eql({ | ||
data: [getExceptionResponseMockWithoutAutoGeneratedValues()], | ||
page: 1, | ||
per_page: 20, | ||
total: 1, | ||
}); | ||
}); | ||
}); | ||
}); | ||
}; |
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
Oops, something went wrong.