Browse Source

ENGINE-750: MOAR left joins, plus small tests

ENGINE-750
parent
commit
bfaac483f5
8 changed files with 131 additions and 6 deletions
  1. +6
    -6
      src/pEpEngine.c
  2. +125
    -0
      test/src/CleanInvalidOwnKeysTest.cc
  3. BIN
      test/test_files/ENGINE-750_check_clean_invalid_own_keys_no_alts_expired_keys.db
  4. BIN
      test/test_files/ENGINE-750_check_clean_invalid_own_keys_no_alts_expired_mgmt.db
  5. BIN
      test/test_files/ENGINE-750_check_clean_invalid_own_keys_no_alts_mistrusted_keys.db
  6. BIN
      test/test_files/ENGINE-750_check_clean_invalid_own_keys_no_alts_mistrusted_mgmt.db
  7. BIN
      test/test_files/ENGINE-750_check_clean_invalid_own_keys_no_alts_revoked_keys.db
  8. BIN
      test/test_files/ENGINE-750_check_clean_invalid_own_keys_no_alts_revoked_mgmt.db

+ 6
- 6
src/pEpEngine.c View File

@ -103,8 +103,8 @@ static const char *sql_get_identities_by_main_key_id =
" is_own, pEp_version_major, pEp_version_minor"
" from identity"
" join person on id = identity.user_id"
" join pgp_keypair on fpr = identity.main_key_id"
" join trust on id = trust.user_id"
" left join pgp_keypair on fpr = identity.main_key_id"
" left join trust on id = trust.user_id"
" and pgp_keypair_fpr = identity.main_key_id"
" where identity.main_key_id = ?1"
" order by is_own desc, "
@ -143,8 +143,8 @@ static const char *sql_get_identities_by_userid =
" is_own, pEp_version_major, pEp_version_minor"
" from identity"
" join person on id = identity.user_id"
" join pgp_keypair on fpr = identity.main_key_id"
" join trust on id = trust.user_id"
" left join pgp_keypair on fpr = identity.main_key_id"
" left join trust on id = trust.user_id"
" and pgp_keypair_fpr = identity.main_key_id"
" where identity.user_id = ?1"
" order by is_own desc, "
@ -433,8 +433,8 @@ static const char *sql_own_identities_retrieve =
" lang, identity.flags | pgp_keypair.flags, pEp_version_major, pEp_version_minor"
" from identity"
" join person on id = identity.user_id"
" join pgp_keypair on fpr = identity.main_key_id"
" join trust on id = trust.user_id"
" left join pgp_keypair on fpr = identity.main_key_id"
" left join trust on id = trust.user_id"
" and pgp_keypair_fpr = identity.main_key_id"
" where identity.is_own = 1"
" and (identity.flags & ?1) = 0;";


+ 125
- 0
test/src/CleanInvalidOwnKeysTest.cc View File

