diff options
author | Joseph Hunkeler <jhunkeler@users.noreply.github.com> | 2024-06-20 15:10:56 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-20 15:10:56 -0400 |
commit | 931ee28eb9c5b5e3c2b0d3008f5f65d810dc9b0c (patch) | |
tree | 5dbcccffd509fa71a99c351ed4628ed0841e1e46 /include | |
parent | 11aa1d44d95da221073e512fbec3bbccc0f1a46b (diff) | |
download | stasis-931ee28eb9c5b5e3c2b0d3008f5f65d810dc9b0c.tar.gz |
Unit tests (#6)
* Initial commit of unit tests [WIP]
* Address shortcomings and bugs flushed out by unit tests
* Enable unit testing in CI workflow
* Enable verbose ctests
* Handle lack of __FILE_NAME__ define
* Only podman support `run --arch` argument
* Skip docker build testing if CI system cannot pull an image
* Remove errant call to puts()
* Identify local repo user
* Fix missing xmllint
* NULL terminate arrays
* Fix filename assignment in is_url mode
* Break loop when expected lines are exhausted
* strcmp_array expects NULL terminated array. Iterating by size in this case passes NULL to strcmp leading to an invalid read
* Remove debug printf statements
* Disable a few warnings for tests
* Workaround for ctest junit xml truncation
* Update checkout@v4
* Prevent false-positive result
* Return zero on error
* Fix strlist_remove function
* Value argument can be constant
* Fix test to match changes to startswith and endswith
* Add test_ini.c
* Fix redaction code to accept NULL pointers in array
* And let the caller specify the length of the array of strings to redact.
* Redactions now occur directly on authentication strings rather than their command line arguments
* Fix BUILD_TESTING_DEBUG
* Adds missing -D argument
Diffstat (limited to 'include')
-rw-r--r-- | include/ini.h | 2 | ||||
-rw-r--r-- | include/str.h | 31 | ||||
-rw-r--r-- | include/strlist.h | 8 | ||||
-rw-r--r-- | include/system.h | 2 | ||||
-rw-r--r-- | include/template.h | 2 | ||||
-rw-r--r-- | include/utils.h | 2 |
6 files changed, 15 insertions, 32 deletions
diff --git a/include/ini.h b/include/ini.h index fa2bd98..022a066 100644 --- a/include/ini.h +++ b/include/ini.h @@ -98,7 +98,7 @@ struct INIFILE *ini_open(const char *filename); * @param value * @return */ -struct INISection *ini_section_search(struct INIFILE **ini, unsigned mode, char *value); +struct INISection *ini_section_search(struct INIFILE **ini, unsigned mode, const char *value); /** * diff --git a/include/str.h b/include/str.h index 8018cc0..595a055 100644 --- a/include/str.h +++ b/include/str.h @@ -29,7 +29,7 @@ int num_chars(const char *sptr, int ch); * * @param sptr string to scan * @param pattern string to search for - * @return 1 = found, 0 = not found, -1 = error + * @return 1 = found, 0 = not found / error */ int startswith(const char *sptr, const char *pattern); @@ -38,7 +38,7 @@ int startswith(const char *sptr, const char *pattern); * * @param sptr string to scan * @param pattern string to search for - * @return 1 = found, 0 = not found, -1 = error + * @return 1 = found, 0 = not found / error */ int endswith(const char *sptr, const char *pattern); @@ -51,33 +51,6 @@ int endswith(const char *sptr, const char *pattern); void strchrdel(char *sptr, const char *chars); /** - * Find the integer offset of the first occurrence of `ch` in `sptr` - * - * ~~~{.c} - * char buffer[255]; - * char string[] = "abc=123"; - * long int separator_offset = strchroff(string, '='); - * for (long int i = 0; i < separator_offset); i++) { - * buffer[i] = string[i]; - * } - * ~~~ - * - * @param sptr string to scan - * @param ch character to find - * @return offset to character in string, or 0 on failure - */ -long int strchroff(const char *sptr, int ch); - -/** - * This function scans `sptr` from right to left removing any matches to `suffix` - * from the string. - * - * @param sptr string to be modified - * @param suffix string to be removed from `sptr` - */ -void strdelsuffix(char *sptr, const char *suffix); - -/** * Split a string by every delimiter in `delim` string. * * Callee should free memory using `GENERIC_ARRAY_FREE()` diff --git a/include/strlist.h b/include/strlist.h index 2d3c3cf..3f35e23 100644 --- a/include/strlist.h +++ b/include/strlist.h @@ -44,4 +44,12 @@ struct StrList *strlist_copy(struct StrList *pStrList); int strlist_cmp(struct StrList *a, struct StrList *b); void strlist_free(struct StrList **pStrList); +#define STRLIST_E_SUCCESS 0 +#define STRLIST_E_OUT_OF_RANGE 1 +#define STRLIST_E_INVALID_VALUE 2 +#define STRLIST_E_UNKNOWN 3 +extern int strlist_errno; +const char *strlist_get_error(int flag); + + #endif //OMC_STRLIST_H diff --git a/include/system.h b/include/system.h index 7428355..94d5a36 100644 --- a/include/system.h +++ b/include/system.h @@ -14,6 +14,8 @@ #include <sys/wait.h> #include <sys/stat.h> +#define OMC_SHELL_SAFE_RESTRICT ";&|()" + struct Process { // Write stdout stream to file char f_stdout[PATH_MAX]; diff --git a/include/template.h b/include/template.h index a242a08..362eb3d 100644 --- a/include/template.h +++ b/include/template.h @@ -42,7 +42,7 @@ int tpl_render_to_file(char *str, const char *filename); struct tplfunc_frame *tpl_getfunc(char *key); struct tplfunc_frame; -typedef int tplfunc(struct tplfunc_frame *frame); +typedef int tplfunc(struct tplfunc_frame *frame, void *result); struct tplfunc_frame { char *key; tplfunc *func; diff --git a/include/utils.h b/include/utils.h index a340cd7..8840a0d 100644 --- a/include/utils.h +++ b/include/utils.h @@ -329,7 +329,7 @@ char *collapse_whitespace(char **s); * @param maxlen maximum length of dest byte array * @return 0 on success, -1 on error */ -int redact_sensitive(const char **to_redact, char *src, char *dest, size_t maxlen); +int redact_sensitive(const char **to_redact, size_t to_redact_size, char *src, char *dest, size_t maxlen); /** * Given a directory path, return a list of files |