Socket
Socket
Sign inDemoInstall

clamscan

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clamscan - npm Package Compare versions

Comparing version 0.8.1 to 0.8.2

5

HISTORY.md

@@ -75,1 +75,6 @@ # Changes

* Fixed check for database file. Issue #6
### 0.8.2 (2015-08-14)
* Updated to `execFile` instead of `exec`
* Improved test suite

328

index.js

@@ -12,15 +12,16 @@ /*!

var execSync = require('child_process').execSync;
var execFile = require('child_process').execFile;
var spawn = require('child_process').spawn;
var os = require('os');
// ****************************************************************************
// NodeClam class definition
// -----
// @param Object options Key => Value pairs to override default settings
// @param Object options Key => Value pairs to override default settings
// ****************************************************************************
function NodeClam(options) {
options = options || {};
this.default_scanner = 'clamdscan';
// Configuration Settings

@@ -49,3 +50,3 @@ this.defaults = Object.freeze({

});
this.settings = __.extend({},this.defaults);

@@ -63,3 +64,3 @@

this.settings = __.extend({},this.settings,options);
// Backwards compatibilty section

@@ -69,3 +70,3 @@ if (this.settings.quarantine_path && !__.isEmpty(this.settings.quarantine_path)) {

}
// Determine whether to use clamdscan or clamscan

@@ -79,3 +80,3 @@ this.scanner = this.default_scanner;

}
// Check to make sure preferred scanner exists and actually is a clamscan binary

@@ -92,3 +93,3 @@ if (!this.is_clamav_binary_sync(this.scanner)) {

}
// Make sure quarantine infected path exists at specified location

@@ -99,7 +100,7 @@ if (!__.isEmpty(this.settings.quarantine_infected) && !fs.existsSync(this.settings.quarantine_infected)) {

throw new Error(err_msg);
if (this.settings.debug_mode)
console.log("node-clam: " + err_msg);
}
// Make sure scan_log exists at specified location

@@ -112,3 +113,3 @@ if (!__.isEmpty(this.settings.scan_log) && !fs.existsSync(this.settings.scan_log)) {

}
// If using clamscan, make sure definition db exists at specified location

@@ -123,3 +124,3 @@ if (this.scanner === 'clamscan') {

}
// Build clam flags

@@ -147,3 +148,3 @@ this.clam_flags = build_clam_flags(this.scanner, this.settings);

}
var version_cmds = {

@@ -153,3 +154,3 @@ clamdscan: path + ' -c ' + this.settings.clamdscan.config_file + ' --version',

};
fs.exists(path, function(exists) {

@@ -162,2 +163,3 @@ if (exists === false) {

}
exec(version_cmds[scanner], function(err, stdout, stderr) {

@@ -189,3 +191,3 @@ if (stdout.toString().match(/ClamAV/) === null) {

}
var version_cmds = {

@@ -195,5 +197,5 @@ clamdscan: path + ' -c ' + this.settings.clamdscan.config_file + ' --version',

};
/*
* Saving this line for version 1.0 release--the one that requires Node 0> .12
/*
* Saving this line for version 1.0 release--the one that requires Node 0> .12
* if (!fs.existsSync(path) || execSync(version_cmds[scanner]).toString().match(/ClamAV/) === null) {

@@ -207,3 +209,3 @@ */

}
return true;

@@ -215,4 +217,4 @@ }

// -----
// @param String file Path to the file to check
// @param Function callback (optional) What to do after the scan
// @param String file Path to the file to check
// @param Function callback (optional) What to do after the scan
// ****************************************************************************

