[Pkg-mozext-commits] [perspectives-extension] 27/72: cleanup test.html

David Prévot taffit at moszumanska.debian.org
Thu Dec 11 02:12:47 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository perspectives-extension.

commit b154cbd0a8ca4e14966f7d7655d5fb1f8ab0baf2
Author: Gerold Meisinger <gerold.meisinger at gmail.com>
Date:   Tue Jul 8 20:02:54 2014 +0100

    cleanup test.html
---
 test/test.html | 769 +++++++++++++++++++++++++++------------------------------
 1 file changed, 367 insertions(+), 402 deletions(-)

diff --git a/test/test.html b/test/test.html
index bcb0e87..2f7fe27 100644
--- a/test/test.html
+++ b/test/test.html
@@ -5,22 +5,74 @@
 <title>Perspectives - Test cases</title>
 
 <!-- Include every file so we can verify that all of the objects are testable in meta_test() -->
-<script type="text/javascript" src="../about.js"></script>
-<script type="text/javascript" src="../base64.js"></script>
-<script type="text/javascript" src="../client_policy.js"></script>
-<script type="text/javascript" src="../common.js"></script>
-<script type="text/javascript" src="../generate_svg.js"></script>
-<script type="text/javascript" src="../notaries.js"></script>
-<script type="text/javascript" src="../notify.js"></script>
+<script type="text/javascript" src="../about.js"             ></script>
+<script type="text/javascript" src="../base64.js"            ></script>
+<script type="text/javascript" src="../client_policy.js"     ></script>
+<script type="text/javascript" src="../common.js"            ></script>
+<script type="text/javascript" src="../generate_svg.js"      ></script>
+<script type="text/javascript" src="../notaries.js"          ></script>
+<script type="text/javascript" src="../notify.js"            ></script>
 <script type="text/javascript" src="../preferences_dialog.js"></script>
-<script type="text/javascript" src="../report.js"></script>
-<script type="text/javascript" src="../results_dialog.js"></script>
-<script type="text/javascript" src="../statusbar.js"></script>
-<script type="text/javascript" src="../whitelist_dialog.js"></script>
-<script type="text/javascript" src="../xml_notary_client.js"></script>
+<script type="text/javascript" src="../report.js"            ></script>
+<script type="text/javascript" src="../results_dialog.js"    ></script>
+<script type="text/javascript" src="../statusbar.js"         ></script>
+<script type="text/javascript" src="../whitelist_dialog.js"  ></script>
+<script type="text/javascript" src="../xml_notary_client.js" ></script>
 
+<!-- Also include every file for testing in browser (no chrome privileges) and fake some functions -->
 <script type="text/javascript">
+    // if on browser fake objects and make at least some tests work
+    if( typeof Components.classes === "undefined") {
+        Perspectives =
+        { root_prefs :
+          { getIntPref  : function(key) { return Perspectives.root_prefs[key]; }
+          , getCharPref : function(key) { return Perspectives.root_prefs[key]; }
+          , getBoolPref : function(key) { return Perspectives.root_prefs[key]; }
+          , setIntPref  : function(key, value) { Perspectives.root_prefs[key] = value; }
+          , setCharPref : function(key, value) { Perspectives.root_prefs[key] = value; }
+          , setBoolPref : function(key, value) { Perspectives.root_prefs[key] = value; }
+          }
+        , getNotaryList: function() {
+            return [
+                {"host": "heimdal.herokuapp.com:80"            , "public_key": "MIHKMA0GCSqGSIb3DQEBAQUAA4G4ADCBtAKBrAGhzbwVcnEaT2Hb9WD9Wvh9CVYu86w+8ZMdO4KG506K77IsERfIuh84YkE4qoDnjfR7TCQBvreVl81lIh5UE0kzO84X673risoBebbGCNjXQNu5mWkq2Qp7SuuemeXaYFmkpc06t2n6NvNcS9JVm8KJRqBKqlwqlFgDuDZPUcYmWoIL4sF9w/3ep9nPSIJYburTdpCaeXPGhMiMzh4E2GnJc3Y2beezGWtciXUCAwEAAQ=="},
+               	{"host": "nine-eyes.herokuapp.com:80"          , "public_key": "MIHKMA0GCSqGSIb3DQEBAQUAA4G4ADCBtAKBrAEw+W1dv0a00gzVqvHa8SafHhpYESsCIB8kj4bb1ccXr7u6vaiBN83ssaPi1N/ZNDlyOnqZwopoZGkgzUxMUNzg9P6Vph9l7ldMu8XGuwmFoHBgEys633EPcrJcs46lfvNz5JRrYnjh0WMkj0VXvVlYla2g6aAA80+C7u56D2FodNxWscPNpQWUAHDJOnAWr1CI9CNU/rbl5c85KJ7cW6u+LFBmpXk2xzJ2tq8CAwEAAQ=="},
+               	{"host": "perspectives2.networknotary.org:8080", "public_key": "MIHKMA0GCSqGSIb3DQEBAQUAA4G4ADCBtAKBrAHB9gHj3Zyx7u++wTffAsEuRJdjCZSFocs5ZKVamm6O7ywtFCuPgxxYTr3GyrDKj2IBO05iXirOISyX0OtENvs829XjTbKqDgeN1ttDiJmszN939RvBdmzkmXi2zaOXPX3ral56hJOWjOs6NokeBo26ZHux5k9g3AqFer5LNyDVgGrG5q7+INGodDSTYm2W5nvmi55U/pe7MmJCH7EEY1ObGPr17XqZeEbL4ikCAwEAAQ=="},
+               	{"host": "perspectives3.networknotary.org:8080", "public_key": "MIHKMA0GCSqGSIb3DQEBAQUAA4G4ADCBtAKBrAFTgU6nDuhi9TDkzypfgaW2ztQbc9eFlVTiLfUkUCmrfn8FqNzxuYdl/Hin3/Usz443GAvOwx0pXocClZ7Xtve06w6HxtuWMxAR0VMhywdzotTJAb/4a2btqHdrUlOZg6l7R66GbCupVWwyDQF7YBKarEGF2v6mRM/WknwaEYVOMu7XDb6zkEf4MsxptQnY7PfNktMMcuhusYjko3IhFmlUl4lue+c3aFR35Y8CAwEAAQ=="},
+               	{"host": "perspectives4.networknotary.org:8080", "public_key": "MIHKMA0GCSqGSIb3DQEBAQUAA4G4ADCBtAKBrAFiENC/BwZXOfzDOed4Qbvjd/25MixlCMlRUlfArJAvcjeBRmnY4fdQhi7/VH1qZeTQClegX1FMcuOORD29a4lks12WiXrh1HxLKxCTkPp5ZLqP8OiNxWqHdEQyinh2ulYFXZHWMlXhlsQKV2T7VsmfS0rLeukQAWpgGTXhACyZNpOQgjMm1vWEFaIsd2tT59Son7vxyCcaBoFCWv+zRW6kwaoKi0KgnEHwKwcCAwEAAQ=="},
+               	{"host": "perspectives5.networknotary.org:8080", "public_key": "MIHKMA0GCSqGSIb3DQEBAQUAA4G4ADCBtAKBrAGvUdk9PffzqgvXs31Z6Okf8llXat4IK/YuB7QA/JiJ0BZaNIQS+7ndtAJjNesfCC8ktjshOafGLitsc4DsPCjj/7wweV0RNABHHTbE+ObkmoZBlE9RXU5v1gMFVJOQtWZRz3MrNCg/zq93tdo0+SJLqnCy7endY6z1k+3Z9HNSU5bA5e/Er8jE/4IbL0zWhZgWTZcISH5ZuJICUN72Ag4u7yL3poPv+zdl86UCAwEAAQ=="},
+               	{"host": "perspectives6.networknotary.org:8080", "public_key": "MIHKMA0GCSqGSIb3DQEBAQUAA4G4ADCBtAKBrAGgQqPeMH0hYpJqSfsOPkJfZqQ731cYf/yvi54Zlux0S42aUu947T+d7GkH1SF25BAOK9suPfhPq7DKCvZ9MTOyNPlxpb6q82EgKV7LkqRfbBU6G5Xu8vN6Auif/gc4OYunCzru/ZKYM6Inp7tkl60/uEcsoHQtQMDguJEiuDuTFmkhOF6HsM4GAa2Wji612U0bB3hcjpJNQ0L3CWrWQNjpZAoS7ONaLk8IP9kCAwEAAQ=="},
+               	{"host": "perspectives7.networknotary.org:8080", "public_key": "MIHKMA0GCSqGSIb3DQEBAQUAA4G4ADCBtAKBrAFndaQshFiJmW9FDgmGQ8SgVs/5F8e1LQAyTyt2iW9J1Kavu2hisFhIShU2rOkv0w3j9JanO+FbaA0vrqoWN0dnwRpc41JQtjzhNZgE0j78w4nu5lxwMiJ16OlZh7p6L/hoZsDGNYrtGIEm4w8NurncFlAQ5JZPmcbhKkXikVjYi/sNM5G2osRxAZjimscvDpLqWxzDjLv4VpbXXMGY1WsvQwca/ScQhTV/uu0CAwEAAQ=="},
+               	{"host": "perspectives8.networknotary.org:8080", "public_key": "MIHKMA0GCSqGSIb3DQEBAQUAA4G4ADCBtAKBrAHrtkVD3O4XCkOdFwMqlEDVYTW6W82QQomSb9Pa/OGeRvbupk/d1iNNbBAs7B2Irg3Xk+OValBf29cUwXsYbpm3lEKGOqVhwas7YaHz4cnztkQJ5N+fW2eGe7iD1k1/wB7aPECPYVQgXOSpYcmg4999JGxjPE6LWmIu3KQfk1YtZBjGOI9Sa5wNhECvVoIMYGH1oG+oXkACpd6AgUJMfIOdG7BkwW9YFRKHPJkCAwEAAQ=="}
+            ];
+        }, getQuorumAsInt: function() { return 7; }
+        };
+
+        pref = function(key, value) {
+            console.log(key + ": " + value);
+        };
+
+        Pers_pref             = null;
+        Pers_results          = null;
+        Pers_whitelist_dialog = null;
+    }
+</script>
+
+<script type="text/javascript" src="../plugin/defaults/preferences/prefs.js"       ></script>
+<script type="text/javascript" src="../plugin/chrome/content/about.js"             ></script>
+<script type="text/javascript" src="../plugin/chrome/content/base64.js"            ></script>
+<script type="text/javascript" src="../plugin/chrome/content/client_policy.js"     ></script>
+<script type="text/javascript" src="../plugin/chrome/content/common.js"            ></script>
+<script type="text/javascript" src="../plugin/chrome/content/generate_svg.js"      ></script>
+<!--<script type="text/javascript" src="../plugin/chrome/content/notaries.js"          ></script>-->
+<script type="text/javascript" src="../plugin/chrome/content/notify.js"            ></script>
+<!--<script type="text/javascript" src="../plugin/chrome/content/preferences_dialog.js"></script>-->
+<script type="text/javascript" src="../plugin/chrome/content/report.js"            ></script>
+<!--<script type="text/javascript" src="../plugin/chrome/content/results_dialog.js"    ></script>-->
+<script type="text/javascript" src="../plugin/chrome/content/statusbar.js"         ></script>
+<!--<script type="text/javascript" src="../plugin/chrome/content/whitelist_dialog.js"  ></script>-->
+<script type="text/javascript" src="../plugin/chrome/content/xml_notary_client.js" ></script>
 
