-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[SIEM] [Cases] Case API tests #65777
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
21ac8f9
init commit
stephmilovic d7b9b94
more tests
stephmilovic b3b421f
finished tests
stephmilovic fd8f5c9
remove unused const
stephmilovic 4d2c9d0
pr changes 1
stephmilovic 72251e2
Merge branch 'master' into case-api-tests
stephmilovic c66981f
added more user actions tests
stephmilovic 6f6e446
pr changes 2
stephmilovic 499474c
pr changes 3
stephmilovic 77e142d
merge master
stephmilovic 83d71bc
Merge branch 'master' into case-api-tests
elasticmachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
x-pack/test/case_api_integration/basic/tests/cases/comments/delete_comment.ts
This file contains hidden or 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,76 @@ | ||
| /* | ||
| * 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 { FtrProviderContext } from '../../../../common/ftr_provider_context'; | ||
|
|
||
| import { CASES_URL } from '../../../../../../plugins/case/common/constants'; | ||
| import { postCaseReq, postCommentReq } from '../../../../common/lib/mock'; | ||
| import { deleteCases, deleteCasesUserActions, deleteComments } from '../../../../common/lib/utils'; | ||
|
|
||
| // eslint-disable-next-line import/no-default-export | ||
| export default ({ getService }: FtrProviderContext): void => { | ||
| const supertest = getService('supertest'); | ||
| const es = getService('es'); | ||
|
|
||
| describe('delete_comment', () => { | ||
| afterEach(async () => { | ||
| await deleteCases(es); | ||
| await deleteComments(es); | ||
| await deleteCasesUserActions(es); | ||
| }); | ||
|
|
||
| it('should delete a comment', async () => { | ||
| const { body: postedCase } = await supertest | ||
| .post(CASES_URL) | ||
| .set('kbn-xsrf', 'true') | ||
| .send(postCaseReq) | ||
| .expect(200); | ||
|
|
||
| const { body: patchedCase } = await supertest | ||
| .post(`${CASES_URL}/${postedCase.id}/comments`) | ||
| .set('kbn-xsrf', 'true') | ||
| .send(postCommentReq); | ||
|
|
||
| const { body: comment } = await supertest | ||
| .delete(`${CASES_URL}/${postedCase.id}/comments/${patchedCase.comments[0].id}`) | ||
| .set('kbn-xsrf', 'true') | ||
| .send(); | ||
|
|
||
| expect(comment).to.eql({}); | ||
| }); | ||
|
|
||
| it('unhappy path - 404s when comment belongs to different case', async () => { | ||
| const { body: postedCase } = await supertest | ||
| .post(CASES_URL) | ||
| .set('kbn-xsrf', 'true') | ||
| .send(postCaseReq) | ||
| .expect(200); | ||
|
|
||
| const { body: patchedCase } = await supertest | ||
| .post(`${CASES_URL}/${postedCase.id}/comments`) | ||
| .set('kbn-xsrf', 'true') | ||
| .send(postCommentReq); | ||
|
|
||
| const { body } = await supertest | ||
| .delete(`${CASES_URL}/fake-id/comments/${patchedCase.comments[0].id}`) | ||
| .set('kbn-xsrf', 'true') | ||
| .send() | ||
| .expect(404); | ||
| expect(body.message).to.eql( | ||
| `This comment ${patchedCase.comments[0].id} does not exist in fake-id).` | ||
| ); | ||
| }); | ||
|
|
||
| it('unhappy path - 404s when comment is not there', async () => { | ||
| await supertest | ||
| .delete(`${CASES_URL}/fake-id/comments/fake-id`) | ||
| .set('kbn-xsrf', 'true') | ||
| .send() | ||
| .expect(404); | ||
| }); | ||
| }); | ||
| }; | ||
93 changes: 93 additions & 0 deletions
93
x-pack/test/case_api_integration/basic/tests/cases/comments/find_comments.ts
This file contains hidden or 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,93 @@ | ||
| /* | ||
| * 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 { FtrProviderContext } from '../../../../common/ftr_provider_context'; | ||
|
|
||
| import { CASES_URL } from '../../../../../../plugins/case/common/constants'; | ||
| import { postCaseReq, postCommentReq } from '../../../../common/lib/mock'; | ||
| import { deleteCases, deleteCasesUserActions, deleteComments } from '../../../../common/lib/utils'; | ||
|
|
||
| // eslint-disable-next-line import/no-default-export | ||
| export default ({ getService }: FtrProviderContext): void => { | ||
| const supertest = getService('supertest'); | ||
| const es = getService('es'); | ||
|
|
||
| describe('find_comments', () => { | ||
| afterEach(async () => { | ||
| await deleteCases(es); | ||
| await deleteComments(es); | ||
| await deleteCasesUserActions(es); | ||
| }); | ||
|
|
||
| it('should find all case comment', async () => { | ||
| const { body: postedCase } = await supertest | ||
| .post(CASES_URL) | ||
| .set('kbn-xsrf', 'true') | ||
| .send(postCaseReq) | ||
| .expect(200); | ||
| // post 2 comments | ||
| await supertest | ||
| .post(`${CASES_URL}/${postedCase.id}/comments`) | ||
| .set('kbn-xsrf', 'true') | ||
| .send(postCommentReq); | ||
|
|
||
| const { body: patchedCase } = await supertest | ||
| .post(`${CASES_URL}/${postedCase.id}/comments`) | ||
| .set('kbn-xsrf', 'true') | ||
| .send(postCommentReq); | ||
|
|
||
| const { body: caseComments } = await supertest | ||
| .get(`${CASES_URL}/${postedCase.id}/comments/_find`) | ||
| .set('kbn-xsrf', 'true') | ||
| .send(); | ||
|
|
||
| expect(caseComments.comments).to.eql(patchedCase.comments); | ||
| }); | ||
|
|
||
| it('should filter case comments', async () => { | ||
| const { body: postedCase } = await supertest | ||
| .post(CASES_URL) | ||
| .set('kbn-xsrf', 'true') | ||
| .send(postCaseReq) | ||
| .expect(200); | ||
| // post 2 comments | ||
| await supertest | ||
| .post(`${CASES_URL}/${postedCase.id}/comments`) | ||
| .set('kbn-xsrf', 'true') | ||
| .send(postCommentReq); | ||
|
|
||
| const { body: patchedCase } = await supertest | ||
| .post(`${CASES_URL}/${postedCase.id}/comments`) | ||
| .set('kbn-xsrf', 'true') | ||
| .send({ comment: 'unique' }); | ||
|
|
||
| const { body: caseComments } = await supertest | ||
| .get(`${CASES_URL}/${postedCase.id}/comments/_find?search=unique`) | ||
| .set('kbn-xsrf', 'true') | ||
| .send(); | ||
|
|
||
| expect(caseComments.comments).to.eql([patchedCase.comments[1]]); | ||
| }); | ||
|
|
||
| it('unhappy path - 400s when query is bad', async () => { | ||
| const { body: postedCase } = await supertest | ||
| .post(CASES_URL) | ||
| .set('kbn-xsrf', 'true') | ||
| .send(postCaseReq) | ||
| .expect(200); | ||
| await supertest | ||
| .post(`${CASES_URL}/${postedCase.id}/comments`) | ||
| .set('kbn-xsrf', 'true') | ||
| .send(postCommentReq); | ||
| await supertest | ||
| .get(`${CASES_URL}/${postedCase.id}/comments/_find?perPage=true`) | ||
| .set('kbn-xsrf', 'true') | ||
| .send() | ||
| .expect(400); | ||
| }); | ||
| }); | ||
| }; |
53 changes: 53 additions & 0 deletions
53
x-pack/test/case_api_integration/basic/tests/cases/comments/get_comment.ts
This file contains hidden or 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,53 @@ | ||
| /* | ||
| * 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 { FtrProviderContext } from '../../../../common/ftr_provider_context'; | ||
|
|
||
| import { CASES_URL } from '../../../../../../plugins/case/common/constants'; | ||
| import { postCaseReq, postCommentReq } from '../../../../common/lib/mock'; | ||
| import { deleteCases, deleteCasesUserActions, deleteComments } from '../../../../common/lib/utils'; | ||
|
|
||
| // eslint-disable-next-line import/no-default-export | ||
| export default ({ getService }: FtrProviderContext): void => { | ||
| const supertest = getService('supertest'); | ||
| const es = getService('es'); | ||
|
|
||
| describe('get_comment', () => { | ||
| afterEach(async () => { | ||
| await deleteCases(es); | ||
| await deleteComments(es); | ||
| await deleteCasesUserActions(es); | ||
| }); | ||
|
|
||
| it('should get a comment', async () => { | ||
| const { body: postedCase } = await supertest | ||
| .post(CASES_URL) | ||
| .set('kbn-xsrf', 'true') | ||
| .send(postCaseReq); | ||
|
|
||
| const { body: patchedCase } = await supertest | ||
| .post(`${CASES_URL}/${postedCase.id}/comments`) | ||
| .set('kbn-xsrf', 'true') | ||
| .send(postCommentReq); | ||
|
|
||
| const { body: comment } = await supertest | ||
| .get(`${CASES_URL}/${postedCase.id}/comments/${patchedCase.comments[0].id}`) | ||
| .set('kbn-xsrf', 'true') | ||
| .send() | ||
| .expect(200); | ||
|
|
||
| expect(comment).to.eql(patchedCase.comments[0]); | ||
| }); | ||
| it('unhappy path - 404s when comment is not there', async () => { | ||
| await supertest | ||
| .get(`${CASES_URL}/fake-id/comments/fake-comment`) | ||
| .set('kbn-xsrf', 'true') | ||
| .send() | ||
| .expect(404); | ||
| }); | ||
| }); | ||
| }; |
123 changes: 123 additions & 0 deletions
123
x-pack/test/case_api_integration/basic/tests/cases/comments/patch_comment.ts
This file contains hidden or 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,123 @@ | ||
| /* | ||
| * 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 { FtrProviderContext } from '../../../../common/ftr_provider_context'; | ||
|
|
||
| import { CASES_URL } from '../../../../../../plugins/case/common/constants'; | ||
| import { defaultUser, postCaseReq, postCommentReq } from '../../../../common/lib/mock'; | ||
| import { deleteCases, deleteCasesUserActions, deleteComments } from '../../../../common/lib/utils'; | ||
|
|
||
| // eslint-disable-next-line import/no-default-export | ||
| export default ({ getService }: FtrProviderContext): void => { | ||
| const supertest = getService('supertest'); | ||
| const es = getService('es'); | ||
|
|
||
| describe('patch_comment', () => { | ||
| afterEach(async () => { | ||
| await deleteCases(es); | ||
| await deleteComments(es); | ||
| await deleteCasesUserActions(es); | ||
| }); | ||
|
|
||
| it('should patch a comment', async () => { | ||
stephmilovic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const { body: postedCase } = await supertest | ||
| .post(CASES_URL) | ||
| .set('kbn-xsrf', 'true') | ||
| .send(postCaseReq) | ||
| .expect(200); | ||
|
|
||
| const { body: patchedCase } = await supertest | ||
| .post(`${CASES_URL}/${postedCase.id}/comments`) | ||
| .set('kbn-xsrf', 'true') | ||
| .send(postCommentReq); | ||
| const newComment = 'Well I decided to update my comment. So what? Deal with it.'; | ||
stephmilovic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const { body } = await supertest | ||
| .patch(`${CASES_URL}/${postedCase.id}/comments`) | ||
| .set('kbn-xsrf', 'true') | ||
| .send({ | ||
| id: patchedCase.comments[0].id, | ||
| version: patchedCase.comments[0].version, | ||
| comment: newComment, | ||
| }); | ||
| expect(body.comments[0].comment).to.eql(newComment); | ||
| expect(body.updated_by).to.eql(defaultUser); | ||
| }); | ||
|
|
||
| it('unhappy path - 404s when comment is not there', async () => { | ||
| const { body: postedCase } = await supertest | ||
| .post(CASES_URL) | ||
| .set('kbn-xsrf', 'true') | ||
| .send(postCaseReq); | ||
| await supertest | ||
| .patch(`${CASES_URL}/${postedCase.id}/comments`) | ||
| .set('kbn-xsrf', 'true') | ||
| .send({ | ||
| id: 'id', | ||
| version: 'version', | ||
| comment: 'comment', | ||
| }) | ||
| .expect(404); | ||
| }); | ||
|
|
||
| it('unhappy path - 404s when case is not there', async () => { | ||
| await supertest | ||
| .patch(`${CASES_URL}/fake-id/comments`) | ||
| .set('kbn-xsrf', 'true') | ||
| .send({ | ||
| id: 'id', | ||
| version: 'version', | ||
| comment: 'comment', | ||
| }) | ||
| .expect(404); | ||
| }); | ||
|
|
||
| it('unhappy path - 400s when patch body is bad', async () => { | ||
| const { body: postedCase } = await supertest | ||
| .post(CASES_URL) | ||
| .set('kbn-xsrf', 'true') | ||
| .send(postCaseReq) | ||
| .expect(200); | ||
|
|
||
| const { body: patchedCase } = await supertest | ||
| .post(`${CASES_URL}/${postedCase.id}/comments`) | ||
| .set('kbn-xsrf', 'true') | ||
| .send(postCommentReq); | ||
| await supertest | ||
| .patch(`${CASES_URL}/${postedCase.id}/comments`) | ||
| .set('kbn-xsrf', 'true') | ||
| .send({ | ||
| id: patchedCase.comments[0].id, | ||
| version: patchedCase.comments[0].version, | ||
| comment: true, | ||
| }) | ||
| .expect(400); | ||
| }); | ||
|
|
||
| it('unhappy path - 409s when conflict', async () => { | ||
| const { body: postedCase } = await supertest | ||
| .post(CASES_URL) | ||
| .set('kbn-xsrf', 'true') | ||
| .send(postCaseReq) | ||
| .expect(200); | ||
|
|
||
| const { body: patchedCase } = await supertest | ||
| .post(`${CASES_URL}/${postedCase.id}/comments`) | ||
| .set('kbn-xsrf', 'true') | ||
| .send(postCommentReq); | ||
| const newComment = 'Well I decided to update my comment. So what? Deal with it.'; | ||
| await supertest | ||
| .patch(`${CASES_URL}/${postedCase.id}/comments`) | ||
| .set('kbn-xsrf', 'true') | ||
| .send({ | ||
| id: patchedCase.comments[0].id, | ||
| version: 'version-mismatch', | ||
| comment: newComment, | ||
| }) | ||
| .expect(409); | ||
| }); | ||
| }); | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should add two tests that check error handling: 1) test if the comment does not exist 2) test if the comment does not belong to the specific case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we're actually not allowing this in the UI and could remove the endpoint entirely.... it's lucky to get one test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true but users can call the API directly if they want to, so we should test the API independently of the UI, to make sure that the API is doing what we expect without considering the UI.