added test program for identity import

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6926 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2013-12-07 13:10:57 +00:00
parent e2384724c3
commit 214375ede1
3 changed files with 92 additions and 2 deletions

View File

@ -11,8 +11,8 @@ OPENPGP_INCLUDE_DIR = ../../../../openpgpsdk/src
include $(RS_TOP_DIR)/tests/scripts/config.mk
###############################################################
TESTOBJ = test_pgp_handler.o test_pgp_signature_parsing.o test_key_parsing.o test_certificate.o
TESTS = test_pgp_handler test_pgp_signature_parsing test_key_parsing test_certificate
TESTOBJ = test_pgp_handler.o test_pgp_signature_parsing.o test_key_parsing.o test_certificate.o test_identity_import.o
TESTS = test_pgp_handler test_pgp_signature_parsing test_key_parsing test_certificate test_identity_import
#rsbaseitem_test
@ -21,6 +21,9 @@ all: tests
test_certificate : test_certificate.o
$(CC) $(CFLAGS) -o test_certificate test_certificate.o $(OBJ) $(LIBS) -L../../../../openpgpsdk/src/lib/ -lops -lbz2
test_identity_import : test_identity_import.o
$(CC) $(CFLAGS) -o test_identity_import test_identity_import.o $(OBJ) $(LIBS) -L../../../../openpgpsdk/src/lib/ -lops -lbz2
test_pgp_handler : test_pgp_handler.o
$(CC) $(CFLAGS) -o test_pgp_handler test_pgp_handler.o $(OBJ) $(LIBS) -L../../../../openpgpsdk/src/lib/ -lops -lbz2

View File

@ -10,6 +10,18 @@
INITTEST() ;
static std::string pgp_pwd_cb(void * /*hook*/, const char *uid_hint, const char * /*passphrase_info*/, int prev_was_bad)
{
#define GPG_DEBUG2
#ifdef GPG_DEBUG2
fprintf(stderr, "pgp_pwd_callback() called.\n");
#endif
std::string password;
std::cerr << "SHould not be called!" << std::endl;
return password ;
}
int main(int argc,char *argv[])
{
try
@ -95,6 +107,25 @@ int main(int argc,char *argv[])
}
CHECK(found) ;
// try to load the certificate.
std::cerr << "Checking that the certificate is imported correctly" << std::endl;
std::string error_string ;
PGPIdType found_id ;
PGPHandler::setPassphraseCallback(pgp_pwd_cb) ;
PGPHandler pgph("pubring.pgp","secring.pgp","trustdb.pgp","lock") ;
bool result = pgph.LoadCertificateFromString(res,found_id,error_string) ;
if(!result)
std::cerr << "Certificate error: " << error_string << std::endl;
else
std::cerr << "Certificate loaded correctly. Id = " << found_id.toStdString() << std::endl;
CHECK(result) ;
FINALREPORT("Test certificate parsing") ;
return TESTRESULT();

View File

@ -0,0 +1,56 @@
#include <fstream>
#include <string.h>
#include <util/utest.h>
#include <util/argstream.h>
//#include <pqi/cleanupxpgp.h>
#include <retroshare/rspeers.h>
#include <pgp/rscertificate.h>
#include <pgp/pgphandler.h>
INITTEST() ;
static std::string pgp_pwd_cb(void * /*hook*/, const char *uid_hint, const char * /*passphrase_info*/, int prev_was_bad)
{
#define GPG_DEBUG2
#ifdef GPG_DEBUG2
fprintf(stderr, "pgp_pwd_callback() called.\n");
#endif
std::string password;
std::cerr << "SHould not be called!" << std::endl;
return password ;
}
int main(int argc,char *argv[])
{
try
{
argstream as(argc,argv) ;
std::string idfile ;
bool clean_cert = false ;
as >> parameter('i',"input",idfile,"input retroshare identity file, ascii format",true)
>> help() ;
as.defaultErrorHandling() ;
PGPHandler handler("toto1","toto2","toto3","toto4") ;
PGPIdType imported_key_id ;
std::string import_error_string ;
bool res = handler.importGPGKeyPair(idfile,imported_key_id,import_error_string) ;
if(!res)
std::cerr << "Identity Import error: " << import_error_string << std::endl;
CHECK(res) ;
}
catch(std::exception& e)
{
std::cerr << "Exception never handled: " << e.what() << std::endl;
return 1 ;
}
}