Browse Source

Added bigkey test and reverted changed_key tests

neal-sequoia-update-staging archive/neal-sequoia-update-staging
parent
commit
954d612fd8
3 changed files with 63 additions and 32 deletions
  1. +3
    -2
      test/src/Engine.h
  2. +60
    -30
      test/src/ImportKeyTest.cc
  3. BIN
      test/test_keys/bigkey.pgp

+ 3
- 2
test/src/Engine.h View File

@ -19,11 +19,12 @@ class Engine {
void shut_down();
PEP_SESSION session;
protected:
string engine_home;
string real_home;
string prev_pgp_home;
protected:
messageToSend_t cached_messageToSend;
inject_sync_event_t cached_inject_sync_event;


+ 60
- 30
test/src/ImportKeyTest.cc View File

@ -1,6 +1,12 @@
#include <stdlib.h>
#include <string>
#include <cstring>
#include <iostream>
#include <fstream>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "pEpEngine.h"
#include "test_util.h"
@ -66,17 +72,6 @@ namespace {
session = NULL;
}
PEP_STATUS import_and_and_fix_key(string filename, stringlist_t** keylist, uint64_t* changes, char** fixed_key, size_t* fixed_key_size) {
string pubkey = slurp(filename);
PEP_STATUS status = _import_key_with_fpr_return(session, pubkey.c_str(), pubkey.size(), NULL, keylist, changes);
if (status != PEP_KEY_IMPORTED)
return status;
else if (*changes != 1)
return PEP_TEST_NO_KEY_IMPORT;
else
return export_key(session, (*keylist)->value, fixed_key, fixed_key_size);
}
private:
const char* test_suite_name;
const char* test_name;
@ -133,27 +128,16 @@ TEST_F(ImportKeyTest, check_import_fpr_priv_new) {
TEST_F(ImportKeyTest, check_import_change_pub_nochange) {
PEP_STATUS status = PEP_STATUS_OK;
char* fixed_key = NULL;
size_t fixed_key_size = 0;
string pubkey = slurp("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
stringlist_t* keylist = NULL;
uint64_t changes = 0;
// this checks to see if a key was imported and if it changed the first time.
status = import_and_and_fix_key("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc", &keylist, &changes, &fixed_key, &fixed_key_size);
ASSERT_OK;
string pubkey = string(fixed_key);
// N.B. This is transitional - ideally, we'll test it this way, but we first need to understand what the equality metric is and change the heuristic.
// free_stringlist(keylist);
// keylist = NULL;
// uint64_t changes = 0;
// status = _import_key_with_fpr_return(session, pubkey.c_str(), pubkey.size(), NULL, &keylist, &changes);
// ASSERT_EQ(status, PEP_KEY_IMPORTED);
// ASSERT_NE(keylist, nullptr);
// ASSERT_STREQ(keylist->value, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97");
// ASSERT_EQ(keylist->next, nullptr);
// ASSERT_EQ(changes, 1);
status = _import_key_with_fpr_return(session, pubkey.c_str(), pubkey.size(), NULL, &keylist, &changes);
ASSERT_EQ(status, PEP_KEY_IMPORTED);
ASSERT_NE(keylist, nullptr);
ASSERT_STREQ(keylist->value, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97");
ASSERT_EQ(keylist->next, nullptr);
ASSERT_EQ(changes, 1);
// import again!
free_stringlist(keylist);
@ -167,6 +151,52 @@ TEST_F(ImportKeyTest, check_import_change_pub_nochange) {
ASSERT_EQ(changes, 0);
}
TEST_F(ImportKeyTest, check_import_change_pub_nochange_binary_bigkey) {
PEP_STATUS status = PEP_STATUS_OK;
int retval = 0;
#ifndef WIN32
struct stat fst;
retval = stat("test_keys/bigkey.pgp", &fst);
#else
struct _stat fst;
retval = _stat("test_keys/bigkey.pgp", &fst);
#endif
ASSERT_EQ(retval, 0);
size_t img_size = (size_t)(fst.st_size);
ASSERT_NE(img_size, 0);
char* img = (char*)calloc(1, img_size);
ifstream img_file("test_keys/bigkey.pgp", ios::in | ios::binary);
img_file.read(img, img_size);
img_file.close();
cout << img_size << endl;
stringlist_t* keylist = NULL;
uint64_t changes = 0;
status = _import_key_with_fpr_return(session, img, img_size, NULL, &keylist, &changes);
ASSERT_EQ(status, PEP_KEY_IMPORTED);
ASSERT_NE(keylist, nullptr);
// ASSERT_STREQ(keylist->value, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97");
ASSERT_EQ(keylist->next, nullptr);
ASSERT_EQ(changes, 1);
// import again!
free_stringlist(keylist);
keylist = NULL;
changes = 0;
status = _import_key_with_fpr_return(session, img, img_size, NULL, &keylist, &changes);
ASSERT_EQ(status, PEP_KEY_IMPORTED);
ASSERT_NE(keylist, nullptr);
// ASSERT_STREQ(keylist->value, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97");
ASSERT_EQ(keylist->next, nullptr);
ASSERT_EQ(changes, 0);
}
TEST_F(ImportKeyTest, check_import_change_wo_fpr_illegal) {
PEP_STATUS status = PEP_STATUS_OK;


BIN
test/test_keys/bigkey.pgp View File


Loading…
Cancel
Save