forked from firewalla/firewalla
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BUG: not updating unmonitored list in redis
- Loading branch information
Showing
54 changed files
with
431 additions
and
188 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.