1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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)
|