123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- /*
- * Copyright (c) 2019 - 2024 Stefan Strobel <stefan.strobel@shimatta.net>
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at https://mozilla.org/MPL/2.0/.
- */
- /**
- * @file test_integration_auth.cpp
- * @brief integration test implementation for the authentication functions
- * @author Stefan Strobel <stefan.strobel@shimatta.net>
- */
- #include "test/framework/catch.hpp"
- extern "C" {
- #include "shellmatta.h"
- }
- #include <string.h>
- static uint32_t write_callCnt = 0u;
- static char write_data[1024];
- static uint32_t write_length;
- static shellmatta_retCode_t writeFct(const char* data, uint32_t length)
- {
- write_callCnt ++;
- while((length > 0) && (write_length < sizeof(write_data)))
- {
- write_data[write_length] = *data;
- data ++;
- length --;
- write_length ++;
- }
- return SHELLMATTA_OK;
- }
- static shellmatta_retCode_t publicCmdFct(shellmatta_handle_t handle, const char *arguments, uint32_t length)
- {
- (void) handle;
- (void) arguments;
- (void) length;
- shellmatta_retCode_t ret = SHELLMATTA_OK;
- return ret;
- }
- shellmatta_cmd_t publicCmd = {(char*)"public", (char*)"p", NULL, NULL, publicCmdFct, NULL, NULL};
- static shellmatta_retCode_t privateCmdFct(shellmatta_handle_t handle, const char *arguments, uint32_t length)
- {
- (void) handle;
- (void) arguments;
- (void) length;
- return SHELLMATTA_OK;
- }
- shellmatta_cmd_t privateCmd = {(char*)"private", (char*)"r", NULL, NULL, privateCmdFct, NULL, NULL};
- TEST_CASE( "check unauthenticated help" ) {
- 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"
- "logout lo Logout command\r\n"
- "private r\r\n"
- "public p\r\n"
- "\r\n"
- "shellmatta->";
- shellmatta_doInit( &inst,
- &handle,
- buffer,
- sizeof(buffer),
- historyBuffer,
- sizeof(historyBuffer),
- "shellmatta->",
- NULL,
- writeFct);
- shellmatta_auth_init(handle, NULL, 0, NULL, 0, false, NULL, NULL);
- write_callCnt = 0u;
- memset(write_data, 0, sizeof(write_data));
- write_length = 0u;
- shellmatta_addCmd(handle, &publicCmd);
- shellmatta_addCmd(handle, &privateCmd);
- ret = shellmatta_processData(handle, (char*)"help\r", 5);
- CHECK(ret == SHELLMATTA_OK);
- CHECK(write_length == strlen(dummyData));
- REQUIRE_THAT(write_data, Catch::Matchers::Equals(dummyData));
- }
|