2025-02-03 13:34:52 +01:00
|
|
|
import { expect, tap } from '../ts/plugins.js';
|
2025-01-10 03:09:32 +01:00
|
|
|
import * as smartantivirus from '../ts/index.js';
|
2025-02-03 13:34:52 +01:00
|
|
|
import { setupClamAV, cleanupClamAV } from './helpers/clamav.helper.js';
|
2025-01-10 03:09:32 +01:00
|
|
|
|
2025-02-03 13:34:52 +01:00
|
|
|
const EICAR_TEST_STRING = 'X5O!P%@AP[4\\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*';
|
2025-01-10 03:09:32 +01:00
|
|
|
let clamService: smartantivirus.ClamAvService;
|
|
|
|
|
2025-02-03 13:34:52 +01:00
|
|
|
tap.test('setup', async () => {
|
|
|
|
await setupClamAV();
|
|
|
|
});
|
|
|
|
|
|
|
|
tap.test('should create a ClamAvService instance and initialize ClamAV', async () => {
|
2025-01-10 03:09:32 +01:00
|
|
|
clamService = new smartantivirus.ClamAvService();
|
2025-02-03 13:34:52 +01:00
|
|
|
expect(clamService).toBeTruthy();
|
|
|
|
// The manager will start the container and wait for initialization
|
|
|
|
await clamService.verifyConnection();
|
2025-01-10 03:09:32 +01:00
|
|
|
});
|
|
|
|
|
2025-02-03 13:34:52 +01:00
|
|
|
tap.test('should detect EICAR test string', async () => {
|
|
|
|
const scanResult = await clamService.scanString(EICAR_TEST_STRING);
|
2025-01-10 03:09:32 +01:00
|
|
|
console.log('Scan Result:', scanResult);
|
2025-02-03 13:34:52 +01:00
|
|
|
expect(scanResult.isInfected).toEqual(true);
|
|
|
|
expect(scanResult.reason).toBeTruthy();
|
2025-01-10 03:09:32 +01:00
|
|
|
});
|
|
|
|
|
2025-02-03 13:34:52 +01:00
|
|
|
tap.test('should not detect clean string', async () => {
|
|
|
|
const scanResult = await clamService.scanString('This is a clean string with no virus signature');
|
|
|
|
console.log('Clean Scan Result:', scanResult);
|
|
|
|
expect(scanResult.isInfected).toEqual(false);
|
|
|
|
expect(scanResult.reason).toBeUndefined();
|
|
|
|
});
|
2025-01-10 03:09:32 +01:00
|
|
|
|
2025-02-03 13:34:52 +01:00
|
|
|
tap.test('cleanup', async () => {
|
|
|
|
await cleanupClamAV();
|
|
|
|
});
|
2025-01-10 03:09:32 +01:00
|
|
|
|
2025-02-03 13:34:52 +01:00
|
|
|
tap.start();
|
2025-01-10 03:09:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
|