From: "cron2 (Code Review)" Date: Wed, 8 Oct 2025 10:47:47 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <90ff0eb1e10496763c2e4b68575fb6498fc077ee-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="WvEoMZtA7n0="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: test_options_parse: Add test for read_config_string List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld , plaisthos Cc: openvpn-devel --WvEoMZtA7n0= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#3) to the change originally created by= flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1247?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by cron2 Change subject: test_options_parse: Add test for read_config_string ...................................................................... test_options_parse: Add test for read_config_string The test discovered the issue fixed by commit "buffer: Fix buf_parse eating input". Change-Id: Icb91d9c560b6f78f16571ac3052cc566d94afe99 Signed-off-by: Frank Lichtenheld Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1247 Message-Id: <20251008100222.4610-1-gert@...1296...> URL: https://sourceforge.net/p/openvpn/mailman/message/59243809/ Signed-off-by: Gert Doering --- M tests/unit_tests/openvpn/test_options_parse.c 1 file changed, 109 insertions(+), 0 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/47/1247/3 diff --git a/tests/unit_tests/openvpn/test_options_parse.c b/tests/unit_tes= ts/openvpn/test_options_parse.c index 9472c78..e552dd7 100644 --- a/tests/unit_tests/openvpn/test_options_parse.c +++ b/tests/unit_tests/openvpn/test_options_parse.c @@ -43,6 +43,9 @@ const unsigned int permission_mask, unsigned int *option= _types_found, struct env_set *es) { + function_called(); + check_expected(p); + check_expected(is_inline); } void @@ -185,11 +188,117 @@ gc_free(&gc); } +static void +read_single_config(struct options *options, const char *config) +{ + unsigned int option_types_found =3D 0; + struct env_set es; + CLEAR(es); + read_config_string("test_options_parse", options, config, M_INFO, OPT_= P_DEFAULT, + &option_types_found, &es); +} + +union tokens_parameter +{ + uintmax_t as_int; + void *as_pointer; +}; + +static int +check_tokens(const uintmax_t value, const uintmax_t expected) +{ + union tokens_parameter temp; + temp.as_int =3D value; + const char **p =3D (const char **)temp.as_pointer; + temp.as_int =3D expected; + const char **expected_p =3D (const char **)temp.as_pointer; + for (int i =3D 0; i < MAX_PARMS; i++) + { + if (!p[i] && !expected_p[i]) + { + return true; + } + if ((p[i] && !expected_p[i]) + || (!p[i] && expected_p[i])) + { + fprintf(stderr, "diff at i=3D%d\n", i); + return false; + } + if (strcmp(p[i], expected_p[i])) + { + fprintf(stderr, "diff at i=3D%d, p=3D<%s> ep=3D<%s>\n", i, p[i= ], expected_p[i]); + return false; + } + } + fprintf(stderr, "fallthrough"); + return false; +} + +static void +test_read_config(void **state) +{ + struct options o; + CLEAR(o); /* NB: avoiding init_options to limit dependencies */ + gc_init(&o.gc); + gc_init(&o.dns_options.gc); + o.gc_owned =3D true; + + char *p_expect_someopt[MAX_PARMS]; + char *p_expect_otheropt[MAX_PARMS]; + char *p_expect_inlineopt[MAX_PARMS]; + CLEAR(p_expect_someopt); + CLEAR(p_expect_otheropt); + CLEAR(p_expect_inlineopt); + p_expect_someopt[0] =3D "someopt"; + p_expect_someopt[1] =3D "parm1"; + p_expect_someopt[2] =3D "parm2"; + p_expect_otheropt[0] =3D "otheropt"; + p_expect_otheropt[1] =3D "1"; + p_expect_otheropt[2] =3D "2"; + p_expect_inlineopt[0] =3D "inlineopt"; + p_expect_inlineopt[1] =3D "some text\nother text\n"; + + /* basic test */ + expect_function_call(__wrap_add_option); + expect_check(__wrap_add_option, p, check_tokens, p_expect_someopt); + expect_value(__wrap_add_option, is_inline, 0); + expect_function_call(__wrap_add_option); + expect_check(__wrap_add_option, p, check_tokens, p_expect_otheropt); + expect_value(__wrap_add_option, is_inline, 0); + read_single_config(&o, "someopt parm1 parm2\n otheropt 1 2"); + + /* -- gets stripped */ + expect_function_call(__wrap_add_option); + expect_check(__wrap_add_option, p, check_tokens, p_expect_someopt); + expect_value(__wrap_add_option, is_inline, 0); + expect_function_call(__wrap_add_option); + expect_check(__wrap_add_option, p, check_tokens, p_expect_otheropt); + expect_value(__wrap_add_option, is_inline, 0); + read_single_config(&o, "someopt parm1 parm2\n\t--otheropt 1 2"); + + /* inline options */ + expect_function_call(__wrap_add_option); + expect_check(__wrap_add_option, p, check_tokens, p_expect_inlineopt); + expect_value(__wrap_add_option, is_inline, 1); + read_single_config(&o, "\nsome text\nother text\n"); + + p_expect_inlineopt[0] =3D "inlineopt"; + p_expect_inlineopt[1] =3D A_TIMES_256 A_TIMES_256 A_TIMES_256 A_TIMES_= 256 A_TIMES_256 "\n"; + expect_function_call(__wrap_add_option); + expect_check(__wrap_add_option, p, check_tokens, p_expect_inlineopt); + expect_value(__wrap_add_option, is_inline, 1); + read_single_config(&o, "\n" A_TIMES_256 A_TIMES_256 A_TIMES= _256 A_TIMES_256 A_TIMES_256 "\n"); + + gc_free(&o.gc); + gc_free(&o.dns_options.gc); +} + int main(void) { const struct CMUnitTest tests[] =3D { cmocka_unit_test(test_parse_line), + cmocka_unit_test(test_read_config), }; return cmocka_run_group_tests_name("options_parse", tests, NULL, NULL); -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1247?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newpatchset Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Icb91d9c560b6f78f16571ac3052cc566d94afe99 Gerrit-Change-Number: 1247 Gerrit-PatchSet: 3 Gerrit-Owner: flichtenheld Gerrit-Reviewer: cron2 Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel --WvEoMZtA7n0= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 upl= oaded patch set #3 to the change originally created by flichtenhel= d.

