|
Packit |
d7e8d0 |
/* t-support.cpp
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
This file is part of qgpgme, the Qt API binding for gpgme
|
|
Packit |
d7e8d0 |
Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik
|
|
Packit |
d7e8d0 |
Software engineering by Intevation GmbH
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
QGpgME is free software; you can redistribute it and/or
|
|
Packit |
d7e8d0 |
modify it under the terms of the GNU General Public License as
|
|
Packit |
d7e8d0 |
published by the Free Software Foundation; either version 2 of the
|
|
Packit |
d7e8d0 |
License, or (at your option) any later version.
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
QGpgME is distributed in the hope that it will be useful,
|
|
Packit |
d7e8d0 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
d7e8d0 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
d7e8d0 |
General Public License for more details.
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
You should have received a copy of the GNU General Public License
|
|
Packit |
d7e8d0 |
along with this program; if not, write to the Free Software
|
|
Packit |
d7e8d0 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
In addition, as a special exception, the copyright holders give
|
|
Packit |
d7e8d0 |
permission to link the code of this program with any edition of
|
|
Packit |
d7e8d0 |
the Qt library by Trolltech AS, Norway (or with modified versions
|
|
Packit |
d7e8d0 |
of Qt that use the same license as Qt), and distribute linked
|
|
Packit |
d7e8d0 |
combinations including the two. You must obey the GNU General
|
|
Packit |
d7e8d0 |
Public License in all respects for all of the code used other than
|
|
Packit |
d7e8d0 |
Qt. If you modify this file, you may extend this exception to
|
|
Packit |
d7e8d0 |
your version of the file, but you are not obligated to do so. If
|
|
Packit |
d7e8d0 |
you do not wish to do so, delete this exception statement from
|
|
Packit |
d7e8d0 |
your version.
|
|
Packit |
d7e8d0 |
*/
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
#ifdef HAVE_CONFIG_H
|
|
Packit |
d7e8d0 |
#include "config.h"
|
|
Packit |
d7e8d0 |
#endif
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
#include "t-support.h"
|
|
Packit |
d7e8d0 |
#include "context.h"
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
#include <QTest>
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
#include <QProcess>
|
|
Packit |
d7e8d0 |
#include <QCoreApplication>
|
|
Packit |
d7e8d0 |
#include <QObject>
|
|
Packit |
d7e8d0 |
#include <QDir>
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
void QGpgMETest::initTestCase()
|
|
Packit |
d7e8d0 |
{
|
|
Packit |
d7e8d0 |
GpgME::initializeLibrary();
|
|
Packit |
d7e8d0 |
const QString gpgHome = qgetenv("GNUPGHOME");
|
|
Packit |
d7e8d0 |
QVERIFY2(!gpgHome.isEmpty(), "GNUPGHOME environment variable is not set.");
|
|
Packit |
d7e8d0 |
}
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
void QGpgMETest::cleanupTestCase()
|
|
Packit |
d7e8d0 |
{
|
|
Packit |
d7e8d0 |
QCoreApplication::sendPostedEvents();
|
|
Packit |
d7e8d0 |
killAgent();
|
|
Packit |
d7e8d0 |
}
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
bool QGpgMETest::copyKeyrings(const QString &src, const QString &dest)
|
|
Packit |
d7e8d0 |
{
|
|
Packit |
d7e8d0 |
bool is21dir = QFileInfo(src + QDir::separator() + QStringLiteral("pubring.kbx")).exists();
|
|
Packit |
d7e8d0 |
const QString name = is21dir ? QStringLiteral("pubring.kbx") :
|
|
Packit |
d7e8d0 |
QStringLiteral("pubring.gpg");
|
|
Packit |
d7e8d0 |
if (!QFile::copy(src + QDir::separator() + name, dest + QDir::separator() + name)) {
|
|
Packit |
d7e8d0 |
return false;
|
|
Packit |
d7e8d0 |
}
|
|
Packit |
d7e8d0 |
if (!is21dir) {
|
|
Packit |
d7e8d0 |
return (QFile::copy(src + QDir::separator() + QStringLiteral("secring.gpg"),
|
|
Packit |
d7e8d0 |
dest + QDir::separator() + QStringLiteral("secring.gpg")));
|
|
Packit |
d7e8d0 |
}
|
|
Packit |
d7e8d0 |
QDir dir (src + QDir::separator() + QStringLiteral("private-keys-v1.d"));
|
|
Packit |
d7e8d0 |
QDir target(dest);
|
|
Packit |
d7e8d0 |
if (!target.mkdir("private-keys-v1.d")) {
|
|
Packit |
d7e8d0 |
return false;
|
|
Packit |
d7e8d0 |
}
|
|
Packit |
d7e8d0 |
foreach (QString f, dir.entryList(QDir::Files)) {
|
|
Packit |
d7e8d0 |
if (!QFile::copy(dir.path() + QDir::separator() + f,
|
|
Packit |
d7e8d0 |
dest + QDir::separator() +
|
|
Packit |
d7e8d0 |
QStringLiteral("private-keys-v1.d") + QDir::separator() + f)) {
|
|
Packit |
d7e8d0 |
return false;
|
|
Packit |
d7e8d0 |
}
|
|
Packit |
d7e8d0 |
}
|
|
Packit |
d7e8d0 |
return true;
|
|
Packit |
d7e8d0 |
}
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
void killAgent(const QString& dir)
|
|
Packit |
d7e8d0 |
{
|
|
Packit |
d7e8d0 |
QProcess proc;
|
|
Packit |
d7e8d0 |
proc.setProgram(QStringLiteral("gpg-connect-agent"));
|
|
Packit |
d7e8d0 |
QStringList arguments;
|
|
Packit |
d7e8d0 |
arguments << "-S " << dir + "/S.gpg-agent";
|
|
Packit |
d7e8d0 |
proc.start();
|
|
Packit |
d7e8d0 |
proc.waitForStarted();
|
|
Packit |
d7e8d0 |
proc.write("KILLAGENT\n");
|
|
Packit |
d7e8d0 |
proc.write("BYE\n");
|
|
Packit |
d7e8d0 |
proc.closeWriteChannel();
|
|
Packit |
d7e8d0 |
proc.waitForFinished();
|
|
Packit |
d7e8d0 |
}
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
#include "t-support.hmoc"
|