Skip to content

Commit

Permalink
updating tags and utils
Browse files Browse the repository at this point in the history
  • Loading branch information
yctercero committed Nov 29, 2023
1 parent 9b2c3ec commit abe2ffd
Show file tree
Hide file tree
Showing 15 changed files with 380 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ import {
getSimpleRuleWithoutRuleId,
removeServerGeneratedProperties,
removeServerGeneratedPropertiesIncludingRuleId,
updateUsername,
} from '../../utils';

export default ({ getService }: FtrProviderContext): void => {
const esArchiver = getService('esArchiver');
const supertest = getService('supertest');
const log = getService('log');
const es = getService('es');
// TODO: add a new service
const config = getService('config');
const ELASTICSEARCH_USERNAME = config.get('servers.kibana.username');

// TODO: add a new service
const isServerless = config.get('serverless');
const dataPathBuilder = new EsArchivePathBuilder(isServerless);
const auditbeatPath = dataPathBuilder.getPath('auditbeat/hosts');
Expand All @@ -53,18 +56,25 @@ export default ({ getService }: FtrProviderContext): void => {
});

it('should create a single rule with a rule_id', async () => {
const rule = getSimpleRule();
const { body } = await supertest
.post(DETECTION_ENGINE_RULES_BULK_CREATE)
.set('kbn-xsrf', 'true')
.set('elastic-api-version', '2023-10-31')
.send([getSimpleRule()])
.send([rule])
.expect(200);

const bodyToCompare = removeServerGeneratedProperties(body[0]);
expect(bodyToCompare).to.eql(getSimpleRuleOutput());
const expectedRule = updateUsername(
getSimpleRuleOutput(rule.rule_id),
ELASTICSEARCH_USERNAME
);

expect(bodyToCompare).to.eql(expectedRule);
});

