Bug 985623: Force url classifier clients to specify which tables to lookup, add a pref to skip hash completion checks (r=gcp)

This commit is contained in:
Monica Chew 2014-03-20 14:25:35 -07:00
parent a9f77f87f7
commit 9b092b1051
16 changed files with 163 additions and 70 deletions

View File

@ -1,3 +1,5 @@
// Force SafeBrowsing to be initialized for the tests
Services.prefs.setCharPref("urlclassifier.malware_table", "test-malware-simple");
Services.prefs.setCharPref("urlclassifier.phish_table", "test-phish-simple");
SafeBrowsing.init();

View File

@ -4388,10 +4388,11 @@ pref("dom.voicemail.defaultServiceId", 0);
pref("dom.inter-app-communication-api.enabled", false);
// The tables used for Safebrowsing phishing and malware checks.
pref("urlclassifier.malware_table", "goog-malware-shavar");
pref("urlclassifier.phish_table", "goog-phish-shavar");
pref("urlclassifier.malware_table", "goog-malware-shavar,test-malware-simple");
pref("urlclassifier.phish_table", "goog-phish-shavar,test-phish-simple");
pref("urlclassifier.download_block_table", "");
pref("urlclassifier.download_allow_table", "");
pref("urlclassifier.disallow_completions", "test-malware-simple,test-phish-simple,goog-downloadwhite-digest256");
// Turn off Spatial navigation by default.
pref("snav.enabled", false);

View File

@ -273,7 +273,19 @@ PendingDBLookup::LookupSpecInternal(const nsACString& aSpec)
LOG(("Checking DB service for principal %s [this = %p]", mSpec.get(), this));
nsCOMPtr<nsIUrlClassifierDBService> dbService =
do_GetService(NS_URLCLASSIFIERDBSERVICE_CONTRACTID, &rv);
return dbService->Lookup(principal, this);
nsAutoCString tables;
nsAutoCString allowlist;
Preferences::GetCString(PREF_DOWNLOAD_ALLOW_TABLE, &allowlist);
if (!allowlist.IsEmpty()) {
tables.Append(allowlist);
}
nsAutoCString blocklist;
Preferences::GetCString(PREF_DOWNLOAD_BLOCK_TABLE, &blocklist);
if (!mAllowlistOnly && !blocklist.IsEmpty()) {
tables.Append(",");
tables.Append(blocklist);
}
return dbService->Lookup(principal, tables, this);
}
NS_IMETHODIMP

View File

