Browse Source

added test for root user

Strobel, Stefan | Friedrich Lütze GmbH 9 months ago
parent
commit
0a1c52e3de
2 changed files with 36 additions and 5 deletions
  1. 7 3
      src/shellmatta_auth.c
  2. 29 2
      test/integrationtest_auth/test_integration_auth.cpp

+ 7 - 3
src/shellmatta_auth.c

@@ -402,6 +402,7 @@ shellmatta_retCode_t shellmatta_auth_init(shellmatta_handle_t       handle,
  * @param[in]   handle      shellmatta instance handle
  * @param[in]   userId      userId to login
  * @return      errorcode   #SHELLMATTA_OK
+ *                          #SHELLMATTA_ERR (user does not exist)
  *                          #SHELLMATTA_USE_FAULT (param err)
  */
 shellmatta_retCode_t shellmatta_auth_login(shellmatta_handle_t handle, uint32_t userId)
@@ -416,6 +417,7 @@ shellmatta_retCode_t shellmatta_auth_login(shellmatta_handle_t handle, uint32_t
     {
         /** -# log passed user id into the instance */
         inst->userId = userId;
+        inst->userPointer = NULL;
         if (0 != userId)
         {
             /** -# set user pointer to print the name in the prompt */
@@ -428,15 +430,17 @@ shellmatta_retCode_t shellmatta_auth_login(shellmatta_handle_t handle, uint32_t
                 }
             }
         }
-        else
+
+        /** -# check if the user did exist */
+        if (NULL == inst->userPointer)
         {
-            inst->userPointer = NULL;
+            ret = SHELLMATTA_ERROR;
         }
 
         /** -# call log function */
         if (inst->logFct)
         {
-            inst->logFct(userId, userId != 0u ? true : false);
+            inst->logFct(userId, NULL != inst->userPointer ? true : false);
         }
     }
     else

+ 29 - 2
test/integrationtest_auth/test_integration_auth.cpp

@@ -51,7 +51,8 @@ static bool successTemp;
 
 #define TEST_SHELLMATTA_AUTH_SETUP  shellmatta_auth_user_t userList[] = {                                                   \
                                         {1, false, "shimatta", "12345678"},                                                 \
-                                        {2, false, "not_shimatta", "87654321"}                                              \
+                                        {2, false, "not_shimatta", "87654321"},                                             \
+                                        {3, true, "root", "rootpw"}                                                         \
                                     };                                                                                      \
                                                                                                                             \
                                     uint32_t privateCmdPerms[] = {1};                                                       \
@@ -59,7 +60,7 @@ static bool successTemp;
                                         {"private", privateCmdPerms, sizeof(privateCmdPerms)/sizeof(privateCmdPerms[0])}    \
                                     };                                                                                      \
                                                                                                                             \
-                                    shellmatta_auth_init(handle, userList, 2, permList, 1, false, NULL, NULL);
+                                    shellmatta_auth_init(handle, userList, 3, permList, 1, false, NULL, NULL);
 
 static shellmatta_retCode_t writeFct(const char* data, uint32_t length)
 {
@@ -276,6 +277,32 @@ SCENARIO("Check help authorized") {
                 }
             }
         }
+        WHEN("The user root is logged in") {
+            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("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"
+                                                "root@shellmatta->";
+
+                    CHECK(ret == SHELLMATTA_OK);
+                    CHECK(write_length == strlen(dummyData));
+                    REQUIRE_THAT(write_data, Catch::Matchers::Equals(dummyData));
+                }
+            }
+        }
     }
 }