it('should create a single rule without a rule_id', async () => {
const rule = getSimpleRuleWithoutRuleId();
const { body } = await supertest
.post(DETECTION_ENGINE_RULES_BULK_CREATE)
.set('kbn-xsrf', 'true')
Expand All @@ -73,7 +83,12 @@ export default ({ getService }: FtrProviderContext): void => {
.expect(200);

const bodyToCompare = removeServerGeneratedPropertiesIncludingRuleId(body[0]);
expect(bodyToCompare).to.eql(getSimpleRuleOutputWithoutRuleId());
const expectedRule = updateUsername(
getSimpleRuleOutputWithoutRuleId(rule.rule_id),
ELASTICSEARCH_USERNAME
);

expect(bodyToCompare).to.eql(expectedRule);
});

it('should return a 200 ok but have a 409 conflict if we attempt to create the same rule_id twice', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ import {
getSimpleRuleWithoutRuleId,
removeServerGeneratedProperties,
removeServerGeneratedPropertiesIncludingRuleId,
updateUsername,
} from '../../utils';

export default ({ getService }: FtrProviderContext): void => {
const supertest = getService('supertest');
const log = getService('log');
const es = getService('es');
const config = getService('config');
const ELASTICSEARCH_USERNAME = config.get('servers.kibana.username');

describe('@ess @serverless delete_rules', () => {
describe('deleting rules', () => {
Expand All @@ -39,7 +42,7 @@ export default ({ getService }: FtrProviderContext): void => {
});

it('should delete a single rule with a rule_id', async () => {
await createRule(supertest, log, getSimpleRule('rule-1'));
const rule = await createRule(supertest, log, getSimpleRule('rule-1'));

// delete the rule by its rule_id
const { body } = await supertest
Expand All @@ -49,7 +52,12 @@ export default ({ getService }: FtrProviderContext): void => {
.expect(200);

const bodyToCompare = removeServerGeneratedProperties(body);
expect(bodyToCompare).to.eql(getSimpleRuleOutput());
const expectedRule = updateUsername(
getSimpleRuleOutput(rule.rule_id),
ELASTICSEARCH_USERNAME
);

expect(bodyToCompare).to.eql(expectedRule);
});

it('should delete a single rule using an auto generated rule_id', async () => {
Expand All @@ -63,7 +71,12 @@ export default ({ getService }: FtrProviderContext): void => {
.expect(200);

const bodyToCompare = removeServerGeneratedPropertiesIncludingRuleId(body);
expect(bodyToCompare).to.eql(getSimpleRuleOutputWithoutRuleId());
const expectedRule = updateUsername(
getSimpleRuleOutputWithoutRuleId(bodyWithCreatedRule.rule_id),
ELASTICSEARCH_USERNAME
);

expect(bodyToCompare).to.eql(expectedRule);
});

it('should delete a single rule using an auto generated id', async () => {
Expand All @@ -77,7 +90,12 @@ export default ({ getService }: FtrProviderContext): void => {
.expect(200);

const bodyToCompare = removeServerGeneratedPropertiesIncludingRuleId(body);
expect(bodyToCompare).to.eql(getSimpleRuleOutputWithoutRuleId());
const expectedRule = updateUsername(
getSimpleRuleOutputWithoutRuleId(bodyWithCreatedRule.rule_id),
ELASTICSEARCH_USERNAME
);

expect(bodyToCompare).to.eql(expectedRule);
});

it('should return an error if the id does not exist when trying to delete it', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ import {
getSimpleRuleWithoutRuleId,
removeServerGeneratedProperties,
removeServerGeneratedPropertiesIncludingRuleId,
updateUsername,
} from '../../utils';

export default ({ getService }: FtrProviderContext): void => {
const supertest = getService('supertest');
const log = getService('log');
const es = getService('es');
const config = getService('config');
const ELASTICSEARCH_USERNAME = config.get('servers.kibana.username');

describe('@ess @serverless delete_rules_bulk', () => {
describe('deleting rules bulk using DELETE', () => {
Expand All @@ -39,7 +42,7 @@ export default ({ getService }: FtrProviderContext): void => {
});

it('should delete a single rule with a rule_id', async () => {
await createRule(supertest, log, getSimpleRule());
const rule = await createRule(supertest, log, getSimpleRule());

// delete the rule in bulk
const { body } = await supertest
Expand All @@ -50,7 +53,11 @@ export default ({ getService }: FtrProviderContext): void => {
.expect(200);

const bodyToCompare = removeServerGeneratedProperties(body[0]);
expect(bodyToCompare).to.eql(getSimpleRuleOutput());
const expectedRule = updateUsername(
getSimpleRuleOutput(rule.rule_id),
ELASTICSEARCH_USERNAME
);
expect(bodyToCompare).to.eql(expectedRule);
});

it('should delete a single rule using an auto generated rule_id', async () => {
Expand All @@ -65,7 +72,11 @@ export default ({ getService }: FtrProviderContext): void => {
.expect(200);

const bodyToCompare = removeServerGeneratedPropertiesIncludingRuleId(body[0]);
expect(bodyToCompare).to.eql(getSimpleRuleOutputWithoutRuleId());
const expectedRule = updateUsername(
getSimpleRuleOutputWithoutRuleId(bodyWithCreatedRule.rule_id),
ELASTICSEARCH_USERNAME
);
expect(bodyToCompare).to.eql(expectedRule);
});

it('should delete a single rule using an auto generated id', async () => {
Expand All @@ -80,7 +91,12 @@ export default ({ getService }: FtrProviderContext): void => {
.expect(200);

const bodyToCompare = removeServerGeneratedPropertiesIncludingRuleId(body[0]);
expect(bodyToCompare).to.eql(getSimpleRuleOutputWithoutRuleId());
const expectedRule = updateUsername(
getSimpleRuleOutputWithoutRuleId(bodyWithCreatedRule.rule_id),
ELASTICSEARCH_USERNAME
);

expect(bodyToCompare).to.eql(expectedRule);
});

it('should return an error if the ruled_id does not exist when trying to delete a rule_id', async () => {
Expand Down Expand Up @@ -133,7 +149,10 @@ export default ({ getService }: FtrProviderContext): void => {

const bodyToCompare = removeServerGeneratedPropertiesIncludingRuleId(body[0]);
expect([bodyToCompare, body[1]]).to.eql([
getSimpleRuleOutputWithoutRuleId(),
updateUsername(
getSimpleRuleOutputWithoutRuleId(bodyWithCreatedRule.rule_id),
ELASTICSEARCH_USERNAME
),
{
id: 'c4e80a0d-e20f-4efc-84c1-08112da5a612',
error: {
Expand All @@ -157,7 +176,7 @@ export default ({ getService }: FtrProviderContext): void => {
});

it('should delete a single rule with a rule_id', async () => {
await createRule(supertest, log, getSimpleRule());
const rule = await createRule(supertest, log, getSimpleRule());

// delete the rule in bulk
const { body } = await supertest
Expand All @@ -168,7 +187,12 @@ export default ({ getService }: FtrProviderContext): void => {
.expect(200);

const bodyToCompare = removeServerGeneratedProperties(body[0]);
expect(bodyToCompare).to.eql(getSimpleRuleOutput());
const expectedRule = updateUsername(
getSimpleRuleOutput(rule.rule_id),
ELASTICSEARCH_USERNAME
);

expect(bodyToCompare).to.eql(expectedRule);
});

it('should delete a single rule using an auto generated rule_id', async () => {
Expand All @@ -183,7 +207,12 @@ export default ({ getService }: FtrProviderContext): void => {
.expect(200);

const bodyToCompare = removeServerGeneratedPropertiesIncludingRuleId(body[0]);
expect(bodyToCompare).to.eql(getSimpleRuleOutputWithoutRuleId());
const expectedRule = updateUsername(
getSimpleRuleOutputWithoutRuleId(bodyWithCreatedRule.rule_id),
ELASTICSEARCH_USERNAME
);

expect(bodyToCompare).to.eql(expectedRule);
});

it('should delete a single rule using an auto generated id', async () => {
Expand All @@ -198,7 +227,12 @@ export default ({ getService }: FtrProviderContext): void => {
.expect(200);

const bodyToCompare = removeServerGeneratedPropertiesIncludingRuleId(body[0]);
expect(bodyToCompare).to.eql(getSimpleRuleOutputWithoutRuleId());
const expectedRule = updateUsername(
getSimpleRuleOutputWithoutRuleId(bodyWithCreatedRule.rule_id),
ELASTICSEARCH_USERNAME
);

expect(bodyToCompare).to.eql(expectedRule);
});

it('should return an error if the ruled_id does not exist when trying to delete a rule_id', async () => {
Expand Down Expand Up @@ -251,7 +285,11 @@ export default ({ getService }: FtrProviderContext): void => {

const bodyToCompare = removeServerGeneratedPropertiesIncludingRuleId(body[0]);
expect([bodyToCompare, body[1]]).to.eql([
getSimpleRuleOutputWithoutRuleId(),
getSimpleRuleOutputWithoutRuleId(
bodyWithCreatedRule.rule_id,
bodyWithCreatedRule.enabled,
ELASTICSEARCH_USERNAME
),
{
id: 'c4e80a0d-e20f-4efc-84c1-08112da5a612',
error: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export default function ({ loadTestFile }: FtrProviderContext) {
describe('Rules edit Basic and Essentials API', function () {
loadTestFile(require.resolve('./patch_rules_bulk'));
loadTestFile(require.resolve('./patch_rules'));
loadTestFile(require.resolve('./patch_rules_ess'));
loadTestFile(require.resolve('./update_rules_bulk'));
loadTestFile(require.resolve('./update_rules'));
loadTestFile(require.resolve('./update_rules_ess'));
});
}
Loading

0 comments on commit abe2ffd

Please sign in to comment.