Expand full Companion terminal tooling
This commit is contained in:
1 parent
88ba5b26cb
commit
4e91cc9487
10 files changed
+1235
-41
No files matched your search
@@ -40,6 +40,98 @@ TEST(CLICommandUtils, HandlesLeadingWhitespaceAndSingleWordCommands) {
|
||||
EXPECT_STREQ("powersaving", single_command);
|
||||
}
|
||||
|
||||
TEST(CLICommandUtils, ParsesTerminalChannelMessagesWithUtf8Text) {
|
||||
using mesh::cli::TerminalChannelCommandMatch;
|
||||
mesh::cli::TerminalChannelMessage message;
|
||||
|
||||
EXPECT_EQ(TerminalChannelCommandMatch::Valid,
|
||||
mesh::cli::parseTerminalChannelMessage(
|
||||
"channel #rgdata Hello from Eugene 👋", message));
|
||||
EXPECT_EQ(7u, message.selector_len);
|
||||
EXPECT_EQ(0, memcmp("#rgdata", message.selector, message.selector_len));
|
||||
EXPECT_STREQ("Hello from Eugene 👋", message.text);
|
||||
EXPECT_TRUE(mesh::cli::terminalChannelNameMatches(message, "#rgdata"));
|
||||
EXPECT_FALSE(mesh::cli::terminalChannelNameMatches(message, "#RGDATA"));
|
||||
}
|
||||
|
||||
TEST(CLICommandUtils, ParsesTerminalChannelSlotsStrictly) {
|
||||
using mesh::cli::TerminalChannelCommandMatch;
|
||||
mesh::cli::TerminalChannelMessage message;
|
||||
size_t channel_index = 99;
|
||||
|
||||
EXPECT_EQ(TerminalChannelCommandMatch::Valid,
|
||||
mesh::cli::parseTerminalChannelMessage(
|
||||
"channel 2 Slot message", message));
|
||||
EXPECT_TRUE(mesh::cli::parseTerminalChannelIndex(message, 8,
|
||||
channel_index));
|
||||
EXPECT_EQ(2u, channel_index);
|
||||
|
||||
EXPECT_EQ(TerminalChannelCommandMatch::Valid,
|
||||
mesh::cli::parseTerminalChannelMessage(
|
||||
"channel 8 Out of range", message));
|
||||
EXPECT_FALSE(mesh::cli::parseTerminalChannelIndex(message, 8,
|
||||
channel_index));
|
||||
|
||||
EXPECT_EQ(TerminalChannelCommandMatch::Valid,
|
||||
mesh::cli::parseTerminalChannelMessage(
|
||||
"channel 2name Named channel", message));
|
||||
EXPECT_FALSE(mesh::cli::parseTerminalChannelIndex(message, 8,
|
||||
channel_index));
|
||||
EXPECT_TRUE(mesh::cli::terminalChannelNameMatches(message, "2name"));
|
||||
}
|
||||
|
||||
TEST(CLICommandUtils, RejectsIncompleteTerminalChannelMessages) {
|
||||
using mesh::cli::TerminalChannelCommandMatch;
|
||||
mesh::cli::TerminalChannelMessage message;
|
||||
|
||||
EXPECT_EQ(TerminalChannelCommandMatch::MissingSelector,
|
||||
mesh::cli::parseTerminalChannelMessage("channel", message));
|
||||
EXPECT_EQ(TerminalChannelCommandMatch::MissingMessage,
|
||||
mesh::cli::parseTerminalChannelMessage("channel #rgdata", message));
|
||||
EXPECT_EQ(TerminalChannelCommandMatch::NoMatch,
|
||||
mesh::cli::parseTerminalChannelMessage("channels", message));
|
||||
EXPECT_EQ(TerminalChannelCommandMatch::NoMatch,
|
||||
mesh::cli::parseTerminalChannelMessage("channelized test", message));
|
||||
}
|
||||
|
||||
TEST(CLICommandUtils, ParsesTerminalLoginAndRemoteCommandArguments) {
|
||||
using mesh::cli::TerminalArgumentCommandMatch;
|
||||
const char* argument = nullptr;
|
||||
|
||||
EXPECT_EQ(TerminalArgumentCommandMatch::Valid,
|
||||
mesh::cli::parseTerminalArgumentCommand(
|
||||
"login admin password", "login", argument));
|
||||
EXPECT_STREQ("admin password", argument);
|
||||
|
||||
EXPECT_EQ(TerminalArgumentCommandMatch::Valid,
|
||||
mesh::cli::parseTerminalArgumentCommand(
|
||||
"LOGIN CaseSensitivePassword", "login", argument));
|
||||
EXPECT_STREQ("CaseSensitivePassword", argument);
|
||||
|
||||
EXPECT_EQ(TerminalArgumentCommandMatch::Valid,
|
||||
mesh::cli::parseTerminalArgumentCommand(
|
||||
"cmd\tget stats", "cmd", argument));
|
||||
EXPECT_STREQ("get stats", argument);
|
||||
|
||||
EXPECT_EQ(TerminalArgumentCommandMatch::MissingArgument,
|
||||
mesh::cli::parseTerminalArgumentCommand(
|
||||
"login ", "login", argument));
|
||||
EXPECT_EQ(nullptr, argument);
|
||||
EXPECT_EQ(TerminalArgumentCommandMatch::NoMatch,
|
||||
mesh::cli::parseTerminalArgumentCommand(
|
||||
"logins password", "login", argument));
|
||||
}
|
||||
|
||||
TEST(CLICommandUtils, MasksOnlyTerminalLoginPasswordInput) {
|
||||
EXPECT_FALSE(mesh::cli::shouldMaskTerminalInput("login"));
|
||||
EXPECT_FALSE(mesh::cli::shouldMaskTerminalInput("login "));
|
||||
EXPECT_TRUE(mesh::cli::shouldMaskTerminalInput("login s"));
|
||||
EXPECT_TRUE(mesh::cli::shouldMaskTerminalInput("LOGIN s"));
|
||||
EXPECT_TRUE(mesh::cli::shouldMaskTerminalInput(" login secret phrase"));
|
||||
EXPECT_FALSE(mesh::cli::shouldMaskTerminalInput("cmd login secret"));
|
||||
EXPECT_FALSE(mesh::cli::shouldMaskTerminalInput("login-status"));
|
||||
}
|
||||
|
||||
TEST(CLICommandUtils, ParsesStrictDecimalValues) {
|
||||
float value = 0.0f;
|
||||
|
||||
|
||||
@@ -0,0 +1,173 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <helpers/TracePathHelpers.h>
|
||||
|
||||
TEST(TracePathHelpers, BuildsOneByteRoundTripThroughEndpoint) {
|
||||
const uint8_t saved[] = {0x11, 0x22};
|
||||
const uint8_t endpoint[] = {0x33};
|
||||
uint8_t route[8] = {0};
|
||||
mesh::RoundTripTracePath result;
|
||||
|
||||
ASSERT_TRUE(mesh::buildRoundTripTracePath(
|
||||
saved, 2, endpoint, true, route, sizeof(route), result));
|
||||
|
||||
const uint8_t expected[] = {0x11, 0x22, 0x33, 0x22, 0x11};
|
||||
EXPECT_EQ(1, result.hash_size);
|
||||
EXPECT_EQ(5, result.hop_count);
|
||||
EXPECT_EQ(sizeof(expected), result.byte_len);
|
||||
EXPECT_EQ(0, memcmp(expected, route, sizeof(expected)));
|
||||
EXPECT_EQ(0, mesh::traceFlagsForHashSize(result.hash_size));
|
||||
}
|
||||
|
||||
TEST(TracePathHelpers, OmitsNonForwardingEndpoint) {
|
||||
const uint8_t saved[] = {0x11, 0x22};
|
||||
uint8_t route[8] = {0};
|
||||
mesh::RoundTripTracePath result;
|
||||
|
||||
ASSERT_TRUE(mesh::buildRoundTripTracePath(
|
||||
saved, 2, nullptr, false, route, sizeof(route), result));
|
||||
|
||||
const uint8_t expected[] = {0x11, 0x22, 0x22, 0x11};
|
||||
EXPECT_EQ(4, result.hop_count);
|
||||
EXPECT_EQ(sizeof(expected), result.byte_len);
|
||||
EXPECT_EQ(0, memcmp(expected, route, sizeof(expected)));
|
||||
}
|
||||
|
||||
TEST(TracePathHelpers, PreservesTwoByteHashes) {
|
||||
const uint8_t saved[] = {0x11, 0x12, 0x21, 0x22};
|
||||
const uint8_t endpoint[] = {0x31, 0x32};
|
||||
uint8_t route[16] = {0};
|
||||
mesh::RoundTripTracePath result;
|
||||
|
||||
ASSERT_TRUE(mesh::buildRoundTripTracePath(
|
||||
saved, static_cast<uint8_t>((1 << 6) | 2), endpoint, true,
|
||||
route, sizeof(route), result));
|
||||
|
||||
const uint8_t expected[] = {
|
||||
0x11, 0x12, 0x21, 0x22, 0x31, 0x32, 0x21, 0x22, 0x11, 0x12};
|
||||
EXPECT_EQ(2, result.hash_size);
|
||||
EXPECT_EQ(5, result.hop_count);
|
||||
EXPECT_EQ(sizeof(expected), result.byte_len);
|
||||
EXPECT_EQ(0, memcmp(expected, route, sizeof(expected)));
|
||||
EXPECT_EQ(1, mesh::traceFlagsForHashSize(result.hash_size));
|
||||
}
|
||||
|
||||
TEST(TracePathHelpers, SafelyDownConvertsThreeByteHashes) {
|
||||
const uint8_t saved[] = {
|
||||
0x11, 0x12, 0x13, 0x21, 0x22, 0x23};
|
||||
const uint8_t endpoint[] = {0x31, 0x32, 0x33};
|
||||
uint8_t route[16] = {0};
|
||||
mesh::RoundTripTracePath result;
|
||||
|
||||
ASSERT_TRUE(mesh::buildRoundTripTracePath(
|
||||
saved, static_cast<uint8_t>((2 << 6) | 2), endpoint, true,
|
||||
route, sizeof(route), result));
|
||||
|
||||
const uint8_t expected[] = {
|
||||
0x11, 0x12, 0x21, 0x22, 0x31, 0x32, 0x21, 0x22, 0x11, 0x12};
|
||||
EXPECT_EQ(2, result.hash_size);
|
||||
EXPECT_EQ(5, result.hop_count);
|
||||
EXPECT_EQ(sizeof(expected), result.byte_len);
|
||||
EXPECT_EQ(0, memcmp(expected, route, sizeof(expected)));
|
||||
}
|
||||
|
||||
TEST(TracePathHelpers, RejectsUnknownEmptyAndOversizedRoutes) {
|
||||
const uint8_t saved[] = {0x11, 0x22};
|
||||
const uint8_t endpoint[] = {0x33};
|
||||
uint8_t route[4] = {0};
|
||||
mesh::RoundTripTracePath result;
|
||||
|
||||
EXPECT_FALSE(mesh::buildRoundTripTracePath(
|
||||
saved, 0xFF, endpoint, true, route, sizeof(route), result));
|
||||
EXPECT_FALSE(mesh::buildRoundTripTracePath(
|
||||
nullptr, 0, nullptr, false, route, sizeof(route), result));
|
||||
EXPECT_FALSE(mesh::buildRoundTripTracePath(
|
||||
saved, 2, endpoint, true, route, sizeof(route), result));
|
||||
}
|
||||
|
||||
TEST(TracePathHelpers, ParsesOneBytePrefixesSeparatedBySpaces) {
|
||||
uint8_t route[8] = {0};
|
||||
mesh::RawTracePath result;
|
||||
|
||||
ASSERT_EQ(mesh::RawTracePathParseResult::Valid,
|
||||
mesh::parseRawTracePath("1 11 22 3a 22 11", route,
|
||||
sizeof(route), 63, result));
|
||||
|
||||
const uint8_t expected[] = {0x11, 0x22, 0x3A, 0x22, 0x11};
|
||||
EXPECT_EQ(1, result.hash_size);
|
||||
EXPECT_EQ(5, result.hop_count);
|
||||
EXPECT_EQ(sizeof(expected), result.byte_len);
|
||||
EXPECT_EQ(0, memcmp(expected, route, sizeof(expected)));
|
||||
}
|
||||
|
||||
TEST(TracePathHelpers, ParsesTwoBytePrefixesWithMixedSeparators) {
|
||||
uint8_t route[16] = {0};
|
||||
mesh::RawTracePath result;
|
||||
|
||||
ASSERT_EQ(mesh::RawTracePathParseResult::Valid,
|
||||
mesh::parseRawTracePath("2 1122, 3344 ,AAbb,3344 1122",
|
||||
route, sizeof(route), 63, result));
|
||||
|
||||
const uint8_t expected[] = {
|
||||
0x11, 0x22, 0x33, 0x44, 0xAA, 0xBB, 0x33, 0x44, 0x11, 0x22};
|
||||
EXPECT_EQ(2, result.hash_size);
|
||||
EXPECT_EQ(5, result.hop_count);
|
||||
EXPECT_EQ(sizeof(expected), result.byte_len);
|
||||
EXPECT_EQ(0, memcmp(expected, route, sizeof(expected)));
|
||||
}
|
||||
|
||||
TEST(TracePathHelpers, ParsesFourBytePrefixesSeparatedByCommas) {
|
||||
uint8_t route[16] = {0};
|
||||
mesh::RawTracePath result;
|
||||
|
||||
ASSERT_EQ(mesh::RawTracePathParseResult::Valid,
|
||||
mesh::parseRawTracePath("4,01234567,89abcdef,01234567,",
|
||||
route, sizeof(route), 63, result));
|
||||
|
||||
const uint8_t expected[] = {
|
||||
0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
|
||||
0x01, 0x23, 0x45, 0x67};
|
||||
EXPECT_EQ(4, result.hash_size);
|
||||
EXPECT_EQ(3, result.hop_count);
|
||||
EXPECT_EQ(sizeof(expected), result.byte_len);
|
||||
EXPECT_EQ(0, memcmp(expected, route, sizeof(expected)));
|
||||
EXPECT_EQ(2, mesh::traceFlagsForHashSize(result.hash_size));
|
||||
}
|
||||
|
||||
TEST(TracePathHelpers, RejectsThreeByteAndMalformedRawPaths) {
|
||||
uint8_t route[8] = {0};
|
||||
mesh::RawTracePath result;
|
||||
|
||||
EXPECT_EQ(mesh::RawTracePathParseResult::InvalidHashSize,
|
||||
mesh::parseRawTracePath("3 112233", route, sizeof(route), 63,
|
||||
result));
|
||||
EXPECT_EQ(mesh::RawTracePathParseResult::MissingHashSize,
|
||||
mesh::parseRawTracePath(" ", route, sizeof(route), 63, result));
|
||||
EXPECT_EQ(mesh::RawTracePathParseResult::MissingPrefixes,
|
||||
mesh::parseRawTracePath("2 , ", route, sizeof(route), 63,
|
||||
result));
|
||||
EXPECT_EQ(mesh::RawTracePathParseResult::InvalidPrefix,
|
||||
mesh::parseRawTracePath("2 123 4567", route, sizeof(route), 63,
|
||||
result));
|
||||
EXPECT_EQ(mesh::RawTracePathParseResult::InvalidPrefix,
|
||||
mesh::parseRawTracePath("1 GG", route, sizeof(route), 63,
|
||||
result));
|
||||
}
|
||||
|
||||
TEST(TracePathHelpers, EnforcesRawPathHopAndByteLimits) {
|
||||
uint8_t route[8] = {0};
|
||||
mesh::RawTracePath result;
|
||||
|
||||
EXPECT_EQ(mesh::RawTracePathParseResult::TooManyHops,
|
||||
mesh::parseRawTracePath("1 11 22 33", route, sizeof(route), 2,
|
||||
result));
|
||||
EXPECT_EQ(mesh::RawTracePathParseResult::RouteTooLong,
|
||||
mesh::parseRawTracePath("4 11223344 55667788 99AABBCC", route,
|
||||
sizeof(route), 63, result));
|
||||
EXPECT_EQ(0xFF, mesh::traceFlagsForHashSize(3));
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
Reference in new issue
Block a user