2007-07-25 23:39:22 -07:00
|
|
|
var checkUrls = [];
|
|
|
|
var checkExpect;
|
|
|
|
|
|
|
|
var chunk1Urls = [
|
|
|
|
"test.com/aba",
|
|
|
|
"test.com/foo/bar",
|
|
|
|
"foo.bar.com/a/b/c"
|
|
|
|
];
|
|
|
|
var chunk1 = chunk1Urls.join("\n");
|
|
|
|
|
|
|
|
var chunk2Urls = [
|
|
|
|
"blah.com/a",
|
|
|
|
"baz.com/",
|
2007-10-01 16:53:53 -07:00
|
|
|
"255.255.0.1/",
|
|
|
|
"www.foo.com/test2?param=1"
|
2007-07-25 23:39:22 -07:00
|
|
|
];
|
|
|
|
var chunk2 = chunk2Urls.join("\n");
|
|
|
|
|
|
|
|
var chunk3Urls = [
|
|
|
|
"test.com/a",
|
|
|
|
"foo.bar.com/a",
|
|
|
|
"blah.com/a",
|
|
|
|
];
|
|
|
|
var chunk3 = chunk3Urls.join("\n");
|
|
|
|
|
2008-01-29 12:57:18 -08:00
|
|
|
var chunk3SubUrls = [
|
|
|
|
"1:test.com/a",
|
|
|
|
"1:foo.bar.com/a",
|
|
|
|
"2:blah.com/a" ];
|
|
|
|
var chunk3Sub = chunk3SubUrls.join("\n");
|
|
|
|
|
2007-12-04 16:16:41 -08:00
|
|
|
var chunk4Urls = [
|
|
|
|
"a.com/b",
|
|
|
|
"b.com/c",
|
|
|
|
];
|
|
|
|
var chunk4 = chunk3Urls.join("\n");
|
|
|
|
|
|
|
|
var chunk5Urls = [
|
|
|
|
"d.com/e",
|
|
|
|
"f.com/g",
|
|
|
|
];
|
|
|
|
var chunk5 = chunk3Urls.join("\n");
|
|
|
|
|
|
|
|
var chunk6Urls = [
|
|
|
|
"h.com/i",
|
|
|
|
"j.com/k",
|
|
|
|
];
|
|
|
|
var chunk6 = chunk3Urls.join("\n");
|
|
|
|
|
|
|
|
// we are going to add chunks 1, 2, 4, 5, and 6 to phish-simple, and
|
|
|
|
// chunk 2 to malware-simple. Then we'll remove the urls in chunk3
|
|
|
|
// from phish-simple, then expire chunk 1 and chunks 4-5 from
|
|
|
|
// phish-simple.
|
2007-07-25 23:39:22 -07:00
|
|
|
var phishExpected = {};
|
|
|
|
var phishUnexpected = {};
|
|
|
|
var malwareExpected = {};
|
|
|
|
for (var i = 0; i < chunk2Urls.length; i++) {
|
|
|
|
phishExpected[chunk2Urls[i]] = true;
|
|
|
|
malwareExpected[chunk2Urls[i]] = true;
|
|
|
|
}
|
|
|
|
for (var i = 0; i < chunk3Urls.length; i++) {
|
|
|
|
delete phishExpected[chunk3Urls[i]];
|
|
|
|
phishUnexpected[chunk3Urls[i]] = true;
|
|
|
|
}
|
|
|
|
for (var i = 0; i < chunk1Urls.length; i++) {
|
|
|
|
// chunk1 urls are expired
|
|
|
|
phishUnexpected[chunk1Urls[i]] = true;
|
|
|
|
}
|
2007-12-04 16:16:41 -08:00
|
|
|
for (var i = 0; i < chunk4Urls.length; i++) {
|
|
|
|
// chunk4 urls are expired
|
|
|
|
phishUnexpected[chunk4Urls[i]] = true;
|
|
|
|
}
|
|
|
|
for (var i = 0; i < chunk5Urls.length; i++) {
|
|
|
|
// chunk5 urls are expired
|
|
|
|
phishUnexpected[chunk5Urls[i]] = true;
|
|
|
|
}
|
|
|
|
for (var i = 0; i < chunk6Urls.length; i++) {
|
|
|
|
// chunk6 urls are expired
|
|
|
|
phishUnexpected[chunk6Urls[i]] = true;
|
|
|
|
}
|
2007-07-25 23:39:22 -07:00
|
|
|
|
2007-11-05 11:31:55 -08:00
|
|
|
// Check that the entries hit based on sub-parts
|
|
|
|
phishExpected["baz.com/foo/bar"] = true;
|
|
|
|
phishExpected["foo.bar.baz.com/foo"] = true;
|
|
|
|
phishExpected["bar.baz.com/"] = true;
|
|
|
|
|
2007-07-25 23:39:22 -07:00
|
|
|
var numExpecting;
|
|
|
|
|
|
|
|
function testFailure(arg) {
|
|
|
|
do_throw(arg);
|
|
|
|
}
|
|
|
|
|
2007-11-27 12:08:02 -08:00
|
|
|
function checkNoHost()
|
|
|
|
{
|
|
|
|
// Looking up a no-host uri such as a data: uri should throw an exception.
|
|
|
|
var exception;
|
|
|
|
try {
|
|
|
|
dbservice.lookup("data:text/html,<b>test</b>");
|
|
|
|
|
|
|
|
exception = false;
|
|
|
|
} catch(e) {
|
|
|
|
exception = true;
|
|
|
|
}
|
|
|
|
do_check_true(exception);
|
|
|
|
|
|
|
|
do_test_finished();
|
|
|
|
}
|
|
|
|
|
2007-12-04 16:16:41 -08:00
|
|
|
function tablesCallbackWithoutSub(tables)
|
2007-07-25 23:39:22 -07:00
|
|
|
{
|
|
|
|
var parts = tables.split("\n");
|
|
|
|
parts.sort();
|
2007-12-04 16:16:41 -08:00
|
|
|
|
2007-07-25 23:39:22 -07:00
|
|
|
// there's a leading \n here because splitting left an empty string
|
|
|
|
// after the trailing newline, which will sort first
|
|
|
|
do_check_eq(parts.join("\n"),
|
2007-12-04 16:16:41 -08:00
|
|
|
"\ntesting-malware-simple;a:1\ntesting-phish-simple;a:2");
|
2007-11-27 12:08:02 -08:00
|
|
|
|
|
|
|
checkNoHost();
|
2007-07-25 23:39:22 -07:00
|
|
|
}
|
|
|
|
|
2007-12-04 16:16:41 -08:00
|
|
|
|
|
|
|
function expireSubSuccess(result) {
|
|
|
|
dbservice.getTables(tablesCallbackWithoutSub);
|
|
|
|
}
|
|
|
|
|
|
|
|
function tablesCallbackWithSub(tables)
|
2007-07-25 23:39:22 -07:00
|
|
|
{
|
2007-12-04 16:16:41 -08:00
|
|
|
var parts = tables.split("\n");
|
|
|
|
parts.sort();
|
|
|
|
|
|
|
|
// there's a leading \n here because splitting left an empty string
|
|
|
|
// after the trailing newline, which will sort first
|
|
|
|
do_check_eq(parts.join("\n"),
|
|
|
|
"\ntesting-malware-simple;a:1\ntesting-phish-simple;a:2:s:3");
|
|
|
|
|
|
|
|
// verify that expiring a sub chunk removes its name from the list
|
|
|
|
var data =
|
|
|
|
"n:1000\n" +
|
|
|
|
"i:testing-phish-simple\n" +
|
|
|
|
"sd:3\n";
|
|
|
|
|
2008-01-12 14:22:03 -08:00
|
|
|
doSimpleUpdate(data, expireSubSuccess, testFailure);
|
2007-12-04 16:16:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
function checkChunksWithSub()
|
|
|
|
{
|
|
|
|
dbservice.getTables(tablesCallbackWithSub);
|
2007-07-25 23:39:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function checkDone() {
|
|
|
|
if (--numExpecting == 0)
|
2007-12-04 16:16:41 -08:00
|
|
|
checkChunksWithSub();
|
2007-07-25 23:39:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function phishExists(result) {
|
|
|
|
dumpn("phishExists: " + result);
|
|
|
|
try {
|
|
|
|
do_check_true(result.indexOf("testing-phish-simple") != -1);
|
|
|
|
} finally {
|
|
|
|
checkDone();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function phishDoesntExist(result) {
|
|
|
|
dumpn("phishDoesntExist: " + result);
|
|
|
|
try {
|
|
|
|
do_check_true(result.indexOf("testing-phish-simple") == -1);
|
|
|
|
} finally {
|
|
|
|
checkDone();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function malwareExists(result) {
|
|
|
|
dumpn("malwareExists: " + result);
|
|
|
|
|
|
|
|
try {
|
|
|
|
do_check_true(result.indexOf("testing-malware-simple") != -1);
|
|
|
|
} finally {
|
|
|
|
checkDone();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkState()
|
|
|
|
{
|
|
|
|
numExpecting = 0;
|
|
|
|
for (var key in phishExpected) {
|
|
|
|
dbservice.lookup("http://" + key, phishExists, true);
|
|
|
|
numExpecting++;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var key in phishUnexpected) {
|
|
|
|
dbservice.lookup("http://" + key, phishDoesntExist, true);
|
|
|
|
numExpecting++;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var key in malwareExpected) {
|
|
|
|
dbservice.lookup("http://" + key, malwareExists, true);
|
|
|
|
numExpecting++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function testSubSuccess(result)
|
|
|
|
{
|
|
|
|
do_check_eq(result, "1000");
|
|
|
|
checkState();
|
|
|
|
}
|
|
|
|
|
|
|
|
function do_subs() {
|
|
|
|
var data =
|
|
|
|
"n:1000\n" +
|
|
|
|
"i:testing-phish-simple\n" +
|
2008-01-29 12:57:18 -08:00
|
|
|
"s:3:32:" + chunk3Sub.length + "\n" +
|
|
|
|
chunk3Sub + "\n" +
|
2007-12-04 16:16:41 -08:00
|
|
|
"ad:1\n" +
|
|
|
|
"ad:4-6\n";
|
2007-07-25 23:39:22 -07:00
|
|
|
|
2008-01-12 14:22:03 -08:00
|
|
|
doSimpleUpdate(data, testSubSuccess, testFailure);
|
2007-07-25 23:39:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function testAddSuccess(arg) {
|
|
|
|
do_check_eq(arg, "1000");
|
|
|
|
|
|
|
|
do_subs();
|
|
|
|
}
|
|
|
|
|
|
|
|
function do_adds() {
|
|
|
|
// This test relies on the fact that only -regexp tables are ungzipped,
|
|
|
|
// and only -hash tables are assumed to be pre-md5'd. So we use
|
|
|
|
// a 'simple' table type to get simple hostname-per-line semantics.
|
|
|
|
|
|
|
|
var data =
|
|
|
|
"n:1000\n" +
|
|
|
|
"i:testing-phish-simple\n" +
|
2008-01-29 12:57:18 -08:00
|
|
|
"a:1:32:" + chunk1.length + "\n" +
|
2007-07-25 23:39:22 -07:00
|
|
|
chunk1 + "\n" +
|
2008-01-29 12:57:18 -08:00
|
|
|
"a:2:32:" + chunk2.length + "\n" +
|
2007-07-25 23:39:22 -07:00
|
|
|
chunk2 + "\n" +
|
2008-01-29 12:57:18 -08:00
|
|
|
"a:4:32:" + chunk4.length + "\n" +
|
2007-12-04 16:16:41 -08:00
|
|
|
chunk4 + "\n" +
|
2008-01-29 12:57:18 -08:00
|
|
|
"a:5:32:" + chunk5.length + "\n" +
|
2007-12-04 16:16:41 -08:00
|
|
|
chunk5 + "\n" +
|
2008-01-29 12:57:18 -08:00
|
|
|
"a:6:32:" + chunk6.length + "\n" +
|
2007-12-04 16:16:41 -08:00
|
|
|
chunk6 + "\n" +
|
2007-07-25 23:39:22 -07:00
|
|
|
"i:testing-malware-simple\n" +
|
2008-01-29 12:57:18 -08:00
|
|
|
"a:1:32:" + chunk2.length + "\n" +
|
2007-12-04 16:16:41 -08:00
|
|
|
chunk2 + "\n";
|
|
|
|
|
2008-01-12 14:22:03 -08:00
|
|
|
doSimpleUpdate(data, testAddSuccess, testFailure);
|
2007-07-25 23:39:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function run_test() {
|
|
|
|
do_adds();
|
|
|
|
do_test_pending();
|
|
|
|
}
|