Loading .vscode/c_cpp_properties.json +2 −1 Changes for .vscode/c_cpp_properties.json: 2 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -12,7 +12,8 @@ "intelliSenseMode": "linux-clang-x64", "compileCommands": [ "${workspaceFolder}/build/compile_commands.json" ] ], "configurationProvider": "ms-vscode.cmake-tools" } ], "version": 4 Loading CMakeLists.txt +1 −1 Changes for CMakeLists.txt: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -63,7 +63,7 @@ if(BUILD_BINDINGS) add_subdirectory(bindings) endif() option(BUILD_TESTING "Build unit tests" OFF) option(BUILD_TESTING "Build unit tests" ON) if(BUILD_TESTING) add_subdirectory(tests) endif() Loading tests/CMakeLists.txt +9 −0 Changes for tests/CMakeLists.txt: 9 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -96,3 +96,12 @@ target_link_libraries(test_cluster_ops PRIVATE GTest::gtest_main ) gtest_discover_tests(test_cluster_ops) # ── Client tests ── add_executable(test_client test_client.cpp) target_include_directories(test_client PRIVATE ${CMAKE_SOURCE_DIR}/src) target_link_libraries(test_client PRIVATE authobj GTest::gtest_main ) gtest_discover_tests(test_client) No newline at end of file tests/test_client.cpp 0 → 100644 +159 −0 Changes for tests/test_client.cpp: 159 added lines, 0 removed lines. Original line number Diff line number Diff line /* * Unit tests for Client functionality */ #include <gtest/gtest.h> #include <string> #include <uuidp.h> #include <memory> #include "backend.h" #include "client.h" #include "exception.h" #include "authdb.h" using namespace authdb; class ClientTest : public ::testing::Test { protected: std::unique_ptr<AuthBackend> backend; void SetUp() override { backend = std::make_unique<AuthBackend>(authdb::File, "/tmp/authdb_client_test.db", "testdomain"); } void TearDown() override { // Clean up test database file unlink("/tmp/authdb_client_test.db"); } }; TEST_F(ClientTest, ClientDataCreation) { uuid::uuid clientId; clientId.generate(); class ClientData clientData(clientId); // Test setting and getting name const char* testName = "TestClient"; clientData.setName(testName); EXPECT_STREQ(testName, clientData.getName()); // Test setting and getting key const char* testKey = "testkey123"; clientData.setKey(testKey); EXPECT_STREQ(testKey, clientData.getKey()); // Test setting and getting krb key std::string testKrbKey = "krbkey123"; clientData.setKrbKey(testKrbKey); EXPECT_EQ(testKrbKey, clientData.getKrbKey()); } TEST_F(ClientTest, ClientCreationAndRetrieval) { uuid::uuid clientId; clientId.generate(); class ClientData clientData(clientId); const char* testName = "TestClient"; clientData.setName(testName); const char* testKey = "testkey123"; clientData.setKey(testKey); Client client; // Create client client.create(*backend, &clientData); // Test if client exists int ret = 0; bool exists = client.exits(*backend, clientId, testName, ret); EXPECT_TRUE(exists); EXPECT_EQ(2, ret); // Should return 2 for UUID match // Test retrieving client info class ClientData retrievedData(clientId); size_t pos = 0; client.info(*backend, retrievedData, pos); EXPECT_STREQ(testName, retrievedData.getName()); EXPECT_STREQ(testKey, retrievedData.getKey()); } TEST_F(ClientTest, ClientList) { class Client client; std::vector<uuid::uuid> uuids; // Initially should be empty client.list(*backend, uuids); EXPECT_TRUE(uuids.empty()); // Create a few clients for (int i = 0; i < 3; i++) { uuid::uuid clientId; clientId.generate(); class ClientData clientData(clientId); std::string name = "Client" + std::to_string(i); clientData.setName(name.c_str()); clientData.setKey( (std::string("key") + std::to_string(i)).c_str() ); client.create(*backend, &clientData); } // List all clients uuids.clear(); client.list(*backend, uuids); EXPECT_EQ(3, uuids.size()); } TEST_F(ClientTest, ClientEdit) { uuid::uuid clientId; clientId.generate(); class ClientData clientData(clientId); const char* testName = "OriginalClient"; clientData.setName(testName); clientData.setKey("originalkey"); class Client client; client.create(*backend, &clientData); // Edit the client const char* newName = "EditedClient"; clientData.setName(newName); clientData.setKey("editedkey"); client.edit(*backend, clientData); // Verify edit worked class ClientData retrievedData(clientId); size_t pos = 0; client.info(*backend, retrievedData, pos); EXPECT_STREQ(newName, retrievedData.getName()); EXPECT_STREQ("editedkey", retrievedData.getKey()); } TEST_F(ClientTest, ClientRemoval) { uuid::uuid clientId; clientId.generate(); class ClientData clientData(clientId); const char* testName = "ClientToBeRemoved"; clientData.setName(testName); clientData.setKey("removekey"); Client client; client.create(*backend, &clientData); // Verify client exists int ret = 0; bool exists = client.exits(*backend, clientId, testName, ret); EXPECT_TRUE(exists); // Remove client client.remove(*backend, clientId); // Verify client no longer exists exists = client.exits(*backend, clientId, testName, ret); EXPECT_FALSE(exists); } No newline at end of file Loading
.vscode/c_cpp_properties.json +2 −1 Changes for .vscode/c_cpp_properties.json: 2 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -12,7 +12,8 @@ "intelliSenseMode": "linux-clang-x64", "compileCommands": [ "${workspaceFolder}/build/compile_commands.json" ] ], "configurationProvider": "ms-vscode.cmake-tools" } ], "version": 4 Loading
CMakeLists.txt +1 −1 Changes for CMakeLists.txt: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -63,7 +63,7 @@ if(BUILD_BINDINGS) add_subdirectory(bindings) endif() option(BUILD_TESTING "Build unit tests" OFF) option(BUILD_TESTING "Build unit tests" ON) if(BUILD_TESTING) add_subdirectory(tests) endif() Loading
tests/CMakeLists.txt +9 −0 Changes for tests/CMakeLists.txt: 9 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -96,3 +96,12 @@ target_link_libraries(test_cluster_ops PRIVATE GTest::gtest_main ) gtest_discover_tests(test_cluster_ops) # ── Client tests ── add_executable(test_client test_client.cpp) target_include_directories(test_client PRIVATE ${CMAKE_SOURCE_DIR}/src) target_link_libraries(test_client PRIVATE authobj GTest::gtest_main ) gtest_discover_tests(test_client) No newline at end of file
tests/test_client.cpp 0 → 100644 +159 −0 Changes for tests/test_client.cpp: 159 added lines, 0 removed lines. Original line number Diff line number Diff line /* * Unit tests for Client functionality */ #include <gtest/gtest.h> #include <string> #include <uuidp.h> #include <memory> #include "backend.h" #include "client.h" #include "exception.h" #include "authdb.h" using namespace authdb; class ClientTest : public ::testing::Test { protected: std::unique_ptr<AuthBackend> backend; void SetUp() override { backend = std::make_unique<AuthBackend>(authdb::File, "/tmp/authdb_client_test.db", "testdomain"); } void TearDown() override { // Clean up test database file unlink("/tmp/authdb_client_test.db"); } }; TEST_F(ClientTest, ClientDataCreation) { uuid::uuid clientId; clientId.generate(); class ClientData clientData(clientId); // Test setting and getting name const char* testName = "TestClient"; clientData.setName(testName); EXPECT_STREQ(testName, clientData.getName()); // Test setting and getting key const char* testKey = "testkey123"; clientData.setKey(testKey); EXPECT_STREQ(testKey, clientData.getKey()); // Test setting and getting krb key std::string testKrbKey = "krbkey123"; clientData.setKrbKey(testKrbKey); EXPECT_EQ(testKrbKey, clientData.getKrbKey()); } TEST_F(ClientTest, ClientCreationAndRetrieval) { uuid::uuid clientId; clientId.generate(); class ClientData clientData(clientId); const char* testName = "TestClient"; clientData.setName(testName); const char* testKey = "testkey123"; clientData.setKey(testKey); Client client; // Create client client.create(*backend, &clientData); // Test if client exists int ret = 0; bool exists = client.exits(*backend, clientId, testName, ret); EXPECT_TRUE(exists); EXPECT_EQ(2, ret); // Should return 2 for UUID match // Test retrieving client info class ClientData retrievedData(clientId); size_t pos = 0; client.info(*backend, retrievedData, pos); EXPECT_STREQ(testName, retrievedData.getName()); EXPECT_STREQ(testKey, retrievedData.getKey()); } TEST_F(ClientTest, ClientList) { class Client client; std::vector<uuid::uuid> uuids; // Initially should be empty client.list(*backend, uuids); EXPECT_TRUE(uuids.empty()); // Create a few clients for (int i = 0; i < 3; i++) { uuid::uuid clientId; clientId.generate(); class ClientData clientData(clientId); std::string name = "Client" + std::to_string(i); clientData.setName(name.c_str()); clientData.setKey( (std::string("key") + std::to_string(i)).c_str() ); client.create(*backend, &clientData); } // List all clients uuids.clear(); client.list(*backend, uuids); EXPECT_EQ(3, uuids.size()); } TEST_F(ClientTest, ClientEdit) { uuid::uuid clientId; clientId.generate(); class ClientData clientData(clientId); const char* testName = "OriginalClient"; clientData.setName(testName); clientData.setKey("originalkey"); class Client client; client.create(*backend, &clientData); // Edit the client const char* newName = "EditedClient"; clientData.setName(newName); clientData.setKey("editedkey"); client.edit(*backend, clientData); // Verify edit worked class ClientData retrievedData(clientId); size_t pos = 0; client.info(*backend, retrievedData, pos); EXPECT_STREQ(newName, retrievedData.getName()); EXPECT_STREQ("editedkey", retrievedData.getKey()); } TEST_F(ClientTest, ClientRemoval) { uuid::uuid clientId; clientId.generate(); class ClientData clientData(clientId); const char* testName = "ClientToBeRemoved"; clientData.setName(testName); clientData.setKey("removekey"); Client client; client.create(*backend, &clientData); // Verify client exists int ret = 0; bool exists = client.exits(*backend, clientId, testName, ret); EXPECT_TRUE(exists); // Remove client client.remove(*backend, clientId); // Verify client no longer exists exists = client.exits(*backend, clientId, testName, ret); EXPECT_FALSE(exists); } No newline at end of file