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--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
gnupgt::reset_key();
$gpg = new gnupg();
$gpg->seterrormode(gnupg::ERROR_WARNING);

View file

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

View file

@ -10,7 +10,7 @@ class gnupgt {
{
global $testkey;
self::delete_key();
self::reset_key();
$gpg = new gnupg();
$gpg->import($testkey);
@ -21,19 +21,53 @@ 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';
}
/**

View file

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