# # # delete "test_hooks.lua" # # add_dir "tests/signature_round_trip" # # add_file "tests/signature_round_trip/__driver__.lua" # content [47afde61e285df6199e413c59a45e435f269f227] # # patch "Makefile.am" # from [dfaa00d12056b5dc7a53ea779ba605d890669470] # to [fbd8a4f969f93fad2158db91ca84782b0665f7f8] # # patch "README.encapsulation" # from [79dd1f01334e681277c7a3b715d5a8b74fca258c] # to [dc81088d6bf35555821f076556a68dbdce3b15be] # # patch "keys.cc" # from [0aca0eebd8f2edd07c9b8a4382f37c2bd39398b1] # to [af15a184ec33c8df05cfb54b3db515d66ba47479] # # patch "lua-testsuite.lua" # from [e54e556ba16227039d6f464a138a43eb400d1623] # to [b3c5868689f9c7ba3c3c85478eb10b59f1ceeb6c] # # patch "lua_hooks.cc" # from [26dbfb8306a7b7b4871f61877c7fd0f72abadfdd] # to [5f4045fd523ea215bfc705555b03c4f2dbd38b45] # # patch "lua_hooks.hh" # from [a03b6a9de65a23204776355184e50a093f65f649] # to [2604a4a3a5244ba91c7b74a60a5bb762b114ddc5] # ============================================================ --- tests/signature_round_trip/__driver__.lua 47afde61e285df6199e413c59a45e435f269f227 +++ tests/signature_round_trip/__driver__.lua 47afde61e285df6199e413c59a45e435f269f227 @@ -0,0 +1,27 @@ +mtn_setup() + +-- create a revision to apply our fake cert to +addfile("testfile", "a file\n") +commit() +rev = base_revision() + +-- apply a cert to that revision +check(mtn("cert", rev, "signature-check", "test string to sign"), + 0, false, false) + +-- check it +value, goodsig = certvalue(rev, "signature-check") +check(value == "test string to sign") +check(goodsig == "ok") + +-- change the cert value with raw database ops +check(mtn("db", "execute", + 'update revision_certs' .. + ' set value = "test string to sign ...with a lie"' .. + ' where name = "signature-check"'), + 0, false, false) + +-- certvalue should now report a bad signature +value, goodsig = certvalue(rev, "signature-check") +check(value == "test string to sign ...with a lie") +check(goodsig == "bad") ============================================================ --- Makefile.am dfaa00d12056b5dc7a53ea779ba605d890669470 +++ Makefile.am fbd8a4f969f93fad2158db91ca84782b0665f7f8 @@ -346,7 +346,6 @@ unit_tester_SOURCES = $(UNIT_TEST_SOURCE nodist_mtn_SOURCES = std_hooks.c schema.c unit_tester_SOURCES = $(UNIT_TEST_SOURCES) $(UNIT_TEST_SRC_SUPPORT) -nodist_unit_tester_SOURCES = test_hooks.c unit_tester_LDADD = $(UNIT_TEST_OBJ_SUPPORT) tester_SOURCES = tester.cc @@ -505,8 +504,8 @@ EXTRA_DIST = $(PDF_FIGURES) $(PNG_FIGURE info_TEXINFOS = monotone.texi EXTRA_DIST = $(PDF_FIGURES) $(PNG_FIGURES) INSTALL README.changesets \ UPGRADE monotone.spec monotone.html texinfo.css schema.sql \ - std_hooks.lua test_hooks.lua testlib.lua lua-testsuite.lua \ - $(srcdir)/tests tester-testsuite.lua $(srcdir)/tester-tests \ + std_hooks.lua testlib.lua lua-testsuite.lua$(srcdir)/tests \ + tester-testsuite.lua $(srcdir)/tester-tests \ unit-testsuite.lua package.m4 package_revision.txt \ package_full_revision_dist.txt $(wildcard $(srcdir)/m4/*.m4) \ sqlite/keywordhash.h contrib/README contrib/monoprof.sh \ @@ -687,7 +686,7 @@ $(srcdir)/package.m4: $(top_srcdir)/conf # that need to be generated early on 'make all'; this is _not_ true of # generated source files, but it is true for the PCH if used. -CLEAN_SOURCES = std_hooks.c test_hooks.c testlib.c schema.c \ +CLEAN_SOURCES = std_hooks.c testlib.c schema.c \ package_revision.c package_full_revision.txt \ package_full_revision_raw.txt package_full_revision.c ============================================================ --- README.encapsulation 79dd1f01334e681277c7a3b715d5a8b74fca258c +++ README.encapsulation dc81088d6bf35555821f076556a68dbdce3b15be @@ -86,12 +86,6 @@ netsync.cc: app.keys.ensure_in_database()_netsync_protocol(): app.opts.bind_stdio - -keys.cc: - Only a unit test left, which uses app_state. This should be cleaned - up as soon as we remove the hackish hooks in the key_store. - - cmd_diff_log.cc: CMD(diff: ============================================================ --- keys.cc 0aca0eebd8f2edd07c9b8a4382f37c2bd39398b1 +++ keys.cc af15a184ec33c8df05cfb54b3db515d66ba47479 @@ -23,6 +23,7 @@ #include "constants.hh" #include "keys.hh" +#include "key_store.hh" #include "lua_hooks.hh" #include "netio.hh" #include "platform.hh" @@ -32,7 +33,6 @@ #include "sanity.hh" #include "ui.hh" #include "cert.hh" -#include "app_state.hh" #include "charset.hh" #include "ssh_agent.hh" @@ -689,18 +689,16 @@ require_password(rsa_keypair_id const & #ifdef BUILD_UNIT_TESTS #include "unit_tests.hh" +// This is not much of a unit test, but there is no point in strengthening +// it, because the only thing we still use arc4 for is migrating *really* +// old in-database private keys out to pkcs#8 files in the keystore. UNIT_TEST(key, arc4) { + static Botan::byte const pt[] = "new fascist tidiness regime in place"; + static Botan::byte const phr[] = "still spring water"; - string pt("new fascist tidiness regime in place"); - string phr("still spring water"); - - SecureVector phrase(reinterpret_cast(phr.data()), - phr.size()); - - SecureVector orig(reinterpret_cast(pt.data()), - pt.size()); - + SecureVector phrase(phr, sizeof phr - 1); + SecureVector orig(pt, sizeof pt - 1); SecureVector data(orig); UNIT_TEST_CHECKPOINT("encrypting data"); @@ -712,37 +710,8 @@ UNIT_TEST(key, arc4) do_arc4(phrase, data); UNIT_TEST_CHECK(data == orig); - } -UNIT_TEST(key, signature_round_trip) -{ - app_state app; - app.set_key_dir(system_path(get_current_working_dir()) / ".monotone_tmp" / "keys"); - app.lua.add_std_hooks(); - app.lua.add_test_hooks(); - - UNIT_TEST_CHECKPOINT("generating key pairs"); - keypair kp; - utf8 passphrase("address@hidden"); - rsa_keypair_id key("address@hidden"); - generate_key_pair(kp, passphrase); - app.keys.put_key_pair(key, kp); - - UNIT_TEST_CHECKPOINT("signing plaintext"); - string plaintext("test string to sign"); - base64 sig; - make_signature(app.keys, key, kp.priv, plaintext, sig); - - UNIT_TEST_CHECKPOINT("checking signature"); - UNIT_TEST_CHECK(check_signature(app.keys, key, kp.pub, plaintext, sig)); - - string broken_plaintext = plaintext + " ...with a lie"; - UNIT_TEST_CHECKPOINT("checking non-signature"); - UNIT_TEST_CHECK(!check_signature(app.keys, key, kp.pub, broken_plaintext, sig)); - app.keys.delete_key(key); -} - #endif // BUILD_UNIT_TESTS // Local Variables: ============================================================ --- lua-testsuite.lua e54e556ba16227039d6f464a138a43eb400d1623 +++ lua-testsuite.lua b3c5868689f9c7ba3c3c85478eb10b59f1ceeb6c @@ -97,9 +97,13 @@ function certvalue(rev, name) check(safe_mtn("automate", "certs", rev), 0, false) local parsed = parse_basic_io(readfile("ts-stdout")) local cname + local goodsig + -- note: this relies on the name and signature elements appearing + -- before the value element, in each stanza. for _,l in pairs(parsed) do if l.name == "name" then cname = l.values[1] end - if cname == name and l.name == "value" then return l.values[1] end + if l.name == "signature" then goodsig = l.values[1] end + if cname == name and l.name == "value" then return l.values[1], goodsig end end return nil end ============================================================ --- lua_hooks.cc 26dbfb8306a7b7b4871f61877c7fd0f72abadfdd +++ lua_hooks.cc 5f4045fd523ea215bfc705555b03c4f2dbd38b45 @@ -32,11 +32,8 @@ #include "commands.hh" #include "globish.hh" -// defined in {std,test}_hooks.lua, converted to {std,test}_hooks.c respectively +// defined in std_hooks.c, generated from std_hooks.lua extern char const std_hooks_constant[]; -#ifdef BUILD_UNIT_TESTS -extern char const test_hooks_constant[]; -#endif using std::make_pair; using std::map; @@ -135,16 +132,7 @@ lua_hooks::check_lua_state(lua_State * p return (p_st == st); } -#ifdef BUILD_UNIT_TESTS void -lua_hooks::add_test_hooks() -{ - if (!run_string(st, test_hooks_constant, "")) - throw oops("lua error while setting up testing hooks"); -} -#endif - -void lua_hooks::add_std_hooks() { if (!run_string(st, std_hooks_constant, "")) ============================================================ --- lua_hooks.hh a03b6a9de65a23204776355184e50a093f65f649 +++ lua_hooks.hh 2604a4a3a5244ba91c7b74a60a5bb762b114ddc5 @@ -34,9 +34,6 @@ public: public: lua_hooks(); ~lua_hooks(); -#ifdef BUILD_UNIT_TESTS - void add_test_hooks(); -#endif void set_app(app_state *_app); bool check_lua_state(lua_State * st) const; void add_std_hooks();