Path: blob/main/libexec/nuageinit/tests/decode_base64.lua
288915 views
#!/usr/libexec/flua1---2-- SPDX-License-Identifier: BSD-2-Clause3--4-- Copyright (c) 2026 Baptiste Daroussin <[email protected]>56local n = require("nuage")78-- decode_base64 is not exported, test via addfile910local function test_decode(input, expected)11local r, err = n.addfile({12content = input,13encoding = "base64",14path = "/tmp/nuage_test_b64"15}, false)16if not r then17n.err(err)18end19local root = os.getenv("NUAGE_FAKE_ROOTDIR")20if not root then21root = ""22end23local f = assert(io.open(root .. "/tmp/nuage_test_b64", "r"))24local str = f:read("*all")25f:close()26if str ~= expected then27n.err("base64 decode failed: expected '" .. expected28.. "' got '" .. str .. "'")29end30end3132-- empty input33test_decode("", "")3435-- single byte: 'a'36test_decode("YQ==", "a")3738-- two bytes: 'ab'39test_decode("YWI=", "ab")4041-- three bytes: 'abc'42test_decode("YWJj", "abc")4344-- newline in base6445test_decode("YmxhCg==", "bla\n")4647-- spaces should be ignored48test_decode("Y Q = =", "a")4950-- b64 alias51local r, err = n.addfile({52content = "YQ==",53encoding = "b64",54path = "/tmp/nuage_test_b64_b64"55}, false)56if not r then57n.err("b64 encoding alias should work: " .. tostring(err))58end5960os.exit(0)616263