View Change

The following approvals got outdated and were remove= d: Code-Review+2 by cron2

test_options_parse: Add test for re=
ad_config_string

The <inlineopt> test discovered the issue
= fixed by commit "buffer: Fix buf_parse eating input".

Chan= ge-Id: Icb91d9c560b6f78f16571ac3052cc566d94afe99
Signed-off-by: Frank Li= chtenheld <frank@...2641...>
Acked-by: Gert Doering <gert@...1711...= 96...>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1247
Mes= sage-Id: <20251008100222.4610-1-gert@...1296...>
URL: https://sour= ceforge.net/p/openvpn/mailman/message/59243809/
Signed-off-by: Gert Doer= ing <gert@...1296...>
---
M tests/unit_tests/openvpn/test_optio= ns_parse.c
1 file changed, 109 insertions(+), 0 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/change=
s/47/1247/3
diff --git a/tests/unit_tests/openvpn/test_options_pars=
e.c b/tests/unit_tests/openvpn/test_options_parse.c
index 9= 472c78..e552dd7 100644
--- a/tests/unit_tests/openvpn/test_= options_parse.c
+++ b/tests/unit_tests/openvpn/test_options= _parse.c
@@ -43,6 +43,9 @@
= const unsigned int permission_mask, unsigned int *option_types_found,
struct env_set *es)
{
+ function_called();<= /span>
+ check_expected(p= );
+ check_expecte= d(is_inline);
}

void
@@ -185,11 +188,117 @@
gc_free(&gc);=
}

