forked from PathOfBuildingCommunity/PathOfBuilding
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestBuildSiteTools_spec.lua
More file actions
118 lines (107 loc) · 4.17 KB
/
Copy pathTestBuildSiteTools_spec.lua
File metadata and controls
118 lines (107 loc) · 4.17 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
describe("BuildSiteTools", function()
local downloadCalls
local origDownloadPage
before_each(function()
downloadCalls = {}
origDownloadPage = launch.DownloadPage
launch.DownloadPage = function(_self, url, callback, params)
table.insert(downloadCalls, { url = url, callback = callback, params = params })
end
end)
after_each(function()
launch.DownloadPage = origDownloadPage
end)
describe("DownloadBuild", function()
-- Pass: Returns the payload, no DownloadPage call
-- Fail: HTTP fetch made or wrong data returned, breaking offline imports
it("returns the inline build code for pob://code/ without fetching", function()
local result = {}
buildSites.DownloadBuild("pob://code/ABCxyz_-123", nil, function(isSuccess, data, link)
result.isSuccess = isSuccess
result.data = data
result.link = link
end)
assert.is_true(result.isSuccess)
assert.are.equal("ABCxyz_-123", result.data)
assert.are.equal("pob://code/ABCxyz_-123", result.link)
assert.are.equal(0, #downloadCalls)
end)
-- Pass: Routes to https://pobb.in/pob/abcd
-- Fail: No fetch made, breaking existing pobb.in imports
it("preserves existing pob://pobbin/ handling", function()
buildSites.DownloadBuild("pob://pobbin/abcd", nil, function() end)
assert.are.equal(1, #downloadCalls)
assert.are.equal("https://pobb.in/pob/abcd", downloadCalls[1].url)
end)
-- Pass: Returns "Download information not found"
-- Fail: Accepts the URI, indicating regex over-match, passing junk downstream
it("rejects unknown providers", function()
local result = {}
buildSites.DownloadBuild("pob://unknown/xyz", nil, function(isSuccess, data)
result.isSuccess = isSuccess
result.data = data
end)
assert.is_false(result.isSuccess)
assert.are.equal("Download information not found", result.data)
assert.are.equal(0, #downloadCalls)
end)
-- Pass: Empty payload rejected
-- Fail: Empty string reaches base64.decode
it("requires a non-empty inline payload", function()
local result = {}
buildSites.DownloadBuild("pob://code/", nil, function(isSuccess, data)
result.isSuccess = isSuccess
result.data = data
end)
assert.is_false(result.isSuccess)
assert.are.equal("Download information not found", result.data)
assert.are.equal(0, #downloadCalls)
end)
-- Pass: Spaces and punctuation rejected
-- Fail: Non-base64 chars reach the decoder, failing with a cryptic error
it("rejects payloads outside the base64url alphabet", function()
local result = {}
buildSites.DownloadBuild("pob://code/has spaces!", nil, function(isSuccess, data)
result.isSuccess = isSuccess
result.data = data
end)
assert.is_false(result.isSuccess)
assert.are.equal("Download information not found", result.data)
assert.are.equal(0, #downloadCalls)
end)
-- Pass: ABCD, ABC=, AB== all accepted
-- Fail: Padded codes rejected, breaking imports from emitters that pad
it("accepts optional trailing base64 padding", function()
for _, code in ipairs({ "ABCD", "ABC=", "AB==" }) do
local data
buildSites.DownloadBuild("pob://code/" .. code, nil, function(_, d) data = d end)
assert.are.equal(code, data)
end
end)
-- Pass: =abc, a=bc, AAAA=== rejected
-- Fail: Bad padding reaches the decoder
it("rejects misplaced '=' padding", function()
for _, link in ipairs({ "pob://code/=abc", "pob://code/a=bc", "pob://code/AAAA===" }) do
local result = {}
buildSites.DownloadBuild(link, nil, function(isSuccess, data)
result.isSuccess = isSuccess
result.data = data
end)
assert.is_false(result.isSuccess, "should reject " .. link)
assert.are.equal("Download information not found", result.data)
end
end)
end)
describe("ParseImportLinkFromURI", function()
-- Pass: Returns nil
-- Fail: Returns a URL, attaching the build to a site that wasn't used
it("returns nil for pob://code/", function()
assert.is_nil(buildSites.ParseImportLinkFromURI("pob://code/abc"))
end)
-- Pass: Returns https://pobb.in/abc
-- Fail: Regression in existing site URI parsing
it("still resolves pob://pobbin/", function()
assert.are.equal("https://pobb.in/abc", buildSites.ParseImportLinkFromURI("pob://pobbin/abc"))
end)
end)
end)