-
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.
Merge branch 'main' into entity-risk-scoring-new-doc-link
- Loading branch information
Showing
8 changed files
with
251 additions
and
0 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
73 changes: 73 additions & 0 deletions
73
x-pack/test/api_integration/apis/management/index_management/enrich_policies.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,73 @@ | ||
/* | ||
* 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 { FtrProviderContext } from '../../../ftr_provider_context'; | ||
|
||
import { enrichPoliciesApi } from './lib/enrich_policies.api'; | ||
import { enrichPoliciesHelpers } from './lib/enrich_policies.helpers'; | ||
|
||
export default function ({ getService }: FtrProviderContext) { | ||
const log = getService('log'); | ||
|
||
const { createIndex, deleteIndex, createEnrichPolicy } = enrichPoliciesHelpers(getService); | ||
|
||
const { getAllEnrichPolicies, removeEnrichPolicy, executeEnrichPolicy } = | ||
enrichPoliciesApi(getService); | ||
|
||
describe('Enrich policies', function () { | ||
const INDEX_NAME = `index-${Math.random()}`; | ||
const POLICY_NAME = `policy-${Math.random()}`; | ||
|
||
before(async () => { | ||
try { | ||
await createIndex(INDEX_NAME); | ||
await createEnrichPolicy(POLICY_NAME, INDEX_NAME); | ||
} catch (err) { | ||
log.debug('[Setup error] Error creating test index and policy'); | ||
throw err; | ||
} | ||
}); | ||
|
||
after(async () => { | ||
try { | ||
await deleteIndex(INDEX_NAME); | ||
} catch (err) { | ||
log.debug('[Cleanup error] Error deleting test index'); | ||
throw err; | ||
} | ||
}); | ||
|
||
it('should list all policies', async () => { | ||
const { body } = await getAllEnrichPolicies().expect(200); | ||
|
||
expect(body).toStrictEqual([ | ||
{ | ||
enrichFields: ['firstName'], | ||
matchField: 'email', | ||
name: POLICY_NAME, | ||
sourceIndices: [INDEX_NAME], | ||
type: 'match', | ||
}, | ||
]); | ||
}); | ||
|
||
it('should be able to execute a policy', async () => { | ||
await executeEnrichPolicy(POLICY_NAME).expect(200); | ||
|
||
// Wait for a little bit for the policy to be executed, so that it can | ||
// be deleted in the next test. | ||
await new Promise((resolve) => setTimeout(resolve, 2000)); | ||
}); | ||
|
||
it('should be able to delete a policy', async () => { | ||
const { body } = await removeEnrichPolicy(POLICY_NAME).expect(200); | ||
|
||
expect(body).toStrictEqual({ acknowledged: true }); | ||
}); | ||
}); | ||
} |
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
37 changes: 37 additions & 0 deletions
37
x-pack/test/api_integration/apis/management/index_management/lib/enrich_policies.api.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,37 @@ | ||
/* | ||
* 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 { INTERNAL_API_BASE_PATH } from '../constants'; | ||
import { FtrProviderContext } from '../../../../ftr_provider_context'; | ||
|
||
export function enrichPoliciesApi(getService: FtrProviderContext['getService']) { | ||
const supertest = getService('supertest'); | ||
|
||
const getAllEnrichPolicies = () => | ||
supertest | ||
.get(`${INTERNAL_API_BASE_PATH}/enrich_policies`) | ||
.set('kbn-xsrf', 'xxx') | ||
.set('x-elastic-internal-origin', 'xxx'); | ||
|
||
const executeEnrichPolicy = (name: string) => | ||
supertest | ||
.put(`${INTERNAL_API_BASE_PATH}/enrich_policies/${name}`) | ||
.set('kbn-xsrf', 'xxx') | ||
.set('x-elastic-internal-origin', 'xxx'); | ||
|
||
const removeEnrichPolicy = (name: string) => | ||
supertest | ||
.delete(`${INTERNAL_API_BASE_PATH}/enrich_policies/${name}`) | ||
.set('kbn-xsrf', 'xxx') | ||
.set('x-elastic-internal-origin', 'xxx'); | ||
|
||
return { | ||
getAllEnrichPolicies, | ||
removeEnrichPolicy, | ||
executeEnrichPolicy, | ||
}; | ||
} |
51 changes: 51 additions & 0 deletions
51
x-pack/test/api_integration/apis/management/index_management/lib/enrich_policies.helpers.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,51 @@ | ||
/* | ||
* 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 { FtrProviderContext } from '../../../../ftr_provider_context'; | ||
|
||
export function enrichPoliciesHelpers(getService: FtrProviderContext['getService']) { | ||
const es = getService('es'); | ||
|
||
const createEnrichPolicy = async (policyName: string, indexName: string) => { | ||
await es.enrich.putPolicy({ | ||
name: policyName, | ||
match: { | ||
match_field: 'email', | ||
enrich_fields: ['firstName'], | ||
indices: [indexName], | ||
}, | ||
}); | ||
}; | ||
|
||
const createIndex = async (indexName: string) => { | ||
await es.indices.create({ | ||
index: indexName, | ||
body: { | ||
mappings: { | ||
properties: { | ||
email: { | ||
type: 'text', | ||
}, | ||
firstName: { | ||
type: 'text', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
}; | ||
|
||
const deleteIndex = async (indexName: string) => { | ||
await es.indices.delete({ index: indexName }); | ||
}; | ||
|
||
return { | ||
createEnrichPolicy, | ||
createIndex, | ||
deleteIndex, | ||
}; | ||
} |
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
81 changes: 81 additions & 0 deletions
81
...ck/test_serverless/api_integration/test_suites/common/index_management/enrich_policies.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,81 @@ | ||
/* | ||
* 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 { FtrProviderContext } from '../../../ftr_provider_context'; | ||
|
||
export default function ({ getService }: FtrProviderContext) { | ||
const log = getService('log'); | ||
const indexManagementService = getService('indexManagement'); | ||
|
||
describe('Enrich policies', function () { | ||
const INDEX_NAME = `index-${Math.random()}`; | ||
const POLICY_NAME = `policy-${Math.random()}`; | ||
|
||
let createIndex: typeof indexManagementService['enrichPolicies']['helpers']['createIndex']; | ||
let deleteIndex: typeof indexManagementService['enrichPolicies']['helpers']['deleteIndex']; | ||
let createEnrichPolicy: typeof indexManagementService['enrichPolicies']['helpers']['createEnrichPolicy']; | ||
|
||
let getAllEnrichPolicies: typeof indexManagementService['enrichPolicies']['api']['getAllEnrichPolicies']; | ||
let removeEnrichPolicy: typeof indexManagementService['enrichPolicies']['api']['removeEnrichPolicy']; | ||
let executeEnrichPolicy: typeof indexManagementService['enrichPolicies']['api']['executeEnrichPolicy']; | ||
|
||
before(async () => { | ||
({ | ||
enrichPolicies: { | ||
helpers: { createIndex, deleteIndex, createEnrichPolicy }, | ||
api: { getAllEnrichPolicies, removeEnrichPolicy, executeEnrichPolicy }, | ||
}, | ||
} = indexManagementService); | ||
|
||
try { | ||
await createIndex(INDEX_NAME); | ||
await createEnrichPolicy(POLICY_NAME, INDEX_NAME); | ||
} catch (err) { | ||
log.debug('[Setup error] Error creating test index and policy'); | ||
throw err; | ||
} | ||
}); | ||
|
||
after(async () => { | ||
try { | ||
await deleteIndex(INDEX_NAME); | ||
} catch (err) { | ||
log.debug('[Cleanup error] Error deleting test index'); | ||
throw err; | ||
} | ||
}); | ||
|
||
it('should list all policies', async () => { | ||
const { body } = await getAllEnrichPolicies().expect(200); | ||
|
||
expect(body).toEqual([ | ||
{ | ||
enrichFields: ['firstName'], | ||
matchField: 'email', | ||
name: POLICY_NAME, | ||
sourceIndices: [INDEX_NAME], | ||
type: 'match', | ||
}, | ||
]); | ||
}); | ||
|
||
it('should be able to execute a policy', async () => { | ||
await executeEnrichPolicy(POLICY_NAME).expect(200); | ||
|
||
// Wait for a little bit for the policy to be executed, so that it can | ||
// be deleted in the next test. | ||
await new Promise((resolve) => setTimeout(resolve, 2000)); | ||
}); | ||
|
||
it('should be able to delete a policy', async () => { | ||
const { body } = await removeEnrichPolicy(POLICY_NAME).expect(200); | ||
|
||
expect(body).toEqual({ acknowledged: true }); | ||
}); | ||
}); | ||
} |
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