Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3393840
D3654.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D3654.diff
View Options
diff --git a/services/tunnelbroker/test/ToolsTest.cpp b/services/tunnelbroker/test/ToolsTest.cpp
new file mode 100644
--- /dev/null
+++ b/services/tunnelbroker/test/ToolsTest.cpp
@@ -0,0 +1,72 @@
+#include "Tools.h"
+#include "Constants.h"
+
+#include <gtest/gtest.h>
+
+#include <string>
+
+using namespace comm::network;
+
+class ToolsTest : public testing::Test {};
+
+TEST(ToolsTest, GeneratedRandomStringHasValidLength) {
+ const std::size_t length = 32;
+ const std::string generated = tools::generateRandomString(length);
+ EXPECT_EQ(generated.length(), length)
+ << "Generated random string \"" << generated << "\" length "
+ << generated.length() << " is not equal to " << length;
+}
+
+TEST(ToolsTest, ValidateDeviceIDReturnsTrueOnStaticValidDeviceID) {
+ const std::string validDeviceID =
+ "mobile:EMQNoQ7b2ueEmQ4QsevRWlXxFCNt055y20T1PHdoYAQRt0S6TLzZWNM6XSvdWqxm";
+ EXPECT_EQ(tools::validateDeviceID(validDeviceID), true)
+ << "Valid deviceID \"" << validDeviceID
+ << "\" is invalid by the function";
+}
+
+TEST(ToolsTest, ValidateDeviceIDReturnsTrueOnGeneratedValidDeviceID) {
+ const std::string validDeviceID =
+ "mobile:" + tools::generateRandomString(DEVICEID_CHAR_LENGTH);
+ EXPECT_EQ(tools::validateDeviceID(validDeviceID), true)
+ << "Valid generated deviceID \"" << validDeviceID
+ << "\" is invalid by the function";
+}
+
+TEST(ToolsTest, ValidateDeviceIDReturnsFalseOnInvalidDeviceIDPrefix) {
+ const std::string invalidDeviceIDPrefix =
+ "invalid-"
+ "EMQNoQ7b2ueEmQ4QsevRWlXxFCNt055y20T1PHdoYAQRt0S6TLzZWNM6XSvdWqxm";
+ EXPECT_EQ(tools::validateDeviceID(invalidDeviceIDPrefix), false)
+ << "Invalid prefix deviceID \"" << invalidDeviceIDPrefix
+ << "\" is valid by the function";
+}
+
+TEST(ToolsTest, ValidateDeviceIDReturnsFalseOnInvalidDeviceIDSuffix) {
+ const std::string invalidDeviceIDSuffix =
+ "mobile:tQNoQ7b2ueEmQ4QsevRWlXxFCNt055y20T1PHdoYAQRt0S6TLzZWNM6XSvdWqxm";
+ EXPECT_EQ(tools::validateDeviceID(invalidDeviceIDSuffix), false)
+ << "Invalid suffix deviceID \"" << invalidDeviceIDSuffix
+ << "\" is valid by the function";
+}
+
+TEST(ToolsTest, ValidateSessionIDReturnsTrueOnValidStaticSessionID) {
+ const std::string validSessionID = "bc0c1aa2-bf09-11ec-9d64-0242ac120002";
+ EXPECT_EQ(tools::validateSessionID(validSessionID), true)
+ << "Valid sessionID \"" << validSessionID
+ << "\" is invalid by the function";
+}
+
+TEST(ToolsTest, ValidateSessionIDReturnsTrueOnValidGeneratedSessionID) {
+ const std::string validSessionID = tools::generateUUID();
+ EXPECT_EQ(tools::validateSessionID(validSessionID), true)
+ << "Valid generated sessionID \"" << validSessionID
+ << "\" is invalid by the function";
+}
+
+TEST(ToolsTest, ValidateSessionIDReturnsFalseOnInvalidSessionID) {
+ const std::string invalidSessionID = "bc0c1aa29bf09-11ec-9d64-0242ac120002";
+ EXPECT_EQ(tools::validateSessionID(invalidSessionID), false)
+ << "Invalid sessionID \"" << invalidSessionID
+ << "\" is valid by the function";
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Dec 1, 4:09 PM (21 h, 44 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2605494
Default Alt Text
D3654.diff (3 KB)
Attached To
Mode
D3654: [services] Tunnelbroker - Tools tests
Attached
Detach File
Event Timeline
Log In to Comment