-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…10999) ## Summary [Internal link](elastic/security-team#10820) to the feature details Part of elastic/security-team#11232 This PR covers SIEM Migrations CREATE API (route: `/internal/siem_migrations/rules/{migration_id?}`) integration test: * Create migration with provided ID * Create migration without provided ID * Create migration with rules that have resources * Error handling ("no content") when no rules provided Also, as part of this PR, I addressed this comment to my previous changes #210867 (comment)
- Loading branch information
Showing
9 changed files
with
395 additions
and
206 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
105 changes: 105 additions & 0 deletions
105
...n_api_integration/test_suites/siem_migrations/rules/trial_license_complete_tier/create.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,105 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import expect from 'expect'; | ||
import { v4 as uuidv4 } from 'uuid'; | ||
import { SiemMigrationStatus } from '@kbn/security-solution-plugin/common/siem_migrations/constants'; | ||
import { | ||
defaultOriginalRule, | ||
deleteAllMigrationRules, | ||
migrationResourcesRouteHelpersFactory, | ||
migrationRulesRouteHelpersFactory, | ||
splunkRuleWithResources, | ||
} from '../../utils'; | ||
import { FtrProviderContext } from '../../../../ftr_provider_context'; | ||
|
||
export default ({ getService }: FtrProviderContext) => { | ||
const es = getService('es'); | ||
const supertest = getService('supertest'); | ||
const migrationRulesRoutes = migrationRulesRouteHelpersFactory(supertest); | ||
const migrationResourcesRoutes = migrationResourcesRouteHelpersFactory(supertest); | ||
|
||
describe('@ess @serverless @serverlessQA Create API', () => { | ||
beforeEach(async () => { | ||
await deleteAllMigrationRules(es); | ||
}); | ||
|
||
it('should create migrations with provided id', async () => { | ||
const migrationId = uuidv4(); | ||
await migrationRulesRoutes.create({ migrationId, body: [defaultOriginalRule] }); | ||
|
||
// fetch migration rule | ||
const response = await migrationRulesRoutes.get({ migrationId }); | ||
expect(response.body.total).toEqual(1); | ||
|
||
const migrationRule = response.body.data[0]; | ||
expect(migrationRule).toEqual( | ||
expect.objectContaining({ | ||
migration_id: migrationId, | ||
original_rule: defaultOriginalRule, | ||
status: SiemMigrationStatus.PENDING, | ||
}) | ||
); | ||
}); | ||
|
||
it('should create migrations without provided id', async () => { | ||
const { | ||
body: { migration_id: migrationId }, | ||
} = await migrationRulesRoutes.create({ body: [defaultOriginalRule] }); | ||
|
||
// fetch migration rule | ||
const response = await migrationRulesRoutes.get({ migrationId }); | ||
expect(response.body.total).toEqual(1); | ||
|
||
const migrationRule = response.body.data[0]; | ||
expect(migrationRule).toEqual( | ||
expect.objectContaining({ | ||
migration_id: migrationId, | ||
original_rule: defaultOriginalRule, | ||
status: SiemMigrationStatus.PENDING, | ||
}) | ||
); | ||
}); | ||
|
||
it('should create migrations with the rules that have resources', async () => { | ||
const migrationId = uuidv4(); | ||
await migrationRulesRoutes.create({ migrationId, body: [splunkRuleWithResources] }); | ||
|
||
// fetch migration rule | ||
const response = await migrationRulesRoutes.get({ migrationId }); | ||
expect(response.body.total).toEqual(1); | ||
|
||
const migrationRule = response.body.data[0]; | ||
expect(migrationRule).toEqual( | ||
expect.objectContaining({ | ||
migration_id: migrationId, | ||
original_rule: splunkRuleWithResources, | ||
status: SiemMigrationStatus.PENDING, | ||
}) | ||
); | ||
|
||
// fetch missing resources | ||
const resourcesResponse = await migrationResourcesRoutes.getMissingResources({ | ||
migrationId, | ||
}); | ||
expect(resourcesResponse.body).toEqual([ | ||
{ type: 'macro', name: 'summariesonly' }, | ||
{ type: 'macro', name: 'drop_dm_object_name(1)' }, | ||
{ type: 'lookup', name: 'malware_tracker' }, | ||
]); | ||
}); | ||
|
||
it('should return no content error', async () => { | ||
const migrationId = uuidv4(); | ||
await migrationRulesRoutes.create({ migrationId, body: [], expectStatusCode: 204 }); | ||
|
||
// fetch migration rule | ||
const response = await migrationRulesRoutes.get({ migrationId }); | ||
expect(response.body.total).toEqual(0); | ||
}); | ||
}); | ||
}; |
Oops, something went wrong.