Ver Fonte

extended tests to cover functions actually being called

stefan há 9 meses atrás
pai
commit
7758d28cc8
1 ficheiros alterados com 57 adições e 3 exclusões
  1. 57 3
      test/integrationtest_auth/test_integration_auth.cpp

+ 57 - 3
test/integrationtest_auth/test_integration_auth.cpp

@@ -21,6 +21,7 @@ extern "C" {
 static uint32_t write_callCnt = 0u;
 static char write_data[1024];
 static uint32_t write_length;
+static uint32_t privateTemp;
 static uint32_t userIdTemp;
 static bool successTemp;
 
@@ -43,6 +44,7 @@ static bool successTemp;
                                 write_callCnt = 0u;                         \
                                 memset(write_data, 0, sizeof(write_data));  \
                                 write_length = 0u;                          \
+                                privateTemp = 0u;                           \
                                 userIdTemp = 255u;                          \
                                 successTemp = false;                        \
                                                                             \
@@ -95,6 +97,8 @@ static shellmatta_retCode_t privateCmdFct(shellmatta_handle_t handle, const char
     (void)      arguments;
     (void)      length;
 
+    privateTemp ++;
+
     return SHELLMATTA_OK;
 }
 shellmatta_cmd_t privateCmd = {(char*)"private", (char*)"r", NULL, NULL, privateCmdFct, NULL, NULL};
@@ -140,7 +144,7 @@ SCENARIO("Check help auth uninitialized") {
     }
 }
 
-SCENARIO("Check help auth unauthorized") {
+SCENARIO("Check auth unauthorized") {
     GIVEN("An initialized shellmatta instance with initialized auth") {
 
         TEST_SHELLMATTA_SETUP;
@@ -162,7 +166,24 @@ SCENARIO("Check help auth unauthorized") {
                                             "\r\n"
                                             "shellmatta->";
 
-                CHECK(ret == SHELLMATTA_OK);
+                CHECK(write_length == strlen(dummyData));
+                REQUIRE_THAT(write_data, Catch::Matchers::Equals(dummyData));
+            }
+        }
+
+        WHEN("The a private function is called") {
+
+            ret = shellmatta_processData(handle, (char*)"private\r", 8);
+            CHECK(ret == SHELLMATTA_OK);
+
+            THEN("The command is not executed.") {
+
+                char *dummyData =   (char*) "private\r\n"
+                                            "\r\n"
+                                            "Command: private not found\r\n"
+                                            "shellmatta->";
+
+                CHECK(privateTemp == 0u);
                 CHECK(write_length == strlen(dummyData));
                 REQUIRE_THAT(write_data, Catch::Matchers::Equals(dummyData));
             }
@@ -170,7 +191,7 @@ SCENARIO("Check help auth unauthorized") {
     }
 }
 
-SCENARIO("Check help authorized") {
+SCENARIO("Check authorized") {
     GIVEN("An initialized shellmatta instance with initialized auth") {
 
         TEST_SHELLMATTA_SETUP;
@@ -252,6 +273,22 @@ SCENARIO("Check help authorized") {
                     }
                 }
             }
+            AND_WHEN("The a private function is called") {
+
+                ret = shellmatta_processData(handle, (char*)"private\r", 8);
+                CHECK(ret == SHELLMATTA_OK);
+
+                THEN("The command executed.") {
+
+                    char *dummyData =   (char*) "private\r\n"
+                                                "\r\n"
+                                                "shimatta@shellmatta->";
+
+                    CHECK(privateTemp == 1u);
+                    CHECK(write_length == strlen(dummyData));
+                    REQUIRE_THAT(write_data, Catch::Matchers::Equals(dummyData));
+                }
+            }
         }
         WHEN("The user not_shellmatta is logged in") {
 
@@ -289,6 +326,23 @@ SCENARIO("Check help authorized") {
                     }
                 }
             }
+            AND_WHEN("The a private function is called") {
+
+                ret = shellmatta_processData(handle, (char*)"private\r", 8);
+                CHECK(ret == SHELLMATTA_OK);
+
+                THEN("The command is not executed.") {
+
+                    char *dummyData =   (char*) "private\r\n"
+                                                "\r\n"
+                                                "Command: private not found\r\n"
+                                                "not_shimatta@shellmatta->";
+
+                    CHECK(privateTemp == 0u);
+                    CHECK(write_length == strlen(dummyData));
+                    REQUIRE_THAT(write_data, Catch::Matchers::Equals(dummyData));
+                }
+            }
         }
         WHEN("The user root is logged in") {
             ret = shellmatta_auth_login(handle, 3);