Skip to content

Commit

Permalink
[Uptime] Fix TLS alert query (elastic#119451) (elastic#119525)
Browse files Browse the repository at this point in the history
Co-authored-by: Shahzad <[email protected]>
  • Loading branch information
kibanamachine and shahzad31 authored Nov 23, 2021
1 parent f536044 commit 7308001
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 23 deletions.
53 changes: 31 additions & 22 deletions x-pack/plugins/uptime/common/requests/get_certs_request_body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,28 +85,37 @@ export const getCertsRequestBody = ({
},
},
},
...(notValidBefore
? [
{
range: {
'tls.certificate_not_valid_before': {
lte: notValidBefore,
},
},
},
]
: []),
...(notValidAfter
? [
{
range: {
'tls.certificate_not_valid_after': {
lte: notValidAfter,
},
},
},
]
: []),
{
bool: {
// these notValidBefore and notValidAfter should be inside should block, since
// we want to match either of the condition, making ir an OR operation
minimum_should_match: 1,
should: [
...(notValidBefore
? [
{
range: {
'tls.certificate_not_valid_before': {
lte: notValidBefore,
},
},
},
]
: []),
...(notValidAfter
? [
{
range: {
'tls.certificate_not_valid_after': {
lte: notValidAfter,
},
},
},
]
: []),
],
},
},
] as estypes.QueryDslQueryContainer,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const useCertSearch = ({

const { data: result, loading } = useEsSearch<Ping, typeof esParams>(
esParams,
[settings.settings?.heartbeatIndices, size, pageIndex, lastRefresh, search],
[settings.settings?.heartbeatIndices, size, pageIndex, lastRefresh, search, sortBy, direction],
{
name: 'getTLSCertificates',
}
Expand Down
15 changes: 15 additions & 0 deletions x-pack/plugins/uptime/server/lib/requests/get_certs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ describe('getCerts', () => {
size: 30,
sortBy: 'not_after',
direction: 'desc',
notValidAfter: 'now+100d',
});
expect(result).toMatchInlineSnapshot(`
Object {
Expand Down Expand Up @@ -184,6 +185,20 @@ describe('getCerts', () => {
},
},
},
Object {
"bool": Object {
"minimum_should_match": 1,
"should": Array [
Object {
"range": Object {
"tls.certificate_not_valid_after": Object {
"lte": "now+100d",
},
},
},
],
},
},
],
"minimum_should_match": 1,
"should": Array [
Expand Down

0 comments on commit 7308001

Please sign in to comment.