[Pkg-mozext-commits] [perspectives-extension] 11/22: Pers_client_policy - Fix use of quorum_size for key_weakly_seen_by_quorum()

David Prévot taffit at moszumanska.debian.org
Mon May 12 17:17:43 UTC 2014


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

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

commit c7ca588bbbdda212a403d045ce8fb2aee6000cfa
Author: Dave Schaefer <dave.schaefer at gmail.com>
Date:   Mon May 5 22:10:19 2014 -0600

    Pers_client_policy - Fix use of quorum_size for key_weakly_seen_by_quorum()
    
    quorum_size should actually be used in the calculation.
    Now the function does what the docs say it should.
    Note the new check is actually less strict -
    earlier it only returned true if the key was seen by *all* notaries.
    But now it is correct.
    
    Add unit tests for this function too.
---
 plugin/chrome/content/client_policy.js | 23 +++++++++++-----
 test/test.html                         | 49 ++++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+), 6 deletions(-)

diff --git a/plugin/chrome/content/client_policy.js b/plugin/chrome/content/client_policy.js
index 618ef03..c5bccfa 100644
--- a/plugin/chrome/content/client_policy.js
+++ b/plugin/chrome/content/client_policy.js
@@ -222,6 +222,12 @@ key_weakly_seen_by_quorum : function(test_key, results, quorum_size, check_lengt
 		return false;
 	}
 
+	if (quorum_size < 1) {
+		Pers_debug.d_print("error",
+				"Quorum size must be a positive integer when testing for weakly seen certificates!");
+		return false;
+	}
+
  	var cutoff_sec = Pers_util.get_unix_time() - Pers_util.DAY2SEC(check_length); 
 
 	if (cutoff_sec < 1) {
@@ -230,8 +236,9 @@ key_weakly_seen_by_quorum : function(test_key, results, quorum_size, check_lengt
 		return false;
 	}
 
+	var seen_count = 0;
+
 	for(var i = 0; i < results.length; i++) {
-		var seen = false;  
 		for(var j = 0; j < results[i].obs.length; j++) { 
 			if(results[i].obs[j].key != test_key) { 
 				continue; 
@@ -239,16 +246,20 @@ key_weakly_seen_by_quorum : function(test_key, results, quorum_size, check_lengt
 			for(var k = 0; k < results[i].obs[j].timestamps.length; k++) { 
 				var ts = results[i].obs[j].timestamps[k]; 
 				if (ts.end >= cutoff_sec) { 
-					seen = true; 
+					seen_count += 1;
 					break; 
 				}  
 			}
 		}
-		if(!seen) { 
-			return false; 
-		} 
+		if (seen_count >= quorum_size) {
+			return true;
+		}
 	}
-	return true; 
+	if (seen_count >= quorum_size) {
+			return true;
+	}
+
+	return false;
 }, 
 
 
diff --git a/test/test.html b/test/test.html
index 1a7b24c..d4d4bf6 100644
--- a/test/test.html
+++ b/test/test.html
@@ -164,6 +164,22 @@ 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 old_start = Pers_util.get_unix_time() - Pers_util.DAY2SEC(days_last_seen - duration);
+
+ var second_result_list = [
+     { "server" : "test1:8080",
+       "obs" : [  { "key" : key,
+        "timestamps" : [ { "start" : old_start , "end" : old_end  } ] } ]
+     },
+     { "server" : "test2:8080",
+       "obs" : [  { "key" : key,
+        "timestamps" : [ { "start" : old_start , "end" : old_end  } ] } ]
+     }
+   ];
+
  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");
@@ -173,6 +189,39 @@ function client_sanity() {
           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.");
+
 
 }
 

-- 
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