feat(ClamAvService): Add ClamAV Manager with Docker container management capabilities.
This commit is contained in:
49
test/test.ts
49
test/test.ts
@@ -1,35 +1,40 @@
|
||||
import { expect, expectAsync, tap } from '@push.rocks/tapbundle';
|
||||
import { expect, tap } from '../ts/plugins.js';
|
||||
import * as smartantivirus from '../ts/index.js';
|
||||
import { setupClamAV, cleanupClamAV } from './helpers/clamav.helper.js';
|
||||
|
||||
const EICAR_TEST_STRING = 'X5O!P%@AP[4\\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*';
|
||||
let clamService: smartantivirus.ClamAvService;
|
||||
|
||||
tap.test('should create a ClamAvService instance', async () => {
|
||||
clamService = new smartantivirus.ClamAvService();
|
||||
expect(clamService).toBeDefined();
|
||||
tap.test('setup', async () => {
|
||||
await setupClamAV();
|
||||
});
|
||||
|
||||
tap.test('should scan a string', async () => {
|
||||
const scanResult = await clamService.scanString('X5O!P%@AP[4\PZX54(P^)7CC)7}' + '$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*');
|
||||
tap.test('should create a ClamAvService instance and initialize ClamAV', async () => {
|
||||
clamService = new smartantivirus.ClamAvService();
|
||||
expect(clamService).toBeTruthy();
|
||||
// The manager will start the container and wait for initialization
|
||||
await clamService.verifyConnection();
|
||||
});
|
||||
|
||||
tap.test('should detect EICAR test string', async () => {
|
||||
const scanResult = await clamService.scanString(EICAR_TEST_STRING);
|
||||
console.log('Scan Result:', scanResult);
|
||||
// expect(scanResult).toEqual({ isInfected: true, reason: 'FOUND' });
|
||||
expect(scanResult.isInfected).toEqual(true);
|
||||
expect(scanResult.reason).toBeTruthy();
|
||||
});
|
||||
|
||||
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();
|
||||
});
|
||||
|
||||
tap.test('cleanup', async () => {
|
||||
await cleanupClamAV();
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
||||
|
||||
/* (async () => {
|
||||
|
||||
try {
|
||||
|
||||
await clamService.updateVirusDefinitions(); // Step 2: Update definitions
|
||||
await clamService.startClamDaemon(); // Step 3: Start daemon
|
||||
|
||||
const scanResult = await clamService.scanString('EICAR test string...');
|
||||
console.log('Scan Result:', scanResult);
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
}
|
||||
})(); */
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user