+<script type="text/javascript">
 d_print_all = true;
 other_cache = { "debug": "" }; // needed for common.js
 
@@ -28,6 +80,10 @@ var g_test_count = 0;
 var g_pass_count = 0;
 var g_fail_count = 0;
 
+var MIN_SECS  = 60;
+var HOUR_SECS = 60 * MIN_SECS;
+var DAY_SECS  = 24 * HOUR_SECS;
+
 /******* Helper Functions *******/
 function clear() {
     var node = document.getElementById('results');
@@ -51,21 +107,18 @@ function write_string_to_element(str, elname) {
 function assert(test, case_name) {
     g_test_count++;
     if(test) {
-        write_string_to_element('[' + g_test_count +
-                '] <span style="color: green">passed</span> : ' + case_name, 'li');
+        write_string_to_element('[' + g_test_count + '] <span style="color: green">passed</span> : ' + case_name, 'li');
         g_pass_count++;
     }
     else {
-        write_string_to_element('[' + g_test_count +
-                '] <b style="color: red">FAILED</b> : ' + case_name, 'li');
+        write_string_to_element('[' + g_test_count + '] <b style="color: red">FAILED</b> : ' + case_name, 'li');
         g_fail_count++;
     }
 
     // if people are looking through the console to debug,
     // give them some help tracing the action.
-    if(window.console != undefined) {
-        console.log("------- Finished test " +
-                g_test_count + ": " + case_name);
+    if(typeof window.console !== "undefined") {
+        console.log("------- Finished test " + g_test_count + ": " + case_name);
     }
 }
 
@@ -78,19 +131,17 @@ function error(str) {
 // it's here so you can easily set up tests and enable/disable them
 // by renaming the function they call.
 function assert_fixme(test, case_name) {
-    write_string_to_element('[-] <span style="color: grey">not implemented</span> : '
-            + case_name, 'li');
+    write_string_to_element('[-] <span style="color: grey">not implemented</span> : ' + case_name, 'li');
 }
 
 // add a horizontal bar to visuall separate some items or tests
 function spacer(category_name) {
-    write_string_to_element('------- <span style="color: grey">' + category_name +
-            ':</span>', 'li');
+    write_string_to_element('------- <span style="color: grey">' + category_name + ':</span>', 'li');
 }
 
 // if you're lazy and want to print some text while debugging
 function debug(obj) {
-    if(obj === null) {
+    if(obj == null) {
         return;
     }
 
@@ -105,12 +156,11 @@ function debug(obj) {
     }
 
     // strip out < so strings always appear on the page
-    write_string_to_element('<span style="color: grey">DEBUG: ' +
-            JSON.stringify(obj).replace(/</g, '<') + '</span>', 'li');
+    write_string_to_element('<span style="color: grey">DEBUG: ' + JSON.stringify(obj).replace(/</g, '<') + '</span>', 'li');
 }
 
 function deb_console(obj) {
-    if(window.console != undefined) {
+    if(typeof window.console !== "undefined") {
         console.log("DEBUG: " + obj);
     }
 }
@@ -118,28 +168,35 @@ function deb_console(obj) {
 /******* Tests *******/
 
 function meta_tests() {
-
     // make sure we can include and parse every object
     // so we'll be able to run tests on them.
     // if you add objects, add a test here
 
     write_string("Starting object creation tests");
 
-    assert(typeof Pers_about === 'object', "Pers_about is type '" + typeof Pers_about + "'."); //about.js
-    assert(typeof Pers_Base64 === 'object', "Pers_Base64 is type '" + typeof Pers_Base64 + "'.");
-    assert(typeof Pers_client_policy === 'object', "Pers_client_policy is type '" + typeof Pers_client_policy + "'."); //client_policy.js
-    assert(typeof Pers_debug === 'object', "Pers_debug is type '" + typeof Pers_debug + "'."); //common.js
-    assert(typeof Pers_util === 'object', "Pers_util is type '" + typeof Pers_util + "'.");
-    assert(typeof Pers_keypress === 'object', "Pers_keypress is type '" + typeof Pers_keypress + "'.");
-    assert(typeof Pers_gen === 'object', "Pers_gen is type '" + typeof Pers_gen + "'."); //generate_svg.js
-    assert(typeof Perspectives === 'object', "Perspectives is type '" + typeof Perspectives + "'."); //notaries.js
-    assert(typeof Pers_notify === 'object', "Pers_notify is type '" + typeof Pers_notify + "'."); //notify.js
-    assert(typeof Pers_pref === 'object', "Pers_pref is type '" + typeof Pers_pref + "'."); //preferences_dialog.js FIXME
-    assert(typeof Pers_report === 'object', "Pers_report is type '" + typeof Pers_report + "'."); //report.js
-    assert(typeof Pers_results === 'object', "Pers_results is type '" + typeof Pers_results + "'."); //results_dialog.js FIXME
-    assert(typeof Pers_statusbar === 'object', "Pers_statusbar is type '" + typeof Pers_statusbar + "'."); //statusbar.js
-    assert(typeof Pers_whitelist_dialog === 'object', "Pers_whitelist_dialog is type '" + typeof Pers_whitelist_dialog + "'."); //whitelist_dialog.js FIXME
-    assert(typeof Pers_xml === 'object', "Pers_xml is type '" + typeof Pers_xml + "'."); //xml_notary_client.js
+    var objs =
+        [ "Pers_about"
+        , "Pers_Base64"
+        , "Pers_client_policy"
+        , "Pers_debug"
+        , "Pers_util"
+        , "Pers_keypress"
+        , "Pers_gen"
+        , "Perspectives"
+        , "Pers_notify"
+        , "Pers_pref"
+        , "Pers_report"
+        , "Pers_results"
+        , "Pers_statusbar"
+        , "Pers_whitelist_dialog"
+        , "Pers_xml"
+        ];
+
+    for(var i = 0; i < objs.length; i++) {
+        var key  = objs[i];
+        var type = typeof window[key];
+        assert(type === 'object', key + " is type '" + type + "'.");
+    }
 
     write_string("Finished");
 }
@@ -162,8 +219,8 @@ function client_sanity() {
     ];
 
     var days_last_seen = 3;
-    var duration = 2; // days
-    var old_end = Pers_util.get_unix_time() - Pers_util.DAY2SEC(days_last_seen);
+    var duration       = 2; // days
+    var old_end   = Pers_util.get_unix_time() - Pers_util.DAY2SEC(days_last_seen           );
     var old_start = Pers_util.get_unix_time() - Pers_util.DAY2SEC(days_last_seen - duration);
 
     var second_result_list = [
@@ -185,47 +242,38 @@ function client_sanity() {
         }
     ];
 
-    var weakly_seen = Pers_client_policy.key_weakly_seen_by_quorum(key,
-            short_result_list, 1, -10);
-    assert((weakly_seen === false), "Negative Check lengths can't be weakly seen");
+    var weakly_seen0 = Pers_client_policy.key_weakly_seen_by_quorum(key, short_result_list, 1, -10);
+    assert(weakly_seen0 === false, "Negative Check lengths can't be weakly seen");
 
     var weak_check_time_limit = Pers_util.SEC2DAY(curtime + curtime);
-    weakly_seen = Pers_client_policy.key_weakly_seen_by_quorum(key,
-            short_result_list, 1, weak_check_time_limit);
-    assert((weakly_seen === false), "Check lengths longer than time since the epoch can't be weakly seen");
-
-    weakly_seen = Pers_client_policy.key_weakly_seen_by_quorum(key,
-            short_result_list, -1, 1);
-    assert((weakly_seen === false), "Negative quorum sizes can't be weakly seen");
-
-    weakly_seen = Pers_client_policy.key_weakly_seen_by_quorum(key,
-            short_result_list, 0, 1);
-    assert((weakly_seen === false), "Quorum size 0 can't be weakly seen");
-
-    var check_length = (days_last_seen + 1); //days
-    assert((check_length >= days_last_seen), "(meta) Test setup: check length >= ending day of observation.");
-    var weakly_seen_test = Pers_client_policy.key_weakly_seen_by_quorum(key,
-            second_result_list, 3, check_length);
-    assert((weakly_seen_test === false), "Keys seen but by fewer than quorum_size notaries do not count as weakly seen.");
-
-    check_length = (days_last_seen - 1); //days
-    assert((check_length <= days_last_seen), "(meta) Test setup: check length <= ending day of observation.");
-    weakly_seen_test = Pers_client_policy.key_weakly_seen_by_quorum(key,
-            second_result_list, 2, check_length);
-    assert((weakly_seen_test === false), "Keys seen by quorum_size notaries but not in the past X days do not count as weakly seen.");
-
-    check_length = (days_last_seen + 1); //days
-    assert((check_length >= days_last_seen), "(meta) Test setup: check length >= ending day of observation.");
-    weakly_seen_test = Pers_client_policy.key_weakly_seen_by_quorum(key,
-            second_result_list, 2, check_length);
-    assert((weakly_seen_test === true), "Keys seen by quorum_size notaries AND in the past X days DO count as weakly seen.");
-
-    check_length = days_last_seen; //days
-    assert((check_length === days_last_seen), "(meta) Test setup: check length === ending day of observation.");
-    weakly_seen_test = Pers_client_policy.key_weakly_seen_by_quorum(key,
-            second_result_list, 2, check_length);
-    assert((weakly_seen_test === true), "Keys seen by quorum_size notaries exactly in the past X days DO count as weakly seen.");
-
+    var weakly_seen1 = Pers_client_policy.key_weakly_seen_by_quorum(key, short_result_list, 1, weak_check_time_limit);
+    assert(weakly_seen1 === false, "Check lengths longer than time since the epoch can't be weakly seen");
+
+    var weakly_seen2 = Pers_client_policy.key_weakly_seen_by_quorum(key, short_result_list, -1, 1);
+    assert(weakly_seen2 === false, "Negative quorum sizes can't be weakly seen");
+
+    var weakly_seen3 = Pers_client_policy.key_weakly_seen_by_quorum(key, short_result_list, 0, 1);
+    assert(weakly_seen3 === false, "Quorum size 0 can't be weakly seen");
+
+    var check_length0 = days_last_seen + 1; //days
+    assert(check_length0 >= days_last_seen, "(meta) Test setup: check length >= ending day of observation.");
+    var weakly_seen_test = Pers_client_policy.key_weakly_seen_by_quorum(key, second_result_list, 3, check_length0);
+    assert(weakly_seen_test === false, "Keys seen but by fewer than quorum_size notaries do not count as weakly seen.");
+
+    var check_length1 = days_last_seen - 1; //days
+    assert((check_length1 <= days_last_seen), "(meta) Test setup: check length <= ending day of observation.");
+    weakly_seen_test = Pers_client_policy.key_weakly_seen_by_quorum(key, second_result_list, 2, check_length1);
+    assert(weakly_seen_test === false, "Keys seen by quorum_size notaries but not in the past X days do not count as weakly seen.");
+
+    var check_length2 = days_last_seen + 1; //days
+    assert(check_length2 >= days_last_seen, "(meta) Test setup: check length >= ending day of observation.");
+    weakly_seen_test = Pers_client_policy.key_weakly_seen_by_quorum(key, second_result_list, 2, check_length2);
+    assert(weakly_seen_test === true, "Keys seen by quorum_size notaries AND in the past X days DO count as weakly seen.");
+
+    var check_length3 = days_last_seen; //days
+    assert(check_length3 === days_last_seen, "(meta) Test setup: check length === ending day of observation.");
+    weakly_seen_test = Pers_client_policy.key_weakly_seen_by_quorum(key, second_result_list, 2, check_length3);
+    assert(weakly_seen_test === true, "Keys seen by quorum_size notaries exactly in the past X days DO count as weakly seen.");
 }
 
 function nonrouted_ips() {
@@ -233,90 +281,51 @@ function nonrouted_ips() {
 
     // nonrouted means the address is private and unreachable by notaries.
     spacer("Reachable addresses");
-    var host = "perspectives-project.org";
-    assert((Perspectives.is_nonrouted_ip(host) === false), host);
-
-    host = "github.com";
-    assert((Perspectives.is_nonrouted_ip(host) === false), host);
-
-    host = "test0.net";
-    assert((Perspectives.is_nonrouted_ip(host) === false), host);
-
-    host = "test1.net";
-    assert((Perspectives.is_nonrouted_ip(host) === false), host);
-
-    host = "test2.net";
-    assert((Perspectives.is_nonrouted_ip(host) === false), host);
-
-    host = "test3.net";
-    assert((Perspectives.is_nonrouted_ip(host) === false), host);
-
-    host = "test4.net";
-    assert((Perspectives.is_nonrouted_ip(host) === false), host);
-
-    host = "test5.net";
-    assert((Perspectives.is_nonrouted_ip(host) === false), host);
-
-    host = "test6.net";
-    assert((Perspectives.is_nonrouted_ip(host) === false), host);
-
-    host = "test7.net";
-    assert((Perspectives.is_nonrouted_ip(host) === false), host);
-
-    host = "test8.net";
-    assert((Perspectives.is_nonrouted_ip(host) === false), host);
-
-    host = "test9.net";
-    assert((Perspectives.is_nonrouted_ip(host) === false), host);
 
-    // hosts that contain numbers should still work
-    host = "100tests.net";
-    assert((Perspectives.is_nonrouted_ip(host) === false), host);
-
-    host = "1000tests.net";
-    assert((Perspectives.is_nonrouted_ip(host) === false), host);
-
-    host = "test100tests.net";
-    assert((Perspectives.is_nonrouted_ip(host) === false), host);
-
-    host = "192168tests.net";
-    assert((Perspectives.is_nonrouted_ip(host) === false), host);
+    var names =
+        [ "perspectives-project.org"
+        , "github.com"
+        , "test0.net"
+        , "test1.net"
+        , "test2.net"
+        , "test3.net"
+        , "test4.net"
+        , "test5.net"
+        , "test6.net"
+        , "test7.net"
+        , "test8.net"
+        , "test9.net"
+        , "100tests.net" // hosts that contain numbers should still work
+        , "1000tests.net"
+        , "test100tests.net"
+        , "192168tests.net"
+        ];
+
+    for(var n = 0; n < names.length; n++) {
+        var name = names[n];
+        assert((Perspectives.is_nonrouted_ip(name) === false), name);
+    }
 
     spacer("Unreachable by notaries");
 
-    host = "127.0.0.1";
-    assert((Perspectives.is_nonrouted_ip(host) === true), host);
-
-    host = "169.254.15.59";
-    assert((Perspectives.is_nonrouted_ip(host) === true), host);
-
-    // pick something in the beginning/middle/end of each RFC1918 private space
-    host = "10.0.0.0";
-    assert((Perspectives.is_nonrouted_ip(host) === true), host);
-
-    host = "10.0.0.1";
-    assert((Perspectives.is_nonrouted_ip(host) === true), host);
-
-    host = "10.255.254.254";
-    assert((Perspectives.is_nonrouted_ip(host) === true), host);
-
-    host = "172.16.0.0";
-    assert((Perspectives.is_nonrouted_ip(host) === true), host);
-
-    host = "172.16.1.1";
-    assert((Perspectives.is_nonrouted_ip(host) === true), host);
-
-    host = "172.31.254.254";
-    assert((Perspectives.is_nonrouted_ip(host) === true), host);
-
-    host = "192.168.0.0";
-    assert((Perspectives.is_nonrouted_ip(host) === true), host);
-
-    host = "192.168.10.21";
-    assert((Perspectives.is_nonrouted_ip(host) === true), host);
-
-    host = "192.168.254.254";
-    assert((Perspectives.is_nonrouted_ip(host) === true), host);
+    var ips =
+        [ "127.0.0.1"
+        , "169.254.15.59"
+        , "10.0.0.0" // pick something in the beginning/middle/end of each RFC1918 private space
+        , "10.0.0.1"
+        , "10.255.254.254"
+        , "172.16.0.0"
+        , "172.16.1.1"
+        , "172.31.254.254"
+        , "192.168.0.0"
+        , "192.168.10.21"
+        , "192.168.254.254"
+        ];
+
+    for(var i = 0; i < ips.length; i++) {
+        var ip = ips[i];
+        assert((Perspectives.is_nonrouted_ip(host) === true), host);
+    }
 
     write_string("Done!");
 }
@@ -324,21 +333,19 @@ function nonrouted_ips() {
 function quorum_basics() {
     write_string("Starting basic quorum tests...");
 
-    var key = "b1:7f:b1:15:25:4e:7b:fb:93:83:ac:5c:26:df:f7:00";
+    var key1 = "b1:7f:b1:15:25:4e:7b:fb:93:83:ac:5c:26:df:f7:00";
     var key2 = "b2:7f:b1:15:25:4e:7b:fb:93:83:ac:5c:26:df:f7:00";
     var key3 = "b3:7f:b1:15:25:4e:7b:fb:93:83:ac:5c:26:df:f7:00";
-    var cur_time = 10000;
-    var max_stale_sec = 200;
-
-    var key_start_diff = 1000;
-    var key_start_time = (cur_time - key_start_diff);
-
-    var key_end_time = cur_time;
+    var cur_time       = 10000;
+    var max_stale_sec  =   200;
+    var key_beg_diff   =  1000;
+    var key_beg_time   = cur_time - key_beg_diff;
+    var key_end_time   = cur_time;
 
     var server_result_list = [
         { "server": "204.255.124.41:8080",
             "obs": [
-                { "key": key,
+                { "key": key1,
                     "timestamps": [
                         { "start": 0, "end": key_end_time  }
                     ] }
@@ -346,9 +353,9 @@ function quorum_basics() {
         },
         { "server": "128.2.185.85:8080",
             "obs": [
-                { "key": key,
+                { "key": key1,
                     "timestamps": [
-                        { "start": key_start_time, "end": key_end_time  }
+                        { "start": key_beg_time, "end": key_end_time  }
                     ] }
             ]
         }
@@ -356,91 +363,75 @@ function quorum_basics() {
 
     var quorum_duration = 0;
 
-    quorum_duration = Pers_client_policy.get_quorum_duration(key,
-            server_result_list, 2, max_stale_sec, cur_time);
-    assert((quorum_duration === (cur_time - key_start_time) + 1), "Requiring larger quorum gives a shorter duration");
+    quorum_duration = Pers_client_policy.get_quorum_duration(key1, server_result_list, 2, max_stale_sec, cur_time);
+    assert(quorum_duration === cur_time - key_beg_time + 1  , "Requiring larger quorum gives a shorter duration");
 
-    quorum_duration = Pers_client_policy.get_quorum_duration(key,
-            server_result_list, 1, max_stale_sec, cur_time);
-    assert((quorum_duration === cur_time + 1), "Requiring smaller quorum gives a longer duration");
-    assert((quorum_duration > (cur_time - max_stale_sec)), "Getting enough quorum voters passes");
+    quorum_duration = Pers_client_policy.get_quorum_duration(key1, server_result_list, 1, max_stale_sec, cur_time);
+    assert(quorum_duration === cur_time + 1                 , "Requiring smaller quorum gives a longer duration");
+    assert(quorum_duration > cur_time - max_stale_sec       , "Getting enough quorum voters passes");
 
-    quorum_duration = Pers_client_policy.get_quorum_duration(key,
-            server_result_list, 10, max_stale_sec, cur_time);
-    assert((quorum_duration === -1), "Getting fewer quorum voters than required fails");
+    quorum_duration = Pers_client_policy.get_quorum_duration(key1, server_result_list, 10, max_stale_sec, cur_time);
+    assert(quorum_duration === -1                           , "Getting fewer quorum voters than required fails");
 
     spacer('When observations end at the current time');
-    quorum_duration = Pers_client_policy.get_quorum_duration(key,
-            server_result_list, 1, max_stale_sec,
-            cur_time);
-    assert((key_end_time > (cur_time - max_stale_sec)), "The key is within the quorum time limit.");
-    assert((quorum_duration >= 1 ), "Searching for an existing key within the time limit has a positive duration");
-    assert((quorum_duration === (cur_time + max_stale_sec + 1)), "The duration is as long as the observation.start to observation.end (Expected " + (cur_time + max_stale_sec + 1) +
-            ", got " + quorum_duration + ")");
-
-    quorum_duration = Pers_client_policy.get_quorum_duration(key,
-            server_result_list, 1, max_stale_sec,
-            cur_time + max_stale_sec + 1);
-    assert((quorum_duration === -1), "Being over the quorum duration time limit fails");
+    quorum_duration = Pers_client_policy.get_quorum_duration(key1, server_result_list, 1, max_stale_sec, cur_time);
+    assert(key_end_time > cur_time - max_stale_sec          , "The key is within the quorum time limit.");
+    assert(quorum_duration >= 1                             , "Searching for an existing key within the time limit has a positive duration");
+    assert(quorum_duration === cur_time + max_stale_sec + 1 , "The duration is as long as the observation.start to observation.end (Expected " + (cur_time + max_stale_sec + 1) + ", got " + quorum_duration + ")");
+
+    quorum_duration = Pers_client_policy.get_quorum_duration(key1, server_result_list, 1, max_stale_sec, cur_time + max_stale_sec + 1);
+    assert((quorum_duration === -1)                         , "Being over the quorum duration time limit fails");
 
     // run tests with keys that don't end exactly at the current time
     spacer('When observations *do not* end at the current time');
     cur_time += 100;
 
-    assert((key_end_time > (cur_time - max_stale_sec)), "Key is inside the quorum duration limit.");
-    quorum_duration = Pers_client_policy.get_quorum_duration(key,
-            server_result_list, 1, max_stale_sec,
-            cur_time);
-    assert((quorum_duration >= 1 ), "2. Being at the edge of the quorum duration time limit passes");
-    assert((quorum_duration === (cur_time + max_stale_sec + 1)), "2. The duration is as long as the observation.start to observation.end (i.e. it does NOT also count time that is white/a gap between it's end an the current time). (Expected " + (cur_time + max_stale_sec + 1) +
-            ", got " + quorum_duration + ")");
+    assert(key_end_time > cur_time - max_stale_sec          , "Key is inside the quorum duration limit.");
+    quorum_duration = Pers_client_policy.get_quorum_duration(key1, server_result_list, 1, max_stale_sec, cur_time);
+    assert(quorum_duration >= 1                             , "2. Being at the edge of the quorum duration time limit passes");
+    assert(quorum_duration === cur_time + max_stale_sec + 1 , "2. The duration is as long as the observation.start to observation.end (i.e. it does NOT also count time that is white/a gap between it's end an the current time). (Expected " + (cur_time + max_stale_sec + 1) + ", got " + quorum_duration + ")");
 
     cur_time += 2 * max_stale_sec;
-    assert((key_end_time < (cur_time - max_stale_sec)), "With changes, key is *outside* the quorum duration limit.");
-    quorum_duration = Pers_client_policy.get_quorum_duration(key,
-            server_result_list, 1, max_stale_sec,
-            cur_time + max_stale_sec + 1);
-    assert((quorum_duration === -1), "2. Being over the quorum duration time limit fails");
+    assert(key_end_time < cur_time - max_stale_sec          , "With changes, key is *outside* the quorum duration limit.");
+    quorum_duration = Pers_client_policy.get_quorum_duration(key1, server_result_list, 1, max_stale_sec, cur_time + max_stale_sec + 1);
+    assert(quorum_duration === -1                           , "2. Being over the quorum duration time limit fails");
 
-    quorum_duration = Pers_client_policy.get_quorum_duration(key2,
-            server_result_list, 1, max_stale_sec, cur_time);
-    assert((quorum_duration === -1), "Looking for a key that has no results fails");
+    quorum_duration = Pers_client_policy.get_quorum_duration(key2, server_result_list, 1, max_stale_sec, cur_time);
+    assert(quorum_duration === -1                           , "Looking for a key that has no results fails");
 
     var empty_result_list = [];
-
-    quorum_duration = Pers_client_policy.get_quorum_duration(key,
-            empty_result_list, 1, max_stale_sec, cur_time);
-    assert((quorum_duration === -1), "Passing an empty results list fails");
+    quorum_duration = Pers_client_policy.get_quorum_duration(key1, empty_result_list, 1, max_stale_sec, cur_time);
+    assert(quorum_duration === -1                           , "Passing an empty results list fails");
 
     spacer('Observations with gaps (duration is still counted correctly if there is a gap between keys)');
 
-    max_stale_sec = 600;
-    cur_time = 2000;
+    max_stale_sec         =  600;
+    cur_time              = 2000;
     // leave a gap between the end of the key and the current time
-    var key1_duration = 200;
-    var end_time_1 = (cur_time - 100);
-    var start_time_1 = end_time_1 - key1_duration;
-    var key2_duration = 400;
-    var end_time_2 = (start_time_1 - 150);
-    var orig_end_time_2 = end_time_2;
-    var start_time_2 = end_time_2 - key2_duration;
-    var orig_start_time_2 = start_time_2;
-
-    assert(cur_time > end_time_1, "Gap setup: key1 ends before the current time");
-    assert(end_time_1 > start_time_1, "Gap setup: key1 starts before it ends");
-    assert(start_time_1 > end_time_2, "Gap setup: key2 ends before key1 starts");
-    assert(end_time_2 > start_time_2, "Gap setup: key2 starts before it ends");
-    assert(start_time_2 >= 0, "Gap setup: all times are non-negative");
-    assert(end_time_1 > (cur_time - max_stale_sec), "Gap setup: Target key1 ends inside the cutoff limit");
-    assert((end_time_1 - start_time_1 === key1_duration), "Gap setup: key one lasts " + key1_duration + ".");
-    assert((end_time_2 - start_time_2 === key2_duration), "Gap setup: key two lasts " + key2_duration + ".");
+    var key1_duration     =  200;
+    var end_time_1        = cur_time - 100;
+    var beg_time_1        = end_time_1 - key1_duration;
+    var key2_duration     =  400;
+    var end_time_2        = beg_time_1 - 150;
+    var orig_end_time_2   = end_time_2;
+    var beg_time_2        = end_time_2 - key2_duration;
+    var orig_beg_time_2   = beg_time_2;
+
+    assert(cur_time   >  end_time_1                 , "Gap setup: key1 ends before the current time"       );
+    assert(end_time_1 >  beg_time_1                 , "Gap setup: key1 begins before it ends"              );
+    assert(beg_time_1 >  end_time_2                 , "Gap setup: key2 ends before key1 begins"            );
+    assert(end_time_2 >  beg_time_2                 , "Gap setup: key2 begins before it ends"              );
+    assert(beg_time_2 >= 0                          , "Gap setup: all times are non-negative"              );
+    assert(end_time_1 >  cur_time - max_stale_sec   , "Gap setup: Target key1 ends inside the cutoff limit");
+    assert(end_time_1 - beg_time_1 === key1_duration, "Gap setup: key one lasts " + key1_duration + "."    );
+    assert(end_time_2 - beg_time_2 === key2_duration, "Gap setup: key two lasts " + key2_duration + "."    );
 
     var gap_result_list = [
         { "server": "204.255.124.41:8080",
             "obs": [
-                { "key": key,
+                { "key": key1,
                     "timestamps": [
-                        { "start": start_time_1, "end": end_time_1  }
+                        { "start": beg_time_1, "end": end_time_1  }
                     ] }
             ]
         },
@@ -448,57 +439,49 @@ function quorum_basics() {
             "obs": [
                 { "key": key2,
                     "timestamps": [
-                        { "start": start_time_2, "end": end_time_2  }
+                        { "start": beg_time_2, "end": end_time_2  }
                     ] }
             ]
         }
     ];
 
     //(i.e. only as long as the bar, and only if inside cutoff)
-    var gap_quorum_duration1 = Pers_client_policy.get_quorum_duration(key,
-            gap_result_list, 1, max_stale_sec, cur_time);
-    assert((gap_quorum_duration1 === (end_time_1 - start_time_1 + 1)), "Target key first: |curtime| .. |current key| .. |other key| {cutoff} (should be " +
-            (end_time_1 - start_time_1 + 1) + ", not " + (cur_time - start_time_1 + 1) +
-            ": got " + gap_quorum_duration1 + ").");
+    var gap_quorum_duration1 = Pers_client_policy.get_quorum_duration(key1, gap_result_list, 1, max_stale_sec, cur_time);
+    assert(gap_quorum_duration1 === end_time_1 - beg_time_1 + 1  , "Target key first: |curtime| .. |current key| .. |other key| {cutoff} (should be " + (end_time_1 - beg_time_1 + 1) + ", not " + (cur_time - beg_time_1 + 1) + ": got " + gap_quorum_duration1 + ").");
 
     // the 'weakly seen' property is relative to the current time,
     // so allow a check length going back to the end date of the observation.
     var weak_check_time_limit = Pers_util.SEC2DAY(Pers_util.get_unix_time() - end_time_2);
-    var gap_weakly_seen1 = Pers_client_policy.key_weakly_seen_by_quorum(key,
-            gap_result_list, 1, weak_check_time_limit);
-    assert((gap_weakly_seen1 === true), "key is 'weakly seen'");
+    var gap_weakly_seen1      = Pers_client_policy.key_weakly_seen_by_quorum(key1, gap_result_list, 1, weak_check_time_limit);
+    assert(gap_weakly_seen1 === true                             , "key is 'weakly seen'");
 
-    assert(end_time_2 > (cur_time - max_stale_sec), "Gap setup: New target key2 ends inside the cutoff limit");
-    var gap_quorum_duration2 = Pers_client_policy.get_quorum_duration(key2,
-            gap_result_list, 1, max_stale_sec, cur_time);
-    assert((gap_quorum_duration2 === (end_time_2 - start_time_2 + 1)), "Target key second: |curtime| .. |other key| .. |current key.. {cutoff} .. |(should be " +
-            (end_time_2 - start_time_2 + 1) + ", not " + (cur_time - start_time_2 + 1) +
-            ": got " + gap_quorum_duration2 + ").");
+    assert(end_time_2 > cur_time - max_stale_sec                 , "Gap setup: New target key2 ends inside the cutoff limit");
+    var gap_quorum_duration2 = Pers_client_policy.get_quorum_duration(key2, gap_result_list, 1, max_stale_sec, cur_time);
+    assert(gap_quorum_duration2 === end_time_2 - beg_time_2 + 1  , "Target key second: |curtime| .. |other key| .. |current key.. {cutoff} .. |(should be " + (end_time_2 - beg_time_2 + 1) + ", not " + (cur_time - beg_time_2 + 1) + ": got " + gap_quorum_duration2 + ").");
 
-    var gap_weakly_seen2 = Pers_client_policy.key_weakly_seen_by_quorum(key2,
-            gap_result_list, 1, weak_check_time_limit);
-    assert((gap_weakly_seen2 === true), "key2 is 'weakly seen'");
+    var gap_weakly_seen2 = Pers_client_policy.key_weakly_seen_by_quorum(key2, gap_result_list, 1, weak_check_time_limit);
+    assert(gap_weakly_seen2 === true                             , "key2 is 'weakly seen'");
 
     // if we had the same result set without the gap, the durations should be the same
     spacer("Gap and non-gap durations should be the same");
-    end_time_2 = start_time_1; // all other variables from above are the same.
-    start_time_2 = end_time_2 - key2_duration;
-
-    assert(cur_time > end_time_1, "Nongap setup: key1 ends before the current time");
-    assert(end_time_1 > start_time_1, "Nongap setup: key1 starts before it ends");
-    assert(start_time_1 === end_time_2, "Nongap setup: key2 ends *exactly when* key1 starts");
-    assert(end_time_2 > start_time_2, "Nongap setup: key2 starts before it ends");
-    assert(start_time_2 >= 0, "Nongap setup: all times are non-negative");
-    assert(end_time_1 > (cur_time - max_stale_sec), "Nongap setup: Target key1 ends inside the cutoff limit");
-    assert((end_time_1 - start_time_1 === key1_duration), "Nongap setup: key one lasts " + key1_duration + ".");
-    assert((end_time_2 - start_time_2 === key2_duration), "Nongap setup: key two lasts " + key2_duration + ".");
+    end_time_2 = beg_time_1; // all other variables from above are the same.
+    beg_time_2 = end_time_2 - key2_duration;
+
+    assert(cur_time   >   end_time_1                , "Nongap setup: key1 ends before the current time");
+    assert(end_time_1 >   beg_time_1                , "Nongap setup: key1 begins before it ends");
+    assert(beg_time_1 === end_time_2                , "Nongap setup: key2 ends *exactly when* key1 begins");
+    assert(end_time_2 >   beg_time_2                , "Nongap setup: key2 begins before it ends");
+    assert(beg_time_2 >=  0                         , "Nongap setup: all times are non-negative");
+    assert(end_time_1 >   cur_time - max_stale_sec  , "Nongap setup: Target key1 ends inside the cutoff limit");
+    assert(end_time_1 - beg_time_1 === key1_duration, "Nongap setup: key one lasts " + key1_duration + ".");
+    assert(end_time_2 - beg_time_2 === key2_duration, "Nongap setup: key two lasts " + key2_duration + ".");
 
     var non_gap_result_list = [
         { "server": "204.255.124.41:8080",
             "obs": [
-                { "key": key,
+                { "key": key1,
                     "timestamps": [
-                        { "start": start_time_1, "end": end_time_1  }
+                        { "start": beg_time_1, "end": end_time_1  }
                     ] }
             ]
         },
@@ -506,66 +489,57 @@ function quorum_basics() {
             "obs": [
                 { "key": key2,
                     "timestamps": [
-                        { "start": start_time_2, "end": end_time_2  }
+                        { "start": beg_time_2, "end": end_time_2  }
                     ] }
             ]
         }
     ];
 
-    var nongap_quorum_duration1 = Pers_client_policy.get_quorum_duration(key,
-            non_gap_result_list, 1, max_stale_sec, cur_time);
-    assert((nongap_quorum_duration1 === (end_time_1 - start_time_1 + 1)), "Target key first: |curtime| .. |current key||other key| {cutoff} (should be " +
-            (end_time_1 - start_time_1 + 1) + ", not " + (cur_time - start_time_1 + 1) +
-            ": got " + nongap_quorum_duration1 + ").");
-    assert((nongap_quorum_duration1 === gap_quorum_duration1), "Duration is the same with and without gaps.");
+    var nongap_quorum_duration1 = Pers_client_policy.get_quorum_duration(key1, non_gap_result_list, 1, max_stale_sec, cur_time);
+    assert(nongap_quorum_duration1 === end_time_1 - beg_time_1 + 1, "Target key first: |curtime| .. |current key||other key| {cutoff} (should be " + (end_time_1 - beg_time_1 + 1) + ", not " + (cur_time - beg_time_1 + 1) + ": got " + nongap_quorum_duration1 + ").");
+    assert(nongap_quorum_duration1 === gap_quorum_duration1       , "Duration is the same with and without gaps.");
 
     // the 'weakly seen' property is relative to the current time,
     // so allow a check length going back to the end date of the observation.
     weak_check_time_limit = Pers_util.SEC2DAY(Pers_util.get_unix_time() - end_time_2);
-    var nongap_weakly_seen1 = Pers_client_policy.key_weakly_seen_by_quorum(key,
-            non_gap_result_list, 1, weak_check_time_limit);
-    assert((nongap_weakly_seen1 === true), "key is 'weakly seen'");
+    var nongap_weakly_seen1 = Pers_client_policy.key_weakly_seen_by_quorum(key1, non_gap_result_list, 1, weak_check_time_limit);
+    assert(nongap_weakly_seen1 === true                           , "key is 'weakly seen'");
     // the important tests - that results with and without gaps are the same.
-    assert((nongap_weakly_seen1 === gap_weakly_seen1), "'weakly seen' result is the same with and without gaps.");
+    assert(nongap_weakly_seen1 === gap_weakly_seen1               , "'weakly seen' result is the same with and without gaps.");
+    assert(end_time_2 > cur_time - max_stale_sec                  , "Nongap setup: New target key2 ends inside the cutoff limit");
 
-    assert(end_time_2 > (cur_time - max_stale_sec), "Nongap setup: New target key2 ends inside the cutoff limit");
-    var nongap_quorum_duration2 = Pers_client_policy.get_quorum_duration(key2,
-            non_gap_result_list, 1, max_stale_sec, cur_time);
-    assert((nongap_quorum_duration2 === (end_time_2 - start_time_2 + 1)), "Target key second: |curtime| .. |other key||current key.. {cutoff} .. |(should be " +
-            (end_time_2 - start_time_2 + 1) + ", not " + (cur_time - start_time_2 + 1) +
-            ": got " + nongap_quorum_duration2 + ").");
-    assert((nongap_quorum_duration2 === gap_quorum_duration2), "Duration is the same with and without gaps.");
+    var nongap_quorum_duration2 = Pers_client_policy.get_quorum_duration(key2, non_gap_result_list, 1, max_stale_sec, cur_time);
+    assert(nongap_quorum_duration2 === end_time_2 - beg_time_2 + 1, "Target key second: |curtime| .. |other key||current key.. {cutoff} .. |(should be " + (end_time_2 - beg_time_2 + 1) + ", not " + (cur_time - beg_time_2 + 1) + ": got " + nongap_quorum_duration2 + ").");
+    assert(nongap_quorum_duration2 === gap_quorum_duration2       , "Duration is the same with and without gaps.");
 
     // the 'weakly seen' property is relative to the current time,
     // so allow a check length going back to the end date of the observation.
-    var nongap_weakly_seen2 = Pers_client_policy.key_weakly_seen_by_quorum(key2,
-            non_gap_result_list, 1, weak_check_time_limit);
-    assert((nongap_weakly_seen2 === true), "key is 'weakly seen'");
-    assert((nongap_weakly_seen2 === gap_weakly_seen2), "'weakly seen' result is the same with and without gaps.");
+    var nongap_weakly_seen2 = Pers_client_policy.key_weakly_seen_by_quorum(key2, non_gap_result_list, 1, weak_check_time_limit);
+    assert(nongap_weakly_seen2 === true                           , "key is 'weakly seen'");
+    assert(nongap_weakly_seen2 === gap_weakly_seen2               , "'weakly seen' result is the same with and without gaps.");
 
     spacer("Further gap tests");
     end_time_2 = orig_end_time_2;
-    start_time_2 = orig_start_time_2;
+    beg_time_2 = orig_beg_time_2;
     max_stale_sec = 200;
-    assert(end_time_2 < (cur_time - max_stale_sec), "Gap setup: After change, target key2 ends *outside* the cutoff limit");
-    quorum_duration = Pers_client_policy.get_quorum_duration(key2,
-            gap_result_list, 1, max_stale_sec, cur_time);
-    assert((quorum_duration === -1), "Results with gaps do not give a duration if they happen after the time cutoff.");
+    assert(end_time_2 < cur_time - max_stale_sec, "Gap setup: After change, target key2 ends *outside* the cutoff limit");
+    quorum_duration = Pers_client_policy.get_quorum_duration(key2, gap_result_list, 1, max_stale_sec, cur_time);
+    assert(quorum_duration === -1               , "Results with gaps do not give a duration if they happen after the time cutoff.");
 
     var gap_result_list2 = [
         { "server": "204.255.124.41:8080",
             "obs": [
-                { "key": key,
+                { "key": key1,
                     "timestamps": [
-                        { "start": start_time_1, "end": end_time_1  }
+                        { "start": beg_time_1, "end": end_time_1  }
                     ] }
             ]
         },
         { "server": "128.2.185.85:8080",
             "obs": [
-                { "key": key,
+                { "key": key1,
                     "timestamps": [
-                        { "start": start_time_2, "end": end_time_2  }
+                        { "start": beg_time_2, "end": end_time_2  }
                     ] }
             ]
         }
@@ -574,11 +548,8 @@ function quorum_basics() {
     // currently this will calculate duration using the oldest matching key inside the
     // cutoff range.
     // TODO: should we use the longest or shortest one instead?
-    quorum_duration = Pers_client_policy.get_quorum_duration(key,
-            gap_result_list2, 1, max_stale_sec, cur_time);
-    assert((quorum_duration === (end_time_2 - start_time_2 + 1)), "Target key second: |curtime| .. |current key| .. |current key.. {cutoff} .. |(should be " +
-            (end_time_2 - start_time_2 + 1) + ", not " + (cur_time - start_time_2 + 1) +
-            ": got " + quorum_duration + ").");
+    quorum_duration = Pers_client_policy.get_quorum_duration(key1, gap_result_list2, 1, max_stale_sec, cur_time);
+    assert(quorum_duration === end_time_2 - beg_time_2 + 1, "Target key second: |curtime| .. |current key| .. |current key.. {cutoff} .. |(should be " + (end_time_2 - beg_time_2 + 1) + ", not " + (cur_time - beg_time_2 + 1) + ": got " + quorum_duration + ").");
     // testing against a result set without gaps doesn't make sense here;
     // the two observations would be joined together.
 
@@ -587,11 +558,11 @@ function quorum_basics() {
     spacer('Quorums for certificates with short durations');
 
     var short_start = 10;
-    var short_end = 11;
+    var short_end   = 11;
     var short_result_list = [
         { "server": "test1:8080",
             "obs": [
-                { "key": key,
+                { "key": key1,
                     "timestamps": [
                         { "start": short_start, "end": short_end  }
                     ] }
@@ -600,32 +571,26 @@ function quorum_basics() {
     ];
 
     // place cur_time within the 'valid range' cutoff
-    cur_time = 24 * 3600;
+    cur_time      =   1 * DAY_SECS;
     max_stale_sec = 200;
-    quorum_duration = Pers_client_policy.get_quorum_duration(key,
-            short_result_list, 1, max_stale_sec, cur_time);
-    assert((quorum_duration === -1), "A one-second duration out of the valid time window is inconsistent (got " +
-            quorum_duration + ").");
+    quorum_duration = Pers_client_policy.get_quorum_duration(key1, short_result_list, 1, max_stale_sec, cur_time);
+    assert(quorum_duration === -1              , "A one-second duration out of the valid time window is inconsistent (got " + quorum_duration + ").");
 
     // the 'weakly seen' property is relative to the current time,
     // so allow a check length going back to the end date of the observation.
     weak_check_time_limit = Pers_util.SEC2DAY(Pers_util.get_unix_time() - short_end);
-    var weakly_seen = Pers_client_policy.key_weakly_seen_by_quorum(key,
-            short_result_list, 1, weak_check_time_limit);
-    assert((weakly_seen === true), "keys with one second duration count as 'weakly seen'");
+    var weakly_seen = Pers_client_policy.key_weakly_seen_by_quorum(key1, short_result_list, 1, weak_check_time_limit);
+    assert(weakly_seen === true                , "keys with one second duration count as 'weakly seen'");
 
-    max_stale_sec = 3 * 24 * 3600;
-    quorum_duration = Pers_client_policy.get_quorum_duration(key,
+    max_stale_sec = 3 * DAY_SECS;
+    quorum_duration = Pers_client_policy.get_quorum_duration(key1,
             short_result_list, 1, max_stale_sec, cur_time);
-    assert((quorum_duration === 1), "A one-second duration within the valid time window is one second (got " +
-            quorum_duration + ").");
+    assert(quorum_duration === 1               , "A one-second duration within the valid time window is one second (got " + quorum_duration + ").");
 
-    cur_time += 24 * 3600;
-    assert(((cur_time - max_stale_sec) < short_end), "(meta) Current time for the next test is still within the valid window.");
-    var quorum_duration2 = Pers_client_policy.get_quorum_duration(key,
-            short_result_list, 1, max_stale_sec, cur_time);
-    assert((quorum_duration === quorum_duration2), "Changing the curtime within the valid window doesn't change the duration of the cert observation (got " +
-            quorum_duration2 + ").");
+    cur_time += 1 * DAY_SECS;
+    assert(cur_time - max_stale_sec < short_end, "(meta) Current time for the next test is still within the valid window.");
+    var quorum_duration2 = Pers_client_policy.get_quorum_duration(key1, short_result_list, 1, max_stale_sec, cur_time);
+    assert(quorum_duration === quorum_duration2, "Changing the curtime within the valid window doesn't change the duration of the cert observation (got " + quorum_duration2 + ").");
 
     spacer('Quorums with a small number of notaries');
 
@@ -633,9 +598,9 @@ function quorum_basics() {
     //so it doesn't matter which we alter.
     var pref_string_extra_notaries = "perspectives.additional_notary_list";
     var pref_string_use_def_notary = "perspectives.use_default_notary_list";
-    var orig_thresh = Perspectives.root_prefs.getIntPref("perspectives.quorum_thresh");
-    var orig_extra_notaries = Perspectives.root_prefs.getCharPref(pref_string_extra_notaries);
-    var orig_use_default_notaries = Perspectives.root_prefs.getBoolPref(pref_string_use_def_notary);
+    var orig_thresh               = Perspectives.root_prefs.getIntPref ("perspectives.quorum_thresh");
+    var orig_extra_notaries       = Perspectives.root_prefs.getCharPref(pref_string_extra_notaries  );
+    var orig_use_default_notaries = Perspectives.root_prefs.getBoolPref(pref_string_use_def_notary  );
 
     var single_notary = "localhost:8080\n\
 -----BEGIN PUBLIC KEY-----\n\
@@ -648,42 +613,37 @@ JaJ2Lw7kRVMCAwEAAQ==\
 
     try {
         var small_quorum_thresh = 1;
-        Perspectives.root_prefs.setIntPref("perspectives.quorum_thresh", small_quorum_thresh);
-        Perspectives.root_prefs.setBoolPref(pref_string_use_def_notary, false);
-        Perspectives.root_prefs.setCharPref(pref_string_extra_notaries, single_notary);
+        Perspectives.root_prefs.setIntPref ("perspectives.quorum_thresh", small_quorum_thresh);
+        Perspectives.root_prefs.setBoolPref(pref_string_use_def_notary  , false              );
+        Perspectives.root_prefs.setCharPref(pref_string_extra_notaries  , single_notary      );
 
         var qint = Perspectives.getQuorumAsInt();
-        assert(qint >= 1, small_quorum_thresh +
-                "% Quorum Threhold with 1 notary still returns a required quorum count >= 1 (got " + qint + ").");
+        assert(qint >= 1            , small_quorum_thresh + "% Quorum Threhold with 1 notary still returns a required quorum count >= 1 (got " + qint + ").");
 
         var unixtime = Pers_util.get_unix_time();
-        max_stale_sec = 2 * 24 * 3600;
+        max_stale_sec = 2 * DAY_SECS;
 
-        var consistent = Pers_client_policy.check_current_consistency(
-                key, server_result_list, 0, max_stale_sec, unixtime);
-        assert((consistent === false), "Quorum size 0 is not consistent.");
+        var consistent = Pers_client_policy.check_current_consistency(key1, server_result_list, 0, max_stale_sec, unixtime);
+        assert(consistent === false , "Quorum size 0 is not consistent.");
 
-        var has_quorum = Pers_client_policy.has_quorum_at_time(key,
-                server_result_list, 0, null);
-        assert((has_quorum === false), "Quorum size 0 is fails at any given time.");
+        var has_quorum = Pers_client_policy.has_quorum_at_time(key1, server_result_list, 0, null);
+        assert(has_quorum === false , "Quorum size 0 is fails at any given time.");
 
-        quorum_duration = Pers_client_policy.get_quorum_duration(key,
-                server_result_list, 0, max_stale_sec, unixtime);
-        assert((quorum_duration === 0), "Quorum size 0 gives zero duration");
+        quorum_duration = Pers_client_policy.get_quorum_duration(key1, server_result_list, 0, max_stale_sec, unixtime);
+        assert(quorum_duration === 0, "Quorum size 0 gives zero duration");
 
         var full_quorum_thresh = 100;
-        Perspectives.root_prefs.setIntPref("perspectives.quorum_thresh", full_quorum_thresh);
-        Perspectives.root_prefs.setBoolPref(pref_string_use_def_notary, true);
+        Perspectives.root_prefs.setIntPref ("perspectives.quorum_thresh", full_quorum_thresh);
+        Perspectives.root_prefs.setBoolPref(pref_string_use_def_notary  , true              );
 
         qint = Perspectives.getQuorumAsInt();
-        assert(qint === Perspectives.getNotaryList().length, full_quorum_thresh +
-                "% Quorum Threhold with many notaries returns a full required quorum count (got " + qint + ").");
+        assert(qint === Perspectives.getNotaryList().length, full_quorum_thresh + "% Quorum Threhold with many notaries returns a full required quorum count (got " + qint + ").");
 
     }
     finally {
-        Perspectives.root_prefs.setIntPref("perspectives.quorum_thresh", orig_thresh);
-        Perspectives.root_prefs.setCharPref(pref_string_extra_notaries, orig_extra_notaries);
-        Perspectives.root_prefs.setBoolPref(pref_string_use_def_notary, orig_use_default_notaries);
+        Perspectives.root_prefs.setIntPref ("perspectives.quorum_thresh", orig_thresh              );
+        Perspectives.root_prefs.setCharPref(pref_string_extra_notaries  , orig_extra_notaries      );
+        Perspectives.root_prefs.setBoolPref(pref_string_use_def_notary  , orig_use_default_notaries);
     }
 
     write_string("Finished");
@@ -693,18 +653,15 @@ JaJ2Lw7kRVMCAwEAAQ==\
 // Originally this was found because get_quorum_duration() was passing
 // parameters to oldest_most_recent() in the wrong order,
 // making certain valid keys show up as not trusted.
-
 function quorum_oldkey() {
-
     var keybc = "bc:7f:b1:15:25:4e:7b:fb:93:83:ac:5c:26:df:f7:00"; //the key we're looking for
     var keybd = "bd:7f:b1:15:25:4e:7b:fb:93:83:ac:5c:26:df:f7:00";
 
-    var cur_time = 200 * 24 * 3600; //i.e. 200 days since epoch
-    var max_stale_sec = 2 * 24 * 3600; // 2 days
-    var q_required = 1;
-    var q_duration_required = 100 * 24 * 3600;
-
-    var foundkey_start = 100;
+    var cur_time            = 200 * DAY_SECS; //i.e. 200 days since epoch
+    var max_stale_sec       =   2 * DAY_SECS;
+    var q_required          =   1;
+    var q_duration_required = 100 * DAY_SECS;
+    var foundkey_start      = 100;
 
     // see testcase description inside assert() calls, below, for explanations
     // of array contents.
@@ -713,7 +670,7 @@ function quorum_oldkey() {
             "obs": [
                 {"key": keybc,
                     "timestamps": [
-                        { "start": foundkey_start * 24 * 3600, "end": (foundkey_start + q_duration_required) * 24 * 3600  }
+                        { "start": foundkey_start * DAY_SECS, "end": (foundkey_start + q_duration_required) * DAY_SECS }
                     ] }
             ]
         }
@@ -724,7 +681,7 @@ function quorum_oldkey() {
             "obs": [
                 {"key": keybc,
                     "timestamps": [
-                        { "start": foundkey_start * 24 * 3600, "end": (foundkey_start + q_duration_required) * 24 * 3600  }
+                        { "start": foundkey_start * DAY_SECS, "end": (foundkey_start + q_duration_required) * DAY_SECS }
                     ] }
             ]
         },
@@ -733,7 +690,7 @@ function quorum_oldkey() {
                 { "key": keybd,
                     // start date of 10 is arbitrary
                     "timestamps": [
-                        { "start": 10 * 24 * 3600, "end": foundkey_start * 24 * 3600  }
+                        { "start": 10 * DAY_SECS, "end": foundkey_start * DAY_SECS }
                     ] }
             ]
         }
@@ -745,7 +702,7 @@ function quorum_oldkey() {
             "obs": [
                 { "key": keybd,
                     "timestamps": [
-                        { "start": 10 * 24 * 3600, "end": (foundkey_start - 1 ) * 24 * 3600  }
+                        { "start": 10 * DAY_SECS, "end": (foundkey_start - 1 ) * DAY_SECS }
                     ] }
             ]
         },
@@ -753,7 +710,7 @@ function quorum_oldkey() {
             "obs": [
                 {"key": keybc,
                     "timestamps": [
-                        { "start": foundkey_start * 24 * 3600, "end": (foundkey_start + q_duration_required) * 24 * 3600  }
+                        { "start": foundkey_start * DAY_SECS, "end": (foundkey_start + q_duration_required) * DAY_SECS }
                     ] }
             ]
         }
@@ -762,40 +719,31 @@ function quorum_oldkey() {
     write_string("Starting oldkey quorum tests...");
     var quorum_duration = 0;
 
-    quorum_duration = Pers_client_policy.get_quorum_duration(keybc, results_oldkey,
-            q_required, max_stale_sec, cur_time);
-    assert((quorum_duration >= q_duration_required),
-            "1) Old key within duration accepted");
+    quorum_duration = Pers_client_policy.get_quorum_duration(keybc, results_oldkey, q_required, max_stale_sec, cur_time);
+    assert(quorum_duration >= q_duration_required    , "1) Old key within duration accepted");
 
-    quorum_duration = Pers_client_policy.get_quorum_duration(keybc, results_oldkey,
-            q_required, max_stale_sec, cur_time);
-    assert((quorum_duration <= (q_duration_required * 2)),
-            "2) Old key outside duration rejected");
+    quorum_duration = Pers_client_policy.get_quorum_duration(keybc, results_oldkey, q_required, max_stale_sec, cur_time);
+    assert(quorum_duration <= q_duration_required * 2, "2) Old key outside duration rejected");
 
-    quorum_duration = Pers_client_policy.get_quorum_duration(keybc, results_oldkey_notpushed,
-            q_required, max_stale_sec, cur_time);
-    assert((quorum_duration > q_duration_required),
-            "3) Same as (1), but an unrelated key result ends on day target key begins");
+    quorum_duration = Pers_client_policy.get_quorum_duration(keybc, results_oldkey_notpushed, q_required, max_stale_sec, cur_time);
+    assert(quorum_duration > q_duration_required     , "3) Same as (1), but an unrelated key result ends on day target key begins");
 
-    quorum_duration = Pers_client_policy.get_quorum_duration(keybc, results_oldkey_pushedout,
-            q_required, max_stale_sec, cur_time);
-    assert((quorum_duration > q_duration_required),
-            "4) Same as (1), but an unrelated key result ends the day before target key begins");
+    quorum_duration = Pers_client_policy.get_quorum_duration(keybc, results_oldkey_pushedout, q_required, max_stale_sec, cur_time);
+    assert(quorum_duration > q_duration_required     , "4) Same as (1), but an unrelated key result ends the day before target key begins");
 
     write_string("Finished");
 }
 
 function notary_parsing() {
-
     var pref_string_extra_notaries = "perspectives.additional_notary_list";
     var pref_string_use_def_notary = "perspectives.use_default_notary_list";
-    var orig_extra_notaries = null;
-    var orig_use_default_notaries = null;
+    var orig_extra_notaries        = null;
+    var orig_use_default_notaries  = null;
 
     write_string("Starting notary parsing tests.");
 
     // save preferences so we can restore state afterward
-    orig_extra_notaries = Perspectives.root_prefs.getCharPref(pref_string_extra_notaries);
+    orig_extra_notaries       = Perspectives.root_prefs.getCharPref(pref_string_extra_notaries);
     orig_use_default_notaries = Perspectives.root_prefs.getBoolPref(pref_string_use_def_notary);
 
     if(orig_extra_notaries === null || orig_use_default_notaries === null) {
@@ -806,15 +754,14 @@ function notary_parsing() {
     }
 
     // set preferences to known state so we can run our tests in a controlled env
-    Perspectives.root_prefs.setCharPref(pref_string_extra_notaries, "");
+    Perspectives.root_prefs.setCharPref(pref_string_extra_notaries, ""  );
     Perspectives.root_prefs.setBoolPref(pref_string_use_def_notary, true);
 
-    var notaries = "";
+    var notaries     = "";
     var count_before = 0;
 
     notaries = Perspectives.getNotaryList();
-    assert(notaries.length > 0,
-            "Default notary list gets us > 0 notaries (we have " + notaries.length + ")");
+    assert(notaries.length > 0, "Default notary list gets us > 0 notaries (we have " + notaries.length + ")");
 
     var nonsense_notary = "aaaaaaaa";
     // clear the extra notaries list to be sure what we're dealing with
@@ -822,8 +769,7 @@ function notary_parsing() {
     count_before = Perspectives.getNotaryList().length;
     Perspectives.root_prefs.setCharPref(pref_string_extra_notaries, nonsense_notary);
     notaries = Perspectives.getNotaryList();
-    assert(notaries.length === count_before,
-            "Trying to save a garbled notary string doesn't work.");
+    assert(notaries.length === count_before, "Trying to save a garbled notary string doesn't work.");
 
     // TODO bad method of declaration?
     // We need newlines after the server name and 'BEGIN PUBLIC KEY' lines
@@ -841,8 +787,7 @@ JaJ2Lw7kRVMCAwEAAQ==\
     count_before = Perspectives.getNotaryList().length;
     Perspectives.root_prefs.setCharPref(pref_string_extra_notaries, notary_dupe);
     notaries = Perspectives.getNotaryList();
-    assert_fixme(notaries.length === count_before,
-            "Trying to add a duplicate notary doesn't work.");
+    assert_fixme(notaries.length === count_before, "Trying to add a duplicate notary doesn't work.");
     //FIXME - note: this currently fails. We want to write code to prevent dupes.
 
     var sparse_notary = "perspectivesFAKETEST.networknotary.org:8080\n\n\n\n\
@@ -858,19 +803,16 @@ JaJ2Lw7kRVMCAwEAAQ==\n\n\n\n\
     count_before = Perspectives.getNotaryList().length;
     Perspectives.root_prefs.setCharPref(pref_string_extra_notaries, sparse_notary);
     notaries = Perspectives.getNotaryList();
-    assert(notaries.length === (count_before + 1),
-            "Trying to add a notary with many blank lines works.");
+    assert(notaries.length === count_before + 1, "Trying to add a notary with many blank lines works.");
 
-    // -------------
     // restore state once we're finished all of the tests
-    Perspectives.root_prefs.setCharPref(pref_string_extra_notaries, orig_extra_notaries);
+    Perspectives.root_prefs.setCharPref(pref_string_extra_notaries, orig_extra_notaries      );
     Perspectives.root_prefs.setBoolPref(pref_string_use_def_notary, orig_use_default_notaries);
 
     write_string("Finished");
 }
 
 function notary_replies() {
-
     write_string("Starting notary reply tests");
 
     //TODO: overwrite, or ignore?
@@ -882,7 +824,8 @@ function notary_replies() {
 }
 
 function run_tests() {
-    if(typeof Perspectives != "undefined") {
+    // check if we are running with chrome privileges or from within browser
+    if(typeof Components.classes !== "undefined") {
         // print debug info to console by default
         Pers_debug.d_print_flags["error"] = true;
 
@@ -909,18 +852,40 @@ function run_tests() {
         }
     } else {
         error("You are probably running the test from browser context, but you need to run it from chrome context. Use 'make test' to to build and install the Perspectives extension and open chrome://perspectives/content/test/test.html");
+
+        try {
+            //Perspectives.init_data();
+
+            clear();
+            meta_tests();
+            client_sanity();
+            //nonrouted_ips();
+            quorum_basics();
+            quorum_oldkey();
+            //notary_parsing();
+            notary_replies();
+
+            write_string("Finished: " + g_pass_count + "/" + g_test_count + " successes, "
+                    + g_fail_count + " failures. ");
+            if(g_test_count != (g_pass_count + g_fail_count)) {
+                error("Count totals did not match!");
+            }
+        } catch(e) {
+            alert(e);
+            error("tests did not finish: '" + e + "'.");
+        }
     }
 }
 </script>
 </head>
-<body>
-<img src="../img/default.png" TITLE="Perspectives Logo"/>
-<input type="button" value="Run Tests" onclick="run_tests()">
 
-<p> Run with firebug or the web console to see detailed test output if something fails.</p>
+<body>
+    <img src="../img/default.png" title="Perspectives Logo"/>
+    <input type="button" value="Run Tests" onclick="run_tests();">
 
-<h2> Results: </h2>
+    <p>Run with firebug or the web console to see detailed test output if something fails.</p>
 
-<div id="results"></div>
+    <h2>Results: </h2>
+    <div id="results"></div>
 </body>
 </html>

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/perspectives-extension.git



More information about the Pkg-mozext-commits mailing list