-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kc
committed
Jul 26, 2023
1 parent
fea3270
commit 630de32
Showing
15 changed files
with
2,202 additions
and
2,202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,41 @@ | ||
import { getArpCache } from '../../src/getters'; | ||
import { runOsquery, OsType } from '../../src/runOSQuery'; | ||
import { runOsquery, OsType } from '../../src/runOsquery'; | ||
|
||
// Mock runOsquery function | ||
jest.mock('../../src/runOsquery', () => ({ | ||
runOsquery: jest.fn(), | ||
OsType: { | ||
LINUX: 'linux', | ||
DARWIN: 'darwin', | ||
WINDOWS_NT: 'windows_nt', | ||
}, | ||
runOsquery: jest.fn(), | ||
OsType: { | ||
LINUX: 'linux', | ||
DARWIN: 'darwin', | ||
WINDOWS_NT: 'windows_nt', | ||
}, | ||
})); | ||
|
||
describe('getArpCache', () => { | ||
it('resolves with arp_cache table on success', async () => { | ||
const mockRunOsquery = runOsquery as jest.MockedFunction<typeof runOsquery>; | ||
const expectedArpCache = [ | ||
{ | ||
address: '192.168.1.1', | ||
mac: '00:0a:95:9d:68:16', | ||
interface: 'eth0', | ||
permanent: '0', | ||
}, | ||
]; | ||
mockRunOsquery.mockResolvedValue(JSON.stringify(expectedArpCache)); | ||
it('resolves with arp_cache table on success', async () => { | ||
const mockRunOsquery = runOsquery as jest.MockedFunction<typeof runOsquery>; | ||
const expectedArpCache = [ | ||
{ | ||
address: '192.168.1.1', | ||
mac: '00:0a:95:9d:68:16', | ||
interface: 'eth0', | ||
permanent: '0', | ||
}, | ||
]; | ||
mockRunOsquery.mockResolvedValue(JSON.stringify(expectedArpCache)); | ||
|
||
await expect(getArpCache()).resolves.toEqual(expectedArpCache); | ||
expect(mockRunOsquery).toHaveBeenCalledWith('SELECT * FROM arp_cache', [ | ||
OsType.LINUX, | ||
OsType.DARWIN, | ||
OsType.WINDOWS_NT, | ||
]); | ||
}); | ||
await expect(getArpCache()).resolves.toEqual(expectedArpCache); | ||
expect(mockRunOsquery).toHaveBeenCalledWith('SELECT * FROM arp_cache', [ | ||
OsType.LINUX, | ||
OsType.DARWIN, | ||
OsType.WINDOWS_NT, | ||
]); | ||
}); | ||
|
||
it('rejects with error on command failure', async () => { | ||
const mockRunOsquery = runOsquery as jest.MockedFunction<typeof runOsquery>; | ||
mockRunOsquery.mockRejectedValue('Command failed'); | ||
it('rejects with error on command failure', async () => { | ||
const mockRunOsquery = runOsquery as jest.MockedFunction<typeof runOsquery>; | ||
mockRunOsquery.mockRejectedValue('Command failed'); | ||
|
||
await expect(getArpCache()).rejects.toEqual('Command failed'); | ||
}); | ||
await expect(getArpCache()).rejects.toEqual('Command failed'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,51 @@ | ||
import { getAzureInstanceMetadata } from '../../src/getters'; | ||
import { runOsquery, OsType } from '../../src/runOSQuery'; | ||
import { runOsquery, OsType } from '../../src/runOsquery'; | ||
|
||
jest.mock('../../src/runOsquery', () => ({ | ||
runOsquery: jest.fn(), | ||
OsType: { | ||
LINUX: 'linux', | ||
DARWIN: 'darwin', | ||
WINDOWS_NT: 'windows_nt', | ||
}, | ||
runOsquery: jest.fn(), | ||
OsType: { | ||
LINUX: 'linux', | ||
DARWIN: 'darwin', | ||
WINDOWS_NT: 'windows_nt', | ||
}, | ||
})); | ||
|
||
describe('getAzureInstanceMetadata', () => { | ||
it('resolves with azure_instance_metadata table on success', async () => { | ||
const mockRunOsquery = runOsquery as jest.MockedFunction<typeof runOsquery>; | ||
const expectedMetadata = [ | ||
{ | ||
location: 'location', | ||
name: 'name', | ||
offer: 'offer', | ||
publisher: 'publisher', | ||
sku: 'sku', | ||
version: 'version', | ||
os_type: 'os_type', | ||
platform_update_domain: 'platform_update_domain', | ||
platform_fault_domain: 'platform_fault_domain', | ||
vm_id: 'vm_id', | ||
vm_size: 'vm_size', | ||
subscription_id: 'subscription_id', | ||
resource_group_name: 'resource_group_name', | ||
placement_group_id: 'placement_group_id', | ||
vm_scale_set_name: 'vm_scale_set_name', | ||
zone: 'zone', | ||
}, | ||
]; | ||
mockRunOsquery.mockResolvedValue(JSON.stringify(expectedMetadata)); | ||
it('resolves with azure_instance_metadata table on success', async () => { | ||
const mockRunOsquery = runOsquery as jest.MockedFunction<typeof runOsquery>; | ||
const expectedMetadata = [ | ||
{ | ||
location: 'location', | ||
name: 'name', | ||
offer: 'offer', | ||
publisher: 'publisher', | ||
sku: 'sku', | ||
version: 'version', | ||
os_type: 'os_type', | ||
platform_update_domain: 'platform_update_domain', | ||
platform_fault_domain: 'platform_fault_domain', | ||
vm_id: 'vm_id', | ||
vm_size: 'vm_size', | ||
subscription_id: 'subscription_id', | ||
resource_group_name: 'resource_group_name', | ||
placement_group_id: 'placement_group_id', | ||
vm_scale_set_name: 'vm_scale_set_name', | ||
zone: 'zone', | ||
}, | ||
]; | ||
mockRunOsquery.mockResolvedValue(JSON.stringify(expectedMetadata)); | ||
|
||
await expect(getAzureInstanceMetadata()).resolves.toEqual(expectedMetadata); | ||
expect(mockRunOsquery).toHaveBeenCalledWith( | ||
'SELECT * FROM azure_instance_metadata', | ||
[OsType.LINUX, OsType.DARWIN, OsType.WINDOWS_NT], | ||
); | ||
}); | ||
await expect(getAzureInstanceMetadata()).resolves.toEqual(expectedMetadata); | ||
expect(mockRunOsquery).toHaveBeenCalledWith( | ||
'SELECT * FROM azure_instance_metadata', | ||
[OsType.LINUX, OsType.DARWIN, OsType.WINDOWS_NT], | ||
); | ||
}); | ||
|
||
it('rejects with error on command failure', async () => { | ||
const mockRunOsquery = runOsquery as jest.MockedFunction<typeof runOsquery>; | ||
mockRunOsquery.mockRejectedValue('Command failed'); | ||
it('rejects with error on command failure', async () => { | ||
const mockRunOsquery = runOsquery as jest.MockedFunction<typeof runOsquery>; | ||
mockRunOsquery.mockRejectedValue('Command failed'); | ||
|
||
await expect(getAzureInstanceMetadata()).rejects.toEqual('Command failed'); | ||
}); | ||
await expect(getAzureInstanceMetadata()).rejects.toEqual('Command failed'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,38 @@ | ||
import { getAzureInstanceTags } from '../../src/getters'; | ||
import { runOsquery, OsType } from '../../src/runOSQuery'; | ||
import { runOsquery, OsType } from '../../src/runOsquery'; | ||
|
||
jest.mock('../../src/runOsquery', () => ({ | ||
runOsquery: jest.fn(), | ||
OsType: { | ||
LINUX: 'linux', | ||
DARWIN: 'darwin', | ||
WINDOWS_NT: 'windows_nt', | ||
}, | ||
runOsquery: jest.fn(), | ||
OsType: { | ||
LINUX: 'linux', | ||
DARWIN: 'darwin', | ||
WINDOWS_NT: 'windows_nt', | ||
}, | ||
})); | ||
|
||
describe('getAzureInstanceTags', () => { | ||
it('resolves with azure_instance_tags table on success', async () => { | ||
const mockRunOsquery = runOsquery as jest.MockedFunction<typeof runOsquery>; | ||
const expectedTags = [ | ||
{ | ||
vm_id: 'vm_id', | ||
key: 'key', | ||
value: 'value', | ||
}, | ||
]; | ||
mockRunOsquery.mockResolvedValue(JSON.stringify(expectedTags)); | ||
it('resolves with azure_instance_tags table on success', async () => { | ||
const mockRunOsquery = runOsquery as jest.MockedFunction<typeof runOsquery>; | ||
const expectedTags = [ | ||
{ | ||
vm_id: 'vm_id', | ||
key: 'key', | ||
value: 'value', | ||
}, | ||
]; | ||
mockRunOsquery.mockResolvedValue(JSON.stringify(expectedTags)); | ||
|
||
await expect(getAzureInstanceTags()).resolves.toEqual(expectedTags); | ||
expect(mockRunOsquery).toHaveBeenCalledWith( | ||
'SELECT * FROM azure_instance_tags', | ||
[OsType.LINUX, OsType.DARWIN, OsType.WINDOWS_NT], | ||
); | ||
}); | ||
await expect(getAzureInstanceTags()).resolves.toEqual(expectedTags); | ||
expect(mockRunOsquery).toHaveBeenCalledWith( | ||
'SELECT * FROM azure_instance_tags', | ||
[OsType.LINUX, OsType.DARWIN, OsType.WINDOWS_NT], | ||
); | ||
}); | ||
|
||
it('rejects with error on command failure', async () => { | ||
const mockRunOsquery = runOsquery as jest.MockedFunction<typeof runOsquery>; | ||
mockRunOsquery.mockRejectedValue('Command failed'); | ||
it('rejects with error on command failure', async () => { | ||
const mockRunOsquery = runOsquery as jest.MockedFunction<typeof runOsquery>; | ||
mockRunOsquery.mockRejectedValue('Command failed'); | ||
|
||
await expect(getAzureInstanceTags()).rejects.toEqual('Command failed'); | ||
}); | ||
await expect(getAzureInstanceTags()).rejects.toEqual('Command failed'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,58 @@ | ||
import { getCarbonBlackInfo } from '../../src/getters'; | ||
import { runOsquery, OsType } from '../../src/runOSQuery'; | ||
import { runOsquery, OsType } from '../../src/runOsquery'; | ||
|
||
jest.mock('../../src/runOsquery', () => ({ | ||
runOsquery: jest.fn(), | ||
OsType: { | ||
LINUX: 'linux', | ||
DARWIN: 'darwin', | ||
WINDOWS_NT: 'windows_nt', | ||
}, | ||
runOsquery: jest.fn(), | ||
OsType: { | ||
LINUX: 'linux', | ||
DARWIN: 'darwin', | ||
WINDOWS_NT: 'windows_nt', | ||
}, | ||
})); | ||
|
||
describe('getCarbonBlackInfo', () => { | ||
it('resolves with carbon_black_info table on success', async () => { | ||
const mockRunOsquery = runOsquery as jest.MockedFunction<typeof runOsquery>; | ||
const expectedCarbonBlackInfo = [ | ||
{ | ||
sensor_id: 1, | ||
config_name: 'config_name', | ||
collect_store_files: 1, | ||
collect_module_loads: 1, | ||
collect_module_info: 1, | ||
collect_file_mods: 1, | ||
collect_reg_mods: 1, | ||
collect_net_conns: 1, | ||
collect_processes: 1, | ||
collect_cross_processes: 1, | ||
collect_emet_events: 1, | ||
collect_data_file_writes: 1, | ||
collect_process_user_context: 1, | ||
collect_sensor_operations: 1, | ||
log_file_disk_quota_mb: 1, | ||
log_file_disk_quota_percentage: 1, | ||
protection_disabled: 1, | ||
sensor_ip_addr: 'sensor_ip_addr', | ||
sensor_backend_server: 'sensor_backend_server', | ||
event_queue: 1, | ||
binary_queue: 1, | ||
}, | ||
]; | ||
mockRunOsquery.mockResolvedValue(JSON.stringify(expectedCarbonBlackInfo)); | ||
it('resolves with carbon_black_info table on success', async () => { | ||
const mockRunOsquery = runOsquery as jest.MockedFunction<typeof runOsquery>; | ||
const expectedCarbonBlackInfo = [ | ||
{ | ||
sensor_id: 1, | ||
config_name: 'config_name', | ||
collect_store_files: 1, | ||
collect_module_loads: 1, | ||
collect_module_info: 1, | ||
collect_file_mods: 1, | ||
collect_reg_mods: 1, | ||
collect_net_conns: 1, | ||
collect_processes: 1, | ||
collect_cross_processes: 1, | ||
collect_emet_events: 1, | ||
collect_data_file_writes: 1, | ||
collect_process_user_context: 1, | ||
collect_sensor_operations: 1, | ||
log_file_disk_quota_mb: 1, | ||
log_file_disk_quota_percentage: 1, | ||
protection_disabled: 1, | ||
sensor_ip_addr: 'sensor_ip_addr', | ||
sensor_backend_server: 'sensor_backend_server', | ||
event_queue: 1, | ||
binary_queue: 1, | ||
}, | ||
]; | ||
mockRunOsquery.mockResolvedValue(JSON.stringify(expectedCarbonBlackInfo)); | ||
|
||
await expect(getCarbonBlackInfo()).resolves.toEqual( | ||
expectedCarbonBlackInfo, | ||
); | ||
expect(mockRunOsquery).toHaveBeenCalledWith( | ||
'SELECT * FROM carbon_black_info', | ||
[OsType.LINUX, OsType.DARWIN, OsType.WINDOWS_NT], | ||
); | ||
}); | ||
await expect(getCarbonBlackInfo()).resolves.toEqual( | ||
expectedCarbonBlackInfo, | ||
); | ||
expect(mockRunOsquery).toHaveBeenCalledWith( | ||
'SELECT * FROM carbon_black_info', | ||
[OsType.LINUX, OsType.DARWIN, OsType.WINDOWS_NT], | ||
); | ||
}); | ||
|
||
it('rejects with error on command failure', async () => { | ||
const mockRunOsquery = runOsquery as jest.MockedFunction<typeof runOsquery>; | ||
mockRunOsquery.mockRejectedValue('Command failed'); | ||
it('rejects with error on command failure', async () => { | ||
const mockRunOsquery = runOsquery as jest.MockedFunction<typeof runOsquery>; | ||
mockRunOsquery.mockRejectedValue('Command failed'); | ||
|
||
await expect(getCarbonBlackInfo()).rejects.toEqual('Command failed'); | ||
}); | ||
await expect(getCarbonBlackInfo()).rejects.toEqual('Command failed'); | ||
}); | ||
}); |
Oops, something went wrong.