Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APP-15128 - Fetching more macAddresses #242

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ dist/
.eslintcache
tsconfig.tsbuildinfo
.npmrc
.idea
86 changes: 86 additions & 0 deletions src/steps/vulnerabilities/converters.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import {
getLargestItemKeyAndByteSize,
getMacAddresses,
getPriority,
getSeverity,
} from './converters';
import { AssetExport } from '../../tenable/client';

describe('getSeverity from numericSeverity', () => {
test('Informational for 0', () => {
Expand Down Expand Up @@ -90,3 +92,87 @@ describe('getLargestItemKeyAndByteSize', () => {
});
});
});

describe('getMacAddresses', () => {
test('returns unique MAC addresses based on FQDNs and direct list', () => {
const data = {
fqdns: ['example.com', 'test.com'],
mac_addresses: ['00:11:22:33:44:55', '00:11:22:33:44:66'],
network_interfaces: [
{
fqdns: ['example.com'],
mac_addresses: ['00:AA:BB:CC:DD:EE'],
},
{
fqdns: ['another.com'],
mac_addresses: ['00:FF:EE:DD:CC:BB'],
},
],
} as AssetExport;
expect(getMacAddresses(data)).toEqual([
'00:AA:BB:CC:DD:EE',
'00:11:22:33:44:55',
'00:11:22:33:44:66',
]);
});

test('handles no FQDNs provided', () => {
const data = {
fqdns: [],
mac_addresses: ['00:11:22:33:44:55'],
network_interfaces: [
{
fqdns: ['example.com'],
mac_addresses: ['00:AA:BB:CC:DD:EE'],
},
],
} as unknown as AssetExport;
expect(getMacAddresses(data)).toEqual(['00:11:22:33:44:55']);
});

test('handles no network interfaces provided', () => {
const data = {
fqdns: ['example.com'],
mac_addresses: ['00:11:22:33:44:55'],
network_interfaces: [],
} as unknown as AssetExport;
expect(getMacAddresses(data)).toEqual(['00:11:22:33:44:55']);
});

test('ignores network interfaces without matching FQDNs', () => {
const data = {
fqdns: ['test.com'],
mac_addresses: ['00:11:22:33:44:55'],
network_interfaces: [
{
fqdns: ['example.com'],
mac_addresses: ['00:AA:BB:CC:DD:EE'],
},
],
} as unknown as AssetExport;
expect(getMacAddresses(data)).toEqual(['00:11:22:33:44:55']);
});

test('returns empty array when no FQDNs or mac_addresses are provided', () => {
const data = {
fqdns: [],
mac_addresses: [],
network_interfaces: [],
} as unknown as AssetExport;
expect(getMacAddresses(data)).toEqual([]);
});

test('removes duplicate MAC addresses', () => {
const data = {
fqdns: ['example.com'],
mac_addresses: ['00:11:22:33:44:55'],
network_interfaces: [
{
fqdns: ['example.com'],
mac_addresses: ['00:11:22:33:44:55'],
},
],
} as unknown as AssetExport;
expect(getMacAddresses(data)).toEqual(['00:11:22:33:44:55']);
});
});
40 changes: 38 additions & 2 deletions src/steps/vulnerabilities/converters.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
assignTags,
createIntegrationEntity,
Entity,
IntegrationLogger,
parseTimePropertyValue,
assignTags,
} from '@jupiterone/integration-sdk-core';
import { Entities } from '../constants';
import { AssetExport, VulnerabilityExport } from '../../tenable/client';
Expand Down Expand Up @@ -32,6 +32,42 @@ export function getLargestItemKeyAndByteSize(data: any): KeyAndSize {
return largestItem;
}

/**
* Extracts unique MAC addresses based on specified FQDNs from network interfaces,
* and combines them with additional MAC addresses provided in the data.
*
* @example
* const data = {
* fqdns: ['example.com', 'test.com'],
* mac_addresses: ['00:11:22:33:44:55', '00:11:22:33:44:66'],
* network_interfaces: [
* {
* fqdns: ['example.com'],
* mac_addresses: ['00:AA:BB:CC:DD:EE']
* },
* {
* fqdns: ['another.com'],
* mac_addresses: ['00:FF:EE:DD:CC:BB']
* }
* ]
* };
* const macs = getMacAddresses(data);
* console.log(macs); // Output: ['00:AA:BB:CC:DD:EE', '00:11:22:33:44:55', '00:11:22:33:44:66']
*/
export function getMacAddresses(data: AssetExport): string[] {
const { fqdns, mac_addresses, network_interfaces } = data;
const qualifiedMacAddresses =
(fqdns
?.flatMap(
(dns) =>
network_interfaces.find(
(ni) => ni.fqdns?.length && ni.fqdns.includes(dns),
)?.mac_addresses,
)
?.filter(Boolean) as string[] | undefined) ?? [];
return [...new Set([...qualifiedMacAddresses, ...(mac_addresses ?? [])])]; // Ensures uniqueness
}

export function createAssetEntity(data: AssetExport): Entity {
const entity = createIntegrationEntity({
entityData: {
Expand Down Expand Up @@ -75,7 +111,7 @@ export function createAssetEntity(data: AssetExport): Entity {
ipv4s: data.ipv4s,
ipv6s: data.ipv6s,
fqdns: data.fqdns,
macAddresses: data.mac_addresses,
macAddresses: getMacAddresses(data),
netbiosNames: data.netbios_names,
operatingSystems: data.operating_systems,
// Provider-specific properties
Expand Down
Loading