+static void
+read_single_config(struct options *options, const char *config)
+{
+ unsigned int option_types_found =3D= 0;
+ struct env_s= et es;
+ CLEAR(es)= ;
+ read_config_st= ring("test_options_parse", options, config, M_INFO, OPT_P_DEFAULT= ,
+ = &option_types_found, &es);
+}
+
+union tokens_para= meter
+{
+ uintmax_t as_int;

= + void *as_pointer;+};
+
+static int
+check_tokens(const uintmax_t value, const uintmax_t expected)
<= span style=3D"color: hsl(120, 100%, 40%);">+{

+ union tokens_parameter temp;
+ temp.as_int =3D value;+ const char **p =3D (const= char **)temp.as_pointer;
+ temp.as_int =3D expected;
+ const char **expected_p =3D (const char **)temp.as_poin= ter;
+ for (int i = =3D 0; i < MAX_PARMS; i++)
+ {
+ = if (!p[i] && !expected_p[i])
+ {
+ return true;
+ }
+ if ((p[i] && !expected_p[i])
+ || (!p[i] && expected_p[= i]))
+ {
+ fprintf(stder= r, "diff at i=3D%d\n", i);
+ return false;
+ }
+ if (strcmp(p[i], expected_p[i]))
+ {
+ fprintf(stderr, "diff at i=3D%d, p= =3D<%s> ep=3D<%s>\n", i, p[i], expected_p[i]);
<= span style=3D"color: hsl(120, 100%, 40%);">+ return false;
+ }
+ }

+ fprintf(stderr, "fallthrough");
+ return false;
+}
+
+static void
+test_read_config(void **state)
+{
+= struct options o;
+ CLEAR(o); /* NB: avoiding init_options to limit dependencies */
+ gc_init(&o.gc);
+ gc_init(&o.dn= s_options.gc);
+ o= .gc_owned =3D true;
+=
+ char *p_expect_= someopt[MAX_PARMS];
+= char *p_expect_otheropt[MAX_PARMS];
+ char *p_expect_inlineopt[MAX_PARMS];
+ CLEAR(p_expect_someopt);
+ CLEAR(p_expect_othero= pt);
+ CLEAR(p_exp= ect_inlineopt);
+ = p_expect_someopt[0] =3D "someopt";
+ p_expect_someopt[1] =3D "parm1";
+ p_expect_someopt[2]= =3D "parm2";
+ p_expect_otheropt[0] =3D "otheropt";
+ p_expect_otheropt[1] =3D "1&quo= t;;
+ p_expect_oth= eropt[2] =3D "2";
+ p_expect_inlineopt[0] =3D "inlineopt";
+ p_expect_inlineopt[1] =3D &quo= t;some text\nother text\n";

+
+ /*= basic test */
+ e= xpect_function_call(__wrap_add_option);
+ expect_check(__wrap_add_option, p, check_tokens, p_= expect_someopt);
+ = expect_value(__wrap_add_option, is_inline, 0);
+ expect_function_call(__wrap_add_option);
+ expect_check(__wra= p_add_option, p, check_tokens, p_expect_otheropt);
+ expect_value(__wrap_add_option, is_inlin= e, 0);
+ read_sing= le_config(&o, "someopt parm1 parm2\n otheropt 1 2");<= br>+
+ /* -- gets stripped */
+ expect_function_call(__wrap_add_opt= ion);
+ expect_che= ck(__wrap_add_option, p, check_tokens, p_expect_someopt);
+ expect_value(__wrap_add_option, i= s_inline, 0);
+ ex= pect_function_call(__wrap_add_option);
+ expect_check(__wrap_add_option, p, check_tokens, p_e= xpect_otheropt);
+ = expect_value(__wrap_add_option, is_inline, 0);
+ read_single_config(&o, "someopt pa= rm1 parm2\n\t--otheropt 1 2");
+
+ = /* inline options */
+ expect_function_call(__wrap_add_option);
+ expect_check(__wrap_add_option, p, check_tok= ens, p_expect_inlineopt);
+ expect_value(__wrap_add_option, is_inline, 1);
+ read_single_config(&o, "&= lt;inlineopt>\nsome text\nother text\n</inlineopt>");<= br>+
+ p_expect_inlineopt[0] =3D "inlineopt&= quot;;
+ p_expect_= inlineopt[1] =3D A_TIMES_256 A_TIMES_256 A_TIMES_256 A_TIMES_256 A_TIMES_25= 6 "\n";
+ = expect_function_call(__wrap_add_option);
+ expect_check(__wrap_add_option, p, check_tokens,= p_expect_inlineopt);
+ expect_value(__wrap_add_option, is_inline, 1);
+ read_single_config(&o, "<= inlineopt>\n" A_TIMES_256 A_TIMES_256 A_TIMES_256 A_TIMES_256 A_TIM= ES_256 "\n</inlineopt>");
+
+ gc_free(&o.dns_options.gc);
+}
+
int
main(void)
{
const struct CMUnitTest tests[] =3D {
= cmocka_unit_test(test_parse_line),
+ cmocka_unit_test(test_read_config), };

return cmocka_run_gr= oup_tests_name("options_parse", tests, NULL, NULL);

To view, visit change 1247. To unsubscribe, or for help = writing mail filters, visit settings.

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Icb91d9c560b6f78f16571ac3052= cc566d94afe99
Gerrit-Change-Number: 1247
Gerrit-PatchSet: 3
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
= --WvEoMZtA7n0=--