Skip to content

Commit

Permalink
[SIEM] fix ipv6 bug and write tests for ip details page (#37528)
Browse files Browse the repository at this point in the history
fix ipv6 bug and write tests for ip details page
  • Loading branch information
stephmilovic authored Jun 6, 2019
1 parent 348f10e commit 29e7d63
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ export interface HeaderPageProps {
children?: React.ReactNode;
subtitle?: string | React.ReactNode;
title: string | React.ReactNode;
'data-test-subj'?: string;
}

export const HeaderPage = pure<HeaderPageProps>(
({ badgeLabel, badgeTooltip, children, subtitle, title }) => (
<Header>
({ badgeLabel, badgeTooltip, children, subtitle, title, ...rest }) => (
<Header {...rest}>
<EuiFlexGroup alignItems="center">
<EuiFlexItem>
<EuiTitle size="l">
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 91 additions & 0 deletions x-pack/plugins/siem/public/pages/network/ip_details.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { mount, shallow } from 'enzyme';
import toJson from 'enzyme-to-json';
import * as React from 'react';
import { Router } from 'react-router-dom';

import '../../mock/match_media';
import { apolloClientObservable, mockGlobalState, TestProviders } from '../../mock';
import { IPDetailsComponent, IPDetails } from './ip_details';
import { FlowTarget } from '../../graphql/types';
import { createStore, State } from '../../store';

type Action = 'PUSH' | 'POP' | 'REPLACE';
const pop: Action = 'POP';

const getMockHistory = (ip: string) => ({
length: 2,
location: {
pathname: `/network/ip/${ip}`,
search: '',
state: '',
hash: '',
},
action: pop,
push: jest.fn(),
replace: jest.fn(),
go: jest.fn(),
goBack: jest.fn(),
goForward: jest.fn(),
block: jest.fn(),
createHref: jest.fn(),
listen: jest.fn(),
});

const getMockProps = (ip: string) => ({
filterQuery: 'coolQueryhuh?',
flowTarget: FlowTarget.source,
history: getMockHistory(ip),
location: {
pathname: `/network/ip/${ip}`,
search: '',
state: '',
hash: '',
},
match: { params: { ip }, isExact: true, path: '', url: '' },
});

describe('Ip Details', () => {
const state: State = mockGlobalState;

let store = createStore(state, apolloClientObservable);

beforeEach(() => {
store = createStore(state, apolloClientObservable);
});
test('it renders', () => {
const wrapper = shallow(<IPDetailsComponent {...getMockProps('123.456.78.90')} />);
expect(
wrapper
.dive()
.find('[data-test-subj="ip-details-page"]')
.exists()
).toBe(true);
});

test('it matches the snapshot', () => {
const wrapper = shallow(<IPDetailsComponent {...getMockProps('123.456.78.90')} />);
expect(toJson(wrapper)).toMatchSnapshot();
});

test('it renders ipv6 headline', () => {
const ip = 'fe80--24ce-f7ff-fede-a571';
const wrapper = mount(
<TestProviders store={store}>
<Router history={getMockHistory(ip)}>
<IPDetails {...getMockProps(ip)} />
</Router>
</TestProviders>
);
expect(
wrapper
.find('[data-test-subj="ip-details-headline"] [data-test-subj="page_headline_title"]')
.text()
).toEqual('fe80::24ce:f7ff:fede:a571');
});
});
13 changes: 8 additions & 5 deletions x-pack/plugins/siem/public/pages/network/ip_details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ interface IPDetailsComponentReduxProps {

type IPDetailsComponentProps = IPDetailsComponentReduxProps & NetworkComponentProps;

const IPDetailsComponent = pure<IPDetailsComponentProps>(
export const IPDetailsComponent = pure<IPDetailsComponentProps>(
({
match: {
params: { ip },
},
filterQuery,
flowTarget,
}) => (
<WithSource sourceId="default">
<WithSource sourceId="default" data-test-subj="ip-details-page">
{({ indicesExist, indexPattern }) =>
indicesExistOrDataTemporarilyUnavailable(indicesExist) ? (
<StickyContainer>
Expand All @@ -66,8 +66,11 @@ const IPDetailsComponent = pure<IPDetailsComponentProps>(
</FiltersGlobal>

<HeaderPage
subtitle={<LastEventTime indexKey={LastEventIndexKey.ipDetails} ip={ip} />}
title={ip}
data-test-subj="ip-details-headline"
subtitle={
<LastEventTime indexKey={LastEventIndexKey.ipDetails} ip={decodeIpv6(ip)} />
}
title={decodeIpv6(ip)}
>
<FlowTargetSelectConnected />
</HeaderPage>
Expand Down Expand Up @@ -182,7 +185,7 @@ const IPDetailsComponent = pure<IPDetailsComponentProps>(
</StickyContainer>
) : (
<>
<HeaderPage title={ip} />
<HeaderPage title={decodeIpv6(ip)} />

<NetworkEmptyPage />
</>
Expand Down

0 comments on commit 29e7d63

Please sign in to comment.