From 7ac98c7c9b17b02c32c756b9ba43712055abbd48 Mon Sep 17 00:00:00 2001 From: shahzad Date: Wed, 29 Apr 2020 16:18:34 +0200 Subject: [PATCH] updated tests --- .../__snapshots__/cert_monitors.test.tsx.snap | 66 +++++++++++-------- .../components/certificates/cert_monitors.tsx | 2 +- .../monitor_page_link.test.tsx.snap | 0 .../monitor_list/cert_status_column.tsx | 7 +- .../uptime/public/pages/certificates.tsx | 15 ++--- .../lib/requests/__tests__/get_certs.test.ts | 42 +++++------- .../uptime/server/lib/requests/get_certs.ts | 7 +- .../uptime/server/rest_api/certs/certs.ts | 6 +- 8 files changed, 68 insertions(+), 77 deletions(-) delete mode 100644 x-pack/plugins/uptime/public/components/overview/monitor_list/__tests__/__snapshots__/monitor_page_link.test.tsx.snap diff --git a/x-pack/plugins/uptime/public/components/certificates/__tests__/__snapshots__/cert_monitors.test.tsx.snap b/x-pack/plugins/uptime/public/components/certificates/__tests__/__snapshots__/cert_monitors.test.tsx.snap index 9ef8549aa1754f..99f5cd5f498fd2 100644 --- a/x-pack/plugins/uptime/public/components/certificates/__tests__/__snapshots__/cert_monitors.test.tsx.snap +++ b/x-pack/plugins/uptime/public/components/certificates/__tests__/__snapshots__/cert_monitors.test.tsx.snap @@ -3,45 +3,57 @@ exports[`CertMonitors renders expected elements for valid props 1`] = ` - + + bad-ssl-dashboard + + + , - + + elastic + + + , - + + extended-validation + + + `; diff --git a/x-pack/plugins/uptime/public/components/certificates/cert_monitors.tsx b/x-pack/plugins/uptime/public/components/certificates/cert_monitors.tsx index 4bf0ded4bc2c7b..bfd309e59d0132 100644 --- a/x-pack/plugins/uptime/public/components/certificates/cert_monitors.tsx +++ b/x-pack/plugins/uptime/public/components/certificates/cert_monitors.tsx @@ -7,7 +7,7 @@ import React from 'react'; import { EuiToolTip } from '@elastic/eui'; import { CertMonitor } from '../../../common/runtime_types'; -import { MonitorPageLink } from '../../../../../../plugins/uptime/public/components/common/monitor_page_link'; +import { MonitorPageLink } from '../common/monitor_page_link'; interface Props { monitors: CertMonitor[]; diff --git a/x-pack/plugins/uptime/public/components/overview/monitor_list/__tests__/__snapshots__/monitor_page_link.test.tsx.snap b/x-pack/plugins/uptime/public/components/overview/monitor_list/__tests__/__snapshots__/monitor_page_link.test.tsx.snap deleted file mode 100644 index e69de29bb2d1d6..00000000000000 diff --git a/x-pack/plugins/uptime/public/components/overview/monitor_list/cert_status_column.tsx b/x-pack/plugins/uptime/public/components/overview/monitor_list/cert_status_column.tsx index 5f6622512bbd6c..f711fc8abfd5da 100644 --- a/x-pack/plugins/uptime/public/components/overview/monitor_list/cert_status_column.tsx +++ b/x-pack/plugins/uptime/public/components/overview/monitor_list/cert_status_column.tsx @@ -9,11 +9,8 @@ import moment from 'moment'; import styled from 'styled-components'; import { EuiIcon, EuiText, EuiToolTip } from '@elastic/eui'; import { Cert } from '../../../../common/runtime_types'; -import { CERT_STATUS, useCertStatus } from '../../../../../../legacy/plugins/uptime/public/hooks'; -import { - EXPIRED, - EXPIRES_SOON, -} from '../../../../../../legacy/plugins/uptime/public/components/certificates/translations'; +import { CERT_STATUS, useCertStatus } from '../../../hooks'; +import { EXPIRED, EXPIRES_SOON } from '../../certificates/translations'; interface Props { cert: Cert; diff --git a/x-pack/plugins/uptime/public/pages/certificates.tsx b/x-pack/plugins/uptime/public/pages/certificates.tsx index 945f893bfbfc53..6e0f8de13e5570 100644 --- a/x-pack/plugins/uptime/public/pages/certificates.tsx +++ b/x-pack/plugins/uptime/public/pages/certificates.tsx @@ -15,24 +15,17 @@ import { EuiSpacer, } from '@elastic/eui'; import React, { useContext, useEffect, useState } from 'react'; -import { FormattedMessage } from '@kbn/i18n/target/types/react'; -import { useUptimeTelemetry, UptimePage } from '../../../../legacy/plugins/uptime/public/hooks'; +import { FormattedMessage } from '@kbn/i18n/react'; import { useTrackPageview } from '../../../observability/public'; import { PageHeader } from './page_header'; import { useBreadcrumbs } from '../hooks/use_breadcrumbs'; -import { - CertificateList, - CertSort, - CertificateSearch, -} from '../../../../legacy/plugins/uptime/public/components/certificates'; import { OVERVIEW_ROUTE, SETTINGS_ROUTE } from '../../common/constants'; import { getDynamicSettings } from '../state/actions/dynamic_settings'; -import { - certificatesSelector, - getCertificatesAction, -} from '../../../../legacy/plugins/uptime/public/state/certificates/certificates'; import { UptimeRefreshContext } from '../contexts'; import * as labels from './translations'; +import { UptimePage, useUptimeTelemetry } from '../hooks'; +import { certificatesSelector, getCertificatesAction } from '../state/certificates/certificates'; +import { CertificateList, CertificateSearch, CertSort } from '../components/certificates'; const DEFAULT_PAGE_SIZE = 10; const LOCAL_STORAGE_KEY = 'xpack.uptime.certList.pageSize'; diff --git a/x-pack/plugins/uptime/server/lib/requests/__tests__/get_certs.test.ts b/x-pack/plugins/uptime/server/lib/requests/__tests__/get_certs.test.ts index 982062fb3dde5f..3eb5311a7e3949 100644 --- a/x-pack/plugins/uptime/server/lib/requests/__tests__/get_certs.test.ts +++ b/x-pack/plugins/uptime/server/lib/requests/__tests__/get_certs.test.ts @@ -40,6 +40,9 @@ describe('getCerts', () => { name: 'Real World Test', id: 'real-world-test', }, + url: { + full: 'https://fullurl.com', + }, }, fields: { 'tls.server.hash.sha256': [ @@ -111,6 +114,7 @@ describe('getCerts', () => { Object { "id": "real-world-test", "name": "Real World Test", + "url": undefined, }, ], "sha1": "b7b4b89ef0d0caf39d223736f0fdbb03c7b426f1", @@ -150,6 +154,7 @@ describe('getCerts', () => { "includes": Array [ "monitor.id", "monitor.name", + "url.full", ], }, "collapse": Object { @@ -184,31 +189,16 @@ describe('getCerts', () => { "minimum_should_match": 1, "should": Array [ Object { - "wildcard": Object { - "tls.server.issuer": Object { - "value": "*my_common_name*", - }, - }, - }, - Object { - "wildcard": Object { - "tls.server.x509.issuer.common_name": Object { - "value": "*my_common_name*", - }, - }, - }, - Object { - "wildcard": Object { - "monitor.id": Object { - "value": "*my_common_name*", - }, - }, - }, - Object { - "wildcard": Object { - "monitor.name": Object { - "value": "*my_common_name*", - }, + "multi_match": Object { + "fields": Array [ + "monitor.id.text", + "monitor.name.text", + "url.full.text", + "tls.server.x509.subject.common_name.text", + "tls.server.x509.issuer.common_name.text", + ], + "query": "my_common_name", + "type": "phrase_prefix", }, }, ], @@ -217,7 +207,7 @@ describe('getCerts', () => { "size": 30, "sort": Array [ Object { - "tls.certificate_not_valid_after": Object { + "undefined": Object { "order": "desc", }, }, diff --git a/x-pack/plugins/uptime/server/lib/requests/get_certs.ts b/x-pack/plugins/uptime/server/lib/requests/get_certs.ts index 5cda8986d09028..38eaef6697cf82 100644 --- a/x-pack/plugins/uptime/server/lib/requests/get_certs.ts +++ b/x-pack/plugins/uptime/server/lib/requests/get_certs.ts @@ -25,8 +25,7 @@ export const getCerts: UMElasticsearchQueryFn = asyn sortBy, direction, }) => { - const searchWrapper = `*${search}*`; - const sort = SortFields[sortBy]; + const sort = SortFields[sortBy as keyof SortFields]; const params: any = { index: dynamicSettings.heartbeatIndices, @@ -97,7 +96,7 @@ export const getCerts: UMElasticsearchQueryFn = asyn params.body.query.bool.should = [ { multi_match: { - query: searchWrapper, + query: search, type: 'phrase_prefix', fields: [ 'monitor.id.text', @@ -128,7 +127,7 @@ export const getCerts: UMElasticsearchQueryFn = asyn const monitors = hit.inner_hits.monitors.hits.hits.map((monitor: any) => ({ name: monitor._source?.monitor.name, id: monitor._source?.monitor.id, - url: monitor._source?.url.full, + url: monitor._source?.url?.full, })); return { diff --git a/x-pack/plugins/uptime/server/rest_api/certs/certs.ts b/x-pack/plugins/uptime/server/rest_api/certs/certs.ts index ea14b644f1ca7a..5e1547e94d54c5 100644 --- a/x-pack/plugins/uptime/server/rest_api/certs/certs.ts +++ b/x-pack/plugins/uptime/server/rest_api/certs/certs.ts @@ -5,9 +5,9 @@ */ import { schema } from '@kbn/config-schema'; -import { UMServerLibs } from '../lib/lib'; -import { UMRestApiRouteFactory } from '.'; -import { API_URLS } from '../../common/constants'; +import { API_URLS } from '../../../common/constants'; +import { UMServerLibs } from '../../lib/lib'; +import { UMRestApiRouteFactory } from '../types'; const DEFAULT_INDEX = 0; const DEFAULT_SIZE = 25;