monotone-commits-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Monotone-commits-diffs] net.venge.monotone: 8e04aff40498e10b8b9f7a63896


From: code
Subject: [Monotone-commits-diffs] net.venge.monotone: 8e04aff40498e10b8b9f7a63896dd78b03ea6526
Date: Sat, 22 Dec 2012 21:18:49 +0100 (CET)

revision:            8e04aff40498e10b8b9f7a63896dd78b03ea6526
date:                2012-12-22T20:18:02
author:              Richard Hopkins <address@hidden>
branch:              net.venge.monotone
changelog:
Tweak default 'accept_testresult_change' hook to use key hashes in hex form for 
'wanted-testresults'

A new test has also been added along with updating the documentation.

The current signature for 'accept_testresult_change' has the signing key
in binary form rather than hex form (which we use elsewhere on stdout and
when communicating with Lua; e.g. `mtn ls keys` and 'get_revision_cert_trust').

Lets keep this signature to keep existing clients on 1.x happy in case they
are using this hook and provide their own definition. For others who haven't
provided their own 'accept_testresult_change' definition we can tweak ours a
bit for ease of use as was pointed out on the mailing list recently;
"How does 'mtn testresult' work?".

If we're changing the signature for 2.x maybe we could expand it allow
key name and hash instead of just hash like we do for 'read-permissions'.

manifest:
format_version "1"

new_manifest [f1c5d810e3a3b7ac607c7b8cfbb3f261089214af]

old_revision [3cde6aeb8bb73c45c9d2e8cc278bbe80a2a62614]

add_dir "test/func/wanted_permissions"

add_file "test/func/wanted_permissions/__driver__.lua"
 content [670d2df947c1e878dc53530808a87b5a2647fe87]

patch "doc/monotone.texi"
 from [c3dd09cadd8e773525f3dacb989f65af4cf18bf1]
   to [282fbb9c5b2fa57460fa9835db9664c1559303b9]

patch "src/std_hooks.lua"
 from [a2ec9556e5a0d3b3cc47633b14ad226b5c829925]
   to [6b28a0546b7c608cc23ba36e901ed532022ad5a2]
============================================================
--- doc/monotone.texi	c3dd09cadd8e773525f3dacb989f65af4cf18bf1
+++ doc/monotone.texi	282fbb9c5b2fa57460fa9835db9664c1559303b9
@@ -12235,18 +12235,19 @@ @subsection Trust Evaluation Hooks
 This hook is used by the update algorithm to determine whether a
 change in test results between update source and update target is
 acceptable. The hook is called with two tables, each of which maps a
-signing key -- representing a particular testsuite -- to a boolean
-value indicating whether or not the test run was successful. The
+signing key hash -- representing a particular testsuite -- to a boolean
+value indicating whether or not the test run was successful (calculated
+from the @code{testresult} cert). The
 function should return @code{true} if you consider an update from the
 version carrying the @var{old_results} to the version carrying the
 @var{new_results} to be acceptable.
 
 The default definition of this hook returns @code{true} if
 @file{_MTN/wanted-testresults} does not exist. Otherwise, the file
-should contain a list of signing key ids. The hook returns @code{false}
-if a listed signing key id is present in both @var{old_results} and
address@hidden, and @var{old_results} is @code{true} but
address@hidden is @code{false}; otherwise it returns @code{true}.
+should contain a list of signing key hashes in lowercase. The hook returns @code{false}
+if a listed signing key hash is present in both @var{old_results} and
address@hidden, with the value @code{true} in @var{old_results}
+and @code{false} in @var{new_results}; otherwise it returns @code{true}.
 
 @end ftable
 
============================================================
--- src/std_hooks.lua	a2ec9556e5a0d3b3cc47633b14ad226b5c829925
+++ src/std_hooks.lua	6b28a0546b7c608cc23ba36e901ed532022ad5a2
@@ -419,7 +419,16 @@ end
    return true
 end
 
