[Openvpn-devel,v6] test_user_pass: Add UTs for character filtering

Message ID 20240129105358.11161-1-gert@greenie.muc.de
State Accepted
Headers show
Series [Openvpn-devel,v6] test_user_pass: Add UTs for character filtering | expand

Commit Message

Gert Doering Jan. 29, 2024, 10:53 a.m. UTC
From: Frank Lichtenheld <frank@lichtenheld.com>

For simplicity I implemented them only with the
inline method, but they actually apply to all methods.

Change-Id: Ie8d2d5f6f58679baaf5eb817a7e2ca1afcb8c4db
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Arne Schwabe <arne-openvpn@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
---

This change was reviewed on Gerrit and approved by at least one
developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/473
This mail reflects revision 6 of this Change.
Acked-by according to Gerrit (reflected above):
Arne Schwabe <arne-openvpn@rfc2549.org>
Gert Doering <gert@greenie.muc.de>

Comments

Gert Doering Jan. 29, 2024, 1:55 p.m. UTC | #1
Tested locally and with GHA.  I expect the UTF8 codes in our source to
create issues at some point (because software is so... helpful), but
it's only the test code, and if that happens, we can move to \xbb\xa4
(etc.) in the strings...

Your patch has been applied to the master branch.

commit 55418bf62eaff1c4323d206181cd8a5f88e7c6c7
Author: Frank Lichtenheld
Date:   Mon Jan 29 11:53:57 2024 +0100

     test_user_pass: Add UTs for character filtering

     Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
     Acked-by: Arne Schwabe <arne-openvpn@rfc2549.org>
     Acked-by: Gert Doering <gert@greenie.muc.de>
     Message-Id: <20240129105358.11161-1-gert@greenie.muc.de>
     URL: https://www.mail-archive.com/search?l=mid&q=20240129105358.11161-1-gert@greenie.muc.de
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/tests/unit_tests/openvpn/test_user_pass.c b/tests/unit_tests/openvpn/test_user_pass.c
index ab4dfe4..277cb1d 100644
--- a/tests/unit_tests/openvpn/test_user_pass.c
+++ b/tests/unit_tests/openvpn/test_user_pass.c
@@ -141,6 +141,29 @@ 
 
     reset_user_pass(&up);
 
+    /* Test various valid characters */
+    /*FIXME: query_user_exec() called even though nothing queued */
+    will_return(query_user_exec_builtin, true);
+    /* FIXME? content after first two lines just ignored */
+    assert_true(get_user_pass_cr(&up, "#iuser and 커뮤니티\n//ipasswörd!\nsome other content\nnot relevant", "UT", flags, NULL));
+    assert_true(up.defined);
+    assert_string_equal(up.username, "#iuser and 커뮤니티");
+    assert_string_equal(up.password, "//ipasswörd!");
+
+    reset_user_pass(&up);
+
+    /* Test various invalid characters */
+    /*FIXME: query_user_exec() called even though nothing queued */
+    will_return(query_user_exec_builtin, true);
+    /*FIXME? allows arbitrary crap if c > 127 */
+    /*FIXME? silently removes control characters */
+    assert_true(get_user_pass_cr(&up, "\tiuser\r\nipass\xffwo\x1erd", "UT", flags, NULL));
+    assert_true(up.defined);
+    assert_string_equal(up.username, "iuser");
+    assert_string_equal(up.password, "ipass\xffword");
+
+    reset_user_pass(&up);
+
     expect_string(query_user_exec_builtin, query_user[i].prompt, "Enter UT Password:");
     will_return(query_user_exec_builtin, "cpassword");
     will_return(query_user_exec_builtin, true);