@ -32,6 +32,28 @@ extern PRLogModuleInfo *gUrlClassifierDbServiceLog;
namespace mozilla {
namespace safebrowsing {
void
Classifier::SplitTables(const nsACString& str, nsTArray<nsCString>& tables)
{
tables.Clear();
nsACString::const_iterator begin, iter, end;
str.BeginReading(begin);
str.EndReading(end);
while (begin != end) {
iter = begin;
FindCharInReadable(',', iter, end);
nsDependentCSubstring table = Substring(begin,iter);
if (!table.IsEmpty()) {
tables.AppendElement(Substring(begin, iter));
}
begin = iter;
if (begin != end) {
begin++;
}
}
}
Classifier::Classifier()
: mFreshTime(45 * 60)
{
@ -195,7 +217,9 @@ Classifier::TableRequest(nsACString& aResult)
}
nsresult
Classifier::Check(const nsACString& aSpec, LookupResultArray& aResults)
Classifier::Check(const nsACString& aSpec,
const nsACString& aTables,
LookupResultArray& aResults)
{
Telemetry::AutoTimer<Telemetry::URLCLASSIFIER_CL_CHECK_TIME> timer;
@ -207,10 +231,11 @@ Classifier::Check(const nsACString& aSpec, LookupResultArray& aResults)
NS_ENSURE_SUCCESS(rv, rv);
nsTArray<nsCString> activeTables;
ActiveTables(activeTables);
SplitTables(aTables, activeTables);
nsTArray<LookupCache*> cacheArray;
for (uint32_t i = 0; i < activeTables.Length(); i++) {
LOG(("Checking table %s", activeTables[i].get()));
LookupCache *cache = GetLookupCache(activeTables[i]);
if (cache) {
cacheArray.AppendElement(cache);

View File

@ -43,9 +43,11 @@ public:
nsresult ActiveTables(nsTArray<nsCString>& aTables);
/**
* Check a URL against the database.
* Check a URL against the specified tables.
*/
nsresult Check(const nsACString& aSpec, LookupResultArray& aResults);
nsresult Check(const nsACString& aSpec,
const nsACString& tables,
LookupResultArray& aResults);
/**
* Apply the table updates in the array. Takes ownership of
@ -68,6 +70,8 @@ public:
const nsACString& aTableName,
uint32_t aCount,
PrefixArray* aNoiseEntries);
static void SplitTables(const nsACString& str, nsTArray<nsCString>& tables);
private:
void DropStores();
nsresult CreateStoreDirectory();

View File

@ -66,17 +66,18 @@ interface nsIUrlClassifierUpdateObserver : nsISupports {
* It provides async methods for querying and updating the database. As the
* methods complete, they call the callback function.
*/
[scriptable, uuid(8a389f21-f821-4e29-9c6b-3de6f33cd7cf)]
[scriptable, uuid(3f9e61e5-01bd-45d0-8dd2-f1abcd20dbb7)]
interface nsIUrlClassifierDBService : nsISupports
{
/**
* Looks up a URI in the database.
* Looks up a URI in the specified tables.
*
* @param principal: The principal containing the URI to search.
* @param c: The callback will be called with a comma-separated list
* of tables to which the key belongs.
*/
void lookup(in nsIPrincipal principal,
in ACString tables,
in nsIUrlClassifierCallback c);
/**
@ -184,7 +185,7 @@ interface nsIUrlClassifierDBService : nsISupports
* Interface for the actual worker thread. Implementations of this need not
* be thread aware and just work on the database.
*/
[scriptable, uuid(0445be75-b114-43ea-89dc-aa16af26e77e)]
[scriptable, uuid(abcd7978-c304-4a7d-a44c-33c2ed5441e7)]
interface nsIUrlClassifierDBServiceWorker : nsIUrlClassifierDBService
{
// Provide a way to forcibly close the db connection.

View File

@ -73,6 +73,7 @@ PRLogModuleInfo *gUrlClassifierDbServiceLog = nullptr;
#define PHISH_TABLE_PREF "urlclassifier.phish_table"
#define DOWNLOAD_BLOCK_TABLE_PREF "urlclassifier.download_block_table"
#define DOWNLOAD_ALLOW_TABLE_PREF "urlclassifier.download_allow_table"
#define DISALLOW_COMPLETION_TABLE_PREF "urlclassifier.disallow_completions"
#define CONFIRM_AGE_PREF "urlclassifier.max-complete-age"
#define CONFIRM_AGE_DEFAULT_SEC (45 * 60)
@ -90,24 +91,6 @@ static bool gShuttingDownThread = false;
static mozilla::Atomic<int32_t> gFreshnessGuarantee(CONFIRM_AGE_DEFAULT_SEC);
static void
SplitTables(const nsACString& str, nsTArray<nsCString>& tables)
{
tables.Clear();
nsACString::const_iterator begin, iter, end;
str.BeginReading(begin);
str.EndReading(end);
while (begin != end) {
iter = begin;
FindCharInReadable(',', iter, end);
tables.AppendElement(Substring(begin, iter));
begin = iter;
if (begin != end)
begin++;
}
}
// -------------------------------------------------------------------------
// Actual worker implemenatation
class nsUrlClassifierDBServiceWorker MOZ_FINAL :
@ -123,7 +106,9 @@ public:
nsresult Init(uint32_t aGethashNoise, nsCOMPtr<nsIFile> aCacheDir);
// Queue a lookup for the worker to perform, called in the main thread.
// tables is a comma-separated list of tables to query
nsresult QueueLookup(const nsACString& lookupKey,
const nsACString& tables,
nsIUrlClassifierLookupCallback* callback);
// Handle any queued-up lookups. We call this function during long-running
@ -149,7 +134,9 @@ private:
void ResetUpdate();
// Perform a classifier lookup for a given url.
nsresult DoLookup(const nsACString& spec, nsIUrlClassifierLookupCallback* c);
nsresult DoLookup(const nsACString& spec,
const nsACString& tables,
nsIUrlClassifierLookupCallback* c);
nsresult AddNoise(const Prefix aPrefix,
const nsCString tableName,
@ -192,6 +179,7 @@ private:
public:
TimeStamp mStartTime;
nsCString mKey;
nsCString mTables;
nsCOMPtr<nsIUrlClassifierLookupCallback> mCallback;
};
@ -231,6 +219,7 @@ nsUrlClassifierDBServiceWorker::Init(uint32_t aGethashNoise,
nsresult
nsUrlClassifierDBServiceWorker::QueueLookup(const nsACString& spec,
const nsACString& tables,
nsIUrlClassifierLookupCallback* callback)
{
MutexAutoLock lock(mPendingLookupLock);
@ -241,6 +230,7 @@ nsUrlClassifierDBServiceWorker::QueueLookup(const nsACString& spec,
lookup->mStartTime = TimeStamp::Now();
lookup->mKey = spec;
lookup->mCallback = callback;
lookup->mTables = tables;
return NS_OK;
}
@ -258,6 +248,7 @@ nsUrlClassifierDBServiceWorker::QueueLookup(const nsACString& spec,
*/
nsresult
nsUrlClassifierDBServiceWorker::DoLookup(const nsACString& spec,
const nsACString& tables,
nsIUrlClassifierLookupCallback* c)
{
if (gShuttingDownThread) {
@ -288,7 +279,7 @@ nsUrlClassifierDBServiceWorker::DoLookup(const nsACString& spec,
// we ignore failures from Check because we'd rather return the
// results that were found than fail.
mClassifier->SetFreshTime(gFreshnessGuarantee);
mClassifier->Check(spec, *results);
mClassifier->Check(spec, tables, *results);
LOG(("Found %d results.", results->Length()));
@ -336,7 +327,7 @@ nsUrlClassifierDBServiceWorker::HandlePendingLookups()
mPendingLookups.RemoveElementAt(0);
{
MutexAutoUnlock unlock(mPendingLookupLock);
DoLookup(lookup.mKey, lookup.mCallback);
DoLookup(lookup.mKey, lookup.mTables, lookup.mCallback);
}
double lookupTime = (TimeStamp::Now() - lookup.mStartTime).ToMilliseconds();
Telemetry::Accumulate(Telemetry::URLCLASSIFIER_LOOKUP_TIME,
@ -378,6 +369,7 @@ nsUrlClassifierDBServiceWorker::AddNoise(const Prefix aPrefix,
// Lookup a key in the db.
NS_IMETHODIMP
nsUrlClassifierDBServiceWorker::Lookup(nsIPrincipal* aPrincipal,
const nsACString& aTables,
nsIUrlClassifierCallback* c)
{
return HandlePendingLookups();
@ -447,7 +439,7 @@ nsUrlClassifierDBServiceWorker::BeginUpdate(nsIUrlClassifierUpdateObserver *obse
mUpdateStatus = NS_OK;
mUpdateObserver = observer;
SplitTables(tables, mUpdateTables);
Classifier::SplitTables(tables, mUpdateTables);
return NS_OK;
}
@ -1101,6 +1093,9 @@ nsUrlClassifierDBService::Init()
DOWNLOAD_BLOCK_TABLE_PREF));
mGethashTables.AppendElement(Preferences::GetCString(
DOWNLOAD_ALLOW_TABLE_PREF));
nsCString tables;
Preferences::GetCString(DISALLOW_COMPLETION_TABLE_PREF, &tables);
Classifier::SplitTables(tables, mDisallowCompletionsTables);
// Do we *really* need to be able to change all of these at runtime?
Preferences::AddStrongObserver(this, CHECK_MALWARE_PREF);
@ -1111,6 +1106,7 @@ nsUrlClassifierDBService::Init()
Preferences::AddStrongObserver(this, MALWARE_TABLE_PREF);
Preferences::AddStrongObserver(this, DOWNLOAD_BLOCK_TABLE_PREF);
Preferences::AddStrongObserver(this, DOWNLOAD_ALLOW_TABLE_PREF);
Preferences::AddStrongObserver(this, DISALLOW_COMPLETION_TABLE_PREF);
// Force PSM loading on main thread
nsresult rv;
@ -1156,6 +1152,7 @@ nsUrlClassifierDBService::Init()
return NS_OK;
}
// nsChannelClassifier is the only consumer of this interface.
NS_IMETHODIMP
nsUrlClassifierDBService::Classify(nsIPrincipal* aPrincipal,
nsIURIClassifierCallback* c,
@ -1173,7 +1170,19 @@ nsUrlClassifierDBService::Classify(nsIPrincipal* aPrincipal,
new nsUrlClassifierClassifyCallback(c, mCheckMalware, mCheckPhishing);
if (!callback) return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = LookupURI(aPrincipal, callback, false, result);
nsAutoCString tables;
nsAutoCString malware;
Preferences::GetCString(MALWARE_TABLE_PREF, &malware);
if (!malware.IsEmpty()) {
tables.Append(malware);
}
nsAutoCString phishing;
Preferences::GetCString(PHISH_TABLE_PREF, &phishing);
if (!phishing.IsEmpty()) {
tables.Append(",");
tables.Append(phishing);
}
nsresult rv = LookupURI(aPrincipal, tables, callback, false, result);
if (rv == NS_ERROR_MALFORMED_URI) {
*result = false;
// The URI had no hostname, don't try to classify it.
@ -1186,16 +1195,18 @@ nsUrlClassifierDBService::Classify(nsIPrincipal* aPrincipal,
NS_IMETHODIMP
nsUrlClassifierDBService::Lookup(nsIPrincipal* aPrincipal,
const nsACString& tables,
nsIUrlClassifierCallback* c)
{
NS_ENSURE_TRUE(gDbBackgroundThread, NS_ERROR_NOT_INITIALIZED);
bool dummy;
return LookupURI(aPrincipal, c, true, &dummy);
return LookupURI(aPrincipal, tables, c, true, &dummy);
}
nsresult
nsUrlClassifierDBService::LookupURI(nsIPrincipal* aPrincipal,
const nsACString& tables,
nsIUrlClassifierCallback* c,
bool forceLookup,
bool *didLookup)
@ -1262,11 +1273,12 @@ nsUrlClassifierDBService::LookupURI(nsIPrincipal* aPrincipal,
// Queue this lookup and call the lookup function to flush the queue if
// necessary.
rv = mWorker->QueueLookup(key, proxyCallback);
rv = mWorker->QueueLookup(key, tables, proxyCallback);
NS_ENSURE_SUCCESS(rv, rv);
// This seems to just call HandlePendingLookups.
return mWorkerProxy->Lookup(nullptr, nullptr);
nsAutoCString dummy;
return mWorkerProxy->Lookup(nullptr, dummy, nullptr);
}
NS_IMETHODIMP
@ -1385,14 +1397,20 @@ bool
nsUrlClassifierDBService::GetCompleter(const nsACString &tableName,
nsIUrlClassifierHashCompleter **completer)
{
// If we have specified a completer, go ahead and query it. This is only
// used by tests.
if (mCompleters.Get(tableName, completer)) {
return true;
}
if (!mGethashTables.Contains(tableName)) {
// If we don't know about this table at all, or are disallowing completions
// for it, skip completion checks.
if (!mGethashTables.Contains(tableName) ||
mDisallowCompletionsTables.Contains(tableName)) {
return false;
}
// Otherwise, call gethash to find the hash completions.
return NS_SUCCEEDED(CallGetService(NS_URLCLASSIFIERHASHCOMPLETER_CONTRACTID,
completer));
}
@ -1423,6 +1441,11 @@ nsUrlClassifierDBService::Observe(nsISupports *aSubject, const char *aTopic,
DOWNLOAD_BLOCK_TABLE_PREF));
mGethashTables.AppendElement(Preferences::GetCString(
DOWNLOAD_ALLOW_TABLE_PREF));
} else if (NS_LITERAL_STRING(DISALLOW_COMPLETION_TABLE_PREF).Equals(aData)) {
mDisallowCompletionsTables.Clear();
nsCString tables;
Preferences::GetCString(DISALLOW_COMPLETION_TABLE_PREF, &tables);
Classifier::SplitTables(tables, mDisallowCompletionsTables);
} else if (NS_LITERAL_STRING(CONFIRM_AGE_PREF).Equals(aData)) {
gFreshnessGuarantee = Preferences::GetInt(CONFIRM_AGE_PREF,
CONFIRM_AGE_DEFAULT_SEC);
@ -1456,6 +1479,7 @@ nsUrlClassifierDBService::Shutdown()
prefs->RemoveObserver(MALWARE_TABLE_PREF, this);
prefs->RemoveObserver(DOWNLOAD_BLOCK_TABLE_PREF, this);
prefs->RemoveObserver(DOWNLOAD_ALLOW_TABLE_PREF, this);
prefs->RemoveObserver(DISALLOW_COMPLETION_TABLE_PREF, this);
prefs->RemoveObserver(CONFIRM_AGE_PREF, this);
}

View File

@ -71,6 +71,7 @@ private:
nsUrlClassifierDBService(nsUrlClassifierDBService&);
nsresult LookupURI(nsIPrincipal* aPrincipal,
const nsACString& tables,
nsIUrlClassifierCallback* c,
bool forceCheck, bool *didCheck);
@ -103,6 +104,9 @@ private:
// The list of tables that can use the default hash completer object.
nsTArray<nsCString> mGethashTables;
// The list of tables that should never be hash completed.
nsTArray<nsCString> mDisallowCompletionsTables;
// Thread that we do the updates on.
static nsIThread* gDbBackgroundThread;
};

View File

@ -23,16 +23,18 @@ NS_IMPL_ISUPPORTS1(UrlClassifierDBServiceWorkerProxy,
NS_IMETHODIMP
UrlClassifierDBServiceWorkerProxy::Lookup(nsIPrincipal* aPrincipal,
const nsACString& aTables,
nsIUrlClassifierCallback* aCB)
{
nsCOMPtr<nsIRunnable> r = new LookupRunnable(mTarget, aPrincipal, aCB);
nsCOMPtr<nsIRunnable> r = new LookupRunnable(mTarget, aPrincipal, aTables,
aCB);
return DispatchToWorkerThread(r);
}
NS_IMETHODIMP
UrlClassifierDBServiceWorkerProxy::LookupRunnable::Run()
{
(void) mTarget->Lookup(mPrincipal, mCB);
(void) mTarget->Lookup(mPrincipal, mLookupTables, mCB);
return NS_OK;
}

View File

@ -34,9 +34,11 @@ public:
public:
LookupRunnable(nsIUrlClassifierDBServiceWorker* aTarget,
nsIPrincipal* aPrincipal,
const nsACString& aTables,
nsIUrlClassifierCallback* aCB)
: mTarget(aTarget)
, mPrincipal(aPrincipal)
, mLookupTables(aTables)
, mCB(aCB)
{ }
@ -45,6 +47,7 @@ public:
private:
nsCOMPtr<nsIUrlClassifierDBServiceWorker> mTarget;
nsCOMPtr<nsIPrincipal> mPrincipal;
nsCString mLookupTables;
nsCOMPtr<nsIUrlClassifierCallback> mCB;
};

View File

@ -6,7 +6,6 @@
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body onload="doUpdate(testUpdate);">
<p id="display"></p>
<div id="content" style="display: none">
</div>
@ -61,6 +60,11 @@ function doUpdate(update) {
dbService.finishUpdate();
}
SpecialPowers.pushPrefEnv(
{"set" : [["urlclassifier.malware_table", "test-malware-simple"],
["urlclassifier.phish_table", "test-phish-simple"]]},
function() { doUpdate(testUpdate); });
// Expected finish() call is in "classifierFrame.html".
SimpleTest.waitForExplicitFinish();

View File

@ -6,7 +6,6 @@
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body onload="doUpdate(testUpdate);">
<p id="display"></p>
<div id="content" style="display: none">
</div>
@ -73,6 +72,11 @@ function onmessage(event)
is(pieces[0], "success", pieces[1]);
}
SpecialPowers.pushPrefEnv(
{"set" : [["urlclassifier.malware_table", "test-malware-simple"],
["urlclassifier.phish_table", "test-phish-simple"]]},
function() { doUpdate(testUpdate); });
window.addEventListener("message", onmessage, false);
SimpleTest.waitForExplicitFinish();

View File

@ -19,11 +19,11 @@ var Ci = Components.interfaces;
var dbService = Cc["@mozilla.org/url-classifier/dbservice;1"]
.getService(Ci.nsIUrlClassifierDBService);
dbService.lookup(document.nodePrincipal, function(arg) {});
dbService.lookup(document.nodePrincipal, "", function(arg) {});
ok(true, "lookup() didn't crash");
</script>
</pre>
</body>
</html>
</html>

View File

@ -31,6 +31,9 @@ prefBranch.setIntPref("urlclassifier.gethashnoise", 0);
prefBranch.setBoolPref("browser.safebrowsing.malware.enabled", true);
prefBranch.setBoolPref("browser.safebrowsing.enabled", true);
// Enable all completions for tests
prefBranch.setCharPref("urlclassifier.disallow_completions", "");
function delFile(name) {
try {
// Delete a previously created sqlite file
@ -53,6 +56,8 @@ function cleanUp() {
delFile("safebrowsing/test-malware-simple.pset");
}
var allTables = "test-phish-simple,test-malware-simple";
var dbservice = Cc["@mozilla.org/url-classifier/dbservice;1"].getService(Ci.nsIUrlClassifierDBService);
var streamUpdater = Cc["@mozilla.org/url-classifier/streamupdater;1"]
.getService(Ci.nsIUrlClassifierStreamUpdater);
@ -200,11 +205,11 @@ checkUrls: function(urls, expected, cb)
if (urls.length > 0) {
var fragment = urls.shift();
var principal = secMan.getNoAppCodebasePrincipal(iosvc.newURI("http://" + fragment, null, null));
dbservice.lookup(principal,
function(arg) {
do_check_eq(expected, arg);
doLookup();
}, true);
dbservice.lookup(principal, allTables,
function(arg) {
do_check_eq(expected, arg);
doLookup();
}, true);
} else {
cb();
}

View File

@ -96,7 +96,7 @@ function checkNoHost()
var exception;
try {
var principal = secMan.getNoAppCodebasePrincipal(iosvc.newURI("data:text/html,<b>test</b>", null, null));
dbservice.lookup(principal);
dbservice.lookup(principal, allTables);
exception = false;
} catch(e) {
@ -115,7 +115,7 @@ function tablesCallbackWithoutSub(tables)
// 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");
"\ntest-malware-simple;a:1\ntest-phish-simple;a:2");
checkNoHost();
}
@ -133,12 +133,12 @@ function tablesCallbackWithSub(tables)
// 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");
"\ntest-malware-simple;a:1\ntest-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" +
"i:test-phish-simple\n" +
"sd:3\n";
doSimpleUpdate(data, expireSubSuccess, testFailure);
@ -157,7 +157,7 @@ function checkDone() {
function phishExists(result) {
dumpn("phishExists: " + result);
try {
do_check_true(result.indexOf("testing-phish-simple") != -1);
do_check_true(result.indexOf("test-phish-simple") != -1);
} finally {
checkDone();
}
@ -166,7 +166,7 @@ function phishExists(result) {
function phishDoesntExist(result) {
dumpn("phishDoesntExist: " + result);
try {
do_check_true(result.indexOf("testing-phish-simple") == -1);
do_check_true(result.indexOf("test-phish-simple") == -1);
} finally {
checkDone();
}
@ -176,7 +176,7 @@ function malwareExists(result) {
dumpn("malwareExists: " + result);
try {
do_check_true(result.indexOf("testing-malware-simple") != -1);
do_check_true(result.indexOf("test-malware-simple") != -1);
} finally {
checkDone();
}
@ -188,19 +188,19 @@ function checkState()
for (var key in phishExpected) {
var principal = secMan.getNoAppCodebasePrincipal(iosvc.newURI("http://" + key, null, null));
dbservice.lookup(principal, phishExists, true);
dbservice.lookup(principal, allTables, phishExists, true);
numExpecting++;
}
for (var key in phishUnexpected) {
var principal = secMan.getNoAppCodebasePrincipal(iosvc.newURI("http://" + key, null, null));
dbservice.lookup(principal, phishDoesntExist, true);
dbservice.lookup(principal, allTables, phishDoesntExist, true);
numExpecting++;
}
for (var key in malwareExpected) {
var principal = secMan.getNoAppCodebasePrincipal(iosvc.newURI("http://" + key, null, null));
dbservice.lookup(principal, malwareExists, true);
dbservice.lookup(principal, allTables, malwareExists, true);
numExpecting++;
}
}
@ -214,7 +214,7 @@ function testSubSuccess(result)
function do_subs() {
var data =
"n:1000\n" +
"i:testing-phish-simple\n" +
"i:test-phish-simple\n" +
"s:3:32:" + chunk3Sub.length + "\n" +
chunk3Sub + "\n" +
"ad:1\n" +
@ -236,7 +236,7 @@ function do_adds() {
var data =
"n:1000\n" +
"i:testing-phish-simple\n" +
"i:test-phish-simple\n" +
"a:1:32:" + chunk1.length + "\n" +
chunk1 + "\n" +
"a:2:32:" + chunk2.length + "\n" +
@ -247,7 +247,7 @@ function do_adds() {
chunk5 + "\n" +
"a:6:32:" + chunk6.length + "\n" +
chunk6 + "\n" +
"i:testing-malware-simple\n" +
"i:test-malware-simple\n" +
"a:1:32:" + chunk2.length + "\n" +
chunk2 + "\n";

View File

@ -125,11 +125,12 @@ add_test(function test_update() {
add_test(function test_url_not_whitelisted() {
let uri = createURI("http://example.com");
let principal = gSecMan.getNoAppCodebasePrincipal(uri);
gDbService.lookup(principal, function handleEvent(aEvent) {
// This URI is not on any lists.
do_check_eq("", aEvent);
run_next_test();
});
gDbService.lookup(principal, "goog-downloadwhite-digest256",
function handleEvent(aEvent) {
// This URI is not on any lists.
do_check_eq("", aEvent);
run_next_test();
});
});
add_test(function test_url_whitelisted() {
@ -137,8 +138,9 @@ add_test(function test_url_whitelisted() {
// 93CA5F48E15E9861CD37C2D95DB43D23CC6E6DE5C3F8FA6E8BE66F97CC518907
let uri = createURI("http://whitelisted.com");
let principal = gSecMan.getNoAppCodebasePrincipal(uri);
gDbService.lookup(principal, function handleEvent(aEvent) {
do_check_eq("goog-downloadwhite-digest256", aEvent);
run_next_test();
});
gDbService.lookup(principal, "goog-downloadwhite-digest256",
function handleEvent(aEvent) {
do_check_eq("goog-downloadwhite-digest256", aEvent);
run_next_test();
});
});