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)
--CLEAN--
<?php
$homedir = __DIR__ . '/init_oo_home';
foreach (glob($homedir . '/*') as $filename) {
unlink($filename);
}
rmdir($homedir);
require_once "gnupgt.inc";
gnupgt::delete_key(__DIR__ . '/init_oo_home');
?>

View file

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

View file

@ -18,23 +18,24 @@ class gnupgt {
/**
* Delete all keys.
* @param null|string $homeDir
*/
static public function delete_key()
static public function delete_key($homeDir = null)
{
if (is_null($homeDir)) {
$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();
foreach (glob($homeDir . '/*') as $filename) {
if (is_file($filename)) {
unlink($filename);
}
}
$privKeyDir = self::get_priv_key_dir($homeDir);
if (is_dir($privKeyDir)) {
foreach (glob($privKeyDir . '/*.key') as $key) {
foreach (glob($privKeyDir . '/*') as $key) {
unlink($key);
}
rmdir($privKeyDir);
@ -60,14 +61,27 @@ class gnupgt {
self::init_key_dir();
}
/**
* Get home directory.
*
* @return string
*/
static private function get_home_dir()
{
return __DIR__ . '/home';
}
static private function get_priv_key_dir()
/**
* Get private key directory (for GPG2).
* @param null|string $homeDir
* @return string
*/
static private function get_priv_key_dir($homeDir = null)
{
return self::get_home_dir() . '/private-keys-v1.d';
if (is_null($homeDir)) {
$homeDir = self::get_home_dir();
}
return $homeDir . '/private-keys-v1.d';
}
/**
@ -126,7 +140,7 @@ class gnupgt {
*/
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;
}