From 1c8645ec19b2fe9dbe747639f54c3ac87ac5a4c2 Mon Sep 17 00:00:00 2001 From: Dinesh Date: Thu, 14 May 2026 00:01:59 +0530 Subject: [PATCH] test(utils): add unit tests for GeneratePassword --- tests/test_utils.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/test_utils.cpp b/tests/test_utils.cpp index 5589ea4..9224f3a 100644 --- a/tests/test_utils.cpp +++ b/tests/test_utils.cpp @@ -6,7 +6,7 @@ */ #include "test_helpers.h" - +#include "../src/PasswordGen.h" #include #include @@ -271,3 +271,25 @@ TEST_F(HexTokenExtractionTest, WhitespaceOnly) EXPECT_TRUE(tokens.empty()); } + +// Test suite for password generation +class PasswordGenTest : public ::testing::Test +{ +}; + +TEST_F(PasswordGenTest, ClampsLength) +{ + EXPECT_EQ(seal::GeneratePassword(1).size(), 8u); + EXPECT_EQ(seal::GeneratePassword(999).size(), 128u); + EXPECT_EQ(seal::GeneratePassword(20).size(), 20u); +} + +TEST_F(PasswordGenTest, UsesDocumentedCharset) +{ + static constexpr std::string_view allowed = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_=+"; + + auto password = seal::GeneratePassword(64); + for (char ch : password.view()) + EXPECT_NE(allowed.find(ch), std::string_view::npos); +} \ No newline at end of file