mirror of
https://github.com/QRouland/UTPass.git
synced 2025-06-25 15:02:28 +00:00
First draft Rewrite get all key with rnp
This commit is contained in:
BIN
tests/assets/gpghome/pubring.pgp
Normal file
BIN
tests/assets/gpghome/pubring.pgp
Normal file
Binary file not shown.
BIN
tests/assets/gpghome/secring.pgp
Normal file
BIN
tests/assets/gpghome/secring.pgp
Normal file
Binary file not shown.
@ -7,13 +7,14 @@
|
||||
|
||||
class TesTPassphraseProvider : public QObject, public GpgME::PassphraseProvider
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
char *getPassphrase(const char *useridHint,
|
||||
const char *description,
|
||||
bool previousWasBad,
|
||||
bool &canceled) override {
|
||||
bool &canceled) override
|
||||
{
|
||||
|
||||
char *ret;
|
||||
gpgrt_asprintf(&ret, "%s", "utpasspassphrase");
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include "utils.h"
|
||||
|
||||
TestsUtils::TestsUtils():
|
||||
m_passphrase_povider(std::unique_ptr<TesTPassphraseProvider>(new TesTPassphraseProvider()))
|
||||
m_passphrase_povider(std::unique_ptr<TesTPassphraseProvider>(new TesTPassphraseProvider()))
|
||||
{}
|
||||
|
||||
|
||||
@ -28,12 +28,47 @@ QString TestsUtils::getTempPath()
|
||||
QDir dir;
|
||||
dir.mkpath(newTempDir);
|
||||
|
||||
qDebug() << "TempDir : " << newTempDir;
|
||||
qDebug() << "[TestUtils] TempDir : " << newTempDir;
|
||||
return newTempDir;
|
||||
}
|
||||
|
||||
bool TestsUtils::fileExists(QUrl path)
|
||||
{
|
||||
QString p = path.toLocalFile();
|
||||
auto ret = QFileInfo::exists(p) && QFileInfo(p).isFile();
|
||||
qDebug() << "[TestUtils]" << p << "is existing file :" << ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
QObject* TestsUtils::getTestPassphraseProvider()
|
||||
void TestsUtils::copyFolder(QUrl sourceFolderUrl, QUrl destFolderUrl)
|
||||
{
|
||||
auto sourceFolder = sourceFolderUrl.toLocalFile();
|
||||
auto destFolder = destFolderUrl.toLocalFile();
|
||||
QDir sourceDir(sourceFolder);
|
||||
if (!sourceDir.exists())
|
||||
return;
|
||||
QDir destDir(destFolder);
|
||||
if (!destDir.exists()) {
|
||||
destDir.mkdir(destFolder);
|
||||
}
|
||||
qDebug() << "[TestUtils]" << "Copy files from" << sourceFolder << "to" << destFolder;
|
||||
QStringList files = sourceDir.entryList(QDir::Files);
|
||||
for (int i = 0; i < files.count(); i++) {
|
||||
QString srcName = sourceFolder + "/" + files[i];
|
||||
QString destName = destFolder + "/" + files[i];
|
||||
QFile::copy(srcName, destName);
|
||||
qDebug() << "[TestUtils]" << "Copy file from" << srcName << "to" << destName;
|
||||
}
|
||||
files.clear();
|
||||
files = sourceDir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
|
||||
for (int i = 0; i < files.count(); i++) {
|
||||
QString srcName = sourceFolder + "/" + files[i];
|
||||
QString destName = destFolder + "/" + files[i];
|
||||
this->copyFolder(srcName, destName);
|
||||
}
|
||||
}
|
||||
|
||||
QObject *TestsUtils::getTestPassphraseProvider()
|
||||
{
|
||||
return this->m_passphrase_povider.get();
|
||||
}
|
||||
|
@ -19,7 +19,10 @@ public:
|
||||
~TestsUtils() override = default;
|
||||
|
||||
Q_INVOKABLE QString getTempPath();
|
||||
Q_INVOKABLE QObject* getTestPassphraseProvider();
|
||||
Q_INVOKABLE bool fileExists(QUrl path);
|
||||
Q_INVOKABLE void copyFolder(QUrl sourceFolder, QUrl destFolder);
|
||||
Q_INVOKABLE QObject *getTestPassphraseProvider();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,13 +1,19 @@
|
||||
import Pass 1.0
|
||||
import QtQuick 2.9
|
||||
import QtTest 1.2
|
||||
import TestsUtils 1.0
|
||||
import Pass 1.0
|
||||
|
||||
TestCase {
|
||||
property string password_store
|
||||
property string gpg_home
|
||||
|
||||
function init() {
|
||||
Pass.initialize(null);
|
||||
Pass.gpg_home = TestsUtils.getTempPath();
|
||||
Pass.password_store = TestsUtils.getTempPath();
|
||||
gpg_home = TestsUtils.getTempPath();
|
||||
Pass.gpg_home = gpg_home;
|
||||
password_store = TestsUtils.getTempPath();
|
||||
Pass.password_store = password_store;
|
||||
Pass.passphrase_provider = TestsUtils.getTestPassphraseProvider();
|
||||
}
|
||||
|
||||
}
|
||||
|
52
tests/units/pass/tst_get_keys.qml
Normal file
52
tests/units/pass/tst_get_keys.qml
Normal file
@ -0,0 +1,52 @@
|
||||
import Pass 1.0
|
||||
import QtQuick 2.9
|
||||
import QtTest 1.2
|
||||
import TestsUtils 1.0
|
||||
|
||||
PassTestCase {
|
||||
function init_data() {
|
||||
//TODO some additionanl error test
|
||||
|
||||
return [{
|
||||
"spy": getAllGPGKeysSucceed,
|
||||
"signal": Pass.getAllGPGKeysSucceed,
|
||||
"err_msg": null,
|
||||
"add_home_gpg_data": false,
|
||||
"nb_keys": 0
|
||||
}, {
|
||||
"spy": getAllGPGKeysSucceed,
|
||||
"signal": Pass.getAllGPGKeysSucceed,
|
||||
"err_msg": null,
|
||||
"add_home_gpg_data": true,
|
||||
"nb_keys": 2
|
||||
}];
|
||||
}
|
||||
|
||||
function test_get_keys(data) {
|
||||
if (data.add_home_gpg_data === true)
|
||||
TestsUtils.copyFolder(Qt.resolvedUrl("../../assets/gpghome"), Qt.resolvedUrl(gpg_home));
|
||||
|
||||
var keys;
|
||||
data.signal.connect(function(keys_info) {
|
||||
keys = keys_info;
|
||||
});
|
||||
Pass.getAllGPGKeys();
|
||||
data.spy.wait();
|
||||
verify(keys.length === data.nb_keys, "Nb keys %1 but was excepted %2".arg(keys.length).arg(data.nb_keys));
|
||||
}
|
||||
|
||||
SignalSpy {
|
||||
id: getAllGPGKeysSucceed
|
||||
|
||||
target: Pass
|
||||
signalName: "getAllGPGKeysSucceed"
|
||||
}
|
||||
|
||||
SignalSpy {
|
||||
id: getAllGPGKeysFailed
|
||||
|
||||
target: Pass
|
||||
signalName: "getAllGPGKeysFailed"
|
||||
}
|
||||
|
||||
}
|
@ -1,47 +1,56 @@
|
||||
import Pass 1.0
|
||||
import QtQuick 2.9
|
||||
import QtTest 1.2
|
||||
import TestsUtils 1.0
|
||||
import Pass 1.0
|
||||
|
||||
PassTestCase {
|
||||
function init_data() {
|
||||
return [
|
||||
{ file: Qt.resolvedUrl("../../assets/gpg/test_key.gpg"), spy: importGPGKeySucceed, signal: Pass.importGPGKeySucceed, err_msg : null }
|
||||
, { file: Qt.resolvedUrl("../../assets/gpg/test_key_do_not_exist.gpg"), spy: importGPGKeyFailed, signal: Pass.importGPGKeyFailed, err_msg : "Error reading file" }
|
||||
, { file: Qt.resolvedUrl("../../assets/gpg/test_key_invalid.gpg"), spy: importGPGKeyFailed, signal: Pass.importGPGKeyFailed, err_msg : "Bad format" }
|
||||
];
|
||||
return [{
|
||||
"file": Qt.resolvedUrl("../../assets/gpg/test_key.gpg"),
|
||||
"spy": importGPGKeySucceed,
|
||||
"signal": Pass.importGPGKeySucceed,
|
||||
"err_msg": null
|
||||
}, {
|
||||
"file": Qt.resolvedUrl("../../assets/gpg/test_key_do_not_exist.gpg"),
|
||||
"spy": importGPGKeyFailed,
|
||||
"signal": Pass.importGPGKeyFailed,
|
||||
"err_msg": "Error reading file"
|
||||
}, {
|
||||
"file": Qt.resolvedUrl("../../assets/gpg/test_key_invalid.gpg"),
|
||||
"spy": importGPGKeyFailed,
|
||||
"signal": Pass.importGPGKeyFailed,
|
||||
"err_msg": "Bad state"
|
||||
}];
|
||||
}
|
||||
|
||||
function test_import_key(data) {
|
||||
var err_msg;
|
||||
data.signal.connect(function(message) {
|
||||
err_msg = message;
|
||||
});
|
||||
Pass.importGPGKey(data.file);
|
||||
data.spy.wait();
|
||||
if (data.err_msg) {
|
||||
verify(err_msg === data.err_msg, "Should return arg msg %1 but return %2".arg(data.err_msg).arg(err_msg));
|
||||
} else {
|
||||
console.info(Qt.resolvedUrl("%1/pubkeyring.pgp".arg(gpg_home)));
|
||||
verify(TestsUtils.fileExists(Qt.resolvedUrl("%1/pubring.pgp".arg(gpg_home))), "%1/pubring.pgp should be created".arg(gpg_home));
|
||||
verify(TestsUtils.fileExists(Qt.resolvedUrl("%1/secring.pgp".arg(gpg_home))), "%1/secring.pgp should be created".arg(gpg_home));
|
||||
}
|
||||
}
|
||||
|
||||
SignalSpy {
|
||||
id: importGPGKeySucceed
|
||||
|
||||
target: Pass
|
||||
signalName: "importGPGKeySucceed"
|
||||
}
|
||||
|
||||
SignalSpy {
|
||||
id: importGPGKeyFailed
|
||||
|
||||
target: Pass
|
||||
signalName: "importGPGKeyFailed"
|
||||
}
|
||||
|
||||
SignalSpy {
|
||||
id: importGPGKeyCancelled
|
||||
target: Pass
|
||||
signalName: "importGPGKeyCancelled"
|
||||
}
|
||||
|
||||
function test_import_key(data) {
|
||||
var err_msg;
|
||||
|
||||
data.signal.connect(function(message) {
|
||||
err_msg = message;
|
||||
});
|
||||
|
||||
Pass.importGPGKey(data.file);
|
||||
|
||||
data.spy.wait();
|
||||
if(data.err_msg) {
|
||||
verify(err_msg === data.err_msg, "Should return arg msg %1 but return %2".arg(data.err_msg).arg(err_msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,9 +3,9 @@ import QtQuick 2.9
|
||||
import QtTest 1.2
|
||||
|
||||
TestCase {
|
||||
function test_import_key(){
|
||||
function test_import_key() {
|
||||
var homedir = TestUtils.getTempPath();
|
||||
Pass
|
||||
Pass;
|
||||
verify(false);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user