From patchwork Mon Jan 29 12:25:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "plaisthos (Code Review)" X-Patchwork-Id: 3598 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7001:10:b0:550:f63e:f504 with SMTP id rm16csp1382177mab; Mon, 29 Jan 2024 04:26:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IGZTn014Ztze2v+jo/WLUD6dAG9yEOjU7vfW+D+57ElYVQ4+ym7e2MC0LVrCjP5s5uRDoAy X-Received: by 2002:a05:6a21:6d96:b0:19c:a64c:b715 with SMTP id wl22-20020a056a216d9600b0019ca64cb715mr4890351pzb.5.1706531190953; Mon, 29 Jan 2024 04:26:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1706531190; cv=none; d=google.com; s=arc-20160816; b=O5XUph9zP8I3OOVYiGvDts2l6To+5zDj5neEFe3mfMdbM0re6qD834qJ0xVRSbozRd xqLsne6nXLq36/f9bXWu+ybuWddQmkvZ+kRjakkQpRrXJ9sBiocDULC8K7+ygaFnq2Vp l6ZlK0G8UJkOfmrGpp0ccFZDrVRl2PHfga9ZfCYP/eBHdjbrr1dk8Lxj9gcts7c7Jb50 ZaXUAvRMaiyBCgkDmFiQfQowVyvAOLdgNOTepNURlr9i8GVWj0GsbPJtq8Au+1d3K3pu qbKmEc8RFu/0ix7g0Gc+vp6ePN+i3U2A3D4zQYvYj8g8bMblEAFdWY3WSwqn59hxng4j eQoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:cc:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:user-agent :mime-version:message-id:references:auto-submitted:to:date:from :dkim-signature:dkim-signature:dkim-signature; bh=Sdt96HbJ9HqEijG0Zr7EIMnVFJXF90Odxl99IM06W24=; fh=lm0MLPW7DntlrDqRECIiC9JlE1uPxhepE0URYHIf+eE=; b=eHteIcvotqsEZre1iJzt61cIwsn6gF72FwhyyW52gVHwfagS4oaaOoIpEoI7Jg9+gC 9MG911BBL8s4mtpDOQD4WuW2zzO4mPXKw+EfXhsq6BiRY/OEGJkKUEVahYIoVjXxVltm TCAsExfXBqMecIFJaOreYotu9yxvEaOAcnxa6nTLJ+9t+kESLc8jRB3I7eiA+MTdPrk1 wnV28P6RyDdlnJ+vjTK2wJ/UEQ2GhqKqLLoVpA5YiBwKJM91GqzH4PGJoX1Lf11owKCd Gpfz6esqIODCQXrNDT0qH35A3J70tuCTDzdvTCDmhoeocxKO5l/JgeNOb5pmu+/Qm+Qj q7rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=KSmHu7x1; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=dPsmsee4; dkim=neutral (body hash did not verify) header.i=@openvpn.net header.s=google header.b=eQNkQDN1; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=openvpn.net Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id u12-20020a170902e5cc00b001d7204a84e7si5631450plf.5.2024.01.29.04.26.30 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Jan 2024 04:26:30 -0800 (PST) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=KSmHu7x1; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=dPsmsee4; dkim=neutral (body hash did not verify) header.i=@openvpn.net header.s=google header.b=eQNkQDN1; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=openvpn.net Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1rUQiG-0002sa-1Q; Mon, 29 Jan 2024 12:26:08 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rUQiD-0002sS-TF for openvpn-devel@lists.sourceforge.net; Mon, 29 Jan 2024 12:26:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:Content-Transfer-Encoding:MIME-Version :Message-ID:Reply-To:References:Subject:List-Unsubscribe:List-Id:Cc:To:Date: From:Sender:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:List-Help: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Zielw9RarVFOJh5cjfI3MFeA0soC2hZq4sbwK40uGZg=; b=KSmHu7x1ALmJNkfXjtXvc1cOFI 16kw34Ij7jPY8pAW2jbMg2dgEAr9N+z5eAl+pLLnbhT3EKDJUCMYBI95cJNUbys5kjNFcbiYkFXwC rsw/HyRKCVXrMcl+RmAtb1TGhTAg9mtOyHj2UNkoSI9+iHcnNMDpCLZA4wG3HDUxQxEQ=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Type:Content-Transfer-Encoding:MIME-Version:Message-ID:Reply-To: References:Subject:List-Unsubscribe:List-Id:Cc:To:Date:From:Sender:Content-ID :Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To: Resent-Cc:Resent-Message-ID:In-Reply-To:List-Help:List-Subscribe:List-Post: List-Owner:List-Archive; bh=Zielw9RarVFOJh5cjfI3MFeA0soC2hZq4sbwK40uGZg=; b=d Psmsee4Kuj9A4Do25TpUo9aUR3TpBWz8IoIFIsFzoP0hBmGGOdpsNF4XPiT+eJn5bEWsEeZ+y7cjN Ggh3ZBre4rnh/XIl1J4tTX9NLP2MOwyU0zGutH5dNnXsp/tCsDFyo+3j1mc2PoGEZp3H3c11RsfL7 mI/fyB3Hn3BgT1SQ=; Received: from mail-wr1-f45.google.com ([209.85.221.45]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1rUQi8-0005sG-AC for openvpn-devel@lists.sourceforge.net; Mon, 29 Jan 2024 12:26:02 +0000 Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-33af4b34e2cso229073f8f.1 for ; Mon, 29 Jan 2024 04:26:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvpn.net; s=google; t=1706531149; x=1707135949; darn=lists.sourceforge.net; h=user-agent:content-disposition:content-transfer-encoding :mime-version:message-id:reply-to:references:subject :list-unsubscribe:list-id:auto-submitted:cc:to:date:from:from:to:cc :subject:date:message-id:reply-to; bh=Zielw9RarVFOJh5cjfI3MFeA0soC2hZq4sbwK40uGZg=; b=eQNkQDN1fZ47ox8aj+6E84q7dz/9AM+bxUmlB3c1oEmcFbqMgwunZW5/ot4pjw1A2R ZQTpEhfA7660m73D0mWTrRtnaWc6XwNv/NSMQdXPoRwXmiI6qz7+C2k4IgEEXgd3mX7f 3lKEkgFInnSs3x0laZtAAE2kMOSmASzF9ylGFst/Fce2jo/nFz/dPG6Yy6xiy2DAr1iz XUNFJ9LduH4snMO81SmXzzFwAPd+QQXIjAK6FRN292bdGlKD+OQFWzs/lbXZYGf6mdZ8 J1q95KX3el+u1AR/Wp7JpdJEfmFovsZIIMyP08YBp1PV7Rqdt7A5kexOj20Y2cB3hGvP 7mRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706531149; x=1707135949; h=user-agent:content-disposition:content-transfer-encoding :mime-version:message-id:reply-to:references:subject :list-unsubscribe:list-id:auto-submitted:cc:to:date:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Zielw9RarVFOJh5cjfI3MFeA0soC2hZq4sbwK40uGZg=; b=Nz2ankpFvXs7q1yEkLz6B0Pm7rklT3Iha+JhCSRIslpkdLMGpZN2X8WycULAk/LMta AJZvsN7lU/9P5O4czIz/eDRQMfvzaR7VP8blQTDWt5oq8EK5Kstt1EngnVotS9LG+TNg FEoNSMjHlMDDhPnp8JDZ+F4dkudpGieIH4D7c481QArcOOBb+NhlryqGpHwVO5yeIeaY C0FRe+wQgJRd7IFjOerszvgqtsEfgdkaHnnVPVHtkhHB2G/Jh+ahCe0oQS1mHneT5/K1 pjVIuN28Qo+9SvKif6nX/2PMq10YxOrAqyZz33zxsh67iCaYOl8CnHksu4d29mRQUVfP Iaww== X-Gm-Message-State: AOJu0YzotZRRVdXUk2t06dEODtAssH4c/IIRNyaUdWMTu32cBWS8Z41A BlxnegrTuIViLhpTL+iZYyih6TxmrADgGzHPOoAs9hO1Zh7IUr241GRLpzysocH3JLTslKpMmoZ 7 X-Received: by 2002:adf:eb04:0:b0:33a:ef3c:a0b8 with SMTP id s4-20020adfeb04000000b0033aef3ca0b8mr1668055wrn.15.1706531149212; Mon, 29 Jan 2024 04:25:49 -0800 (PST) Received: from gerrit.openvpn.in (ec2-18-159-0-78.eu-central-1.compute.amazonaws.com. [18.159.0.78]) by smtp.gmail.com with ESMTPSA id m4-20020a5d6244000000b0033ae4a3b285sm5646883wrv.36.2024.01.29.04.25.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 04:25:48 -0800 (PST) From: "plaisthos (Code Review)" X-Google-Original-From: "plaisthos (Code Review)" X-Gerrit-PatchSet: 1 Date: Mon, 29 Jan 2024 12:25:48 +0000 To: flichtenheld Auto-Submitted: auto-generated X-Gerrit-MessageType: newchange X-Gerrit-Change-Id: Ide72b81f497088dd0fd2cdcfff83cbce5b48f145 X-Gerrit-Change-Number: 509 X-Gerrit-Project: openvpn X-Gerrit-ChangeURL: X-Gerrit-Commit: 522f5b1a430dd8165a8b50ab05fac2e8c8015909 References: Message-ID: MIME-Version: 1.0 User-Agent: Gerrit/3.8.2 X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "util-spamd-2.v13.lw.sourceforge.com", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Attention is currently required from: flichtenheld. Hello flichtenheld, I'd like you to do a code review. Please visit Content analysis details: (-0.2 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [209.85.221.45 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.221.45 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 WEIRD_PORT URI: Uses non-standard port number for HTTP 0.0 HTML_MESSAGE BODY: HTML included in message -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.0 T_SCC_BODY_TEXT_LINE No description available. 0.0 T_KAM_HTML_FONT_INVALID Test for Invalidly Named or Formatted Colors in HTML X-Headers-End: 1rUQi8-0005sG-AC Subject: [Openvpn-devel] [S] Change in openvpn[master]: [CMake] Allow unit tests to fall back to hard coded location X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: arne-openvpn@rfc2549.org, openvpn-devel@lists.sourceforge.net, frank@lichtenheld.com Cc: openvpn-devel Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1789427650339787325?= X-GMAIL-MSGID: =?utf-8?q?1789427650339787325?= X-getmail-filter-classifier: gerrit message type newchange Attention is currently required from: flichtenheld. Hello flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/509?usp=email to review the following change. Change subject: [CMake] Allow unit tests to fall back to hard coded location ...................................................................... [CMake] Allow unit tests to fall back to hard coded location Settings the environment variable required for running unit tests is tiresome in my IDE (Clion). So allow unit tests to fall back to a hard coded location in case the environment variable is not set. Change-Id: Ide72b81f497088dd0fd2cdcfff83cbce5b48f145 --- M CMakeLists.txt M tests/unit_tests/openvpn/test_common.h M tests/unit_tests/openvpn/test_user_pass.c 3 files changed, 37 insertions(+), 6 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/09/509/1 diff --git a/CMakeLists.txt b/CMakeLists.txt index be55c60..fdd2b01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -682,6 +682,10 @@ target_include_directories(${test_name} PRIVATE src/openvpn) + # for compat with IDEs like Clion that ignore the tests properties + # for the environment variable srcdir when running tests as fallback + target_compile_definitions(${test_name} PRIVATE "-DUNIT_TEST_SOURCEDIR=\"${CMAKE_SOURCE_DIR}/tests/unit_tests/openvpn\"") + if (NOT ${test_name} STREQUAL "test_buffer") target_sources(${test_name} PRIVATE src/openvpn/buffer.c diff --git a/tests/unit_tests/openvpn/test_common.h b/tests/unit_tests/openvpn/test_common.h index 50e16d6..f219e93 100644 --- a/tests/unit_tests/openvpn/test_common.h +++ b/tests/unit_tests/openvpn/test_common.h @@ -32,9 +32,36 @@ * This has a openvpn prefix to avoid confusion with cmocka's unit_test_setup_* * methods */ -void +static inline void openvpn_unit_test_setup() { assert_int_equal(setvbuf(stdout, NULL, _IONBF, BUFSIZ), 0); assert_int_equal(setvbuf(stderr, NULL, _IONBF, BUFSIZ), 0); } + +/** + * Helper function to get a file path from the unit test directory to open it + * or pass its path to another function. This function will first look for + * an environment variable or if failing that, will fall back to a hardcoded + * value from compile time if compiled with CMake. + * + * @param buf buffer holding the path to the file + * @param bufsize size of buf + * @param filename name of the filename to retrieve relative to the + * unit test source directory + */ +void +openvpn_test_get_srcdir_dir(char *buf, size_t bufsize, const char *filename) +{ + const char *srcdir = getenv("srcdir"); + +#if defined(UNIT_TEST_SOURCEDIR) + if (!srcdir) + { + srcdir = UNIT_TEST_SOURCEDIR; + } +#endif + assert_non_null(srcdir); + + snprintf(buf, bufsize, "%s/%s", srcdir, filename); +} diff --git a/tests/unit_tests/openvpn/test_user_pass.c b/tests/unit_tests/openvpn/test_user_pass.c index ab4dfe4..fee5891 100644 --- a/tests/unit_tests/openvpn/test_user_pass.c +++ b/tests/unit_tests/openvpn/test_user_pass.c @@ -35,6 +35,7 @@ #include #include #include +#include "test_common.h" #include "misc.c" @@ -209,11 +210,9 @@ reset_user_pass(&up); unsigned int flags = 0; - const char *srcdir = getenv("srcdir"); - assert_non_null(srcdir); char authfile[PATH_MAX] = { 0 }; + openvpn_test_get_srcdir_dir(authfile, PATH_MAX, "input/user_pass.txt" ); - snprintf(authfile, PATH_MAX, "%s/%s", srcdir, "input/user_pass.txt"); /*FIXME: query_user_exec() called even though nothing queued */ will_return(query_user_exec_builtin, true); assert_true(get_user_pass_cr(&up, authfile, "UT", flags, NULL)); @@ -223,7 +222,7 @@ reset_user_pass(&up); - snprintf(authfile, PATH_MAX, "%s/%s", srcdir, "input/user_only.txt"); + openvpn_test_get_srcdir_dir(authfile, PATH_MAX, "input/user_only.txt"); 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); @@ -236,7 +235,7 @@ reset_user_pass(&up); flags |= GET_USER_PASS_PASSWORD_ONLY; - snprintf(authfile, PATH_MAX, "%s/%s", srcdir, "input/user_only.txt"); + openvpn_test_get_srcdir_dir(authfile, PATH_MAX, "input/user_only.txt"); /*FIXME: query_user_exec() called even though nothing queued */ will_return(query_user_exec_builtin, true); assert_true(get_user_pass_cr(&up, authfile, "UT", flags, NULL)); @@ -256,5 +255,6 @@ int main(void) { + openvpn_unit_test_setup(); return cmocka_run_group_tests(user_pass_tests, NULL, NULL); }