|
@@ -22,6 +22,41 @@ static uint32_t write_callCnt = 0u;
|
|
|
static char write_data[1024];
|
|
|
static uint32_t write_length;
|
|
|
|
|
|
+#define TEST_SHELLMATTA_SETUP shellmatta_retCode_t ret; \
|
|
|
+ shellmatta_instance_t inst; \
|
|
|
+ shellmatta_handle_t handle; \
|
|
|
+ char buffer[1024] = {0}; \
|
|
|
+ char historyBuffer[1024] = {0}; \
|
|
|
+ \
|
|
|
+ shellmatta_doInit( &inst, \
|
|
|
+ &handle, \
|
|
|
+ buffer, \
|
|
|
+ sizeof(buffer), \
|
|
|
+ historyBuffer, \
|
|
|
+ sizeof(historyBuffer), \
|
|
|
+ "shellmatta->", \
|
|
|
+ NULL, \
|
|
|
+ writeFct); \
|
|
|
+ \
|
|
|
+ write_callCnt = 0u; \
|
|
|
+ memset(write_data, 0, sizeof(write_data)); \
|
|
|
+ write_length = 0u; \
|
|
|
+ \
|
|
|
+ shellmatta_addCmd(handle, &publicCmd); \
|
|
|
+ shellmatta_addCmd(handle, &privateCmd);
|
|
|
+
|
|
|
+#define TEST_SHELLMATTA_AUTH_SETUP shellmatta_auth_user_t userList[] = { \
|
|
|
+ {1, "shimatta", "12345678"}, \
|
|
|
+ {2, "not_shimatta", "87654321"} \
|
|
|
+ }; \
|
|
|
+ \
|
|
|
+ uint32_t privateCmdPerms[] = {1}; \
|
|
|
+ shellmatta_auth_perm_t permList[] = { \
|
|
|
+ {"private", privateCmdPerms, sizeof(privateCmdPerms)/sizeof(privateCmdPerms[0])} \
|
|
|
+ }; \
|
|
|
+ \
|
|
|
+ shellmatta_auth_init(handle, userList, 1, permList, 1, false, NULL, NULL);
|
|
|
+
|
|
|
static shellmatta_retCode_t writeFct(const char* data, uint32_t length)
|
|
|
{
|
|
|
write_callCnt ++;
|
|
@@ -58,13 +93,18 @@ static shellmatta_retCode_t privateCmdFct(shellmatta_handle_t handle, const char
|
|
|
}
|
|
|
shellmatta_cmd_t privateCmd = {(char*)"private", (char*)"r", NULL, NULL, privateCmdFct, NULL, NULL};
|
|
|
|
|
|
-TEST_CASE( "check unauthenticated help" ) {
|
|
|
+SCENARIO("Check help auth uninitialized") {
|
|
|
+ GIVEN("An initialized shellmatta instance without initialized auth") {
|
|
|
+
|
|
|
+ TEST_SHELLMATTA_SETUP;
|
|
|
+
|
|
|
+ WHEN("The help command is called") {
|
|
|
+
|
|
|
+ ret = shellmatta_processData(handle, (char*)"help\r", 5);
|
|
|
+ CHECK(ret == SHELLMATTA_OK);
|
|
|
+
|
|
|
+ THEN("The help command prints all commands.") {
|
|
|
|
|
|
- shellmatta_retCode_t ret;
|
|
|
- shellmatta_instance_t inst;
|
|
|
- shellmatta_handle_t handle;
|
|
|
- char buffer[1024] = {0};
|
|
|
- char historyBuffer[1024] = {0};
|
|
|
char *dummyData = (char*) "help\r\n"
|
|
|
"help ? help [command] - print help or usage information\r\n"
|
|
|
"login li Login command\r\n"
|
|
@@ -74,28 +114,116 @@ TEST_CASE( "check unauthenticated help" ) {
|
|
|
"\r\n"
|
|
|
"shellmatta->";
|
|
|
|
|
|
- shellmatta_doInit( &inst,
|
|
|
- &handle,
|
|
|
- buffer,
|
|
|
- sizeof(buffer),
|
|
|
- historyBuffer,
|
|
|
- sizeof(historyBuffer),
|
|
|
- "shellmatta->",
|
|
|
- NULL,
|
|
|
- writeFct);
|
|
|
+ CHECK(ret == SHELLMATTA_OK);
|
|
|
+ CHECK(write_length == strlen(dummyData));
|
|
|
+ REQUIRE_THAT(write_data, Catch::Matchers::Equals(dummyData));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+SCENARIO("Check help auth unauthorized") {
|
|
|
+ GIVEN("An initialized shellmatta instance with initialized auth") {
|
|
|
+
|
|
|
+ TEST_SHELLMATTA_SETUP;
|
|
|
+
|
|
|
+ TEST_SHELLMATTA_AUTH_SETUP;
|
|
|
+
|
|
|
+ WHEN("The help command is called") {
|
|
|
+
|
|
|
+ ret = shellmatta_processData(handle, (char*)"help\r", 5);
|
|
|
+ CHECK(ret == SHELLMATTA_OK);
|
|
|
+
|
|
|
+ THEN("The help command prints only public commands.") {
|
|
|
|
|
|
- shellmatta_auth_init(handle, NULL, 0, NULL, 0, false, NULL, NULL);
|
|
|
+ char *dummyData = (char*) "help\r\n"
|
|
|
+ "help ? help [command] - print help or usage information\r\n"
|
|
|
+ "login li Login command\r\n"
|
|
|
+ "logout lo Logout command\r\n"
|
|
|
+ "public p\r\n"
|
|
|
+ "\r\n"
|
|
|
+ "shellmatta->";
|
|
|
|
|
|
- write_callCnt = 0u;
|
|
|
- memset(write_data, 0, sizeof(write_data));
|
|
|
- write_length = 0u;
|
|
|
+ CHECK(ret == SHELLMATTA_OK);
|
|
|
+ CHECK(write_length == strlen(dummyData));
|
|
|
+ REQUIRE_THAT(write_data, Catch::Matchers::Equals(dummyData));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+SCENARIO("Check help authorized") {
|
|
|
+ GIVEN("An initialized shellmatta instance with initialized auth") {
|
|
|
+
|
|
|
+ TEST_SHELLMATTA_SETUP;
|
|
|
+
|
|
|
+ TEST_SHELLMATTA_AUTH_SETUP;
|
|
|
+
|
|
|
+ WHEN("The user shellmatta is logged in") {
|
|
|
+
|
|
|
+ ret = shellmatta_auth_login(handle, 1);
|
|
|
+ CHECK(ret == SHELLMATTA_OK);
|
|
|
|
|
|
- shellmatta_addCmd(handle, &publicCmd);
|
|
|
- shellmatta_addCmd(handle, &privateCmd);
|
|
|
+ AND_WHEN("The help command is called") {
|
|
|
|
|
|
ret = shellmatta_processData(handle, (char*)"help\r", 5);
|
|
|
+ CHECK(ret == SHELLMATTA_OK);
|
|
|
+
|
|
|
+ THEN("The help command prints all commands.") {
|
|
|
+
|
|
|
+ char *dummyData = (char*) "help\r\n"
|
|
|
+ "help ? help [command] - print help or usage information\r\n"
|
|
|
+ "login li Login command\r\n"
|
|
|
+ "logout lo Logout command\r\n"
|
|
|
+ "private r\r\n"
|
|
|
+ "public p\r\n"
|
|
|
+ "\r\n"
|
|
|
+ "shimatta@shellmatta->";
|
|
|
|
|
|
CHECK(ret == SHELLMATTA_OK);
|
|
|
CHECK(write_length == strlen(dummyData));
|
|
|
REQUIRE_THAT(write_data, Catch::Matchers::Equals(dummyData));
|
|
|
}
|
|
|
+
|
|
|
+ AND_WHEN("The user is logged out using the logout command") {
|
|
|
+ write_length = 0;
|
|
|
+ memset(write_data, 0, sizeof(write_data));
|
|
|
+ ret = shellmatta_processData(handle, (char*)"logout\r", 7);
|
|
|
+ CHECK(ret == SHELLMATTA_OK);
|
|
|
+
|
|
|
+ THEN("The Shellmatta prints the logout message") {
|
|
|
+ char *dummyData = (char*) "logout\r\n" \
|
|
|
+ "good bye\r\n\r\n" \
|
|
|
+ "shellmatta->";
|
|
|
+ CHECK(write_length == strlen(dummyData));
|
|
|
+ REQUIRE_THAT(write_data, Catch::Matchers::Equals(dummyData));
|
|
|
+ }
|
|
|
+
|
|
|
+ AND_WHEN("The help command is called") {
|
|
|
+
|
|
|
+ write_length = 0;
|
|
|
+ memset(write_data, 0, sizeof(write_data));
|
|
|
+ ret = shellmatta_processData(handle, (char*)"help\r", 5);
|
|
|
+ CHECK(ret == SHELLMATTA_OK);
|
|
|
+
|
|
|
+ THEN("The help command prints only public commands.") {
|
|
|
+
|
|
|
+ char *dummyData = (char*) "help\r\n"
|
|
|
+ "help ? help [command] - print help or usage information\r\n"
|
|
|
+ "login li Login command\r\n"
|
|
|
+ "logout lo Logout command\r\n"
|
|
|
+ "public p\r\n"
|
|
|
+ "\r\n"
|
|
|
+ "shellmatta->";
|
|
|
+
|
|
|
+ CHECK(ret == SHELLMATTA_OK);
|
|
|
+ CHECK(write_length == strlen(dummyData));
|
|
|
+ REQUIRE_THAT(write_data, Catch::Matchers::Equals(dummyData));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|