|
@@ -57,10 +57,11 @@ static bool successTemp;
|
|
|
\
|
|
|
uint32_t privateCmdPerms[] = {1}; \
|
|
|
shellmatta_auth_perm_t permList[] = { \
|
|
|
- {"private", privateCmdPerms, sizeof(privateCmdPerms)/sizeof(privateCmdPerms[0])} \
|
|
|
+ {"private", privateCmdPerms, sizeof(privateCmdPerms)/sizeof(privateCmdPerms[0])}, \
|
|
|
+ {"additional", privateCmdPerms, sizeof(privateCmdPerms)/sizeof(privateCmdPerms[0])} \
|
|
|
}; \
|
|
|
\
|
|
|
- shellmatta_auth_init(handle, userList, 3, permList, 1, false, NULL, NULL);
|
|
|
+ shellmatta_auth_init(handle, userList, 3, permList, 2, false, NULL, NULL);
|
|
|
|
|
|
static shellmatta_retCode_t writeFct(const char* data, uint32_t length)
|
|
|
{
|
|
@@ -98,6 +99,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};
|
|
|
|
|
|
+
|
|
|
+static shellmatta_retCode_t additionalCmdFct(shellmatta_handle_t handle, const char *arguments, uint32_t length)
|
|
|
+{
|
|
|
+ (void) handle;
|
|
|
+ (void) arguments;
|
|
|
+ (void) length;
|
|
|
+
|
|
|
+ return SHELLMATTA_OK;
|
|
|
+}
|
|
|
+shellmatta_cmd_t additionalCmd = {(char*)"additional", (char*)"a", NULL, NULL, additionalCmdFct, NULL, NULL};
|
|
|
+
|
|
|
+
|
|
|
SCENARIO("Check help auth uninitialized") {
|
|
|
GIVEN("An initialized shellmatta instance without initialized auth") {
|
|
|
|
|
@@ -502,6 +515,67 @@ SCENARIO("Check login command with unprivileged user") {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+SCENARIO("Check adding commands after the authentication is initialized") {
|
|
|
+ GIVEN("An initialized shellmatta instance with initialized auth") {
|
|
|
+
|
|
|
+ TEST_SHELLMATTA_SETUP;
|
|
|
+
|
|
|
+ TEST_SHELLMATTA_AUTH_SETUP;
|
|
|
+
|
|
|
+ WHEN("A command is added") {
|
|
|
+
|
|
|
+ ret = shellmatta_addCmd(handle, &additionalCmd);
|
|
|
+ CHECK(ret == SHELLMATTA_OK);
|
|
|
+
|
|
|
+ AND_WHEN("The help command is called") {
|
|
|
+
|
|
|
+ ret = shellmatta_processData(handle, (char*)"help\r", 5);
|
|
|
+ CHECK(ret == SHELLMATTA_OK);
|
|
|
+
|
|
|
+ THEN("The additional command is not shown as it requires login") {
|
|
|
+ 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(write_length == strlen(dummyData));
|
|
|
+ REQUIRE_THAT(write_data, Catch::Matchers::Equals(dummyData));
|
|
|
+
|
|
|
+ AND_WHEN("The rot user is logged in") {
|
|
|
+ write_length = 0;
|
|
|
+ memset(write_data, 0, sizeof(write_data));
|
|
|
+
|
|
|
+ ret = shellmatta_auth_login(handle, 3);
|
|
|
+ CHECK(ret == SHELLMATTA_OK);
|
|
|
+
|
|
|
+ AND_WHEN("The help command is called") {
|
|
|
+
|
|
|
+ ret = shellmatta_processData(handle, (char*)"help\r", 5);
|
|
|
+ CHECK(ret == SHELLMATTA_OK);
|
|
|
+
|
|
|
+ THEN("all commands are shown") {
|
|
|
+ char *dummyData = (char*) "help\r\n"
|
|
|
+ "additional a\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"
|
|
|
+ "root@shellmatta->";
|
|
|
+ CHECK(write_length == strlen(dummyData));
|
|
|
+ REQUIRE_THAT(write_data, Catch::Matchers::Equals(dummyData));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
shellmatta_retCode_t customLogin(const uint32_t userId, const char *password)
|
|
|
{
|
|
|
if ((userId == 1) && (0 == strcmp(password, "12345678")))
|