mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-10-16 22:47:38 +00:00

The main purpose of this is to backport the improved parse/runtime errors to older versions. I think they're sufficiently useful that we should try to make it as widely available as possible. We've been running them for a week now on SC3 and the released version and not seen any issues, so I think it's probably stable enough. This is a pretty lazy commit: I ended up copying the whole ROM over and then picking up a few other related changes along the way. - Trim spaces from file paths (b8fce1eecc
) - Correctly format 12AM/PM with %I (9f48395596
) - Fix http.request and htpt.websocketAsync not handling a few failure edge-cases correctly (3b42f22a4f
). - Move the internal modules into the main package path, hidden under cc.internal (34a31abd9c
). - Gather code coverage in Java instead of Lua (28a55349a9
). - Make error messages in edit more obvious (8cfbfe7ceb
). - Make mcfly's test methods global. This means we don't need to pass stub everywhere (7335a892b5
). - Improve runtime and parse errors. This comes from numerous commits, but chieflya12b405acf
, and5502412181
. - Hide the internal redirect methods in multishell (33b6f38339
). Note this does /not/ include the shebang changes (sorry Emma!). I've tried to avoid adding any user-controllable features, mostly because I don't know how to handle the versioning otherwise :).
48 lines
2.0 KiB
Lua
48 lines
2.0 KiB
Lua
local timeout = require "test_helpers".timeout
|
|
|
|
describe("The http library", function()
|
|
describe("http.checkURL", function()
|
|
it("accepts well formed domains", function()
|
|
expect({ http.checkURL("https://google.com") }):same({ true })
|
|
end)
|
|
|
|
it("rejects malformed URLs", function()
|
|
expect({ http.checkURL("google.com") }):same({ false, "Must specify http or https" })
|
|
expect({ http.checkURL("https:google.com") }):same({ false, "URL malformed" })
|
|
expect({ http.checkURL("https:/google.com") }):same({ false, "URL malformed" })
|
|
expect({ http.checkURL("wss://google.com") }):same({ false, "Invalid protocol 'wss'" })
|
|
end)
|
|
|
|
it("rejects local domains", function()
|
|
-- Note, this is tested more thoroughly in AddressRuleTest. We've just got this here
|
|
-- to ensure the general control flow works.
|
|
expect({ http.checkURL("http://localhost") }):same({ false, "Domain not permitted" })
|
|
expect({ http.checkURL("http://127.0.0.1") }):same({ false, "Domain not permitted" })
|
|
end)
|
|
end)
|
|
|
|
describe("http.websocketAsync", function()
|
|
it("queues an event for immediate failures", function()
|
|
timeout(1, function()
|
|
local url = "http://not.a.websocket"
|
|
http.websocketAsync(url)
|
|
local _, url2, message = os.pullEvent("websocket_failure")
|
|
expect(url2):eq(url)
|
|
expect(message):eq("Invalid scheme 'http'")
|
|
end)
|
|
end)
|
|
end)
|
|
|
|
describe("http.requestAsync", function()
|
|
it("queues an event for immediate failures", function()
|
|
timeout(1, function()
|
|
local url = "ws://not.a.request"
|
|
http.request(url)
|
|
local _, url2, message = os.pullEvent("http_failure")
|
|
expect(url2):eq(url)
|
|
expect(message):eq("Invalid protocol 'ws'")
|
|
end)
|
|
end)
|
|
end)
|
|
end)
|