Skip to content

Commit ac300c2

Browse files
committed
NETOBSERV-1969: Fix IcmpType & IcmpCode
Those fields should be correctly displayed when ICMP data is present, and not displayed (in side panel) when ICMP data is absent.
1 parent ce61994 commit ac300c2

File tree

3 files changed

+55
-20
lines changed

3 files changed

+55
-20
lines changed

web/src/components/__tests-data__/columns.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,26 @@ export const ColumnConfigSampleDefs = [
497497
filter: 'dns_flag_response_code',
498498
default: false,
499499
width: 5
500+
},
501+
{
502+
id: 'IcmpType',
503+
group: 'ICMP',
504+
name: 'Type',
505+
tooltip: 'The type of the ICMP message.',
506+
field: 'IcmpType',
507+
filter: 'icmp_type',
508+
default: false,
509+
width: 10
510+
},
511+
{
512+
id: 'IcmpCode',
513+
group: 'ICMP',
514+
name: 'Code',
515+
tooltip: 'The code of the ICMP message.',
516+
field: 'IcmpCode',
517+
filter: 'icmp_code',
518+
default: false,
519+
width: 10
500520
}
501521
];
502522

web/src/components/drawer/record/__tests__/record-panel.spec.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ describe('<RecordPanel />', () => {
3030
// sample contains 20 fields
3131
// JSON tab represent 1 extra field
3232
expect(wrapper.find('.record-field-container')).toHaveLength(20 + 1);
33-
33+
// No ICMP
34+
expect(wrapper.find({ 'data-test-id': 'drawer-field-IcmpType' })).toHaveLength(0);
35+
expect(wrapper.find({ 'data-test-id': 'drawer-field-IcmpCode' })).toHaveLength(0);
3436
// same with 4 valid fields + json
3537
wrapper.setProps({ record: UnknownFlow });
3638
expect(wrapper.find('.record-field-container')).toHaveLength(4 + 1);
@@ -43,4 +45,19 @@ describe('<RecordPanel />', () => {
4345
closeButton.simulate('click');
4446
expect(mocks.onClose).toHaveBeenCalled();
4547
});
48+
49+
it('should render ICMP', async () => {
50+
const flowWithICMP = {
51+
...mocks.record,
52+
fields: {
53+
...mocks.record.fields,
54+
IcmpType: 8,
55+
IcmpCode: 0,
56+
}
57+
}
58+
const wrapper = shallow(<RecordPanel {...mocks} record={flowWithICMP} />);
59+
expect(wrapper.find(RecordPanel)).toBeTruthy();
60+
expect(wrapper.find({ 'data-test-id': 'drawer-field-IcmpType' })).toHaveLength(1);
61+
expect(wrapper.find({ 'data-test-id': 'drawer-field-IcmpCode' })).toHaveLength(1);
62+
});
4663
});

web/src/components/drawer/record/record-field.tsx

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
getICMPCode,
1515
getICMPDocUrl,
1616
getICMPType,
17-
icmpAllCodesValues,
1817
icmpAllTypesValues,
1918
isValidICMPProto
2019
} from '../../../utils/icmp';
@@ -369,41 +368,40 @@ export const RecordField: React.FC<RecordFieldProps> = ({
369368
}
370369
case ColumnsId.icmptype: {
371370
let child = emptyText();
372-
if (Array.isArray(value) && value.length) {
373-
if (isValidICMPProto(Number(value[0]))) {
374-
const type = getICMPType(Number(value[0]), Number(value[1]) as icmpAllTypesValues);
371+
if (typeof value === 'number' && !isNaN(value)) {
372+
const proto = Number(flow.fields.Proto);
373+
if (isValidICMPProto(proto)) {
374+
const type = getICMPType(proto, value as icmpAllTypesValues);
375375
if (type && detailed) {
376-
child = clickableContent(type.name, type.description || '', getICMPDocUrl(Number(value[0])));
376+
child = clickableContent(type.name, type.description || '', getICMPDocUrl(proto));
377377
} else {
378-
child = simpleTextWithTooltip(type?.name || String(value[1]))!;
378+
child = simpleTextWithTooltip(type?.name || String(value))!;
379379
}
380380
} else {
381381
child = errorTextValue(
382-
String(value[1]),
383-
t('ICMP type provided but protocol is {{proto}}', { proto: formatProtocol(value[0] as number, t) })
382+
String(value),
383+
t('ICMP type provided but protocol is {{proto}}', { proto: formatProtocol(proto, t) })
384384
);
385385
}
386386
}
387387
return singleContainer(child);
388388
}
389389
case ColumnsId.icmpcode: {
390390
let child = emptyText();
391-
if (Array.isArray(value) && value.length) {
392-
if (isValidICMPProto(Number(value[0]))) {
393-
const code = getICMPCode(
394-
Number(value[0]),
395-
Number(value[1]) as icmpAllTypesValues,
396-
Number(value[2]) as icmpAllCodesValues
397-
);
391+
if (typeof value === 'number' && !isNaN(value)) {
392+
const proto = Number(flow.fields.Proto);
393+
const typez = Number(flow.fields.IcmpType) as icmpAllTypesValues;
394+
if (isValidICMPProto(proto)) {
395+
const code = getICMPCode(proto, typez, value);
398396
if (code && detailed) {
399-
child = clickableContent(code.name, code.description || '', getICMPDocUrl(Number(value[0])));
397+
child = clickableContent(code.name, code.description || '', getICMPDocUrl(proto));
400398
} else {
401-
child = simpleTextWithTooltip(code?.name || String(value[2]))!;
399+
child = simpleTextWithTooltip(code?.name || String(value))!;
402400
}
403401
} else {
404402
child = errorTextValue(
405-
String(value[1]),
406-
t('ICMP code provided but protocol is {{proto}}', { proto: formatProtocol(value[0] as number, t) })
403+
String(value),
404+
t('ICMP code provided but protocol is {{proto}}', { proto: formatProtocol(proto, t) })
407405
);
408406
}
409407
}

0 commit comments

Comments
 (0)