Skip to content

Commit

Permalink
Added basic support for tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
diosney committed Sep 26, 2014
1 parent 25e5cd2 commit 12f5dbe
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 13 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test:
NODE_ENV=test ./node_modules/mocha/bin/mocha --recursive --timeout 5000 --reporter spec

.PHONY: test
30 changes: 17 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name" : "netfilter",
"version" : "0.2.3",
"description" : "Packet filtering framework. Wrapper to provide netfilter capabilities from Node.js",
"main" : "index.js",
"keywords" : [
"name" : "netfilter",
"version" : "0.2.3",
"description" : "Packet filtering framework. Wrapper to provide netfilter capabilities from Node.js",
"main" : "index.js",
"keywords" : [
"stateless",
"stateful",
"packet",
Expand All @@ -27,28 +27,32 @@
"alias",
"set"
],
"dependencies": {
"dependencies" : {
"async" : "~0.9.0",
"process-queue": "^1.0.1",
"shell-quote" : "^1.4.2"
},
"engines" : {
"devDependencies": {
"should" : "~4.0.4",
"mocha" : "~1.20.1"
},
"engines" : {
"node": ">=0.8.0"
},
"homepage" : "https://github.com/diosney/node-netfilter",
"bugs" : {
"homepage" : "https://github.com/diosney/node-netfilter",
"bugs" : {
"url": "https://github.com/diosney/node-netfilter/issues"
},
"author" : {
"author" : {
"name" : "Diosney Sarmiento",
"email": "[email protected]"
},
"license" : "MIT",
"repository" : {
"license" : "MIT",
"repository" : {
"type": "git",
"url" : "https://github.com/diosney/node-netfilter.git"
},
"scripts" : {
"scripts" : {
"test": "node test/*.js"
}
}
57 changes: 57 additions & 0 deletions test/unit/iptables/fixtures/utils.processCommonRuleSpecs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
module.exports = [
{
options: {
protocol : 'tcp',
source : '!10.10.10.0/24',
destination : '11.11.11.0/24',
'in-interface' : 'eth0',
'out-interface': 'eth1',

matches: {
cluster: {
'cluster-total-nodes': 2,
'cluster-local-node' : 1,
'cluster-hash-seed' : '0xdeadbeef'
},
comment: {
comment: 'Some comment.'
}
},

jump : 'AUDIT',
target_options: {
type: 'drop'
}
},

args: [
'--protocol',
'tcp',
'!',
'--source',
'10.10.10.0/24',
'--destination',
'11.11.11.0/24',
'--in-interface',
'eth0',
'--out-interface',
'eth1',
'--match',
'cluster',
'--cluster-total-nodes',
'2',
'--cluster-local-node',
'1',
'--cluster-hash-seed',
'0xdeadbeef',
'--match',
'comment',
'--comment',
'Some comment.',
'--jump',
'AUDIT',
'--type',
'drop'
]
}
];
47 changes: 47 additions & 0 deletions test/unit/iptables/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
var should = require('should');

var utils = require('../../../lib/iptables/utils');
var fixtures = require('./fixtures/utils.processCommonRuleSpecs');

describe('iptables', function () {
describe('#utils', function () {
it('should be defined', function () {
should.exist(utils);
});

describe('#tables{}', function () {
it('should be defined', function () {
should.exist(utils.tables);
});

it('should have its already known properties', function () {
utils.tables.should.have.properties(
{
filter : 'filter',
nat : 'nat',
mangle : 'mangle',
raw : 'raw',
security: 'security'
});
});
});

describe('#processCommonRuleSpecs()', function () {
it('should be defined', function () {
should.exist(utils.processCommonRuleSpecs);
});

describe('when seed with several options', function () {
it('should return a correct array representation of those options', function () {
for (var i = 0, j = fixtures.length;
i < j;
i++) {

var common_rule_specs = utils.processCommonRuleSpecs(fixtures[i].options);
common_rule_specs.should.be.eql(fixtures[i].args);
}
});
});
});
});
});

0 comments on commit 12f5dbe

Please sign in to comment.