From 7c0366a83748cf990d51fac6f16ddfa0dcd4fa7b Mon Sep 17 00:00:00 2001 From: Nick Logozzo Date: Mon, 11 Dec 2023 23:35:18 -0500 Subject: [PATCH] Squashed commit of the following: commit df1ccfdf1ad24d60d928c19b6f31320a07651f68 Author: Nick Logozzo Date: Mon Dec 11 23:35:04 2023 -0500 Update storetests.cpp commit 837a84dde8e4d4644b85d409a5c8e652f45173fe Author: Nick Logozzo Date: Mon Dec 11 23:19:54 2023 -0500 All - Improve Docs commit c34ba199c09070a8e7275439ec55807ee369eb44 Author: Nick Logozzo Date: Mon Dec 11 23:19:45 2023 -0500 Tests - Better Store Tests commit 5eac9e3bd74136a3d6586b8216685f14871fd401 Author: Nick Logozzo Date: Mon Dec 11 23:18:06 2023 -0500 Create spelling.yml commit be48316144e489d32284ee12a70e8f42f7d2b3f7 Author: Nick Logozzo Date: Mon Dec 11 23:04:56 2023 -0500 Keyring - Better Store Tests commit c4c18e06d1df1ad0cbaf564a22d0bb84b2bb72a8 Author: Nick Logozzo Date: Mon Dec 11 22:50:37 2023 -0500 Keyring - Ensure UTF-8 Path + Fix Tests commit 1921ac6c74c8e88902de679c197eb88382e46ca4 Author: Nick Logozzo Date: Mon Dec 11 19:30:26 2023 -0500 All - Better Compiler Warnings commit 286de47375e945cad33de1871404d8b383b70c5f Author: Nick Logozzo Date: Mon Dec 11 19:21:21 2023 -0500 Keyring - SQL Get Err Message --- .github/workflows/spelling.yml | 17 +++++++++++++ CMakeLists.txt | 5 ++++ include/events/event.h | 2 ++ include/keyring/store.h | 14 +++++------ src/appinfo.cpp | 2 +- src/aura.cpp | 2 +- src/keyring/store.cpp | 6 +++-- tests/storetests.cpp | 45 ++++++++++++++++++++-------------- 8 files changed, 64 insertions(+), 29 deletions(-) create mode 100644 .github/workflows/spelling.yml diff --git a/.github/workflows/spelling.yml b/.github/workflows/spelling.yml new file mode 100644 index 0000000..6f0961a --- /dev/null +++ b/.github/workflows/spelling.yml @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 683e613..a85c0de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/include/events/event.h b/include/events/event.h index 1d26464..b98dfec 100644 --- a/include/events/event.h +++ b/include/events/event.h @@ -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) { @@ -34,6 +35,7 @@ namespace Nickvision::Aura::Events } /** * @brief Constructs an Event via move. + * @param e The object to move */ Event(Event&& e) noexcept { diff --git a/include/keyring/store.h b/include/keyring/store.h index d52135b..f7862b2 100644 --- a/include/keyring/store.h +++ b/include/keyring/store.h @@ -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; /** @@ -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 */ diff --git a/src/appinfo.cpp b/src/appinfo.cpp index dab6cad..af2a293 100644 --- a/src/appinfo.cpp +++ b/src/appinfo.cpp @@ -212,7 +212,7 @@ namespace Nickvision::Aura std::vector AppInfo::convertUrlMapToVector(const std::map& urls) { std::vector vec; - for (const std::pair& pair : urls) + for (const std::pair& pair : urls) { vec.push_back(pair.first + " " + pair.second); } diff --git a/src/aura.cpp b/src/aura.cpp index 3e5536d..598bc13 100644 --- a/src/aura.cpp +++ b/src/aura.cpp @@ -13,7 +13,7 @@ namespace Nickvision::Aura Aura::~Aura() { - for (const std::pair& pair : m_configFiles) + for (const std::pair& pair : m_configFiles) { delete pair.second; } diff --git a/src/keyring/store.cpp b/src/keyring/store.cpp index c53be1f..bac0822 100644 --- a/src/keyring/store.cpp +++ b/src/keyring/store.cpp @@ -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(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) { @@ -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 diff --git a/tests/storetests.cpp b/tests/storetests.cpp index 1f86b14..6002d96 100644 --- a/tests/storetests.cpp +++ b/tests/storetests.cpp @@ -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 m_store; + + static void SetUpTestSuite() + { + Store::destroy("org.nickvision.aura.test"); + PasswordGenerator passGen; + m_store = std::make_shared("org.nickvision.aura.test", passGen.next()); + } +}; + +std::shared_ptr 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", "me@gmail.com", "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", "me@gmail.com", "abc12345!" })); - ASSERT_TRUE(store.getAllCredentials().size() == 2); - std::vector creds{ store.getCredentials("YT") }; + ASSERT_TRUE(m_store->isValid()); + ASSERT_TRUE(m_store->getAllCredentials().size() == 2); + std::vector creds{ m_store->getCredentials("YT") }; ASSERT_TRUE(creds.size() == 1); std::cout << creds[0] << std::endl; ASSERT_EQ(creds[0].getName(), "YT"); @@ -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()); } \ No newline at end of file