# # rename_file "tests/t_genkey_without_db.at" # to "tests/t_key_management_without_db.at" # # patch "ChangeLog" # from [328429c6ea96553c432ab4c36e7983fc9b830282] # to [9fdcf44a6afd4649af17c3ededf4cf5e8dc1ab10] # # patch "commands.cc" # from [7f5675e9a296b976e5ea81b4d7639326c6a3ce02] # to [c043db37f8bb75deed2604fefca8426408264467] # # patch "tests/t_key_management_without_db.at" # from [9f4369d40515411569f9d030694ecfb9222af4b9] # to [284f02e1bd94117133fd7ce45512d6912c3120fb] # # patch "testsuite.at" # from [551e9015ab6f27e259a06d2c89bc694d467167ca] # to [388fd624698f3b9219a28ad8f89df2637d608ca1] # ======================================================================== --- ChangeLog 328429c6ea96553c432ab4c36e7983fc9b830282 +++ ChangeLog 9fdcf44a6afd4649af17c3ededf4cf5e8dc1ab10 @@ -1,5 +1,12 @@ 2005-10-06 Timothy Brownawell + * commands.cc (chkeypass): doesn't use the db, so we don't need a guard + * commands.cc (dropkey): don't insist on having a db + * tests/t_genkey_without_db.at: rename (s/genkey/key_management) and + add checks for chkeypass and dropkey without a db + +2005-10-06 Timothy Brownawell + * database.{cc,hh}: new function, database::database_specified() return whether we were given a database (doesn't care about validity, only that we were told to use one) ======================================================================== --- commands.cc 7f5675e9a296b976e5ea81b4d7639326c6a3ce02 +++ commands.cc c043db37f8bb75deed2604fefca8426408264467 @@ -867,13 +867,19 @@ if (args.size() != 1) throw usage(name); - transaction_guard guard(app.db); rsa_keypair_id ident(idx(args, 0)()); - if (app.db.public_key_exists(ident)) + bool checked_db = false; + if (app.db.database_specified()) { - P(F("dropping public key '%s' from database\n") % ident); - app.db.delete_public_key(ident); - key_deleted = true; + transaction_guard guard(app.db); + if (app.db.public_key_exists(ident)) + { + P(F("dropping public key '%s' from database\n") % ident); + app.db.delete_public_key(ident); + key_deleted = true; + } + guard.commit(); + checked_db = true; } if (app.keys.key_pair_exists(ident)) @@ -883,10 +889,12 @@ key_deleted = true; } - N(key_deleted, - F("public or private key '%s' does not exist") % idx(args, 0)()); - - guard.commit(); + boost::format fmt; + if (checked_db) + fmt = F("public or private key '%s' does not exist in keystore or database"); + else + fmt = F("public or private key '%s' does not exist in keystore, and no database was specified"); + N(key_deleted, fmt % idx(args, 0)()); } CMD(chkeypass, N_("key and cert"), N_("KEYID"), @@ -896,7 +904,6 @@ if (args.size() != 1) throw usage(name); - transaction_guard guard(app.db); rsa_keypair_id ident; internalize_rsa_keypair_id(idx(args, 0), ident); @@ -909,8 +916,6 @@ app.keys.delete_key(ident); app.keys.put_key_pair(ident, key); P(F("passphrase changed\n")); - - guard.commit(); } CMD(cert, N_("key and cert"), N_("REVISION CERTNAME [CERTVAL]"), ======================================================================== --- tests/t_key_management_without_db.at 9f4369d40515411569f9d030694ecfb9222af4b9 +++ tests/t_key_management_without_db.at 284f02e1bd94117133fd7ce45512d6912c3120fb @@ -1,10 +1,14 @@ -AT_SETUP([genkey without a database]) +AT_SETUP([genkey, dropkey, chkeypass without a database]) MONOTONE_SETUP # with no database should work AT_CHECK((echo foobar; echo foobar) | RAW_MONOTONE --keydir=keys genkey foobar, [], [ignore], [ignore]) +AT_CHECK((echo foobar; echo barfoo; echo barfoo) | RAW_MONOTONE --keydir=keys chkeypass foobar, [], [ignore], [ignore]) + +AT_CHECK(RAW_MONOTONE --keydir=keys dropkey foobar, [], [ignore], [ignore]) + # with an invalid database should fail AT_CHECK((echo address@hidden; echo address@hidden) | RAW_MONOTONE --keydir=keys --db=bork genkey address@hidden, [1], [ignore], [ignore]) ======================================================================== --- testsuite.at 551e9015ab6f27e259a06d2c89bc694d467167ca +++ testsuite.at 388fd624698f3b9219a28ad8f89df2637d608ca1 @@ -708,4 +708,4 @@ m4_include(tests/t_automate_get_revision.at) m4_include(tests/t_unreadable_db.at) m4_include(tests/t_restriction_with_exclude.at) +m4_include(tests/t_key_management_without_db.at) -m4_include(tests/t_genkey_without_db.at)