test_integration_auth.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (c) 2019 - 2024 Stefan Strobel <stefan.strobel@shimatta.net>
  3. *
  4. * This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at https://mozilla.org/MPL/2.0/.
  7. */
  8. /**
  9. * @file test_integration_auth.cpp
  10. * @brief integration test implementation for the authentication functions
  11. * @author Stefan Strobel <stefan.strobel@shimatta.net>
  12. */
  13. #include "test/framework/catch.hpp"
  14. extern "C" {
  15. #include "shellmatta.h"
  16. }
  17. #include <string.h>
  18. static uint32_t write_callCnt = 0u;
  19. static char write_data[1024];
  20. static uint32_t write_length;
  21. static uint32_t busyCallCnt;
  22. static uint32_t notBusyCallCnt;
  23. static bool suspendBusy;
  24. static shellmatta_retCode_t writeFct(const char* data, uint32_t length)
  25. {
  26. write_callCnt ++;
  27. while((length > 0) && (write_length < sizeof(write_data)))
  28. {
  29. write_data[write_length] = *data;
  30. data ++;
  31. length --;
  32. write_length ++;
  33. }
  34. return SHELLMATTA_OK;
  35. }
  36. static shellmatta_retCode_t publicCmdFct(shellmatta_handle_t handle, const char *arguments, uint32_t length)
  37. {
  38. (void) handle;
  39. (void) arguments;
  40. (void) length;
  41. shellmatta_retCode_t ret = SHELLMATTA_OK;
  42. return ret;
  43. }
  44. shellmatta_cmd_t publicCmd = {(char*)"public", (char*)"p", NULL, NULL, publicCmdFct, NULL, NULL};
  45. static shellmatta_retCode_t privateCmdFct(shellmatta_handle_t handle, const char *arguments, uint32_t length)
  46. {
  47. (void) handle;
  48. (void) arguments;
  49. (void) length;
  50. return SHELLMATTA_OK;
  51. }
  52. shellmatta_cmd_t privateCmd = {(char*)"private", (char*)"r", NULL, NULL, privateCmdFct, NULL, NULL};
  53. TEST_CASE( "check unauthenticated help" ) {
  54. shellmatta_retCode_t ret;
  55. shellmatta_instance_t inst;
  56. shellmatta_handle_t handle;
  57. char buffer[1024] = {0};
  58. char historyBuffer[1024] = {0};
  59. char *dummyData = (char*) "";
  60. shellmatta_doInit( &inst,
  61. &handle,
  62. buffer,
  63. sizeof(buffer),
  64. historyBuffer,
  65. sizeof(historyBuffer),
  66. "shellmatta->",
  67. NULL,
  68. writeFct);
  69. busyCallCnt = 0u;
  70. notBusyCallCnt = 0u;
  71. write_callCnt = 0u;
  72. memset(write_data, 0, sizeof(write_data));
  73. write_length = 0u;
  74. suspendBusy = false;
  75. shellmatta_addCmd(handle, &publicCmd);
  76. shellmatta_addCmd(handle, &privateCmd);
  77. do
  78. {
  79. ret = shellmatta_processData(handle, (char*)"help\r", 5);
  80. } while (SHELLMATTA_BUSY == ret);
  81. CHECK( write_length == strlen(dummyData));
  82. REQUIRE_THAT(write_data, Catch::Matchers::Equals(dummyData));
  83. }