git: 68fd0feacb8c - main - nuageinit: add decode_base64 tests
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 10 May 2026 15:56:26 UTC
The branch main has been updated by bapt:
URL: https://cgit.FreeBSD.org/src/commit/?id=68fd0feacb8ce5da9c47deea5505b3241b2ba6ec
commit 68fd0feacb8ce5da9c47deea5505b3241b2ba6ec
Author: Baptiste Daroussin <bapt@FreeBSD.org>
AuthorDate: 2026-05-07 17:17:56 +0000
Commit: Baptiste Daroussin <bapt@FreeBSD.org>
CommitDate: 2026-05-10 15:50:53 +0000
nuageinit: add decode_base64 tests
---
libexec/nuageinit/tests/Makefile | 1 +
libexec/nuageinit/tests/decode_base64.lua | 61 +++++++++++++++++++++++++++++++
libexec/nuageinit/tests/nuage.sh | 8 ++++
3 files changed, 70 insertions(+)
diff --git a/libexec/nuageinit/tests/Makefile b/libexec/nuageinit/tests/Makefile
index dc8997717b59..feca49784c9e 100644
--- a/libexec/nuageinit/tests/Makefile
+++ b/libexec/nuageinit/tests/Makefile
@@ -18,5 +18,6 @@ ${PACKAGE}FILES+= sethostname.lua
${PACKAGE}FILES+= settimezone.lua
${PACKAGE}FILES+= warn.lua
${PACKAGE}FILES+= addfile.lua
+${PACKAGE}FILES+= decode_base64.lua
.include <bsd.test.mk>
diff --git a/libexec/nuageinit/tests/decode_base64.lua b/libexec/nuageinit/tests/decode_base64.lua
new file mode 100644
index 000000000000..0951d77f0ed7
--- /dev/null
+++ b/libexec/nuageinit/tests/decode_base64.lua
@@ -0,0 +1,61 @@
+#!/usr/libexec/flua
+---
+-- SPDX-License-Identifier: BSD-2-Clause
+--
+-- Copyright (c) 2026 Baptiste Daroussin <bapt@FreeBSD.org>
+
+local n = require("nuage")
+
+-- decode_base64 is not exported, test via addfile
+
+local function test_decode(input, expected)
+ local r, err = n.addfile({
+ content = input,
+ encoding = "base64",
+ path = "/tmp/nuage_test_b64"
+ }, false)
+ if not r then
+ n.err(err)
+ end
+ local root = os.getenv("NUAGE_FAKE_ROOTDIR")
+ if not root then
+ root = ""
+ end
+ local f = assert(io.open(root .. "/tmp/nuage_test_b64", "r"))
+ local str = f:read("*all")
+ f:close()
+ if str ~= expected then
+ n.err("base64 decode failed: expected '" .. expected
+ .. "' got '" .. str .. "'")
+ end
+end
+
+-- empty input
+test_decode("", "")
+
+-- single byte: 'a'
+test_decode("YQ==", "a")
+
+-- two bytes: 'ab'
+test_decode("YWI=", "ab")
+
+-- three bytes: 'abc'
+test_decode("YWJj", "abc")
+
+-- newline in base64
+test_decode("YmxhCg==", "bla\n")
+
+-- spaces should be ignored
+test_decode("Y Q = =", "a")
+
+-- b64 alias
+local r, err = n.addfile({
+ content = "YQ==",
+ encoding = "b64",
+ path = "/tmp/nuage_test_b64_b64"
+}, false)
+if not r then
+ n.err("b64 encoding alias should work: " .. tostring(err))
+end
+
+os.exit(0)
diff --git a/libexec/nuageinit/tests/nuage.sh b/libexec/nuageinit/tests/nuage.sh
index 57d83b62928a..1c8d717a5b67 100644
--- a/libexec/nuageinit/tests/nuage.sh
+++ b/libexec/nuageinit/tests/nuage.sh
@@ -14,6 +14,7 @@ atf_test_case adduser
atf_test_case adduser_passwd
atf_test_case addgroup
atf_test_case addfile
+atf_test_case decode_base64
settimezone_body()
{
@@ -90,6 +91,12 @@ addfile_body()
atf_check /usr/libexec/flua $(atf_get_srcdir)/addfile.lua
}
+decode_base64_body()
+{
+ mkdir tmp
+ atf_check /usr/libexec/flua $(atf_get_srcdir)/decode_base64.lua
+}
+
atf_init_test_cases()
{
atf_add_test_case sethostname
@@ -98,4 +105,5 @@ atf_init_test_cases()
atf_add_test_case adduser_passwd
atf_add_test_case addgroup
atf_add_test_case addfile
+ atf_add_test_case decode_base64
}