Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/libexec/nuageinit/tests/decode_base64.lua
288915 views
1
#!/usr/libexec/flua
2
---
3
-- SPDX-License-Identifier: BSD-2-Clause
4
--
5
-- Copyright (c) 2026 Baptiste Daroussin <[email protected]>
6
7
local n = require("nuage")
8
9
-- decode_base64 is not exported, test via addfile
10
11
local function test_decode(input, expected)
12
local r, err = n.addfile({
13
content = input,
14
encoding = "base64",
15
path = "/tmp/nuage_test_b64"
16
}, false)
17
if not r then
18
n.err(err)
19
end
20
local root = os.getenv("NUAGE_FAKE_ROOTDIR")
21
if not root then
22
root = ""
23
end
24
local f = assert(io.open(root .. "/tmp/nuage_test_b64", "r"))
25
local str = f:read("*all")
26
f:close()
27
if str ~= expected then
28
n.err("base64 decode failed: expected '" .. expected
29
.. "' got '" .. str .. "'")
30
end
31
end
32
33
-- empty input
34
test_decode("", "")
35
36
-- single byte: 'a'
37
test_decode("YQ==", "a")
38
39
-- two bytes: 'ab'
40
test_decode("YWI=", "ab")
41
42
-- three bytes: 'abc'
43
test_decode("YWJj", "abc")
44
45
-- newline in base64
46
test_decode("YmxhCg==", "bla\n")
47
48
-- spaces should be ignored
49
test_decode("Y Q = =", "a")
50
51
-- b64 alias
52
local r, err = n.addfile({
53
content = "YQ==",
54
encoding = "b64",
55
path = "/tmp/nuage_test_b64_b64"
56
}, false)
57
if not r then
58
n.err("b64 encoding alias should work: " .. tostring(err))
59
end
60
61
os.exit(0)
62
63