Skip to content

Commit

Permalink
BUG: not updating unmonitored list in redis
Browse files Browse the repository at this point in the history
  • Loading branch information
MelvinTo committed Jul 8, 2017
1 parent 3c18a41 commit 7d7c478
Show file tree
Hide file tree
Showing 54 changed files with 431 additions and 188 deletions.
462 changes: 277 additions & 185 deletions .idea/workspace.xml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ dist: xenial

install:
- sudo scripts/install.sh
- npm install -g mocha

script:
- cd test; node test_test.js
- mocha

notifications:
slack:
Expand Down
10 changes: 8 additions & 2 deletions net2/Spoofer.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,17 @@ Promise.promisifyAll(redis.Multi.prototype);
module.exports = class {

newSpoof(address) {
return rclient.saddAsync(monitoredKey, address);
return Promise.all([
rclient.saddAsync(monitoredKey, address),
rclient.sremAsync(unmonitoredKey, address),
]);
}

newUnspoof(address) {
return rclient.sremAsync(monitoredKey, address);
return Promise.all([
rclient.sremAsync(monitoredKey, address),
rclient.saddAsync(unmonitoredKey, address)
]);
}

spoof(ipAddr, tellIpAddr, mac, ip6Addrs, gateway6, callback) {
Expand Down
65 changes: 65 additions & 0 deletions test/sample_host.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* Copyright 2016 Firewalla LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
'use strict';

let HostTool = require('../net2/HostTool')
let hostTool = new HostTool();



let Promise = require('bluebird');

function createSampleHost() {
let addHost = hostTool.updateHost({
ipv4Addr: "172.17.0.10",
mac: "F4:0F:24:00:00:01",
uid: "172.17.0.10",
lastActiveTimestamp: new Date() / 1000 + "",
firstFoundTimestamp: new Date() / 1000 + "",
hostname: "Test Device 1",
hostnameType: "PTR",
macVendor: "Apple"
});

let addMac = hostTool.updateMACKey({
bname: "Test Device 1",
host: "Test Device 1",
uid: "172.17.0.10",
lastActiveTimestamp: new Date() / 1000 + "",
firstFoundTimestamp: new Date() / 1000 + "",
pname: "UnknownMobile/iOS",
mac: "F4:0F:24:00:00:01",
_name: "iPhone",
ipv4Addr: "172.17.0.10",
macVendor: "Apple",
deviceClass: "mobile",
ua_os_name: "iOS",
ipv4: "172.17.0.10",
});

return Promise.all([addHost, addMac])
}

function removeSampleHost() {
let removeHost = hostTool.deleteHost("172.17.0.10")
let removeMac = hostTool.deleteMac("F4:0F:24:00:00:01")

return Promise.all([removeHost, removeMac])
}

module.exports = {
createSampleHost: createSampleHost,
removeSampleHost: removeSampleHost
}
79 changes: 79 additions & 0 deletions test/test_host_control.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/* Copyright 2016 Firewalla LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
'use strict'

let chai = require('chai');
let should = chai.should();

let sample = require('./sample_host');

let Spoof = require('../net2/Spoofer');
let spoof = new Spoof("eth0", true, true);

let redis = require('redis');
let rclient = redis.createClient();

let Promise = require('bluebird');
Promise.promisifyAll(redis.RedisClient.prototype);
Promise.promisifyAll(redis.Multi.prototype);

describe('Test control features on host', () => {

beforeEach((done) => {
sample.createSampleHost()
.then(() => done())
});

afterEach((done) => {
sample.removeSampleHost()
.then(() => done())
})

it('should block host to access internet when "internet off" is tapped');

it('should exclude host from montioring when "monitor off" is tapped');

it('should update redis database when spoof', (done) => {
spoof.newSpoof("172.17.0.10")
.then(() => {
rclient.sismemberAsync("monitored_hosts", "172.17.0.10")
.then((result) => {
result.should.equal(1)

rclient.sismemberAsync("unmonitored_hosts", "172.17.0.10")
.then((result) => {
result.should.equal(0)
})
})
});
done();
});

it('should update redis database when unspoof', (done) => {
spoof.newUnspoof("172.17.0.10")
.then(() => {
rclient.sismemberAsync("monitored_hosts", "172.17.0.10")
.then((result) => {
result.should.equal(0)

rclient.sismemberAsync("unmonitored_hosts", "172.17.0.10")
.then((result) => {
result.should.equal(1)
})
})
});
done();
})
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 7d7c478

Please sign in to comment.