tests: cover CLI prefix stripping, set-pin gate, paged reply bounds, and ACL write failures

Changelog: -
This commit is contained in:
tth committed 2026-12-02 00:36:05 +01:00
1 parent 0dcc9c6e06
commit 5f31fc8e50
6 files changed
+192 -35

No files matched your search

+43
View File
@@ -11,7 +11,9 @@
// float a '.' and fraction. No exponent, no hex, no trailing text.
#include <ctype.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
namespace cli_args {
@@ -53,4 +55,45 @@ inline bool parseFloat(const char* s, float lo, float hi, float* out) {
return true;
}
// Strips leading spaces and an optional 3-byte "XX|" prefix (reflected into
// `reply`, deducting 3 from `*reply_max` when provided).
inline void stripPrefix(const char*& command, char*& reply, int* reply_max = nullptr) {
while (*command == ' ') command++;
if (strlen(command) > 4 && command[2] == '|') {
if (!reply_max || *reply_max >= 3) {
memcpy(reply, command, 3);
reply += 3;
*reply = 0;
if (reply_max) *reply_max -= 3;
}
command += 3;
while (*command == ' ') command++;
}
}
// Security gate for companion `set pin`: blocked in locked CLI rescue and over
// unencrypted local transports (USB), allowed over paired BLE or remote ACL.
inline bool canSetPin(uint32_t sender_timestamp, bool cli_rescue, bool locked_node,
bool serial_secure, const char** err_out = nullptr) {
if (locked_node && cli_rescue) {
if (err_out) *err_out = "Error: locked build";
return false;
}
if (sender_timestamp == 0 && !cli_rescue && !serial_secure) {
if (err_out) *err_out = "Error: set pin only over paired BLE";
return false;
}
return true;
}
// Appends `line` to a paged CLI reply only if it fits with `trailer_reserve`
// bytes left for the end marker; returns false when the page is full.
inline bool appendLine(char*& dp, const char* reply, int max_len, int trailer_reserve, const char* line) {
int ll = (int)strlen(line);
if ((dp - reply) + ll + trailer_reserve > max_len) return false;
memcpy(dp, line, ll);
dp += ll;
return true;
}
} // namespace cli_args