@@ -234,15 +236,12 @@ NodeClam.prototype.is_infected = function(file, callback) {

}
var self = this;
if(this.settings.debug_mode)
if(this.settings.debug_mode) {
console.log("node-clam: Scanning " + file);
// Build the actual command to run
var command = this.settings[this.scanner].path + this.clam_flags + file;
if(this.settings.debug_mode === true)
console.log('node-clam: Configured clam command: ' + command);
console.log('node-clam: Configured clam command: ' + this.settings[this.scanner].path + ' ' + this.build_clam_args(file).join(' '));
}
// Execute the clam binary with the proper flags
exec(command, function(err, stdout, stderr) {
execFile(this.settings[this.scanner].path, this.build_clam_args(file), function(err, stdout, stderr) {
if (err || stderr) {

@@ -263,3 +262,3 @@ if (err) {

var result = stdout.trim();
if(self.settings.debug_mode) {

@@ -269,3 +268,3 @@ console.log('node-clam: file size: ' + fs.statSync(file).size);

}
if(result.match(/OK$/)) {

@@ -285,8 +284,8 @@ if(self.settings.debug_mode)

// ****************************************************************************
// Scans an array of files or paths. You must provide the full paths of the
// Scans an array of files or paths. You must provide the full paths of the
// files and/or paths.
// -----
// @param Array files A list of files or paths (full paths) to be scanned.
// @param Function end_cb What to do after the scan
// @param Function file_cb What to do after each file has been scanned
// @param Array files A list of files or paths (full paths) to be scanned.
// @param Function end_cb What to do after the scan
// @param Function file_cb What to do after each file has been scanned
// ****************************************************************************

@@ -297,3 +296,3 @@ NodeClam.prototype.scan_files = function(files, end_cb, file_cb) {

file_cb = file_cb || null;
var bad_files = [];

@@ -304,3 +303,3 @@ var good_files = [];

var file, file_list;
// Verify second param, if supplied, is a function

@@ -310,3 +309,3 @@ if (end_cb && typeof end_cb !== 'function') {

}
// Verify second param, if supplied, is a function

@@ -316,5 +315,5 @@ if (file_cb && typeof file_cb !== 'function') {

}
// The function that parses the stdout from clamscan/clamdscan
var parse_stdout = function(err, stdout) {
var parse_stdout = function(err, stdout) {
stdout.trim()

@@ -324,3 +323,3 @@ .split(String.fromCharCode(10))

if (result.match(/^[\-]+$/) !== null) return;
//console.log("PATH: " + result)

@@ -333,3 +332,3 @@ var path = result.match(/^(.*): /);

}
if (result.match(/OK$/)) {

@@ -344,19 +343,19 @@ if (self.settings.debug_mode === true){

}
bad_files.push(path);
bad_files.push(path);
}
});
if (err)
if (err)
return end_cb(err, [], bad_files);
return end_cb(null, good_files, bad_files);
};
// The function that actually scans the files
var do_scan = function(files) {
var num_files = files.length;
if (self.settings.debug_mode === true) {
console.log("node-clam: Scanning a list of " + num_files + " passed files.");
}
// Slower but more verbose way...

@@ -368,6 +367,6 @@ if (typeof file_cb === 'function') {

completed_files++;
if (self.settings.debug_mode)
console.log("node-clam: " + completed_files + "/" + num_files + " have been scanned!");
if(!infected) {

@@ -378,5 +377,5 @@ good_files.push(file);

}
if(__.isFunction(file_cb)) file_cb(err, file, infected);
if(completed_files >= num_files) {

@@ -391,3 +390,3 @@ if(self.settings.debug_mode) {

if(__.isFunction(end_cb)) end_cb(null, good_files, bad_files);
}
}
// All files have not been scanned yet, scan next item.

@@ -401,27 +400,26 @@ else {

}
// The MUCH quicker but less-verbose way
else {
var all_files = [];
var finish_scan = function() {
// Make sure there are no dupes and no falsy values... just cause we can
all_files = __.uniq(__.compact(all_files));
// If file list is empty, return error
if (all_files.length <= 0)
return end_cb(new Error("No valid files provided to scan!"), [], []);
// List files by space and escape
// List files by space and escape
var items = files.map(function(file) {
return file.replace(/ /g,'\\ ');
}).join(' ');
return file.replace(/ /g,'\\ ');
});
// Build the actual command to run
var command = self.settings[self.scanner].path + self.clam_flags + items;
if(self.settings.debug_mode === true)
console.log('node-clam: Configured clam command: ' + command);
console.log('node-clam: Configured clam command: ' + self.settings[self.scanner].path + ' ' +self.build_clam_args(items).join(' '));
// Execute the clam binary with the proper flags
exec(command, function(err, stdout, stderr) {
execFile(self.settings[self.scanner].path, self.build_clam_args(items), function(err, stdout, stderr) {
if(self.settings.debug_mode === true) {

@@ -436,3 +434,3 @@ console.log('node-clam: stdout:', stdout);

}
if (stderr.length > 0) {

@@ -446,6 +444,6 @@ bad_files = stderr.split(os.EOL).map(function(err_line) {

});
bad_files = __.compact(bad_files);
}
}
}

@@ -455,3 +453,3 @@ return parse_stdout(err, stdout);

};
if (self.scanner === 'clamdscan' && self.scan_recursively === false) {

@@ -481,3 +479,3 @@ (function get_dir_files() {

};
// If string is provided in files param, forgive them... create an array

@@ -487,3 +485,3 @@ if (typeof files === 'string' && files.trim().length > 0) {

}
// Do some parameter validation

@@ -495,3 +493,3 @@ if (!__.isArray(files) || files.length <= 0) {

}
fs.exists(this.settings.file_list, function(exists) {

@@ -502,3 +500,3 @@ if (exists === false) {

}
fs.readFile(self.settings.file_list, function(err, data) {

@@ -510,3 +508,3 @@ if (err) {

return do_scan(data);
});
});
});

@@ -519,12 +517,12 @@ } else {

// ****************************************************************************
// Scans an entire directory. Provides 3 params to end callback: Error, path
// Scans an entire directory. Provides 3 params to end callback: Error, path
// scanned, and whether its infected or not. To scan multiple directories, pass
// them as an array to the scan_files method.
// -----
// NOTE: While possible, it is NOT advisable to use the file_cb parameter when
// using the clamscan binary. Doing so with clamdscan is okay, however. This
// NOTE: While possible, it is NOT advisable to use the file_cb parameter when
// using the clamscan binary. Doing so with clamdscan is okay, however. This
// method also allows for non-recursive scanning with the clamdscan binary.
// -----
// @param String path The directory to scan files of
// @param Function end_cb What to do when all files have been scanned
// @param String path The directory to scan files of
// @param Function end_cb What to do when all files have been scanned
// @param Function file_cb What to do after each file has been scanned

@@ -534,7 +532,7 @@ // ****************************************************************************

var self = this;
path = path || '';
end_cb = end_cb || null;
file_cb = file_cb || null;
// Verify path provided is a string

@@ -544,3 +542,3 @@ if (typeof path !== 'string' || path.length <= 0) {

}
// Verify second param, if supplied, is a function

@@ -550,3 +548,3 @@ if (end_cb && typeof end_cb !== 'function') {

}
// Trim trailing slash

@@ -557,6 +555,6 @@ path = path.replace(/\/$/, '');

console.log("node-clam: Scanning Directory: " + path);
// Get all files recursively
if (this.settings.scan_recursively && typeof file_cb === 'function') {
exec('find ' + path, function(err, stdout, stderr) {
execFile('find', [path], function(err, stdout, stderr) {
if (err || stderr) {

@@ -571,4 +569,4 @@ if(this.settings.debug_mode === true)

});
}
}
// Clamdscan always does recursive, so, here's a way to avoid that if you want...

@@ -591,12 +589,10 @@ else if (this.settings.scan_recursively === false && this.scanner === 'clamdscan') {

}
// If you don't care about individual file progress (which is very slow for clamscan but fine for clamdscan...)
else if (this.settings.scan_recursively && typeof file_cb !== 'function') {
var command = this.settings[this.scanner].path + this.clam_flags + path;
if(this.settings.debug_mode === true)
console.log('node-clam: Configured clam command: ' + command);
console.log('node-clam: Configured clam command: ' + this.settings[this.scanner].path + ' ' + this.build_clam_args(path).join(' '));
// Execute the clam binary with the proper flags
exec(command, function(err, stdout, stderr) {
execFile(this.settings[this.scanner].path, this.build_clam_args(path), function(err, stdout, stderr) {
if (err || stderr) {

@@ -617,3 +613,3 @@ if (err) {

var result = stdout.trim();
if(result.match(/OK$/)) {

@@ -633,2 +629,22 @@ if(self.settings.debug_mode)

// *****************************************************************************
// Builds out the args to pass to execFile
// -----
// @param String|Array item The file(s) / directory(ies) to append to the args
// @api Private
// *****************************************************************************
NodeClam.prototype.build_clam_args = function (item) {
var args = this.clam_flags.slice();
if (typeof item === 'string') {
args.push(item);
}
if ((item instanceof Array) === true) {
args = args.concat(item);
}
return args;
}
module.exports = function(options) {

@@ -641,16 +657,16 @@ return new NodeClam(options);

// -----
// @param String scanner The scanner to use (clamscan or clamdscan)
// @param Object settings The settings used to build the flags
// @return String The concatenated clamav flags
// @api Private
// @param String scanner The scanner to use (clamscan or clamdscan)
// @param Object settings The settings used to build the flags
// @return String The concatenated clamav flags
// @api Private
// *****************************************************************************
function build_clam_flags(scanner, settings) {
var flags_array = ['--no-summary'];
// Flags specific to clamscan
if (scanner == 'clamscan') {
flags_array.push('--stdout');
// Remove infected files
if (settings.remove_infected === true) {
var flags_array = ['--no-summary'];
// Flags specific to clamscan
if (scanner == 'clamscan') {
flags_array.push('--stdout');
// Remove infected files
if (settings.remove_infected === true) {
flags_array.push('--remove=yes');

@@ -660,49 +676,49 @@ } else {

}
// Database file
if (!__.isEmpty(settings.clamscan.db)) flags_array.push('--database=' + settings.clamscan.db);
// Scan archives
if (settings.clamscan.scan_archives === true) {
flags_array.push('--scan-archive=yes');
} else {
flags_array.push('--scan-archive=no');
}
// Recursive scanning (flag is specific, feature is not)
if (settings.scan_recursively === true) {
flags_array.push('-r');
} else {
flags_array.push('--recursive=no');
}
}
// Flags specific to clamdscan
else if (scanner == 'clamdscan') {
flags_array.push('--fdpass');
// Remove infected files
if (settings.remove_infected === true) flags_array.push('--remove');
// Specify a config file
if (!__.isEmpty(settings.clamdscan.config_file)) flags_array.push('--config-file=' + settings.clamdscan.config_file);
// Turn on multi-threaded scanning
if (settings.clamdscan.multiscan === true) flags_array.push('--multiscan');
// Reload the virus DB
if (settings.clamdscan.reload_db === true) flags_array.push('--reload');
}
// ***************
// Common flags
// ***************
// Remove infected files
if (settings.remove_infected !== true) {
if (!__.isEmpty(settings.quarantine_infected))
flags_array.push('--move=' + settings.quarantine_infected);
}
// Write info to a log
if (!__.isEmpty(settings.scan_log)) flags_array.push('--log=' + settings.scan_log);
// Read list of files to scan from a file
if (!__.isEmpty(settings.file_list)) flags_array.push('--file-list=' + settings.file_list);
// Build the String
return ' ' + flags_array.join(' ') + ' ';
// Database file
if (!__.isEmpty(settings.clamscan.db)) flags_array.push('--database=' + settings.clamscan.db);
// Scan archives
if (settings.clamscan.scan_archives === true) {
flags_array.push('--scan-archive=yes');
} else {
flags_array.push('--scan-archive=no');
}
// Recursive scanning (flag is specific, feature is not)
if (settings.scan_recursively === true) {
flags_array.push('-r');
} else {
flags_array.push('--recursive=no');
}
}
// Flags specific to clamdscan
else if (scanner == 'clamdscan') {
flags_array.push('--fdpass');
// Remove infected files
if (settings.remove_infected === true) flags_array.push('--remove');
// Specify a config file
if (!__.isEmpty(settings.clamdscan.config_file)) flags_array.push('--config-file=' + settings.clamdscan.config_file);
// Turn on multi-threaded scanning
if (settings.clamdscan.multiscan === true) flags_array.push('--multiscan');
// Reload the virus DB
if (settings.clamdscan.reload_db === true) flags_array.push('--reload');
}
// ***************
// Common flags
// ***************
// Remove infected files
if (settings.remove_infected !== true) {
if (!__.isEmpty(settings.quarantine_infected))
flags_array.push('--move=' + settings.quarantine_infected);
}
// Write info to a log
if (!__.isEmpty(settings.scan_log)) flags_array.push('--log=' + settings.scan_log);
// Read list of files to scan from a file
if (!__.isEmpty(settings.file_list)) flags_array.push('--file-list=' + settings.file_list);
// Build the String
return flags_array;
}
{
"name": "clamscan",
"version": "0.8.1",
"version": "0.8.2",
"author": "Kyle Farris <kfarris@chomponllc.com> (http://chomponllc.com)",

@@ -10,3 +10,4 @@ "description": "Use Node JS to scan files on your server with ClamAV's clamscan binary or clamdscan daemon. This is especially useful for scanning uploaded files provided by un-trusted sources.",

"nicolaspeixoto",
"urg <Patrick McAndrew>"
"urg <Patrick McAndrew>",
"SaltwaterC <Ștefan Ruso>"
],

@@ -13,0 +14,0 @@ "scripts": {

@@ -17,4 +17,6 @@ ## NodeJS Clamscan Virus Scanning Utility

As for OSX, I've not tried it, but, here's a promising looking site: http://www.clamxav.com/index.php . I would stick with linux varieties, though...
For OS X, you can install clamav with brew:
sudo brew install clamav
This module is not intended to work on a Windows server. This would be a welcome addition if someone wants to add that feature (I may get around to it one day but have no urgent need for this).

@@ -21,0 +23,0 @@

@@ -32,3 +32,3 @@ var __ = require('underscore');

});
it('should return an object when intantiated', function() {

@@ -38,3 +38,3 @@ reset_clam();

});
it('should have certain config properties defined', function() {

@@ -52,3 +52,3 @@ reset_clam();

});
it('should have the proper global default values set', function() {

@@ -64,3 +64,3 @@ reset_clam();

});
it('should have the proper clamscan default values set', function() {

@@ -73,3 +73,3 @@ reset_clam();

});
it('should have the proper clamdscan default values set', function() {

@@ -83,19 +83,19 @@ reset_clam();

});
it('should accept an options array and merge them with the object defaults', function() {
clamscan = clam({
remove_infected: true,
remove_infected: true,
quarantine_infected: config.quarantine_infected,
scan_log: config.scan_log,
debug_mode: true,
file_list: __dirname + '/files_list.txt',
file_list: __dirname + '/files_list.txt',
scan_recursively: true,
clamscan: {
path: config.clamscan.path,
db: '/usr/bin/better_clam_db',
db: '/usr/bin/better_clam_db',
scan_archives: false,
active: false
active: false
},
clamdscan: {
path: config.clamdscan.path,
path: config.clamdscan.path,
config_file: config.clamdscan.config_file,

@@ -108,3 +108,3 @@ multiscan: false,

});
// General

@@ -118,3 +118,3 @@ expect(clamscan.settings.remove_infected).to.eql(true);

expect(clamscan.settings.preference).to.eql('clamscan');
// clamscan

@@ -125,3 +125,3 @@ expect(clamscan.settings.clamscan.path).to.eql(config.clamscan.path);

expect(clamscan.settings.clamscan.active).to.eql(false);
// clamdscan

@@ -134,7 +134,7 @@ expect(clamscan.settings.clamdscan.path).to.eql(config.clamdscan.path);

});
it('should failover to alternate scanner if preferred scanner is not found', function() {
});
it('should fail if an invalid scanner preference is supplied', function() {

@@ -144,13 +144,13 @@ expect(function() { reset_clam({preference: 'clamscan'}); }).to.not.throw(Error);

});
it('should fail to load if no active & valid scanner is found', function() {
var clamdscan_options = __.extend({},config.clamdscan, {path: __dirname + '/should/not/exist', active: true});
var clamscan_options = __.extend({},config.clamscan, {path: __dirname + '/should/not/exist', active: true});
var options = __.extend({}, config, {clamdscan: clamdscan_options});
options = __.extend({}, options, {clamscan: clamscan_options});
expect(function() { reset_clam(options); }).to.throw(Error);
});
it('should fail to load if specified quarantine path (if specified) does not exist or is not writable', function() {

@@ -160,3 +160,3 @@ expect(function() { reset_clam({quarantine_infected: __dirname + '/infected'}); }).to.not.throw(Error);

});
it('should set definition database (clamscan) to null if specified db is not found', function() {

@@ -166,7 +166,7 @@ reset_clam(__.extend({}, config, __.extend({},config.clamscan,{scan_log: __dirname + '/should/not/exist'})));

});
it('should be able have configuration settings changed after instantiation', function() {
reset_clam({scan_log: null});
expect(clamscan.settings.scan_log).to.be.null;
clamscan.settings.scan_log = config.scan_log;

@@ -180,15 +180,24 @@ expect(clamscan.settings.scan_log).to.be.eql(config.scan_log);

// But, we can test what is built by checking the clam_flags property after instantiation
it('should build a string with 1 space worth of paddding on either side', function() {
it('should build an array', function() {
reset_clam();
expect(clamscan.clam_flags).to.not.be.undefined;
expect(clamscan.clam_flags).to.be.a('string');
expect(clamscan.clam_flags).to.match(/^\s{1}(.*)+\s{1}$/);
expect(clamscan.clam_flags).to.be.an('array');
});
it('should build a series of flags', function() {
if (clamscan.settings.preference === 'clamdscan') {
clamscan.clam_flags.should.be.eql(' --no-summary --fdpass --config-file=' + config.clamdscan.config_file + ' --multiscan --move=' + config.quarantine_infected + ' --log=' + config.scan_log + ' ');
clamscan.clam_flags.should.be.eql([
'--no-summary',
'--fdpass',
'--config-file=' + config.clamdscan.config_file,
'--multiscan',
'--move=' + config.quarantine_infected,
'--log=' + config.scan_log
]);
} else {
clamscan.clam_flags.should.be.eql(' --no-summary --log=' + config.scan_log + ' ');
clamscan.clam_flags.should.be.eql([
'--no-summary',
'--log=' + config.scan_log
]);
}

@@ -200,3 +209,3 @@ });

reset_clam();
it('should exist', function() {

@@ -208,3 +217,3 @@ should.exist(clamscan.is_infected);

});
it('should require a string representing the path to a file to be scanned', function() {

@@ -228,3 +237,3 @@ expect(function() { clamscan.is_infected(good_scan_file); }, 'good string provided').to.not.throw(Error);

});
it('should require second parameter to be a callback function (if truthy value provided)', function() {

@@ -246,3 +255,3 @@ expect(function() { clamscan.is_infected(good_scan_file); }, 'nothing provided').to.not.throw(Error);

});
it('should return error if file not found', function(done) {

@@ -255,3 +264,3 @@ clamscan.is_infected(__dirname + '/missing_file.txt', function(err, file, is_infected) {

});
it('should supply filename with path back after the file is scanned', function(done) {

@@ -268,3 +277,3 @@ var scan_file = good_scan_file;

});
it('should respond with FALSE when file is not infected', function(done) {

@@ -280,3 +289,3 @@ var scan_file = good_scan_file;

});
it('should respond with TRUE when non-archive file is infected', function(done) {

@@ -287,3 +296,3 @@ var scan_file = __dirname + '/bad_scan_dir/bad_file_1.txt';

fs.writeFileSync(scan_file, body);
clamscan.is_infected(scan_file, function(err, file, is_infected) {

@@ -294,3 +303,3 @@ check(done, function() {

expect(is_infected).to.eql(true);
if (fs.existsSync(scan_file)) {

@@ -311,3 +320,3 @@ fs.unlinkSync(scan_file);

reset_clam();
it('should exist', function() {

@@ -319,3 +328,3 @@ should.exist(clamscan.scan_files);

});
it('should return err to the "err" parameter of the "end_cb" callback if an array with a bad string is provided as first parameter', function(done) {

@@ -329,3 +338,3 @@ clamscan.scan_files([''], function(err, good_files, bad_files) {

});
it('should return err to the "err" parameter of the "end_cb" callback if an empty array is provided as first parameter', function(done) {

@@ -339,3 +348,3 @@ clamscan.scan_files([], function(err, good_files, bad_files) {

});
it('should return err to the "err" parameter of the "end_cb" callback if nothing is provided as first parameter', function(done) {

@@ -349,3 +358,3 @@ clamscan.scan_files(undefined, function(err, good_files, bad_files) {

});
it('should return err to the "err" parameter of the "end_cb" callback if null is provided as first parameter', function(done) {

@@ -359,3 +368,3 @@ clamscan.scan_files(null, function(err, good_files, bad_files) {

});
it('should return err to the "err" parameter of the "end_cb" callback if an empty string is provided as first parameter', function(done) {

@@ -369,3 +378,3 @@ clamscan.scan_files('', function(err, good_files, bad_files) {

});
it('should return err to the "err" parameter of the "end_cb" callback if TRUE is provided as first parameter', function(done) {

@@ -379,3 +388,3 @@ clamscan.scan_files(true, function(err, good_files, bad_files) {

});
it('should return err to the "err" parameter of the "end_cb" callback if an integer is provided as first parameter', function(done) {

@@ -389,3 +398,3 @@ clamscan.scan_files(5, function(err, good_files, bad_files) {

});
it('should return err to the "err" parameter of the "end_cb" callback if a float is provided as first parameter', function(done) {

@@ -399,3 +408,3 @@ clamscan.scan_files(5.5, function(err, good_files, bad_files) {

});
it('should return err to the "err" parameter of the "end_cb" callback if a Infinity is provided as first parameter', function(done) {

@@ -409,3 +418,3 @@ clamscan.scan_files(Infinity, function(err, good_files, bad_files) {

});
it('should return err to the "err" parameter of the "end_cb" callback if a RegEx is provided as first parameter', function(done) {

@@ -419,3 +428,3 @@ clamscan.scan_files(/foobar/, function(err, good_files, bad_files) {

});
it('should return err to the "err" parameter of the "end_cb" callback if an Standard Object is provided as first parameter', function(done) {

@@ -429,3 +438,3 @@ clamscan.scan_files({}, function(err, good_files, bad_files) {

});
it('should return err to the "err" parameter of the "end_cb" callback if a NaN is provided as first parameter', function(done) {

@@ -439,3 +448,3 @@ clamscan.scan_files(NaN, function(err, good_files, bad_files) {

});
it('should return err to the "err" parameter of the "end_cb" callback if a string-returning function is provided as first parameter', function(done) {

@@ -449,3 +458,3 @@ clamscan.scan_files(function() { return good_scan_file; }, function(err, good_files, bad_files) {

});
it('should return err to the "err" parameter of the "end_cb" callback if a String object is provided as first parameter', function(done) {

@@ -459,3 +468,3 @@ clamscan.scan_files(new String(good_scan_file), function(err, good_files, bad_files) {

});
it('should NOT return err to the "err" parameter of the "end_cb" callback if an array with a non-empty string or strings is provided as first parameter', function(done) {

@@ -470,3 +479,3 @@ clamscan.scan_files([good_scan_file], function(err, good_files, bad_files) {

});
it('should NOT return err to the "err" parameter of the "end_cb" callback if a non-empty string is provided as first parameter', function(done) {

@@ -481,3 +490,3 @@ clamscan.scan_files(good_scan_file, function(err, good_files, bad_files) {

});
it('should NOT return error to the "err" parameter of the "end_cb" callback if nothing is provided as first parameter but file_list is configured in settings', function(done) {

@@ -494,3 +503,3 @@ clamscan.settings.file_list = good_file_list;

});
it('should return error to the "err" parameter of the "end_cb" callback if nothing is provided as first parameter and file_list is configured in settings but has inaccessible files', function(done) {

@@ -507,3 +516,3 @@ clamscan.settings.file_list = bad_file_list;

});
it('should NOT return error to the "err" parameter of the "end_cb" callback if FALSE is provided as first parameter but file_list is configured in settings', function(done) {

@@ -520,3 +529,3 @@ clamscan.settings.file_list = good_file_list;

});
it('should NOT return error to the "err" parameter of the "end_cb" callback if NaN is provided as first parameter but file_list is configured in settings', function(done) {

@@ -533,3 +542,3 @@ clamscan.settings.file_list = good_file_list;

});
it('should NOT return error to the "err" parameter of the "end_cb" callback if NULL is provided as first parameter but file_list is configured in settings', function(done) {

@@ -546,3 +555,3 @@ clamscan.settings.file_list = good_file_list;

});
it('should NOT return error to the "err" parameter of the "end_cb" callback if an empty string is provided as first parameter but file_list is configured in settings', function(done) {

@@ -563,3 +572,3 @@ clamscan.settings.file_list = good_file_list;

reset_clam();
it('should exist', function() {

@@ -571,3 +580,3 @@ should.exist(clamscan.scan_dir);

});
it('should require a string representing the directory to be scanned', function() {

@@ -591,3 +600,3 @@ expect(function() { clamscan.scan_dir(good_scan_dir); },'good string provided').to.not.throw(Error);

});
it('should require the second parameter to be a callback function (if truthy value provided)', function() {

@@ -609,3 +618,3 @@ expect(function() { clamscan.scan_dir(good_scan_dir); }, 'nothing provided').to.not.throw(Error);

});
it('should return error if directory not found', function(done) {

@@ -618,3 +627,3 @@ clamscan.scan_dir(__dirname + '/missing_dir', function(err, file, is_infected) {

});
it('should suppliy good_files array with scanned path when directory has no infected files', function(done) {

@@ -628,3 +637,3 @@ var scan_dir = good_scan_dir;

expect(good_files).to.include(scan_dir);
expect(bad_files).to.be.an('array');

@@ -635,11 +644,11 @@ expect(bad_files).to.be.empty;

});
it('should suppliy bad_files array with scanned path when directory has infected files', function(done) {
var scan_dir = __dirname + '/bad_scan_dir';
var scan_file = __dirname + '/bad_scan_dir/bad_file_1.txt';
request('https://secure.eicar.org/eicar_com.txt', function (error, response, body) {
if (!error && response.statusCode == 200) {
fs.writeFileSync(scan_file, body);
clamscan.scan_dir(scan_dir, function(err, good_files, bad_files) {

@@ -651,6 +660,6 @@ check(done, function() {

expect(bad_files).to.include(scan_dir);
expect(good_files).to.be.an('array');
expect(good_files).to.be.empty;
/* if (fs.existsSync(scan_file)) {

@@ -657,0 +666,0 @@ fs.unlinkSync(scan_file);

@@ -0,1 +1,28 @@

var fs = require('fs');
var p = require('path');
// walk $PATH to find bin
var which = function (bin) {
var dir, file;
var path = process.env.PATH.split(p.delimiter);
for (i in path) {
file = path[i] + p.sep + bin;
if (fs.existsSync(file)) {
return file;
}
}
return '';
};
// return either $CLAMD_PATH or something like /usr/local/etc/clamav/clamd.conf
var findClamdConf = function () {
if (process.env.CLAMD_PATH) {
return process.env.CLAMD_PATH;
}
var clamdscan = which('clamdscan');
clamdscan = clamdscan.split(p.sep);
clamdscan.splice(-2, 2);
return clamdscan.join(p.sep) + p.sep + 'etc/clamav/clamd.conf';
};
module.exports = {

@@ -6,9 +33,9 @@ remove_infected: false, // don't change

clamscan: {
path: '/usr/bin/clamscan', // required for testing (change for your system)
path: which('clamscan'), // required for testing
},
clamdscan: {
path: '/usr/bin/clamdscan', // required for testing (change for your system)
config_file: '/etc/clamd.d/daemon.conf' // required for testing (change for your system)
path: which('clamdscan'), // required for testing
config_file: findClamdConf() || '/etc/clamd.d/daemon.conf' // required for testing
},
debug_mode: false
};
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc