Fix tests with gpg2

This commit is contained in:
Jakub Zelenka 2021-02-14 18:29:37 +00:00
parent a32dc2f988
commit 75a9b387ea
4 changed files with 45 additions and 11 deletions

View file

@ -5,7 +5,7 @@ import a new key into the keyring
--FILE-- --FILE--
<?php <?php
require_once "gnupgt.inc"; require_once "gnupgt.inc";
gnupgt::delete_key(); gnupgt::reset_key();
$gpg = new gnupg(); $gpg = new gnupg();
$gpg->seterrormode(gnupg::ERROR_WARNING); $gpg->seterrormode(gnupg::ERROR_WARNING);

View file

@ -5,7 +5,7 @@ import a new key into the keyring
--FILE-- --FILE--
<?php <?php
require_once "gnupgt.inc"; require_once "gnupgt.inc";
gnupgt::delete_key(); gnupgt::reset_key();
$gpg = gnupg_init(); $gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING); gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);

View file

@ -10,7 +10,7 @@ class gnupgt {
{ {
global $testkey; global $testkey;
self::delete_key(); self::reset_key();
$gpg = new gnupg(); $gpg = new gnupg();
$gpg->import($testkey); $gpg->import($testkey);
@ -21,21 +21,55 @@ class gnupgt {
*/ */
static public function delete_key() static public function delete_key()
{ {
@unlink(__DIR__ . "/pubring.gpg"); $homeDir = self::get_home_dir();
@unlink(__DIR__ . "/secring.gpg"); if (!is_dir($homeDir)) {
@unlink(__DIR__ . "/pubring.kbx"); return;
@unlink(__DIR__ . "/random_seed"); }
@unlink(__DIR__ . "/sshcontrol"); @unlink("$homeDir/pubring.gpg");
@unlink(__DIR__ . "/trustdb.gpg"); @unlink("$homeDir/secring.gpg");
$privKeyDir = __DIR__ . '/private-keys-v1.d'; @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)) { if (is_dir($privKeyDir)) {
foreach (glob($privKeyDir . '/*.key') as $key) { foreach (glob($privKeyDir . '/*.key') as $key) {
unlink($key); unlink($key);
} }
rmdir($privKeyDir); 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. * Print error message and return false.
* *

View file

@ -1,5 +1,5 @@
<?php <?php
putenv("GNUPGHOME=".dirname(__FILE__)); putenv("GNUPGHOME=".dirname(__FILE__) . '/home');
error_reporting (E_ALL); error_reporting (E_ALL);
$fingerprint = "2DF0DD02DC9B70B7F64F572E669E775E0A6284B3"; $fingerprint = "2DF0DD02DC9B70B7F64F572E669E775E0A6284B3";
$passphrase = "blabla"; $passphrase = "blabla";