[KQL] Remove number parsing (#93658)

* [KQL] Remove number parsing

* Update test snapshots
This commit is contained in:
Lukas Olson 2021-03-06 23:45:50 -07:00 committed by GitHub
parent a1ac49a5aa
commit acb7b7726e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 39 additions and 42 deletions

View file

@ -228,8 +228,7 @@ module.exports = (function() {
if (sequence === 'true') return buildLiteralNode(true);
if (sequence === 'false') return buildLiteralNode(false);
if (chars.includes(wildcardSymbol)) return buildWildcardNode(sequence);
const isNumberPattern = /^(-?[1-9]+\d*([.]\d+)?)$|^(-?0[.]\d*[1-9]+)$|^0$|^0.0$|^[.]\d{1,}$/
return buildLiteralNode(isNumberPattern.test(sequence) ? Number(sequence) : sequence);
return buildLiteralNode(sequence);
},
peg$c52 = { type: "any", description: "any character" },
peg$c53 = "*",

View file

@ -168,10 +168,10 @@ describe('kuery AST API', () => {
test('should support exclusive range operators', () => {
const expected = nodeTypes.function.buildNode('and', [
nodeTypes.function.buildNode('range', 'bytes', {
gt: 1000,
gt: '1000',
}),
nodeTypes.function.buildNode('range', 'bytes', {
lt: 8000,
lt: '8000',
}),
]);
const actual = fromKueryExpression('bytes > 1000 and bytes < 8000');
@ -181,10 +181,10 @@ describe('kuery AST API', () => {
test('should support inclusive range operators', () => {
const expected = nodeTypes.function.buildNode('and', [
nodeTypes.function.buildNode('range', 'bytes', {
gte: 1000,
gte: '1000',
}),
nodeTypes.function.buildNode('range', 'bytes', {
lte: 8000,
lte: '8000',
}),
]);
const actual = fromKueryExpression('bytes >= 1000 and bytes <= 8000');
@ -279,25 +279,24 @@ describe('kuery AST API', () => {
const stringLiteral = nodeTypes.literal.buildNode('foo');
const booleanFalseLiteral = nodeTypes.literal.buildNode(false);
const booleanTrueLiteral = nodeTypes.literal.buildNode(true);
const numberLiteral = nodeTypes.literal.buildNode(42);
expect(fromLiteralExpression('foo')).toEqual(stringLiteral);
expect(fromLiteralExpression('true')).toEqual(booleanTrueLiteral);
expect(fromLiteralExpression('false')).toEqual(booleanFalseLiteral);
expect(fromLiteralExpression('42')).toEqual(numberLiteral);
expect(fromLiteralExpression('.3').value).toEqual(0.3);
expect(fromLiteralExpression('.36').value).toEqual(0.36);
expect(fromLiteralExpression('.00001').value).toEqual(0.00001);
expect(fromLiteralExpression('3').value).toEqual(3);
expect(fromLiteralExpression('-4').value).toEqual(-4);
expect(fromLiteralExpression('0').value).toEqual(0);
expect(fromLiteralExpression('0.0').value).toEqual(0);
expect(fromLiteralExpression('2.0').value).toEqual(2.0);
expect(fromLiteralExpression('0.8').value).toEqual(0.8);
expect(fromLiteralExpression('790.9').value).toEqual(790.9);
expect(fromLiteralExpression('0.0001').value).toEqual(0.0001);
expect(fromLiteralExpression('96565646732345').value).toEqual(96565646732345);
expect(fromLiteralExpression('.3').value).toEqual('.3');
expect(fromLiteralExpression('.36').value).toEqual('.36');
expect(fromLiteralExpression('.00001').value).toEqual('.00001');
expect(fromLiteralExpression('3').value).toEqual('3');
expect(fromLiteralExpression('-4').value).toEqual('-4');
expect(fromLiteralExpression('0').value).toEqual('0');
expect(fromLiteralExpression('0.0').value).toEqual('0.0');
expect(fromLiteralExpression('2.0').value).toEqual('2.0');
expect(fromLiteralExpression('0.8').value).toEqual('0.8');
expect(fromLiteralExpression('790.9').value).toEqual('790.9');
expect(fromLiteralExpression('0.0001').value).toEqual('0.0001');
expect(fromLiteralExpression('96565646732345').value).toEqual('96565646732345');
expect(fromLiteralExpression('070').value).toEqual('070');
expect(fromLiteralExpression('..4').value).toEqual('..4');
expect(fromLiteralExpression('.3text').value).toEqual('.3text');

View file

@ -251,8 +251,7 @@ UnquotedLiteral
if (sequence === 'true') return buildLiteralNode(true);
if (sequence === 'false') return buildLiteralNode(false);
if (chars.includes(wildcardSymbol)) return buildWildcardNode(sequence);
const isNumberPattern = /^(-?[1-9]+\d*([.]\d+)?)$|^(-?0[.]\d*[1-9]+)$|^0$|^0.0$|^[.]\d{1,}$/
return buildLiteralNode(isNumberPattern.test(sequence) ? Number(sequence) : sequence);
return buildLiteralNode(sequence);
}
UnquotedCharacter

View file

@ -153,7 +153,7 @@ describe('Filters Agg', () => {
"should": Array [
Object {
"match": Object {
"field": 200,
"field": "200",
},
},
],
@ -171,7 +171,7 @@ describe('Filters Agg', () => {
Object {
"range": Object {
"field": Object {
"gt": 500,
"gt": "500",
},
},
},

View file

@ -1028,7 +1028,7 @@ describe('get_filter', () => {
"should": Array [
Object {
"match": Object {
"suricata.eve.alert.signature_id": 2610182,
"suricata.eve.alert.signature_id": "2610182",
},
},
],
@ -1040,7 +1040,7 @@ describe('get_filter', () => {
"should": Array [
Object {
"match": Object {
"suricata.eve.alert.signature_id": 2610183,
"suricata.eve.alert.signature_id": "2610183",
},
},
],
@ -1052,7 +1052,7 @@ describe('get_filter', () => {
"should": Array [
Object {
"match": Object {
"suricata.eve.alert.signature_id": 2610184,
"suricata.eve.alert.signature_id": "2610184",
},
},
],
@ -1064,7 +1064,7 @@ describe('get_filter', () => {
"should": Array [
Object {
"match": Object {
"suricata.eve.alert.signature_id": 2610185,
"suricata.eve.alert.signature_id": "2610185",
},
},
],
@ -1076,7 +1076,7 @@ describe('get_filter', () => {
"should": Array [
Object {
"match": Object {
"suricata.eve.alert.signature_id": 2610186,
"suricata.eve.alert.signature_id": "2610186",
},
},
],
@ -1088,7 +1088,7 @@ describe('get_filter', () => {
"should": Array [
Object {
"match": Object {
"suricata.eve.alert.signature_id": 2610187,
"suricata.eve.alert.signature_id": "2610187",
},
},
],

View file

@ -332,8 +332,8 @@ describe('Combined Queries', () => {
kqlQuery: { query: '', language: 'kuery' },
kqlMode: 'search',
})!;
expect(filterQuery).toEqual(
'{"bool":{"must":[],"filter":[{"bool":{"should":[{"range":{"@timestamp":{"gte":1521848183232,"lte":1521848183232}}}],"minimum_should_match":1}}],"should":[],"must_not":[]}}'
expect(filterQuery).toMatchInlineSnapshot(
`"{\\"bool\\":{\\"must\\":[],\\"filter\\":[{\\"bool\\":{\\"should\\":[{\\"range\\":{\\"@timestamp\\":{\\"gte\\":\\"1521848183232\\",\\"lte\\":\\"1521848183232\\"}}}],\\"minimum_should_match\\":1}}],\\"should\\":[],\\"must_not\\":[]}}"`
);
});
@ -350,8 +350,8 @@ describe('Combined Queries', () => {
kqlQuery: { query: '', language: 'kuery' },
kqlMode: 'search',
})!;
expect(filterQuery).toEqual(
'{"bool":{"must":[],"filter":[{"bool":{"should":[{"range":{"@timestamp":{"gte":1521848183232,"lte":1521848183232}}}],"minimum_should_match":1}}],"should":[],"must_not":[]}}'
expect(filterQuery).toMatchInlineSnapshot(
`"{\\"bool\\":{\\"must\\":[],\\"filter\\":[{\\"bool\\":{\\"should\\":[{\\"range\\":{\\"@timestamp\\":{\\"gte\\":\\"1521848183232\\",\\"lte\\":\\"1521848183232\\"}}}],\\"minimum_should_match\\":1}}],\\"should\\":[],\\"must_not\\":[]}}"`
);
});
@ -368,8 +368,8 @@ describe('Combined Queries', () => {
kqlQuery: { query: '', language: 'kuery' },
kqlMode: 'search',
})!;
expect(filterQuery).toEqual(
'{"bool":{"must":[],"filter":[{"bool":{"should":[{"match":{"event.end":1521848183232}}],"minimum_should_match":1}}],"should":[],"must_not":[]}}'
expect(filterQuery).toMatchInlineSnapshot(
`"{\\"bool\\":{\\"must\\":[],\\"filter\\":[{\\"bool\\":{\\"should\\":[{\\"match\\":{\\"event.end\\":\\"1521848183232\\"}}],\\"minimum_should_match\\":1}}],\\"should\\":[],\\"must_not\\":[]}}"`
);
});
@ -386,8 +386,8 @@ describe('Combined Queries', () => {
kqlQuery: { query: '', language: 'kuery' },
kqlMode: 'search',
})!;
expect(filterQuery).toEqual(
'{"bool":{"must":[],"filter":[{"bool":{"should":[{"match":{"event.end":1521848183232}}],"minimum_should_match":1}}],"should":[],"must_not":[]}}'
expect(filterQuery).toMatchInlineSnapshot(
`"{\\"bool\\":{\\"must\\":[],\\"filter\\":[{\\"bool\\":{\\"should\\":[{\\"match\\":{\\"event.end\\":\\"1521848183232\\"}}],\\"minimum_should_match\\":1}}],\\"should\\":[],\\"must_not\\":[]}}"`
);
});

View file

@ -354,7 +354,7 @@ describe('status check alert', () => {
"should": Array [
Object {
"match": Object {
"url.port": 12349,
"url.port": "12349",
},
},
],
@ -366,7 +366,7 @@ describe('status check alert', () => {
"should": Array [
Object {
"match": Object {
"url.port": 5601,
"url.port": "5601",
},
},
],
@ -378,7 +378,7 @@ describe('status check alert', () => {
"should": Array [
Object {
"match": Object {
"url.port": 443,
"url.port": "443",
},
},
],
@ -735,7 +735,7 @@ describe('status check alert', () => {
expect(mockAvailability.mock.calls[0]).toMatchInlineSnapshot(`
Array [
Object {
"filters": "{\\"bool\\":{\\"filter\\":[{\\"bool\\":{\\"should\\":[{\\"bool\\":{\\"should\\":[{\\"match\\":{\\"url.port\\":12349}}],\\"minimum_should_match\\":1}},{\\"bool\\":{\\"should\\":[{\\"match\\":{\\"url.port\\":5601}}],\\"minimum_should_match\\":1}},{\\"bool\\":{\\"should\\":[{\\"match\\":{\\"url.port\\":443}}],\\"minimum_should_match\\":1}}],\\"minimum_should_match\\":1}},{\\"bool\\":{\\"should\\":[{\\"match\\":{\\"observer.geo.name\\":\\"harrisburg\\"}}],\\"minimum_should_match\\":1}},{\\"bool\\":{\\"should\\":[{\\"match\\":{\\"monitor.type\\":\\"http\\"}}],\\"minimum_should_match\\":1}},{\\"bool\\":{\\"should\\":[{\\"bool\\":{\\"should\\":[{\\"match\\":{\\"tags\\":\\"unsecured\\"}}],\\"minimum_should_match\\":1}},{\\"bool\\":{\\"should\\":[{\\"match\\":{\\"tags\\":\\"containers\\"}}],\\"minimum_should_match\\":1}},{\\"bool\\":{\\"should\\":[{\\"match_phrase\\":{\\"tags\\":\\"org:google\\"}}],\\"minimum_should_match\\":1}}],\\"minimum_should_match\\":1}}]}}",
"filters": "{\\"bool\\":{\\"filter\\":[{\\"bool\\":{\\"should\\":[{\\"bool\\":{\\"should\\":[{\\"match\\":{\\"url.port\\":\\"12349\\"}}],\\"minimum_should_match\\":1}},{\\"bool\\":{\\"should\\":[{\\"match\\":{\\"url.port\\":\\"5601\\"}}],\\"minimum_should_match\\":1}},{\\"bool\\":{\\"should\\":[{\\"match\\":{\\"url.port\\":\\"443\\"}}],\\"minimum_should_match\\":1}}],\\"minimum_should_match\\":1}},{\\"bool\\":{\\"should\\":[{\\"match\\":{\\"observer.geo.name\\":\\"harrisburg\\"}}],\\"minimum_should_match\\":1}},{\\"bool\\":{\\"should\\":[{\\"match\\":{\\"monitor.type\\":\\"http\\"}}],\\"minimum_should_match\\":1}},{\\"bool\\":{\\"should\\":[{\\"bool\\":{\\"should\\":[{\\"match\\":{\\"tags\\":\\"unsecured\\"}}],\\"minimum_should_match\\":1}},{\\"bool\\":{\\"should\\":[{\\"match\\":{\\"tags\\":\\"containers\\"}}],\\"minimum_should_match\\":1}},{\\"bool\\":{\\"should\\":[{\\"match_phrase\\":{\\"tags\\":\\"org:google\\"}}],\\"minimum_should_match\\":1}}],\\"minimum_should_match\\":1}}]}}",
"range": 35,
"rangeUnit": "d",
"threshold": "99.34",