|
@@ -21,9 +21,9 @@ extern "C" {
|
|
static uint32_t write_callCnt = 0u;
|
|
static uint32_t write_callCnt = 0u;
|
|
static char write_data[1024];
|
|
static char write_data[1024];
|
|
static uint32_t write_length;
|
|
static uint32_t write_length;
|
|
-static uint32_t privateTemp;
|
|
|
|
-static uint32_t userIdTemp;
|
|
|
|
-static bool successTemp;
|
|
|
|
|
|
+static uint32_t privateCallCount;
|
|
|
|
+static uint32_t logUserId;
|
|
|
|
+static bool logSuccess;
|
|
|
|
|
|
#define TEST_SHELLMATTA_SETUP shellmatta_retCode_t ret; \
|
|
#define TEST_SHELLMATTA_SETUP shellmatta_retCode_t ret; \
|
|
shellmatta_instance_t inst; \
|
|
shellmatta_instance_t inst; \
|
|
@@ -44,9 +44,9 @@ static bool successTemp;
|
|
write_callCnt = 0u; \
|
|
write_callCnt = 0u; \
|
|
memset(write_data, 0, sizeof(write_data)); \
|
|
memset(write_data, 0, sizeof(write_data)); \
|
|
write_length = 0u; \
|
|
write_length = 0u; \
|
|
- privateTemp = 0u; \
|
|
|
|
- userIdTemp = 255u; \
|
|
|
|
- successTemp = false; \
|
|
|
|
|
|
+ privateCallCount = 0u; \
|
|
|
|
+ logUserId = 255u; \
|
|
|
|
+ logSuccess = false; \
|
|
\
|
|
\
|
|
shellmatta_addCmd(handle, &publicCmd); \
|
|
shellmatta_addCmd(handle, &publicCmd); \
|
|
shellmatta_addCmd(handle, &privateCmd);
|
|
shellmatta_addCmd(handle, &privateCmd);
|
|
@@ -59,7 +59,7 @@ static bool successTemp;
|
|
\
|
|
\
|
|
uint32_t privateCmdPerms[] = {1}; \
|
|
uint32_t privateCmdPerms[] = {1}; \
|
|
shellmatta_auth_perm_t permList[] = { \
|
|
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])} \
|
|
{"additional", privateCmdPerms, sizeof(privateCmdPerms)/sizeof(privateCmdPerms[0])} \
|
|
}; \
|
|
}; \
|
|
\
|
|
\
|
|
@@ -97,7 +97,7 @@ static shellmatta_retCode_t privateCmdFct(shellmatta_handle_t handle, const char
|
|
(void) arguments;
|
|
(void) arguments;
|
|
(void) length;
|
|
(void) length;
|
|
|
|
|
|
- privateTemp ++;
|
|
|
|
|
|
+ privateCallCount ++;
|
|
|
|
|
|
return SHELLMATTA_OK;
|
|
return SHELLMATTA_OK;
|
|
}
|
|
}
|
|
@@ -125,7 +125,7 @@ SCENARIO("Check help auth uninitialized") {
|
|
ret = shellmatta_processData(handle, (char*)"help\r", 5);
|
|
ret = shellmatta_processData(handle, (char*)"help\r", 5);
|
|
CHECK(ret == SHELLMATTA_OK);
|
|
CHECK(ret == SHELLMATTA_OK);
|
|
|
|
|
|
- THEN("The help command prints all commands.") {
|
|
|
|
|
|
+ THEN("The help command prints all commands - without login/logout.") {
|
|
|
|
|
|
char *dummyData = (char*) "help\r\n"
|
|
char *dummyData = (char*) "help\r\n"
|
|
"help ? help [command] - print help or usage information\r\n"
|
|
"help ? help [command] - print help or usage information\r\n"
|
|
@@ -134,7 +134,6 @@ SCENARIO("Check help auth uninitialized") {
|
|
"\r\n"
|
|
"\r\n"
|
|
"shellmatta->";
|
|
"shellmatta->";
|
|
|
|
|
|
- CHECK(ret == SHELLMATTA_OK);
|
|
|
|
CHECK(write_length == strlen(dummyData));
|
|
CHECK(write_length == strlen(dummyData));
|
|
REQUIRE_THAT(write_data, Catch::Matchers::Equals(dummyData));
|
|
REQUIRE_THAT(write_data, Catch::Matchers::Equals(dummyData));
|
|
}
|
|
}
|
|
@@ -181,7 +180,7 @@ SCENARIO("Check auth unauthorized") {
|
|
"Command: private not found\r\n"
|
|
"Command: private not found\r\n"
|
|
"shellmatta->";
|
|
"shellmatta->";
|
|
|
|
|
|
- CHECK(privateTemp == 0u);
|
|
|
|
|
|
+ CHECK(privateCallCount == 0u);
|
|
CHECK(write_length == strlen(dummyData));
|
|
CHECK(write_length == strlen(dummyData));
|
|
REQUIRE_THAT(write_data, Catch::Matchers::Equals(dummyData));
|
|
REQUIRE_THAT(write_data, Catch::Matchers::Equals(dummyData));
|
|
}
|
|
}
|
|
@@ -212,7 +211,7 @@ SCENARIO("Check authorized") {
|
|
|
|
|
|
TEST_SHELLMATTA_AUTH_SETUP;
|
|
TEST_SHELLMATTA_AUTH_SETUP;
|
|
|
|
|
|
- WHEN("The user shellmatta is logged in") {
|
|
|
|
|
|
+ WHEN("The user shimatta is logged in") {
|
|
|
|
|
|
ret = shellmatta_auth_login(handle, 1);
|
|
ret = shellmatta_auth_login(handle, 1);
|
|
CHECK(ret == SHELLMATTA_OK);
|
|
CHECK(ret == SHELLMATTA_OK);
|
|
@@ -233,7 +232,6 @@ SCENARIO("Check authorized") {
|
|
"\r\n"
|
|
"\r\n"
|
|
"shimatta@shellmatta->";
|
|
"shimatta@shellmatta->";
|
|
|
|
|
|
- CHECK(ret == SHELLMATTA_OK);
|
|
|
|
CHECK(write_length == strlen(dummyData));
|
|
CHECK(write_length == strlen(dummyData));
|
|
REQUIRE_THAT(write_data, Catch::Matchers::Equals(dummyData));
|
|
REQUIRE_THAT(write_data, Catch::Matchers::Equals(dummyData));
|
|
|
|
|
|
@@ -280,14 +278,13 @@ SCENARIO("Check authorized") {
|
|
"\r\n"
|
|
"\r\n"
|
|
"shellmatta->";
|
|
"shellmatta->";
|
|
|
|
|
|
- CHECK(ret == SHELLMATTA_OK);
|
|
|
|
CHECK(write_length == strlen(dummyData));
|
|
CHECK(write_length == strlen(dummyData));
|
|
REQUIRE_THAT(write_data, Catch::Matchers::Equals(dummyData));
|
|
REQUIRE_THAT(write_data, Catch::Matchers::Equals(dummyData));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- AND_WHEN("The a private function is called") {
|
|
|
|
|
|
+ AND_WHEN("A private function is called") {
|
|
|
|
|
|
ret = shellmatta_processData(handle, (char*)"private\r", 8);
|
|
ret = shellmatta_processData(handle, (char*)"private\r", 8);
|
|
CHECK(ret == SHELLMATTA_OK);
|
|
CHECK(ret == SHELLMATTA_OK);
|
|
@@ -298,7 +295,7 @@ SCENARIO("Check authorized") {
|
|
"\r\n"
|
|
"\r\n"
|
|
"shimatta@shellmatta->";
|
|
"shimatta@shellmatta->";
|
|
|
|
|
|
- CHECK(privateTemp == 1u);
|
|
|
|
|
|
+ CHECK(privateCallCount == 1u);
|
|
CHECK(write_length == strlen(dummyData));
|
|
CHECK(write_length == strlen(dummyData));
|
|
REQUIRE_THAT(write_data, Catch::Matchers::Equals(dummyData));
|
|
REQUIRE_THAT(write_data, Catch::Matchers::Equals(dummyData));
|
|
}
|
|
}
|
|
@@ -340,7 +337,7 @@ SCENARIO("Check authorized") {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- AND_WHEN("The a private function is called") {
|
|
|
|
|
|
+ AND_WHEN("A private function is called") {
|
|
|
|
|
|
ret = shellmatta_processData(handle, (char*)"private\r", 8);
|
|
ret = shellmatta_processData(handle, (char*)"private\r", 8);
|
|
CHECK(ret == SHELLMATTA_OK);
|
|
CHECK(ret == SHELLMATTA_OK);
|
|
@@ -352,7 +349,7 @@ SCENARIO("Check authorized") {
|
|
"Command: private not found\r\n"
|
|
"Command: private not found\r\n"
|
|
"not_shimatta@shellmatta->";
|
|
"not_shimatta@shellmatta->";
|
|
|
|
|
|
- CHECK(privateTemp == 0u);
|
|
|
|
|
|
+ CHECK(privateCallCount == 0u);
|
|
CHECK(write_length == strlen(dummyData));
|
|
CHECK(write_length == strlen(dummyData));
|
|
REQUIRE_THAT(write_data, Catch::Matchers::Equals(dummyData));
|
|
REQUIRE_THAT(write_data, Catch::Matchers::Equals(dummyData));
|
|
}
|
|
}
|
|
@@ -394,7 +391,7 @@ SCENARIO("Check login command with privileged user") {
|
|
|
|
|
|
TEST_SHELLMATTA_AUTH_SETUP;
|
|
TEST_SHELLMATTA_AUTH_SETUP;
|
|
|
|
|
|
- WHEN("The user shellmatta logs in interactively using the correct credentials") {
|
|
|
|
|
|
+ WHEN("The user shimatta logs in interactively using the correct credentials") {
|
|
|
|
|
|
ret = shellmatta_processData(handle, (char*)"login\r\n"
|
|
ret = shellmatta_processData(handle, (char*)"login\r\n"
|
|
"shimatta\r\n"
|
|
"shimatta\r\n"
|
|
@@ -419,7 +416,7 @@ SCENARIO("Check login command with privileged user") {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- WHEN("The user shellmatta logs in interactively using wrong credentials") {
|
|
|
|
|
|
+ WHEN("The user shimatta logs in interactively using wrong credentials") {
|
|
|
|
|
|
ret = shellmatta_processData(handle, (char*)"login\r\n"
|
|
ret = shellmatta_processData(handle, (char*)"login\r\n"
|
|
"shimatta\r\n"
|
|
"shimatta\r\n"
|
|
@@ -444,7 +441,7 @@ SCENARIO("Check login command with privileged user") {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- WHEN("The user shellmatta logs in interactively manipulating the input") {
|
|
|
|
|
|
+ WHEN("The user shimatta logs in interactively manipulating the input") {
|
|
|
|
|
|
ret = shellmatta_processData(handle, (char*)"login\r"
|
|
ret = shellmatta_processData(handle, (char*)"login\r"
|
|
"shimg\batta\r"
|
|
"shimg\batta\r"
|
|
@@ -469,7 +466,7 @@ SCENARIO("Check login command with privileged user") {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- WHEN("The user shellmatta logs in passing the credentials none interactive") {
|
|
|
|
|
|
+ WHEN("The user shimatta logs in passing the credentials none interactively") {
|
|
|
|
|
|
ret = shellmatta_processData(handle, (char*)"login -u shimatta -p 12345678\r", 30);
|
|
ret = shellmatta_processData(handle, (char*)"login -u shimatta -p 12345678\r", 30);
|
|
CHECK(ret == SHELLMATTA_OK);
|
|
CHECK(ret == SHELLMATTA_OK);
|
|
@@ -488,7 +485,7 @@ SCENARIO("Check login command with privileged user") {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- WHEN("The user shellmatta logs in passing the credentials half interactive") {
|
|
|
|
|
|
+ WHEN("The user shimatta logs in passing the credentials half interactively") {
|
|
|
|
|
|
ret = shellmatta_processData(handle, (char*)"login -u shimatta\r12345678\r", 27);
|
|
ret = shellmatta_processData(handle, (char*)"login -u shimatta\r12345678\r", 27);
|
|
CHECK(ret == SHELLMATTA_OK);
|
|
CHECK(ret == SHELLMATTA_OK);
|
|
@@ -509,7 +506,7 @@ SCENARIO("Check login command with privileged user") {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- WHEN("The user shellmatta tries to login non interactive without username") {
|
|
|
|
|
|
+ WHEN("The user shimatta tries to login non interactively without username") {
|
|
|
|
|
|
ret = shellmatta_processData(handle, (char*)"login -p 12345678\r", 18);
|
|
ret = shellmatta_processData(handle, (char*)"login -p 12345678\r", 18);
|
|
CHECK(ret == SHELLMATTA_OK);
|
|
CHECK(ret == SHELLMATTA_OK);
|
|
@@ -528,7 +525,7 @@ SCENARIO("Check login command with privileged user") {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- WHEN("The user shellmatta tries to login using the wrong options") {
|
|
|
|
|
|
+ WHEN("The user shimatta tries to login using the wrong options") {
|
|
|
|
|
|
ret = shellmatta_processData(handle, (char*)"login -o meow\r", 14);
|
|
ret = shellmatta_processData(handle, (char*)"login -o meow\r", 14);
|
|
CHECK(ret == SHELLMATTA_OK);
|
|
CHECK(ret == SHELLMATTA_OK);
|
|
@@ -611,7 +608,7 @@ SCENARIO("Check adding commands after the authentication is initialized") {
|
|
CHECK(write_length == strlen(dummyData));
|
|
CHECK(write_length == strlen(dummyData));
|
|
REQUIRE_THAT(write_data, Catch::Matchers::Equals(dummyData));
|
|
REQUIRE_THAT(write_data, Catch::Matchers::Equals(dummyData));
|
|
|
|
|
|
- AND_WHEN("The rot user is logged in") {
|
|
|
|
|
|
+ AND_WHEN("The root user is logged in") {
|
|
write_length = 0;
|
|
write_length = 0;
|
|
memset(write_data, 0, sizeof(write_data));
|
|
memset(write_data, 0, sizeof(write_data));
|
|
|
|
|
|
@@ -623,7 +620,7 @@ SCENARIO("Check adding commands after the authentication is initialized") {
|
|
ret = shellmatta_processData(handle, (char*)"help\r", 5);
|
|
ret = shellmatta_processData(handle, (char*)"help\r", 5);
|
|
CHECK(ret == SHELLMATTA_OK);
|
|
CHECK(ret == SHELLMATTA_OK);
|
|
|
|
|
|
- THEN("all commands are shown") {
|
|
|
|
|
|
+ THEN("all commands are shown including the additional command") {
|
|
char *dummyData = (char*) "help\r\n"
|
|
char *dummyData = (char*) "help\r\n"
|
|
"additional a\r\n"
|
|
"additional a\r\n"
|
|
"help ? help [command] - print help or usage information\r\n"
|
|
"help ? help [command] - print help or usage information\r\n"
|
|
@@ -646,11 +643,11 @@ SCENARIO("Check adding commands after the authentication is initialized") {
|
|
|
|
|
|
shellmatta_retCode_t customLogin(const uint32_t userId, const char *password)
|
|
shellmatta_retCode_t customLogin(const uint32_t userId, const char *password)
|
|
{
|
|
{
|
|
- if ((userId == 1) && (0 == strcmp(password, "12345678")))
|
|
|
|
|
|
+ if ((userId == 1) && (0 == strcmp(password, "123456789")))
|
|
{
|
|
{
|
|
return SHELLMATTA_OK;
|
|
return SHELLMATTA_OK;
|
|
}
|
|
}
|
|
- else if ((userId == 2) && (0 == strcmp(password, "87654321")))
|
|
|
|
|
|
+ else if ((userId == 2) && (0 == strcmp(password, "876543210")))
|
|
{
|
|
{
|
|
return SHELLMATTA_OK;
|
|
return SHELLMATTA_OK;
|
|
}
|
|
}
|
|
@@ -660,8 +657,8 @@ shellmatta_retCode_t customLogin(const uint32_t userId, const char *password)
|
|
|
|
|
|
void logFct(const uint32_t userId, bool success)
|
|
void logFct(const uint32_t userId, bool success)
|
|
{
|
|
{
|
|
- userIdTemp = userId;
|
|
|
|
- successTemp = success;
|
|
|
|
|
|
+ logUserId = userId;
|
|
|
|
+ logSuccess = success;
|
|
}
|
|
}
|
|
|
|
|
|
SCENARIO("Check custom login") {
|
|
SCENARIO("Check custom login") {
|
|
@@ -670,8 +667,8 @@ SCENARIO("Check custom login") {
|
|
TEST_SHELLMATTA_SETUP;
|
|
TEST_SHELLMATTA_SETUP;
|
|
|
|
|
|
shellmatta_auth_user_t userList[] = {
|
|
shellmatta_auth_user_t userList[] = {
|
|
- {1, false, "shimatta", "12345678"},
|
|
|
|
- {2, false, "not_shimatta", "87654321"}
|
|
|
|
|
|
+ {1, false, "shimatta", NULL},
|
|
|
|
+ {2, false, "not_shimatta", NULL}
|
|
};
|
|
};
|
|
|
|
|
|
uint32_t privateCmdPerms[] = {1};
|
|
uint32_t privateCmdPerms[] = {1};
|
|
@@ -685,7 +682,7 @@ SCENARIO("Check custom login") {
|
|
|
|
|
|
ret = shellmatta_processData(handle, (char*)"login\r"
|
|
ret = shellmatta_processData(handle, (char*)"login\r"
|
|
"shimatta\r"
|
|
"shimatta\r"
|
|
- "12345678\r", 24);
|
|
|
|
|
|
+ "123456789\r", 25);
|
|
CHECK(ret == SHELLMATTA_OK);
|
|
CHECK(ret == SHELLMATTA_OK);
|
|
|
|
|
|
THEN("The login message is printed - password is hidden") {
|
|
THEN("The login message is printed - password is hidden") {
|
|
@@ -706,17 +703,17 @@ SCENARIO("Check custom login") {
|
|
}
|
|
}
|
|
|
|
|
|
AND_THEN("The login event is logged") {
|
|
AND_THEN("The login event is logged") {
|
|
- CHECK(1 == userIdTemp);
|
|
|
|
- REQUIRE(true == successTemp);
|
|
|
|
|
|
+ CHECK(1 == logUserId);
|
|
|
|
+ REQUIRE(true == logSuccess);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- WHEN("The user not_shimatta logs in interactively using the wrong credentials") {
|
|
|
|
|
|
+ WHEN("The user shimatta logs in interactively using the wrong credentials") {
|
|
|
|
|
|
ret = shellmatta_processData(handle, (char*)"login\r"
|
|
ret = shellmatta_processData(handle, (char*)"login\r"
|
|
"shimatta\r"
|
|
"shimatta\r"
|
|
- "12345679\r", 24);
|
|
|
|
|
|
+ "12345678\r", 24);
|
|
CHECK(ret == SHELLMATTA_OK);
|
|
CHECK(ret == SHELLMATTA_OK);
|
|
|
|
|
|
THEN("Login error message is printed") {
|
|
THEN("Login error message is printed") {
|
|
@@ -737,8 +734,8 @@ SCENARIO("Check custom login") {
|
|
}
|
|
}
|
|
|
|
|
|
AND_THEN("The failed login event is logged") {
|
|
AND_THEN("The failed login event is logged") {
|
|
- CHECK(1 == userIdTemp);
|
|
|
|
- REQUIRE(false == successTemp);
|
|
|
|
|
|
+ CHECK(1 == logUserId);
|
|
|
|
+ REQUIRE(false == logSuccess);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -751,8 +748,8 @@ SCENARIO("Check custom login with custom login function") {
|
|
TEST_SHELLMATTA_SETUP;
|
|
TEST_SHELLMATTA_SETUP;
|
|
|
|
|
|
shellmatta_auth_user_t userList[] = {
|
|
shellmatta_auth_user_t userList[] = {
|
|
- {1, false, "shimatta", "12345678"},
|
|
|
|
- {2, false, "not_shimatta", "87654321"}
|
|
|
|
|
|
+ {1, false, "shimatta", NULL},
|
|
|
|
+ {2, false, "not_shimatta", NULL}
|
|
};
|
|
};
|
|
|
|
|
|
uint32_t privateCmdPerms[] = {1};
|
|
uint32_t privateCmdPerms[] = {1};
|
|
@@ -794,7 +791,7 @@ SCENARIO("Check if passwords can be changed") {
|
|
ret = shellmatta_auth_chpasswd(handle, "shimatta", "new_password");
|
|
ret = shellmatta_auth_chpasswd(handle, "shimatta", "new_password");
|
|
CHECK(ret == SHELLMATTA_OK);
|
|
CHECK(ret == SHELLMATTA_OK);
|
|
|
|
|
|
- AND_WHEN("The user shellmatta logs in passing the new credentials") {
|
|
|
|
|
|
+ AND_WHEN("The user shimatta logs in passing the new credentials") {
|
|
|
|
|
|
ret = shellmatta_processData(handle, (char*)"login -u shimatta -p new_password\r", 34);
|
|
ret = shellmatta_processData(handle, (char*)"login -u shimatta -p new_password\r", 34);
|
|
CHECK(ret == SHELLMATTA_OK);
|
|
CHECK(ret == SHELLMATTA_OK);
|
|
@@ -805,7 +802,7 @@ SCENARIO("Check if passwords can be changed") {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- AND_WHEN("The user shellmatta logs in passing the old credentials") {
|
|
|
|
|
|
+ AND_WHEN("The user shimatta logs in passing the old credentials") {
|
|
|
|
|
|
ret = shellmatta_processData(handle, (char*)"login -u shimatta -p 12345678\r", 30);
|
|
ret = shellmatta_processData(handle, (char*)"login -u shimatta -p 12345678\r", 30);
|
|
CHECK(ret == SHELLMATTA_OK);
|
|
CHECK(ret == SHELLMATTA_OK);
|
|
@@ -818,7 +815,7 @@ SCENARIO("Check if passwords can be changed") {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-SCENARIO("User functions with wrong parameters") {
|
|
|
|
|
|
+SCENARIO("Use functions with wrong parameters") {
|
|
GIVEN("An initialized shellmatta instance with initialized auth") {
|
|
GIVEN("An initialized shellmatta instance with initialized auth") {
|
|
|
|
|
|
TEST_SHELLMATTA_SETUP;
|
|
TEST_SHELLMATTA_SETUP;
|