diff --git a/tests/rpmsigdig.at b/tests/rpmsigdig.at index 5aeab200fe..50d15ffff5 100644 --- a/tests/rpmsigdig.at +++ b/tests/rpmsigdig.at @@ -35,7 +35,7 @@ runroot rpmkeys -Kv /data/RPMS/hello-1.0-1.i386.rpm []) RPMTEST_CLEANUP -AT_SETUP([rpmkeys key update (rpmdb)]) +AT_SETUP([rpmkeys key update and delete (rpmdb)]) AT_KEYWORDS([rpmkeys signature]) RPMDB_INIT # currently the default but make it explicit @@ -74,6 +74,34 @@ runroot rpmkeys -Kv /data/RPMS/hello-2.0-1.x86_64-signed-with-new-subkey.rpm Payload SHA256 digest: OK ], []) + +RPMTEST_CHECK([ +runroot rpmkeys --delete abcd gimmekey 1111aaaa2222bbbb +], +[3], +[], +[error: invalid key id: abcd +error: invalid key id: gimmekey +error: key not found: 1111aaaa2222bbbb +]) + +RPMTEST_CHECK([ +runroot rpmkeys --delete 1964c5fc +], +[0], +[], +[]) + +RPMTEST_CHECK([ +# XXX rpmkeys on rpmdb returns "package gpg-pubkey is not installed" with +# and error code when no keys are present, paper over +runroot rpmkeys --list | grep -v "not installed" | wc -l +exit 0 +], +[0], +[0 +], +[]) RPMTEST_CLEANUP AT_SETUP([rpmkeys key update (fs)]) @@ -121,6 +149,32 @@ runroot rpmkeys -Kv /data/RPMS/hello-2.0-1.x86_64-signed-with-new-subkey.rpm Payload SHA256 digest: OK ], []) + +RPMTEST_CHECK([ +runroot rpmkeys --delete abcd gimmekey 1111aaaa2222bbbb +], +[3], +[], +[error: invalid key id: abcd +error: invalid key id: gimmekey +error: key not found: 1111aaaa2222bbbb +]) + +RPMTEST_CHECK([ +runroot rpmkeys --delete 1964c5fc +], +[0], +[], +[]) + +RPMTEST_CHECK([ +# XXX rpmkeys --list doesn't yet work with fs keystore +runroot_other find /var/lib/rpm/pubkeys -name "*.key" | wc -l +], +[0], +[0 +], +[]) RPMTEST_CLEANUP # ------------------------------ # Test rpmkeys write errors diff --git a/tools/rpmkeys.cc b/tools/rpmkeys.cc index 0210523f5c..4058fe169c 100644 --- a/tools/rpmkeys.cc +++ b/tools/rpmkeys.cc @@ -3,6 +3,7 @@ #include #include #include +#include #include "cliutils.hh" #include "debug.h" @@ -89,10 +90,24 @@ int main(int argc, char *argv[]) break; case MODE_DELKEY: { - struct rpmInstallArguments_s * ia = &rpmIArgs; - ARGV_t gpgargs = gpgkeyargs(args); - ec = rpmErase(ts, ia, gpgargs); - argvFree(gpgargs); + rpmtxn txn = rpmtxnBegin(ts, RPMTXN_WRITE); + if (txn) { + int nfail = 0; + for (char const * const *arg = args; *arg && **arg; arg++) { + rpmRC delrc = rpmtxnDeletePubkey(txn, *arg); + if (delrc) { + if (delrc == RPMRC_NOTFOUND) + rpmlog(RPMLOG_ERR, ("key not found: %s\n"), *arg); + else if (delrc == RPMRC_NOKEY) + rpmlog(RPMLOG_ERR, ("invalid key id: %s\n"), *arg); + else if (delrc == RPMRC_FAIL) + rpmlog(RPMLOG_ERR, ("failed to delete key: %s\n"), *arg); + nfail++; + } + } + ec = nfail; + rpmtxnEnd(txn); + } break; } case MODE_LISTKEY: