From 42081b0e7e6681677d64c72b1262cabba6f1d080 Mon Sep 17 00:00:00 2001 From: Aki Tuomi Date: Sun, 17 Nov 2024 12:49:02 +0200 Subject: [PATCH] var-expand-crypt: Make test_var_expand_crypt_random() stop on first error --- .../var-expand-crypt/test-var-expand-crypt.c | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/plugins/var-expand-crypt/test-var-expand-crypt.c b/src/plugins/var-expand-crypt/test-var-expand-crypt.c index 1728359bfa..a806db4f5b 100644 --- a/src/plugins/var-expand-crypt/test-var-expand-crypt.c +++ b/src/plugins/var-expand-crypt/test-var-expand-crypt.c @@ -102,20 +102,26 @@ static void test_var_expand_crypt_random(void) const struct var_expand_params params = { .table = table, }; + int ret = 0; for (unsigned int i = 0; i < 1000; i++) { const char *error; str_truncate(input, 0); str_truncate(output, 0); - - test_assert_idx(var_expand(input, + ret += var_expand(input, "%{decrypted|encrypt(algorithm='aes-128-cbc',key=key)}", - ¶ms, &error) == 0, i); - table[5].value = str_c(input); - test_assert_idx(var_expand(output, + ¶ms, &error); + test_assert_cmp_idx(ret, ==, 0, i); + var_expand_table_set_value(table, "encrypted2", str_c(input)); + ret += var_expand(output, "%{encrypted2|decrypt(algorithm='aes-128-cbc',key=key)}", - ¶ms, &error) == 0, i); - test_assert_strcmp_idx(str_c(output), table[4].value, i); + ¶ms, &error); + test_assert_cmp_idx(ret, ==, 0, i); + struct var_expand_table *entry = + var_expand_table_get(table, "decrypted"); + test_assert_strcmp_idx(str_c(output), entry->value, i); + if (strcmp(str_c(output), entry->value) != 0) + break; }; test_end(); -- 2.47.3