commit
8a0e32573c
@ -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);
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue