Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit df1ccfd
Author: Nick Logozzo <[email protected]>
Date:   Mon Dec 11 23:35:04 2023 -0500

    Update storetests.cpp

commit 837a84d
Author: Nick Logozzo <[email protected]>
Date:   Mon Dec 11 23:19:54 2023 -0500

    All - Improve Docs

commit c34ba19
Author: Nick Logozzo <[email protected]>
Date:   Mon Dec 11 23:19:45 2023 -0500

    Tests - Better Store Tests

commit 5eac9e3
Author: Nick Logozzo <[email protected]>
Date:   Mon Dec 11 23:18:06 2023 -0500

    Create spelling.yml

commit be48316
Author: Nick Logozzo <[email protected]>
Date:   Mon Dec 11 23:04:56 2023 -0500

    Keyring - Better Store Tests

commit c4c18e0
Author: Nick Logozzo <[email protected]>
Date:   Mon Dec 11 22:50:37 2023 -0500

    Keyring - Ensure UTF-8 Path + Fix Tests

commit 1921ac6
Author: Nick Logozzo <[email protected]>
Date:   Mon Dec 11 19:30:26 2023 -0500

    All - Better Compiler Warnings

commit 286de47
Author: Nick Logozzo <[email protected]>
Date:   Mon Dec 11 19:21:21 2023 -0500

    Keyring - SQL Get Err Message
  • Loading branch information
nlogozzo committed Dec 12, 2023
1 parent 5789026 commit 7c0366a
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 29 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/spelling.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
types: [ "review_requested", "ready_for_review" ]
name: Spell Check
jobs:
codespell:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: codespell-project/actions-codespell@master
with:
check_filenames: true
skip: cargo-sources.json,.git,*.svg,*.html,*.js,*.po,*.pot,*.page,*.map
ignore_words_list: gir
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ if(LINUX)
pkg_check_modules(gthread-2.0 REQUIRED IMPORTED_TARGET gthread-2.0)
target_link_libraries(${PROJECT_NAME} PUBLIC libsecret::libsecret libuuid::libuuid PkgConfig::glib-2.0 PkgConfig::gio-2.0 PkgConfig::gmodule-2.0 PkgConfig::gobject-2.0 PkgConfig::gthread-2.0)
endif()
if(MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE /W4)
else()
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wpedantic)
endif()

#libaura Install
configure_file(${PROJECT_SOURCE_DIR}/pkg-config/libaura.pc.in libaura.pc @ONLY)
Expand Down
2 changes: 2 additions & 0 deletions include/events/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace Nickvision::Aura::Events
Event() { }
/**
* @brief Constructs an Event via copy.
* @param e The object to copy
*/
Event(const Event& e)
{
Expand All @@ -34,6 +35,7 @@ namespace Nickvision::Aura::Events
}
/**
* @brief Constructs an Event via move.
* @param e The object to move
*/
Event(Event&& e) noexcept
{
Expand Down
14 changes: 7 additions & 7 deletions include/keyring/store.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,30 @@
namespace Nickvision::Aura::Keyring
{
/**
* @brief A store object for credentials. Backed by sqlciphe.
* @brief A store object for credentials. Backed by sqlcipher.
*/
class Store
{
public:
/**
* @brief Constructs a Store object. The isValid() function should be called to ensure the object is valid.
* @brief Constructs a Store object. The isValid() function should be called to ensure that the store was loaded successfully.
* @param name The name of the store
* @param password The password of the store
*/
Store(const std::string& name, const std::string& password);
/**
* @brief Copies a Store object.
* @parma store The object to move
* @brief Deconstructs a Store object.
* @param store The object to move
*/
Store(const Store& store);
/**
* @brief Moves a Store object.
* @parma store The object to move
* @param store The object to move
*/
Store(Store&& store) noexcept;
/**
* @brief Gets whether or not the store object is valid.
* @return True if valid, else false
*/
bool isValid() const;
/**
Expand Down Expand Up @@ -90,13 +90,13 @@ namespace Nickvision::Aura::Keyring
*/
bool destroy();
/**
* @brief Copies an Store
* @brief Copies a Store object.
* @param store The Store to copy
* @return this
*/
Store& operator=(const Store& store);
/**
* @brief Moves an Store
* @brief Moves a Store object.
* @param store The Store to move
* @return this
*/
Expand Down
2 changes: 1 addition & 1 deletion src/appinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ namespace Nickvision::Aura
std::vector<std::string> AppInfo::convertUrlMapToVector(const std::map<std::string, std::string>& urls)
{
std::vector<std::string> vec;
for (const std::pair<std::string, std::string>& pair : urls)
for (const std::pair<const std::string, std::string>& pair : urls)
{
vec.push_back(pair.first + " " + pair.second);
}
Expand Down
2 changes: 1 addition & 1 deletion src/aura.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Nickvision::Aura

Aura::~Aura()
{
for (const std::pair<std::string, ConfigurationBase*>& pair : m_configFiles)
for (const std::pair<const std::string, ConfigurationBase*>& pair : m_configFiles)
{
delete pair.second;
}
Expand Down
6 changes: 4 additions & 2 deletions src/keyring/store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ namespace Nickvision::Aura::Keyring
m_path{ getPathFromName(name) }
{
sqlite3* database{ nullptr };
char* err{ nullptr };
if (sqlite3_open_v2(m_path.string().c_str(), &database, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, nullptr) == SQLITE_OK)
{
if (sqlite3_key(database, m_password.c_str(), static_cast<int>(m_password.size())) == SQLITE_OK)
{
if (sqlite3_exec(database, "CREATE TABLE IF NOT EXISTS credentials (id TEXT PRIMARY KEY, name TEXT, uri TEXT, username TEXT, password TEXT)", nullptr, nullptr, nullptr) == SQLITE_OK)
if (sqlite3_exec(database, "CREATE TABLE IF NOT EXISTS credentials (id TEXT PRIMARY KEY, name TEXT, uri TEXT, username TEXT, password TEXT)", nullptr, nullptr, &err) == SQLITE_OK)
{
m_database = { database, [](sqlite3* sql)
{
Expand All @@ -39,7 +40,8 @@ namespace Nickvision::Aura::Keyring
}
else
{
std::cerr << "[STORE] Unable to exec create table command. Key may be invalid." << std::endl;
std::cerr << "[STORE] Unable to exec create table command. Key may be invalid. " << std::string(err ? err : "") << std::endl;
sqlite3_free(err);
}
}
else
Expand Down
45 changes: 27 additions & 18 deletions tests/storetests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,38 @@

using namespace Nickvision::Aura::Keyring;

static const std::string storeName{ "AuraTestStore" };
static const std::string storePassword{ PasswordGenerator().next() };
class StoreTest : public testing::Test
{
public:
static std::shared_ptr<Store> m_store;

static void SetUpTestSuite()
{
Store::destroy("org.nickvision.aura.test");
PasswordGenerator passGen;
m_store = std::make_shared<Store>("org.nickvision.aura.test", passGen.next());
}
};

std::shared_ptr<Store> StoreTest::m_store = nullptr;

TEST(StoreTest, EnsureNoStore)
TEST_F(StoreTest, CheckValidStore)
{
ASSERT_TRUE(Store::destroy(storeName));
ASSERT_TRUE(m_store->isValid());
}

TEST(StoreTests, CreateStrore)
TEST_F(StoreTest, AddCredentials)
{
Store store{ storeName, storePassword };
ASSERT_TRUE(store.isValid());
ASSERT_TRUE(m_store->isValid());
ASSERT_TRUE(m_store->addCredential({ "YT", "https://youtube.com", "theawesomeguy", "abc123!" }));
ASSERT_TRUE(m_store->addCredential({ "Google", "https://google.com", "[email protected]", "abc12345!" }));
}

TEST(StoreTests, AddCredentials)
TEST_F(StoreTest, EnsureCredentials)
{
Store store{ storeName, storePassword };
ASSERT_TRUE(store.isValid());
ASSERT_TRUE(store.addCredential({ "YT", "https://youtube.com", "theawesomeguy", "abc123!" }));
ASSERT_TRUE(store.addCredential({ "Google", "https://google.com", "[email protected]", "abc12345!" }));
ASSERT_TRUE(store.getAllCredentials().size() == 2);
std::vector<Credential> creds{ store.getCredentials("YT") };
ASSERT_TRUE(m_store->isValid());
ASSERT_TRUE(m_store->getAllCredentials().size() == 2);
std::vector<Credential> creds{ m_store->getCredentials("YT") };
ASSERT_TRUE(creds.size() == 1);
std::cout << creds[0] << std::endl;
ASSERT_EQ(creds[0].getName(), "YT");
Expand All @@ -35,9 +45,8 @@ TEST(StoreTests, AddCredentials)
ASSERT_EQ(creds[0].getPassword(), "abc123!");
}

TEST(StoreTests, DeleteStore)
TEST_F(StoreTest, DestroyStore)
{
Store store{ storeName, storePassword };
ASSERT_TRUE(store.isValid());
ASSERT_TRUE(store.destroy());
ASSERT_TRUE(m_store->isValid());
ASSERT_TRUE(m_store->destroy());
}

0 comments on commit 7c0366a

Please sign in to comment.