diff --git a/tests/gnupg_oo_import.phpt b/tests/gnupg_oo_import.phpt index 80ed575..61c6dfd 100644 --- a/tests/gnupg_oo_import.phpt +++ b/tests/gnupg_oo_import.phpt @@ -5,7 +5,7 @@ import a new key into the keyring --FILE-- seterrormode(gnupg::ERROR_WARNING); diff --git a/tests/gnupg_res_0001_import.phpt b/tests/gnupg_res_0001_import.phpt index ea21e94..a6644b8 100644 --- a/tests/gnupg_res_0001_import.phpt +++ b/tests/gnupg_res_0001_import.phpt @@ -5,7 +5,7 @@ import a new key into the keyring --FILE-- import($testkey); @@ -21,21 +21,55 @@ class gnupgt { */ static public function delete_key() { - @unlink(__DIR__ . "/pubring.gpg"); - @unlink(__DIR__ . "/secring.gpg"); - @unlink(__DIR__ . "/pubring.kbx"); - @unlink(__DIR__ . "/random_seed"); - @unlink(__DIR__ . "/sshcontrol"); - @unlink(__DIR__ . "/trustdb.gpg"); - $privKeyDir = __DIR__ . '/private-keys-v1.d'; + $homeDir = self::get_home_dir(); + if (!is_dir($homeDir)) { + return; + } + @unlink("$homeDir/pubring.gpg"); + @unlink("$homeDir/secring.gpg"); + @unlink("$homeDir/pubring.kbx"); + @unlink("$homeDir/pubring.kbx~"); + @unlink("$homeDir/random_seed"); + @unlink("$homeDir/sshcontrol"); + @unlink("$homeDir/trustdb.gpg"); + $privKeyDir = self::get_priv_key_dir(); if (is_dir($privKeyDir)) { foreach (glob($privKeyDir . '/*.key') as $key) { unlink($key); } rmdir($privKeyDir); } + rmdir($homeDir); } + /** + * Initialize key directory. + */ + static public function init_key_dir() + { + mkdir(self::get_home_dir()); + mkdir(self::get_priv_key_dir(), 0700); + } + + /** + * Reset all keys. + */ + static public function reset_key() + { + self::delete_key(); + self::init_key_dir(); + } + + static private function get_home_dir() + { + return __DIR__ . '/home'; + } + + static private function get_priv_key_dir() + { + return self::get_home_dir() . '/private-keys-v1.d'; + } + /** * Print error message and return false. * diff --git a/tests/vars.inc b/tests/vars.inc index 3629f6c..02d2819 100644 --- a/tests/vars.inc +++ b/tests/vars.inc @@ -1,5 +1,5 @@