git: 126edf41c0b8 - main - nuageinit: Add test for user named "0"

From: Ed Maste <emaste_at_FreeBSD.org>
Date: Fri, 20 Nov 2026 13:46:30 UTC
The branch main has been updated by emaste:

URL: https://cgit.FreeBSD.org/src/commit/?id=126edf41c0b83ed5def57a722bb5d06f989fed50

commit 126edf41c0b83ed5def57a722bb5d06f989fed50
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2026-11-19 15:37:38 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2026-11-20 13:46:17 +0000

    nuageinit: Add test for user named "0"
    
    Commit 7e11a18e74ba ("nuageinit: Use -n with pw usershow") fixed a bug
    with numeric user names.  For a user named "0" we would previously look
    up and return information for uid 0 (root) instead.
    
    Add a test for this.  Confirmed that the new test fails without
    7e11a18e74ba.
    
    Reviewed by:    bapt
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D61759
---
 libexec/nuageinit/tests/adduser.lua | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/libexec/nuageinit/tests/adduser.lua b/libexec/nuageinit/tests/adduser.lua
index 63c5f14bc555..89ae574c3ddf 100644
--- a/libexec/nuageinit/tests/adduser.lua
+++ b/libexec/nuageinit/tests/adduser.lua
@@ -15,12 +15,23 @@ if not res then
 	n.err("valid adduser should return a path")
 end
 
-pw = {}
-pw.name = "underscore_"
--- Call adduser twice to test both addding and looking up an existing user.
-for i = 1, 2 do
-	local res = n.adduser(pw)
-	if not res then
-		n.err("no path returned for username ending with _")
+local function ends_with(s, suffix)
+	if not s then
+		return false
+	end
+	return suffix == "" or s:sub(-#suffix) == suffix
+end
+
+for _, name in ipairs({"underscore_", "0"}) do
+	pw = {}
+	pw.name = name
+	-- Call adduser twice to test both addding and looking up an existing
+	-- user.
+	for i = 1, 2 do
+		local res = n.adduser(pw)
+		if not ends_with(res, "/" .. name) then
+			n.err("expected .../" .. name ..  " for username " ..
+			    name .. ", got " .. tostring(res))
+		end
 	end
 end