Skip to content

Commit

Permalink
updated to remove default of note to empty string, updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yctercero committed Mar 11, 2020
1 parent f8513d3 commit 1e28319
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ export const addPrepackagedRulesSchema = Joi.object({
type: type.required(),
threat: threat.default([]),
references: references.default([]),
note: note.default('').default(''),
note: note.allow(''),
version: version.required(),
});
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ describe('create_rules_bulk_schema', () => {
);
});

test('The default for "note" will be empty string', () => {
test('You can set "note" to a string', () => {
expect(
createRulesBulkSchema.validate<Partial<PatchRuleAlertParamsRest>>([
{
Expand All @@ -156,10 +156,32 @@ describe('create_rules_bulk_schema', () => {
query: 'some query',
language: 'kuery',
max_signals: 1,
note: '# test markdown',
version: 1,
},
]).value[0].note
).toEqual('');
]).error
).toBeFalsy();
});

test('You can set "note" to an empty string', () => {
expect(
createRulesBulkSchema.validate<Partial<PatchRuleAlertParamsRest>>([
{
rule_id: 'rule-1',
risk_score: 50,
description: 'some description',
name: 'some-name',
severity: 'low',
type: 'query',
references: ['index-1'],
query: 'some query',
language: 'kuery',
max_signals: 1,
note: '',
version: 1,
},
]).error
).toBeFalsy();
});

test('You cannot set "note" to anything other than string', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,29 @@ describe('create rules schema', () => {
).toBeFalsy();
});

test('You can set note to an emtpy string', () => {
expect(
createRulesSchema.validate<Partial<RuleAlertParamsRest>>({
rule_id: 'rule-1',
output_index: '.siem-signals',
risk_score: 50,
description: 'some description',
from: 'now-5m',
to: 'now',
index: ['index-1'],
name: 'some-name',
severity: 'low',
interval: '5m',
type: 'query',
references: ['index-1'],
query: 'some query',
language: 'kuery',
max_signals: 1,
note: '',
}).error
).toBeFalsy();
});

test('You cannot create note as an object', () => {
expect(
createRulesSchema.validate<Partial<Omit<RuleAlertParamsRest, 'note'> & { note: object }>>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ export const createRulesSchema = Joi.object({
type: type.required(),
threat: threat.default([]),
references: references.default([]),
note: note.allow('').default(''),
note: note.allow(''),
version: version.default(1),
});
Original file line number Diff line number Diff line change
Expand Up @@ -1479,6 +1479,33 @@ describe('import rules schema', () => {
).toBeFalsy();
});

test('You cannot create note set to null', () => {
expect(
importRulesSchema.validate<Partial<ImportRuleAlertRest>>({
rule_id: 'rule-1',
output_index: '.siem-signals',
risk_score: 50,
description: 'some description',
from: 'now-5m',
to: 'now',
immutable: false,
index: ['index-1'],
name: 'some-name',
severity: 'low',
interval: '5m',
type: 'query',
references: ['index-1'],
query: 'some query',
language: 'kuery',
max_signals: 1,
meta: {
somethingMadeUp: { somethingElse: true },
},
note: null,
}).error.message
).toEqual('child "note" fails because ["note" must be a string]');
});

test('You cannot create note as something other than a string', () => {
expect(
importRulesSchema.validate<Partial<Omit<ImportRuleAlertRest, 'note'> & { note: object }>>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const importRulesSchema = Joi.object({
type: type.required(),
threat: threat.default([]),
references: references.default([]),
note: note.allow('').default(''),
note: note.allow(''),
version: version.default(1),
created_at,
updated_at,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,53 @@ describe('create rules schema', () => {
).toBeFalsy();
});

test('You can set note to an empty string', () => {
expect(
updateRulesSchema.validate<Partial<RuleAlertParamsRest>>({
rule_id: 'rule-1',
output_index: '.siem-signals',
risk_score: 50,
description: 'some description',
from: 'now-5m',
to: 'now',
index: ['index-1'],
name: 'some-name',
severity: 'low',
interval: '5m',
type: 'query',
references: ['index-1'],
query: 'some query',
language: 'kuery',
max_signals: 1,
note: '',
}).error
).toBeFalsy();
});

// Note: If you're looking to remove `note`, omit `note` entirely
test('You cannot set note to null', () => {
expect(
updateRulesSchema.validate<Partial<RuleAlertParamsRest>>({
rule_id: 'rule-1',
output_index: '.siem-signals',
risk_score: 50,
description: 'some description',
from: 'now-5m',
to: 'now',
index: ['index-1'],
name: 'some-name',
severity: 'low',
interval: '5m',
type: 'query',
references: ['index-1'],
query: 'some query',
language: 'kuery',
max_signals: 1,
note: null,
}).error.message
).toEqual('child "note" fails because ["note" must be a string]');
});

test('You cannot set note as an object', () => {
expect(
updateRulesSchema.validate<Partial<Omit<RuleAlertParamsRest, 'note'> & { note: object }>>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ export const updateRulesSchema = Joi.object({
type: type.required(),
threat: threat.default([]),
references: references.default([]),
note: note.allow('').default(''),
note: note.allow(''),
version,
}).xor('id', 'rule_id');
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ describe('create_rules_stream_from_ndjson', () => {
tags: [],
threat: [],
references: [],
note: '',
version: 1,
},
{
Expand All @@ -93,7 +92,6 @@ describe('create_rules_stream_from_ndjson', () => {
tags: [],
threat: [],
references: [],
note: '',
version: 1,
},
]);
Expand Down Expand Up @@ -155,7 +153,6 @@ describe('create_rules_stream_from_ndjson', () => {
tags: [],
threat: [],
references: [],
note: '',
version: 1,
},
{
Expand All @@ -179,7 +176,6 @@ describe('create_rules_stream_from_ndjson', () => {
tags: [],
threat: [],
references: [],
note: '',
version: 1,
},
]);
Expand Down Expand Up @@ -224,7 +220,6 @@ describe('create_rules_stream_from_ndjson', () => {
tags: [],
threat: [],
references: [],
note: '',
version: 1,
},
{
Expand All @@ -248,7 +243,6 @@ describe('create_rules_stream_from_ndjson', () => {
tags: [],
threat: [],
references: [],
note: '',
version: 1,
},
]);
Expand Down Expand Up @@ -293,7 +287,6 @@ describe('create_rules_stream_from_ndjson', () => {
tags: [],
threat: [],
references: [],
note: '',
version: 1,
});
expect(resultOrError[1].message).toEqual('Unexpected token , in JSON at position 1');
Expand All @@ -318,7 +311,6 @@ describe('create_rules_stream_from_ndjson', () => {
tags: [],
threat: [],
references: [],
note: '',
version: 1,
});
});
Expand Down Expand Up @@ -362,7 +354,6 @@ describe('create_rules_stream_from_ndjson', () => {
tags: [],
threat: [],
references: [],
note: '',
version: 1,
});
expect(resultOrError[1].message).toEqual(
Expand All @@ -389,7 +380,6 @@ describe('create_rules_stream_from_ndjson', () => {
tags: [],
threat: [],
references: [],
note: '',
version: 1,
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ export const getComplexRule = (ruleId = 'rule-1'): Partial<OutputRuleAlertRest>
],
timeline_id: 'timeline_id',
timeline_title: 'timeline_title',
note: '# some investigation documentation',
version: 1,
query: 'user.name: root or user.name: admin',
});
Expand Down

0 comments on commit 1e28319

Please sign in to comment.