# # # add_dir "tests/generating_and_extracting_keys_and_certs" # # add_file "tests/generating_and_extracting_keys_and_certs/__driver__.lua" # content [4843c3306f39dfbb7d24124a5de4b72d6dd30324] # # patch "tester.lua" # from [50ffae363ad71070d3a5f8dfd6b5305aa352e2f3] # to [b21c6fd81f597bd8ccf79fe38dbaf8ee562a58bc] # # patch "tests/basic_invocation_and_options/__driver__.lua" # from [f1ffe6e2a14a8e4c212a3382714fe87986d3ac55] # to [2f5545530879be900feceb93e3434485202e8137] # # patch "tests/importing_a_file/__driver__.lua" # from [2d945824ebdb4b72b0273d3df96f286e234029da] # to [11acad99f3b011341763501ced45855ee667ad39] # # patch "tests/scanning_trees/__driver__.lua" # from [db3cde364e0388943bbc59ddb111c9a7b06abcf2] # to [8224a84daabe4f3a86a0c722bd9d8c2a7ec98436] # # patch "testsuite.at" # from [dee883a62b027f45d1b7b0e455394a56688780dd] # to [fcd9860e4d00a6145cd66cc138082ae397c0ec1a] # # patch "testsuite.lua" # from [1d440035999712d7b144f7b62327138977f16427] # to [b1c28cb93b9cfe2ad7b1e76ba0320c40a3d941a7] # ============================================================ --- tests/generating_and_extracting_keys_and_certs/__driver__.lua 4843c3306f39dfbb7d24124a5de4b72d6dd30324 +++ tests/generating_and_extracting_keys_and_certs/__driver__.lua 4843c3306f39dfbb7d24124a5de4b72d6dd30324 @@ -0,0 +1,74 @@ + +mtn_setup() + +tkey = "address@hidden" + +-- fail to enter a passphrase +check(cmd(mtn("genkey", tkey)), 1, false, false) + +-- fail to enter passphrase twice +check(cmd(mtn("genkey", tkey)), 1, false, false, tkey .. "\n") + +-- generate a new key +check(cmd(mtn("genkey", tkey)), 0, false, false, tkey .. "\n" .. tkey .. "\n") + +-- check key exists +check(cmd(mtn("ls", "keys")), 0, true) +check(cmd(grep(tkey, "stdout")), 0, false) + +-- check globbing on name works +check(cmd(mtn("ls", "keys", "happy*")), 0, true) +check(cmd(grep(tkey, "stdout")), 0, false) + +-- check globbing on bogus name misses key +check(cmd(mtn("ls", "keys", "burp*")), 0, true, false) +check(cmd(qgrep(tkey, "stdout")), 1) + + +-- second section, check making certs with this key + +writefile("input.txt", "blah blah blah\n") + +check(cmd(mtn("add", "input.txt")), 0, false, false) +check(cmd(commit()), 0, false, false) +tsha = base_revision() +check(cmd(mtn("--key", tkey, "cert", tsha, "color", "pink")), 0, false, false) +check(cmd(mtn("ls", "certs", tsha)), 0, true) +check(cmd(qgrep("pink", "stdout"))) + +check(cmd(mtn("--key", tkey, "cert", tsha, "color")), 0, false, false, "yellow\n") +check(cmd(mtn("ls", "certs", tsha)), 0, true, false) +check(cmd(qgrep("pink", "stdout"))) +check(cmd(qgrep("yellow", "stdout"))) + +-- third section, keys with a + in the user portion work, keys with a +-- + in the domain portion don't work. +goodkey = "address@hidden" + +check(cmd(mtn("genkey", goodkey)), 0, false, false, string.rep(goodkey .. "\n", 2)) +--exists +check(cmd(mtn("ls", "keys")), 0, true) +-- remember '+' is a special character for regexes +check(cmd(qgrep(string.gsub(goodkey, "+", "\\+"), "stdout"))) + +-- bad keys fail +badkey1 = "address@hidden" +check(cmd(mtn("genkey", badkey1)), 1, false, false, string.rep(badkey1 .. "\n", 2)) +badkey2 = "address@hidden" +check(cmd(mtn("genkey", badkey2)), 1, false, false, string.rep(badkey2 .. "\n", 2)) + +-- fourth section, keys with all supported characters (for the user portion) +-- in the user portion work, keys with the same in the domain portion don't +-- work. +goodkey = "address@hidden" + +check(cmd(mtn("genkey", goodkey)), 0, false, false, string.rep(goodkey .. "\n", 2)) +--exists +check(cmd(mtn("ls", "keys")), 0, true) +check(cmd(qgrep(string.gsub(goodkey, "+", "\\+"), "stdout"))) + +-- bad keys fail +badkey1 = "address@hidden" +check(cmd(mtn("genkey", badkey1)), 1, false, false, string.rep(badkey1 .. "\n", 2)) +badkey2 = "address@hidden" +check(cmd(mtn("genkey", badkey2)), 1, false, false, string.rep(badkey2 .. "\n", 2)) ============================================================ --- tester.lua 50ffae363ad71070d3a5f8dfd6b5305aa352e2f3 +++ tester.lua b21c6fd81f597bd8ccf79fe38dbaf8ee562a58bc @@ -64,7 +64,7 @@ return ret end -function prepare(first, ...) +function cmd(first, ...) if type(first) == "string" then test_log:write("\n", first, " ", table.concat(arg, " "), "\n") return function () return execute(first, unpack(arg)) end @@ -72,7 +72,7 @@ test_log:write("\n ", table.concat(arg, " "), "\n") return function () return first(unpack(arg)) end else - error("prepare() called with argument of unknown type " .. type(first), 2) + error("cmd() called with argument of unknown type " .. type(first), 2) end end @@ -99,11 +99,38 @@ return docmp, left, right end +function grep(...) + local dogrep = function (flags, what, where) + if where == nil and string.sub(flags, 1, 1) ~= "-" then + where = what + what = flags + flags = "" + end + local quiet = string.find(flags, "q") ~= nil + local reverse = string.find(flags, "v") ~= nil + local out = 1 + for line in io.lines(where) do + local matched = regex.search(what, line) + if reverse then matched = not matched end + if matched then + if not quiet then print(line) end + out = 0 + end + end + return out + end + return dogrep, unpack(arg) +end + -- std{out,err} can be: -- * false: ignore -- * true: ignore, copy to stdout -- * string: check that it matches the contents -- * nil: must be empty +-- stdin can be: +-- * true: use existing "stdin" file +-- * nil, false: empty input +-- * string: contents of string function check(func, ret, stdout, stderr, stdin) if ret == nil then ret = 0 end if stdin ~= true then @@ -186,8 +213,15 @@ test_log = io.open(tlog, "w") test_log:write("Test number ", i, ", ", shortname, "\n") - local driver = srcdir .. "/" .. testname .. "/__driver__.lua" - local r,e = xpcall(loadfile(driver), debug.traceback) + local driverfile = srcdir .. "/" .. testname .. "/__driver__.lua" + local driver, e = loadfile(driverfile) + local r + if driver == nil then + r = false + e = "Could not load driver file " .. driverfile .. " .\n" .. e + else + r,e = xpcall(driver, debug.traceback) + end if r then P("ok\n") clean_test_dir(testname) ============================================================ --- tests/basic_invocation_and_options/__driver__.lua f1ffe6e2a14a8e4c212a3382714fe87986d3ac55 +++ tests/basic_invocation_and_options/__driver__.lua 2f5545530879be900feceb93e3434485202e8137 @@ -1,14 +1,14 @@ mtn_setup() +check(cmd(raw_mtn("--norc")), 2, false) +check(cmd(raw_mtn("--help")), 2, false) +check(cmd(raw_mtn("--version")), 0, false) +check(cmd(raw_mtn("--nostd", "--help")), 2, false) +check(cmd(raw_mtn("--norc", "--help")), 2, false) +check(cmd(raw_mtn("--debug", "--help")), 2, false, false) +check(cmd(raw_mtn("--quiet", "--help")), 2, false) +check(cmd(raw_mtn("--db=foo.db", "--help")), 2, false) +check(cmd(raw_mtn("--db", "foo.db", "--help")), 2, false) +check(cmd(raw_mtn("address@hidden", "--help")), 2, false) +check(cmd(raw_mtn("--key", "address@hidden", "--help")), 2, false) -check(prepare(raw_mtn("--norc")), 2, false) -check(prepare(raw_mtn("--help")), 2, false) -check(prepare(raw_mtn("--version")), 0, false) -check(prepare(raw_mtn("--nostd", "--help")), 2, false) -check(prepare(raw_mtn("--norc", "--help")), 2, false) -check(prepare(raw_mtn("--debug", "--help")), 2, false, false) -check(prepare(raw_mtn("--quiet", "--help")), 2, false) -check(prepare(raw_mtn("--db=foo.db", "--help")), 2, false) -check(prepare(raw_mtn("--db", "foo.db", "--help")), 2, false) -check(prepare(raw_mtn("address@hidden", "--help")), 2, false) -check(prepare(raw_mtn("--key", "address@hidden", "--help")), 2, false) ============================================================ --- tests/importing_a_file/__driver__.lua 2d945824ebdb4b72b0273d3df96f286e234029da +++ tests/importing_a_file/__driver__.lua 11acad99f3b011341763501ced45855ee667ad39 @@ -1,13 +1,13 @@ mtn_setup() writefile("importme", "version 0 of test file\n") -check(prepare(sha1("importme")), 0, true) +check(cmd(sha1("importme")), 0, true) tsha = string.gsub(readfile("stdout"), "%s*$", "") +check(cmd(mtn("add", "importme")), 0, false, false) +check(cmd(commit()), 0, false, false) +check(cmd(mtn("automate", "get_file", tsha)), 0, true) +check(cmd(canonicalize("stdout"))) +check(cmd(cmp("importme", "stdout")), 0, false) -check(prepare(mtn("add", "importme")), 0, false, false) -check(prepare(commit()), 0, false, false) -check(prepare(mtn("automate", "get_file", tsha)), 0, true) -check(prepare(canonicalize("stdout"))) -check(prepare(cmp("importme", "stdout")), 0, false) ============================================================ --- tests/scanning_trees/__driver__.lua db3cde364e0388943bbc59ddb111c9a7b06abcf2 +++ tests/scanning_trees/__driver__.lua 8224a84daabe4f3a86a0c722bd9d8c2a7ec98436 @@ -7,10 +7,10 @@ writefile("foo/testfile1", "version 0 of second test file\n") writefile("foo/bar/testfile2", "version 0 of third test file\n") getfile("manifest") -check(prepare(canonicalize("manifest"))) +check(cmd(canonicalize("manifest"))) +check(cmd(mtn("add", "testfile0", "foo")), 0, false, false) +check(cmd(commit("testbranch")), 0, false, false) +check(cmd(mtn("automate", "get_manifest_of")), 0, true) +check(cmd(canonicalize("stdout"))) +check(cmd(cmp("stdout", "manifest")), 0, false) -check(prepare(mtn("add", "testfile0", "foo")), 0, false, false) -check(prepare(commit("testbranch")), 0, false, false) -check(prepare(mtn("automate", "get_manifest_of")), 0, true) -check(prepare(canonicalize("stdout"))) -check(prepare(cmp("stdout", "manifest")), 0, false) ============================================================ --- testsuite.at dee883a62b027f45d1b7b0e455394a56688780dd +++ testsuite.at fcd9860e4d00a6145cd66cc138082ae397c0ec1a @@ -546,10 +546,10 @@ # include all the sub-tests we're going to use -m4_include(tests/t_null.at) -m4_include(tests/t_scan.at) -m4_include(tests/t_import.at) -m4_include(tests/t_genkey.at) +m4_include(tests/t_null.at)# +m4_include(tests/t_scan.at)# +m4_include(tests/t_import.at)# +m4_include(tests/t_genkey.at)# m4_include(tests/t_unidiff.at) m4_include(tests/t_persist_phrase.at) m4_include(tests/t_versions.at) ============================================================ --- testsuite.lua 1d440035999712d7b144f7b62327138977f16427 +++ testsuite.lua b1c28cb93b9cfe2ad7b1e76ba0320c40a3d941a7 @@ -38,12 +38,20 @@ getstdfile("tests/min_hooks.lua", "min_hooks.lua") port = math.random(20000, 50000) - check(prepare(mtn("db", "init")), 0, false, false) - check(prepare(mtn("read", "test_keys")), 0, false, false) - check(prepare(mtn("setup", "--branch=testbranch", ".")), 0, false, false) + check(cmd(mtn("db", "init")), 0, false, false) + check(cmd(mtn("read", "test_keys")), 0, false, false) + check(cmd(mtn("setup", "--branch=testbranch", ".")), 0, false, false) os.remove("test_keys") end +function base_revision() + return string.gsub(readfile("_MTN/revision"), "%s*$", "") +end + +function qgrep(what, where) + return grep("-q", what, where) +end + function canonicalize(filename) local func = function (fn) local f = io.open(filename, "rb") @@ -73,3 +81,4 @@ table.insert(tests, "tests/basic_invocation_and_options") table.insert(tests, "tests/scanning_trees") table.insert(tests, "tests/importing_a_file") +table.insert(tests, "tests/generating_and_extracting_keys_and_certs")