Fix tests to work correctly with gpg1 and older gpgme versions

This commit is contained in:
Jakub Zelenka 2021-02-14 18:49:40 +00:00
parent 75a9b387ea
commit 542d121eca
4 changed files with 51 additions and 43 deletions

View file

@ -26,9 +26,6 @@ bool(true)
bool(true) bool(true)
--CLEAN-- --CLEAN--
<?php <?php
$homedir = __DIR__ . '/init_oo_home'; require_once "gnupgt.inc";
foreach (glob($homedir . '/*') as $filename) { gnupgt::delete_key(__DIR__ . '/init_oo_home');
unlink($filename);
}
rmdir($homedir);
?> ?>

View file

@ -26,9 +26,6 @@ bool(true)
bool(true) bool(true)
--CLEAN-- --CLEAN--
<?php <?php
$homedir = __DIR__ . '/init_res_home'; require_once "gnupgt.inc";
foreach (glob($homedir . '/*') as $filename) { gnupgt::delete_key(__DIR__ . '/init_res_home');
unlink($filename);
}
rmdir($homedir);
?> ?>

View file

@ -18,23 +18,24 @@ class gnupgt {
/** /**
* Delete all keys. * Delete all keys.
* @param null|string $homeDir
*/ */
static public function delete_key() static public function delete_key($homeDir = null)
{ {
$homeDir = self::get_home_dir(); if (is_null($homeDir)) {
$homeDir = self::get_home_dir();
}
if (!is_dir($homeDir)) { if (!is_dir($homeDir)) {
return; return;
} }
@unlink("$homeDir/pubring.gpg"); foreach (glob($homeDir . '/*') as $filename) {
@unlink("$homeDir/secring.gpg"); if (is_file($filename)) {
@unlink("$homeDir/pubring.kbx"); unlink($filename);
@unlink("$homeDir/pubring.kbx~"); }
@unlink("$homeDir/random_seed"); }
@unlink("$homeDir/sshcontrol"); $privKeyDir = self::get_priv_key_dir($homeDir);
@unlink("$homeDir/trustdb.gpg");
$privKeyDir = self::get_priv_key_dir();
if (is_dir($privKeyDir)) { if (is_dir($privKeyDir)) {
foreach (glob($privKeyDir . '/*.key') as $key) { foreach (glob($privKeyDir . '/*') as $key) {
unlink($key); unlink($key);
} }
rmdir($privKeyDir); rmdir($privKeyDir);
@ -42,33 +43,46 @@ class gnupgt {
rmdir($homeDir); rmdir($homeDir);
} }
/** /**
* Initialize key directory. * Initialize key directory.
*/ */
static public function init_key_dir() static public function init_key_dir()
{ {
mkdir(self::get_home_dir()); mkdir(self::get_home_dir());
mkdir(self::get_priv_key_dir(), 0700); mkdir(self::get_priv_key_dir(), 0700);
} }
/** /**
* Reset all keys. * Reset all keys.
*/ */
static public function reset_key() static public function reset_key()
{ {
self::delete_key(); self::delete_key();
self::init_key_dir(); self::init_key_dir();
} }
/**
* Get home directory.
*
* @return string
*/
static private function get_home_dir() static private function get_home_dir()
{ {
return __DIR__ . '/home'; return __DIR__ . '/home';
} }
static private function get_priv_key_dir() /**
{ * Get private key directory (for GPG2).
return self::get_home_dir() . '/private-keys-v1.d'; * @param null|string $homeDir
} * @return string
*/
static private function get_priv_key_dir($homeDir = null)
{
if (is_null($homeDir)) {
$homeDir = self::get_home_dir();
}
return $homeDir . '/private-keys-v1.d';
}
/** /**
* Print error message and return false. * Print error message and return false.
@ -126,7 +140,7 @@ class gnupgt {
*/ */
static public function check_array_from_version($version, $expected, $a, $key1) static public function check_array_from_version($version, $expected, $a, $key1)
{ {
if (version_compare(GNUPG_GPGME_VERSION, $version) > 0) { if (version_compare(GNUPG_GPGME_VERSION, $version) < 0) {
return true; return true;
} }