-function accept_testresult_change(old_results, new_results)
+-- http://snippets.luacode.org/?p=snippets/String_to_Hex_String_68
+function hex_dump(str,spacer)
+   return (string.gsub(str,"(.)",
+      function (c)
+         return string.format("%02x%s",string.byte(c), spacer or "")
+      end)
+   )
+end
+
+function accept_testresult_change_hex(old_results, new_results)
    local reqfile = io.open("_MTN/wanted-testresults", "r")
    if (reqfile == nil) then return true end
    local line = reqfile:read()
@@ -440,6 +449,21 @@ end
    return true
 end
 
+function accept_testresult_change(old_results, new_results)
+   -- Hex encode each of the key hashes to match those in 'wanted-testresults'
+   local old_results_hex = {}
+   for k, v in pairs(old_results) do
+	old_results_hex[hex_dump(k)] = v
+   end
+
+   local new_results_hex = {}
+   for k, v in pairs(new_results) do
+      new_results_hex[hex_dump(k)] = v
+   end
+
+   return accept_testresult_change_hex(old_results_hex, new_results_hex)
+end
+
 -- merger support
 
 -- Fields in the mergers structure:
============================================================
--- /dev/null	
+++ test/func/wanted_permissions/__driver__.lua	670d2df947c1e878dc53530808a87b5a2647fe87
@@ -0,0 +1,79 @@
+-- Create some revisions then attach 'testresult' certs to them.
+-- `mtn update` must not update to a "fail" revision from a "pass"
+-- revision.
+
+-- This is handled by our default definition of 'accept_testresult_change'
+-- which reads '_MTN/wanted-testresults'.
+
+mtn_setup()
+
+addfile("numbers.txt", 1)
+commit()
+good_rev = base_revision()
+
+writefile("numbers.txt", 2)
+commit()
+bad_rev = base_revision()
+
+check(mtn("update", "-r", good_rev), 0, false, false)
+
+check(mtn("testresult", good_rev, "pass"), 0, false, false)
+check(mtn("testresult", bad_rev, "fail"), 0, false, false)
+
+-- Now write out our default 'accept_testresult_change' definition
+-- from 'std_hooks.lua'.
+writefile("_MTN/monotonerc", [[
+-- http://snippets.luacode.org/?p=snippets/String_to_Hex_String_68
+function hex_dump(str,spacer)
+   return (string.gsub(str,"(.)",
+      function (c)
+         return string.format("%02x%s",string.byte(c), spacer or "")
+      end)
+   )
+end
+
+function accept_testresult_change_hex(old_results, new_results)
+   local reqfile = io.open("_MTN/wanted-testresults", "r")
+   if (reqfile == nil) then return true end
+   local line = reqfile:read()
+   local required = {}
+   while (line ~= nil)
+   do
+      required[line] = true
+      line = reqfile:read()
+   end
+   io.close(reqfile)
+   for test, res in pairs(required)
+   do
+      if old_results[test] == true and new_results[test] ~= true
+      then
+         return false
+      end
+   end
+   return true
+end
+
+function accept_testresult_change(old_results, new_results)
+   -- Hex encode each of the key hashes to match those in 'wanted-testresults'
+   local old_results_hex = {}
+   for k, v in pairs(old_results) do
+	old_results_hex[hex_dump(k)] = v
+   end
+
+   local new_results_hex = {}
+   for k, v in pairs(new_results) do
+      new_results_hex[hex_dump(k)] = v
+   end
+
+   return accept_testresult_change_hex(old_results_hex, new_results_hex)
+end
+]])
+writefile("_MTN/wanted-testresults", "46ec58576f9e4f34a9eede521422aa5fd299dc50\n")
+
+check(mtn("update", "--rcfile", "_MTN/monotonerc"), 0, false, true)
+-- stderr now looks something like.
+-- mtn: updating along branch '$BRANCH'
+-- mtn: already up to date at $good_rev
+check(qgrep(good_rev, "stderr"))
+check(base_revision() == good_rev)
+

reply via email to

[Prev in Thread] Current Thread [Next in Thread]