-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Cases] Add space only tests #99409
[Cases] Add space only tests #99409
Changes from all commits
a699e63
206756b
1a685ca
5609c46
d0b8283
7184b0c
3b3da5c
3211311
a1ba735
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ import type { KibanaClient } from '@elastic/elasticsearch/api/kibana'; | |
|
||
import * as st from 'supertest'; | ||
import supertestAsPromised from 'supertest-as-promised'; | ||
import { ObjectRemover as ActionsRemover } from '../../../alerting_api_integration/common/lib'; | ||
import { | ||
CASES_URL, | ||
CASE_CONFIGURE_CONNECTORS_URL, | ||
|
@@ -45,7 +46,7 @@ import { | |
CasesConfigurationsResponse, | ||
CaseUserActionsResponse, | ||
} from '../../../../plugins/cases/common/api'; | ||
import { postCollectionReq, postCommentGenAlertReq } from './mock'; | ||
import { getPostCaseRequest, postCollectionReq, postCommentGenAlertReq } from './mock'; | ||
import { getCaseUserActionUrl, getSubCasesUrl } from '../../../../plugins/cases/common/api/helpers'; | ||
import { ContextTypeGeneratedAlertType } from '../../../../plugins/cases/server/connectors'; | ||
import { SignalHit } from '../../../../plugins/security_solution/server/lib/detection_engine/signals/types'; | ||
|
@@ -539,6 +540,16 @@ export const deleteMappings = async (es: KibanaClient): Promise<void> => { | |
}); | ||
}; | ||
|
||
export const superUserSpace1Auth = getAuthWithSuperUser(); | ||
|
||
/** | ||
* Returns an auth object with the specified space and user set as super user. The result can be passed to other utility | ||
* functions. | ||
*/ | ||
export function getAuthWithSuperUser(space: string = 'space1'): { user: User; space: string } { | ||
return { user: superUser, space }; | ||
} | ||
|
||
export const getSpaceUrlPrefix = (spaceId: string | undefined | null) => { | ||
return spaceId && spaceId !== 'default' ? `/s/${spaceId}` : ``; | ||
}; | ||
|
@@ -556,6 +567,72 @@ export const ensureSavedObjectIsAuthorized = ( | |
entities.forEach((entity) => expect(owners.includes(entity.owner)).to.be(true)); | ||
}; | ||
|
||
export const createCaseWithConnector = async ({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is used by two different files now so I moved it here to make it more easily shared. |
||
supertest, | ||
configureReq = {}, | ||
servicenowSimulatorURL, | ||
actionsRemover, | ||
auth = { user: superUser, space: null }, | ||
createCaseReq = getPostCaseRequest(), | ||
}: { | ||
supertest: st.SuperTest<supertestAsPromised.Test>; | ||
servicenowSimulatorURL: string; | ||
actionsRemover: ActionsRemover; | ||
configureReq?: Record<string, unknown>; | ||
auth?: { user: User; space: string | null }; | ||
createCaseReq?: CasePostRequest; | ||
}): Promise<{ | ||
postedCase: CaseResponse; | ||
connector: CreateConnectorResponse; | ||
}> => { | ||
const connector = await createConnector({ | ||
supertest, | ||
req: { | ||
...getServiceNowConnector(), | ||
config: { apiUrl: servicenowSimulatorURL }, | ||
}, | ||
auth, | ||
}); | ||
|
||
actionsRemover.add(auth.space ?? 'default', connector.id, 'action', 'actions'); | ||
await createConfiguration( | ||
supertest, | ||
{ | ||
...getConfigurationRequest({ | ||
id: connector.id, | ||
name: connector.name, | ||
type: connector.connector_type_id as ConnectorTypes, | ||
}), | ||
...configureReq, | ||
}, | ||
200, | ||
auth | ||
); | ||
|
||
const postedCase = await createCase( | ||
supertest, | ||
{ | ||
...createCaseReq, | ||
connector: { | ||
id: connector.id, | ||
name: connector.name, | ||
type: connector.connector_type_id, | ||
fields: { | ||
urgency: '2', | ||
impact: '2', | ||
severity: '2', | ||
category: 'software', | ||
subcategory: 'os', | ||
}, | ||
} as CaseConnector, | ||
}, | ||
200, | ||
auth | ||
); | ||
|
||
return { postedCase, connector }; | ||
}; | ||
|
||
export const createCase = async ( | ||
supertest: st.SuperTest<supertestAsPromised.Test>, | ||
params: CasePostRequest, | ||
|
@@ -622,19 +699,6 @@ export const createComment = async ({ | |
return theCase; | ||
}; | ||
|
||
export const getAllUserAction = async ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing this one in favor of |
||
supertest: st.SuperTest<supertestAsPromised.Test>, | ||
caseId: string, | ||
expectedHttpCode: number = 200 | ||
): Promise<CaseUserActionResponse[]> => { | ||
const { body: userActions } = await supertest | ||
.get(`${CASES_URL}/${caseId}/user_actions`) | ||
.set('kbn-xsrf', 'true') | ||
.expect(expectedHttpCode); | ||
|
||
return userActions; | ||
}; | ||
|
||
export const updateCase = async ({ | ||
supertest, | ||
params, | ||
|
@@ -742,13 +806,13 @@ export const getComment = async ({ | |
caseId, | ||
commentId, | ||
expectedHttpCode = 200, | ||
auth = { user: superUser }, | ||
auth = { user: superUser, space: null }, | ||
}: { | ||
supertest: st.SuperTest<supertestAsPromised.Test>; | ||
caseId: string; | ||
commentId: string; | ||
expectedHttpCode?: number; | ||
auth?: { user: User; space?: string }; | ||
auth?: { user: User; space: string | null }; | ||
}): Promise<CommentResponse> => { | ||
const { body: comment } = await supertest | ||
.get(`${getSpaceUrlPrefix(auth.space)}${CASES_URL}/${caseId}/comments/${commentId}`) | ||
|
@@ -843,13 +907,18 @@ export const createConnector = async ({ | |
return connector; | ||
}; | ||
|
||
export const getCaseConnectors = async ( | ||
supertest: st.SuperTest<supertestAsPromised.Test>, | ||
expectedHttpCode: number = 200 | ||
): Promise<FindActionResult[]> => { | ||
export const getCaseConnectors = async ({ | ||
supertest, | ||
expectedHttpCode = 200, | ||
auth = { user: superUser, space: null }, | ||
}: { | ||
supertest: st.SuperTest<supertestAsPromised.Test>; | ||
expectedHttpCode?: number; | ||
auth?: { user: User; space: string | null }; | ||
}): Promise<FindActionResult[]> => { | ||
const { body: connectors } = await supertest | ||
.get(`${CASE_CONFIGURE_CONNECTORS_URL}/_find`) | ||
.set('kbn-xsrf', 'true') | ||
.get(`${getSpaceUrlPrefix(auth.space)}${CASE_CONFIGURE_CONNECTORS_URL}/_find`) | ||
.auth(auth.user.username, auth.user.password) | ||
.expect(expectedHttpCode); | ||
|
||
return connectors; | ||
|
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.
Moved this to the utils file so it could leverage the
getAuthWithSuperUser
helper function.