@ -0,0 +1,125 @@
#include <stdlib.h>
#include <string>
#include <cstring>
#include "pEpEngine.h"
#include "test_util.h"
#include "TestConstants.h"
#include "Engine.h"
#include <gtest/gtest.h>
namespace {
//The fixture for CleanInvalidOwnKeysTest
class CleanInvalidOwnKeysTest : public ::testing::Test {
public:
Engine* engine;
PEP_SESSION session;
protected:
// You can remove any or all of the following functions if its body
// is empty.
CleanInvalidOwnKeysTest() {
// You can do set-up work for each test here.
test_suite_name = ::testing::UnitTest::GetInstance()->current_test_info()->GTEST_SUITE_SYM();
test_name = ::testing::UnitTest::GetInstance()->current_test_info()->name();
test_path = get_main_test_home_dir() + "/" + test_suite_name + "/" + test_name;
}
~CleanInvalidOwnKeysTest() override {
// You can do clean-up work that doesn't throw exceptions here.
}
// If the constructor and destructor are not enough for setting up
// and cleaning up each test, you can define the following methods:
void SetUp() override {
// Code here will be called immediately after the constructor (right
// before each test).
// Leave this empty if there are no files to copy to the home directory path
std::vector<std::pair<std::string, std::string>> init_files = std::vector<std::pair<std::string, std::string>>();
string keyfile = string("test_files/ENGINE-750_") + test_name + "_keys.db";
string mgmtfile = string("test_files/ENGINE-750_") + test_name + "_mgmt.db";
init_files.push_back(std::pair<std::string, std::string>(keyfile, std::string("keys.db")));
init_files.push_back(std::pair<std::string, std::string>(mgmtfile, std::string("management.db")));
// Get a new test Engine.
engine = new Engine(test_path);
ASSERT_NE(engine, nullptr);
// Ok, let's initialize test directories etc.
engine->prep(NULL, NULL, init_files);
// Ok, try to start this bugger.
engine->start();
ASSERT_NE(engine->session, nullptr);
session = engine->session;
// Engine is up. Keep on truckin'
}
void TearDown() override {
// Code here will be called immediately after each test (right
// before the destructor).
engine->shut_down();
delete engine;
engine = NULL;
session = NULL;
}
private:
const char* test_suite_name;
const char* test_name;
string test_path;
// Objects declared here can be used by all tests in the CleanInvalidOwnKeysTest suite.
};
} // namespace
TEST_F(CleanInvalidOwnKeysTest, check_clean_invalid_own_keys_no_alts_revoked) {
// This is just a dummy test case. The convention is check_whatever_you_are_checking
// so for multiple test cases in a suite, be more explicit ;)
pEp_identity* alice = NULL;
PEP_STATUS status = get_identity(session, "pep.test.alice@pep-project.org", "ALICE", &alice);
ASSERT_EQ(status, PEP_STATUS_OK);
ASSERT_EQ(alice->fpr, nullptr);
char* fpr = NULL;
status = get_user_default_key(session, "ALICE", &fpr);
ASSERT_EQ(fpr, nullptr);
ASSERT_EQ(status, PEP_STATUS_OK);
}
TEST_F(CleanInvalidOwnKeysTest, check_clean_invalid_own_keys_no_alts_mistrusted) {
// This is just a dummy test case. The convention is check_whatever_you_are_checking
// so for multiple test cases in a suite, be more explicit ;)
pEp_identity* alice = NULL;
PEP_STATUS status = get_identity(session, "pep.test.alice@pep-project.org", "ALICE", &alice);
ASSERT_EQ(status, PEP_STATUS_OK);
ASSERT_EQ(alice->fpr, nullptr);
char* fpr = NULL;
status = get_user_default_key(session, "ALICE", &fpr);
ASSERT_EQ(fpr, nullptr);
ASSERT_EQ(status, PEP_STATUS_OK);
}
TEST_F(CleanInvalidOwnKeysTest, check_clean_invalid_own_keys_no_alts_expired) {
// This is just a dummy test case. The convention is check_whatever_you_are_checking
// so for multiple test cases in a suite, be more explicit ;)
pEp_identity* bob = NULL;
PEP_STATUS status = get_identity(session, "expired_bob_0@darthmama.org", "BOB", &bob);
ASSERT_EQ(status, PEP_STATUS_OK);
ASSERT_NE(bob->fpr, nullptr);
char* fpr = NULL;
status = get_user_default_key(session, "BOB", &fpr);
ASSERT_NE(fpr, nullptr);
ASSERT_EQ(status, PEP_STATUS_OK);
bool expired = true;
status = key_expired(session, bob->fpr, time(NULL), &expired);
ASSERT_FALSE(expired);
ASSERT_STREQ(bob->fpr, fpr);
}

BIN
test/test_files/ENGINE-750_check_clean_invalid_own_keys_no_alts_expired_keys.db View File


BIN
test/test_files/ENGINE-750_check_clean_invalid_own_keys_no_alts_expired_mgmt.db View File


BIN
test/test_files/ENGINE-750_check_clean_invalid_own_keys_no_alts_mistrusted_keys.db View File


BIN
test/test_files/ENGINE-750_check_clean_invalid_own_keys_no_alts_mistrusted_mgmt.db View File


BIN
test/test_files/ENGINE-750_check_clean_invalid_own_keys_no_alts_revoked_keys.db View File


BIN
test/test_files/ENGINE-750_check_clean_invalid_own_keys_no_alts_revoked_mgmt.db View File


Loading…
Cancel
Save