✨ 初始提交:月读第三方书源插件集合
每个书源一个独立插件目录,含微信读书公众号订阅、书架导入等完整功能。 Co-authored-by: Copilot <[email protected]>
This commit is contained in:
commit
2bc5c24ea7
27 files changed
+3760
No files matched your search
@@ -0,0 +1,113 @@
|
||||
--[[--
|
||||
晋江多阶段请求取消、收藏读回、登录竞态与密码不落盘。
|
||||
|
||||
@module tests.moonsource_jjwxc.async_spec
|
||||
--]]
|
||||
---@diagnostic disable: undefined-field, missing-fields, param-type-mismatch
|
||||
|
||||
local Assert = require("support.assert")
|
||||
local JSON = require("support.json_stub")
|
||||
local cfg, requests, synchronous, saved = { cookie = "sid=test", token = "old" }, {}, nil, 0
|
||||
package.loaded["json"] = JSON
|
||||
package.loaded["utils.settings"] = {
|
||||
getSource = function() return cfg end,
|
||||
saveSource = function() saved = saved + 1 end,
|
||||
}
|
||||
local expired = 0
|
||||
package.loaded["source.auth"] = { ok = function() end, expire = function(_id, msg) expired = expired + 1; return msg end }
|
||||
local Request = {
|
||||
get = function(url, opts, cb)
|
||||
local request = { url = url, cb = cb, opts = opts }
|
||||
request.cancel = function() request.cancelled = true end
|
||||
requests[#requests + 1] = request
|
||||
if synchronous then synchronous(request, #requests) end
|
||||
return request
|
||||
end,
|
||||
header = function(res, key) return res and res.headers and res.headers[key] end,
|
||||
}
|
||||
package.loaded["http.request"] = Request
|
||||
package.loaded["utils.charset"] = { toUtf8 = function(raw) return raw end }
|
||||
package.loaded["moonsource_jjwxc.protocols.web"] = nil
|
||||
local Web = require("moonsource_jjwxc.protocols.web")
|
||||
local fav = '<ul id="favul"><li><a href="/book2/1">测试书</a></li></ul>'
|
||||
|
||||
local called
|
||||
synchronous = function(request, index) if index == 1 then request.cb(fav) end end
|
||||
local handle = Web.shelfAsync(function() called = true end)
|
||||
Assert.len(requests, 2)
|
||||
handle.cancel()
|
||||
Assert.is_true(requests[2].cancelled)
|
||||
requests[2].cb('<ul id="favul"></ul>')
|
||||
Assert.is_nil(called)
|
||||
|
||||
requests, synchronous = {}, nil
|
||||
local result, reason
|
||||
Web.shelfAsync(function(value, err) result, reason = value, err end)
|
||||
requests[1].cb(fav)
|
||||
requests[2].cb(fav)
|
||||
Assert.is_nil(result)
|
||||
Assert.eq(reason, "晋江收藏页无法解析", "重复页不能伪装完整书架")
|
||||
|
||||
requests = {}
|
||||
Web.favRemoveAsync("1", function(value, err) result, reason = value, err end)
|
||||
requests[1].cb("<html>HTTP 200 但未删除</html>")
|
||||
requests[2].cb(fav)
|
||||
requests[3].cb('<ul id="favul"></ul>')
|
||||
Assert.is_nil(result)
|
||||
Assert.eq(reason, "晋江没有确认取消收藏")
|
||||
requests = {}
|
||||
Web.favRemoveAsync("1", function(value, err) result, reason = value, err end)
|
||||
requests[1].cb("<html>已执行</html>")
|
||||
requests[2].cb('<ul id="favul"></ul>')
|
||||
Assert.is_true(result)
|
||||
Assert.eq(requests[1].opts.cache_ttl, 0)
|
||||
|
||||
requests = {}
|
||||
Web.favAsync(cfg.cookie, function() end)
|
||||
cfg.cookie = "sid=new"
|
||||
requests[1].cb(nil, "HTTP 302", { code = 302, headers = { Location = "/my/login" } })
|
||||
Assert.eq(expired, 0, "旧 Cookie 迟到不能使新登录过期")
|
||||
Web.favAsync(cfg.cookie, function() end)
|
||||
requests[2].cb(nil, "网络故障")
|
||||
Assert.eq(expired, 0, "网络错误不能使登录过期")
|
||||
|
||||
requests, synchronous = {}, function(request, index)
|
||||
if index == 1 then request.cb(JSON.encode({ code = 1004 })) end
|
||||
end
|
||||
package.loaded["moonsource_jjwxc.protocols"] = { current = function() return {
|
||||
contentAsync = function(_novel, _chapter, cb)
|
||||
local request = { cb = cb, cancel = function() called = "cancelled" end }
|
||||
requests[#requests + 1] = request
|
||||
return request
|
||||
end,
|
||||
} end }
|
||||
package.loaded["moonsource_jjwxc.client"] = nil
|
||||
called = nil
|
||||
local Client = require("moonsource_jjwxc.client")
|
||||
handle = Client.contentAsync("1", "2", function() called = "late" end)
|
||||
handle.cancel()
|
||||
Assert.eq(called, "cancelled")
|
||||
requests[2].cb("测试正文")
|
||||
Assert.eq(called, "cancelled")
|
||||
|
||||
requests, synchronous = {}, nil
|
||||
package.loaded["moonsource_jjwxc.protocols.app"] = nil
|
||||
local App = require("moonsource_jjwxc.protocols.app")
|
||||
App.save("test", "do-not-store", "old")
|
||||
Assert.is_nil(cfg.password)
|
||||
cfg.password = "legacy"
|
||||
Assert.eq(App.get(), "old")
|
||||
Assert.is_nil(cfg.password)
|
||||
Assert.eq(saved, 2)
|
||||
App.shelfAsync(function(value, err) result, reason = value, err end)
|
||||
cfg.token = "new"
|
||||
requests[1].cb(JSON.encode({ code = 1004 }))
|
||||
Assert.matches(requests[2].url, "token=new")
|
||||
requests[2].cb(JSON.encode({ addData = {} }))
|
||||
Assert.len(result, 0)
|
||||
Assert.eq(expired, 0)
|
||||
requests = {}
|
||||
App.shelfAsync(function(value, err) result, reason = value, err end)
|
||||
requests[1].cb(nil, "网络故障")
|
||||
Assert.eq(reason, "网络故障")
|
||||
Assert.eq(expired, 0)
|
||||
@@ -0,0 +1,106 @@
|
||||
--[[--
|
||||
晋江动态分类:真实 HTML 形状、筛选、分页、旧榜单、错误与取消。
|
||||
|
||||
@module tests.moonsource_jjwxc.browse_spec
|
||||
--]]
|
||||
---@diagnostic disable: undefined-field, missing-fields, param-type-mismatch
|
||||
|
||||
local Assert = require("support.assert")
|
||||
local Mapper = require("moonsource_jjwxc.mapper")
|
||||
local html = [[<form id="wap_bookbase_form">
|
||||
<label><input type='checkbox' name='xx0' value="0"/>不限</label>
|
||||
<label><input type='checkbox' name='xx2' value="2"/>纯爱</label>
|
||||
<label><input name='yc0' value="0"/>不限</label><label><input name='yc1' value="1"/>原创</label>
|
||||
<label><input name='sd0' value="0"/>不限</label><label><input name='sd2' value="2"/>古色古香</label>
|
||||
<label><input name='lx0' value="0"/>不限</label><label><input name='lx1' value="1"/>爱情</label>
|
||||
<label><input name='fw0' value="0"/>全站</label><label><input name='fw6' value="6"/>免费</label>
|
||||
</form><select name="sortType"><option value="2">积分</option><option value="1">最近更新</option></select>
|
||||
<select name="isfinish"><option value="0" selected>无限制
|
||||
<option value="1">连载</option><option value="2">完结</option></select>
|
||||
<table width="100%"><tr><td>《<a class="track" href="/book2/101">甲&乙</a>》 ---
|
||||
<a href="/wapauthor/8">测试作者</a></td></tr></table>
|
||||
<div id='pageArea'>共3页,当前第1页</div>]]
|
||||
local parsed = Mapper.category(html)
|
||||
Assert.eq(parsed.filters.xx[2].id, "2")
|
||||
Assert.eq(parsed.filters.isfinish[1].title, "无限制")
|
||||
Assert.eq(parsed.books[1].title, "甲&乙")
|
||||
Assert.eq(parsed.books[1].authors, "测试作者")
|
||||
Assert.eq(parsed.pages, 3)
|
||||
Assert.matches(parsed.books[1].cover, "novelid=101$")
|
||||
Assert.is_nil(Mapper.category("<html>错误</html>"))
|
||||
Assert.len(Mapper.category(html:gsub("<tr>.-</tr>", "")).books, 0)
|
||||
|
||||
local requests, reply, mode = {}, nil, "pending"
|
||||
package.loaded["moonsource_jjwxc.client"] = {
|
||||
categoryAsync = function(params, cb)
|
||||
local saved = {}
|
||||
for key, value in pairs(params) do saved[key] = value end
|
||||
local request = { params = saved, cb = cb, cancelled = false }
|
||||
request.cancel = function() request.cancelled = true end
|
||||
requests[#requests + 1] = request
|
||||
if #requests == 1 then cb(Mapper.category(html))
|
||||
elseif mode == "oversized" then
|
||||
cb({ page = params.page, pages = 3, books = {
|
||||
{ source_id = "ext.jjwxc", stable_id = "201" },
|
||||
{ source_id = "ext.jjwxc", stable_id = "202" },
|
||||
{ source_id = "ext.jjwxc", stable_id = "203" },
|
||||
} })
|
||||
elseif mode == "sync" then
|
||||
cb({ page = params.page, pages = 3, books = { { source_id = "ext.jjwxc", stable_id = tostring(params.page) } } })
|
||||
end
|
||||
return request
|
||||
end,
|
||||
storeHomeAsync = function(cb) cb({}); return { cancel = function() end } end,
|
||||
}
|
||||
package.loaded["moonsource_jjwxc.browse"] = nil
|
||||
local Library = require("moonsource_jjwxc.browse")
|
||||
local handle = Library.run({}, function(value) reply = value end)
|
||||
Assert.eq(requests[2].params.page, 2)
|
||||
handle.cancel()
|
||||
Assert.is_true(requests[2].cancelled)
|
||||
requests[2].cb({ page = 2, pages = 3, books = {} })
|
||||
Assert.is_nil(reply)
|
||||
|
||||
requests, mode = {}, "sync"
|
||||
Library.run({ limit = 2 }, function(value) reply = value end)
|
||||
Assert.len(reply.data, 2)
|
||||
Assert.eq(reply.groups[1].title, "频道")
|
||||
Assert.eq(reply.groups[1].chips[2].id, "cate:2:0:0:0:0:0:2")
|
||||
Assert.eq(reply.groups[5].chips[2].id, "cate:0:0:0:0:6:0:2")
|
||||
Assert.is_true(reply.more)
|
||||
|
||||
requests = {}
|
||||
Library.run({ limit = 1 }, function(value) reply = value end)
|
||||
Assert.len(reply.data, 1)
|
||||
Assert.is_true(reply.more)
|
||||
|
||||
requests, mode = {}, "oversized"
|
||||
Library.run({ limit = 2 }, function(value) reply = value end)
|
||||
Assert.len(reply.data, 2, "聚合整页超过 limit 时只交付要求数量")
|
||||
Assert.eq(reply.data[2].stable_id, "201")
|
||||
Assert.is_true(reply.more)
|
||||
Assert.len(requests, 2)
|
||||
|
||||
requests, mode = {}, "pending"
|
||||
local reason
|
||||
Library.run({}, function(value, err) reply, reason = value, err end)
|
||||
requests[2].cb(nil, "网络故障")
|
||||
Assert.is_nil(reply)
|
||||
Assert.eq(reason, "网络故障")
|
||||
|
||||
requests = {}
|
||||
Library.run({}, function(value, err) reply, reason = value, err end)
|
||||
requests[2].cb({ page = 1, pages = 3, books = {} })
|
||||
Assert.is_nil(reply)
|
||||
Assert.eq(reason, "晋江分类响应无效")
|
||||
|
||||
requests = {}
|
||||
Library.run({ node = "cate:99:0:0:0:0:0:2" }, function(value, err) reply, reason = value, err end)
|
||||
Assert.is_nil(reply)
|
||||
Assert.eq(reason, "晋江分类条件无效")
|
||||
|
||||
package.loaded["moonsource_jjwxc.source"] = nil
|
||||
local source = require("moonsource_jjwxc.source").new()
|
||||
source:browseAsync({ node = "1:1" }, function(value, err) reply, reason = value, err end)
|
||||
Assert.is_nil(reply)
|
||||
Assert.eq(reason, "晋江榜单无法解析", "旧榜单节点仍走榜单")
|
||||
@@ -0,0 +1,139 @@
|
||||
--[[--
|
||||
晋江 VIP 章购买状态探测:句柄挂在源实例上,目录重拉前取消在飞探测,旧目录表不能盖回新目录。
|
||||
|
||||
@module tests.source.jjwxc_probe_spec
|
||||
--]]
|
||||
---@diagnostic disable: undefined-field, missing-fields, param-type-mismatch
|
||||
|
||||
local Assert = require("support.assert")
|
||||
local Stubs = require("support.stubs")
|
||||
Stubs.install()
|
||||
Stubs.reset()
|
||||
|
||||
package.preload["utils.settings"] = function()
|
||||
return { getSource = function() return {} end, saveSource = function() end }
|
||||
end
|
||||
|
||||
-- 内存目录表:put 记每次写入的表
|
||||
local stored, puts = {}, {}
|
||||
package.preload["source.toc"] = function()
|
||||
return {
|
||||
read = function(_source_id, stable_id) return stored[stable_id] end,
|
||||
put = function(_source_id, stable_id, list)
|
||||
stored[stable_id] = list
|
||||
puts[#puts + 1] = list
|
||||
return true
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
-- Web 协议:paidAsync 挂起,由用例手动回
|
||||
local pending = {}
|
||||
local Web = {
|
||||
id = "web",
|
||||
paidAsync = function(_novel, uid, cb)
|
||||
local req = { uid = uid, cb = cb, cancelled = false }
|
||||
req.cancel = function() req.cancelled = true end
|
||||
pending[#pending + 1] = req
|
||||
return req
|
||||
end,
|
||||
}
|
||||
package.preload["moonsource_jjwxc.protocols.web"] = function() return Web end
|
||||
package.preload["moonsource_jjwxc.protocols"] = function()
|
||||
return { list = { Web }, current = function() return Web end }
|
||||
end
|
||||
|
||||
local chapter_cbs = {}
|
||||
package.preload["moonsource_jjwxc.client"] = function()
|
||||
return {
|
||||
chaptersAsync = function(_id, cb)
|
||||
chapter_cbs[#chapter_cbs + 1] = cb
|
||||
return { cancel = function() end }
|
||||
end,
|
||||
}
|
||||
end
|
||||
package.preload["moonsource_jjwxc.mapper"] = function()
|
||||
return {
|
||||
TOC_VERSION = 7,
|
||||
toc = function(wire) return wire end,
|
||||
}
|
||||
end
|
||||
|
||||
for _idx, name in ipairs({ "moonsource_jjwxc.source", "moonsource_jjwxc.init", "source.toc", "moonsource_jjwxc.protocols",
|
||||
"moonsource_jjwxc.protocols.web", "moonsource_jjwxc.client", "moonsource_jjwxc.mapper", "utils.settings" }) do
|
||||
package.loaded[name] = nil
|
||||
end
|
||||
local Jjwxc = require("moonsource_jjwxc.source")
|
||||
|
||||
local function vipToc()
|
||||
return {
|
||||
{ uid = "1", idx = 1, title = "一", vip = true, toc_version = 7 },
|
||||
{ uid = "2", idx = 2, title = "二", vip = true, toc_version = 7 },
|
||||
}
|
||||
end
|
||||
local identity = { source_id = "ext.jjwxc", stable_id = "9" }
|
||||
|
||||
-- 缓存命中:开探测;同一本书再问不重开;问完一次性写回
|
||||
do
|
||||
stored["9"] = vipToc()
|
||||
local src = Jjwxc.new()
|
||||
src:loadTocAsync(identity, function() end)
|
||||
Stubs.flush()
|
||||
Assert.len(pending, 1)
|
||||
Assert.eq(src.probe.stable_id, "9")
|
||||
src:loadTocAsync(identity, function() end)
|
||||
Stubs.flush()
|
||||
Assert.len(pending, 1, "同一本书在飞不重开")
|
||||
pending[1].cb(true)
|
||||
Assert.len(pending, 2)
|
||||
pending[2].cb(false)
|
||||
Assert.is_nil(src.probe)
|
||||
Assert.len(puts, 1)
|
||||
Assert.eq(puts[1][1].paid, true)
|
||||
Assert.eq(puts[1][2].paid, false)
|
||||
pending, puts, stored = {}, {}, {}
|
||||
end
|
||||
|
||||
-- 目录重拉:在飞的探测先取消,旧目录表不能在新目录之后写回
|
||||
do
|
||||
stored["9"] = vipToc()
|
||||
local src = Jjwxc.new()
|
||||
src:loadTocAsync(identity, function() end)
|
||||
Stubs.flush()
|
||||
Assert.len(pending, 1)
|
||||
local old_probe_req = pending[1]
|
||||
stored["9"] = nil -- 缓存失效,下一次走网络
|
||||
local got
|
||||
src:loadTocAsync(identity, function(toc) got = toc end)
|
||||
local fresh = vipToc()
|
||||
fresh[1].title = "新一"
|
||||
chapter_cbs[1](fresh)
|
||||
Assert.eq(got[1].title, "新一")
|
||||
Assert.is_true(old_probe_req.cancelled, "重拉前取消旧探测")
|
||||
old_probe_req.cb(true) -- 迟到的回包
|
||||
Assert.eq(stored["9"][1].title, "新一", "旧表不能盖回新目录")
|
||||
Assert.is_nil(stored["9"][1].paid)
|
||||
-- 新目录自己的探测在跑
|
||||
Assert.eq(src.probe.stable_id, "9")
|
||||
Assert.len(pending, 2)
|
||||
pending, puts, stored, chapter_cbs = {}, {}, {}, {}
|
||||
end
|
||||
|
||||
-- 换书:旧书探测取消;close 取消在飞探测
|
||||
do
|
||||
stored["9"] = vipToc()
|
||||
stored["10"] = vipToc()
|
||||
local src = Jjwxc.new()
|
||||
src:loadTocAsync(identity, function() end)
|
||||
Stubs.flush()
|
||||
src:loadTocAsync({ source_id = "ext.jjwxc", stable_id = "10" }, function() end)
|
||||
Stubs.flush()
|
||||
Assert.is_true(pending[1].cancelled)
|
||||
Assert.eq(src.probe.stable_id, "10")
|
||||
src:close()
|
||||
Assert.is_true(pending[2].cancelled)
|
||||
Assert.is_nil(src.probe)
|
||||
pending[2].cb(true)
|
||||
Assert.len(puts, 0, "取消后不落库")
|
||||
pending, puts, stored = {}, {}, {}
|
||||
end
|
||||
@@ -0,0 +1,309 @@
|
||||
--[[--
|
||||
晋江收藏页 / 目录 / 网页正文映射与 Cookie 解析离线用例。
|
||||
|
||||
@module tests.source.jjwxc_spec
|
||||
--]]
|
||||
---@diagnostic disable: undefined-field, missing-fields, param-type-mismatch
|
||||
|
||||
local Assert = require("support.assert")
|
||||
|
||||
local source_cfg = {}
|
||||
package.preload["utils.settings"] = function()
|
||||
return { getSource = function() return source_cfg end, saveSource = function() end }
|
||||
end
|
||||
package.loaded["moonsource_jjwxc.mapper"] = nil
|
||||
package.loaded["moonsource_jjwxc.setting"] = nil
|
||||
local Mapper = require("moonsource_jjwxc.mapper")
|
||||
local Setting = require("moonsource_jjwxc.setting")
|
||||
|
||||
do
|
||||
local html = '<ul id="favul"><li readingorbookmarktime="1"><a href="/book2/123">书名…</a> - <a href="/wapauthor/9">某作者</a> [删]</li>'
|
||||
.. '<li><a href="/book2/456">另一本</a></li></ul>'
|
||||
local rows = Mapper.favRows(html)
|
||||
Assert.len(rows, 2)
|
||||
Assert.eq(rows[1].id, "123")
|
||||
Assert.eq(rows[1].author, "某作者")
|
||||
Assert.is_nil(Mapper.favRows("<html>请登录</html>"))
|
||||
end
|
||||
|
||||
do
|
||||
local html = '<span> 【言情排行】 </span><div><ul><li><a href="/book2/1" class="track" data-x=\'{"a":1}\'>甲&乙</a></li></ul></div>'
|
||||
.. '<span>【纯爱排行】</span><ul><li><a href="/book2/2">丙</a></li><li><a href="/book2/3">丁</a></li></ul>'
|
||||
local sections = Mapper.rankSections(html)
|
||||
Assert.len(sections, 2)
|
||||
Assert.eq(sections[1].title, "言情排行")
|
||||
Assert.eq(sections[1].books[1].stable_id, "1")
|
||||
Assert.eq(sections[1].books[1].title, "甲&乙")
|
||||
Assert.len(sections[2].books, 2)
|
||||
Assert.len(Mapper.rankSections("<html></html>"), 0)
|
||||
local ranks = Mapper.storeRanks({
|
||||
{ type = "img" },
|
||||
{ type = "rankings", data = {
|
||||
{ more = { rankName = "月榜", channellist = {
|
||||
{ channel = "言情", channelid = "natural_592" },
|
||||
{ channel = "纯爱", channelid = "natural_604" },
|
||||
{ channel = "坏", channelid = "a/b" },
|
||||
} } },
|
||||
{ more = {} },
|
||||
} },
|
||||
})
|
||||
Assert.len(ranks, 1)
|
||||
Assert.eq(ranks[1].title, "月榜")
|
||||
Assert.len(ranks[1].channels, 2)
|
||||
Assert.eq(ranks[1].channels[2].id, "natural_604")
|
||||
local books = Mapper.rankBooks({ data = { data = {
|
||||
{ novelId = "1", novelName = "甲", authorName = "乙", novelIntroShort = "<p>简介</p>" },
|
||||
{ novelname = "无号" },
|
||||
} } })
|
||||
Assert.len(books, 1)
|
||||
Assert.eq(books[1].title, "甲")
|
||||
Assert.eq(books[1].intro, "简介")
|
||||
Assert.eq(books[1].authors, "乙")
|
||||
end
|
||||
|
||||
do
|
||||
local books = Mapper.shelfList({
|
||||
{ id = "1", title = "短…", info = { novelId = 1, novelName = "全名", authorName = "甲", novelSize = "271,300", novelCover = "" } },
|
||||
{ id = "2", title = "截断", local_book = { stable_id = "2", title = "本地全名" } },
|
||||
{ id = "3", title = "兜底", author = "乙" },
|
||||
})
|
||||
Assert.eq(books[1].title, "全名")
|
||||
Assert.eq(books[1].meta.words, 271300)
|
||||
Assert.is_nil(books[1].cover)
|
||||
Assert.eq(books[2].title, "本地全名")
|
||||
Assert.eq(books[3].title, "兜底")
|
||||
end
|
||||
|
||||
do
|
||||
local toc = Mapper.toc({ chapterlist = {
|
||||
{ chapterid = "0", chaptertype = "1", chaptername = "卷一", islock = "0" },
|
||||
{ chapterid = "1", chaptertype = "0", chaptername = "第一章", islock = "0", chaptersize = "100" },
|
||||
{ chapterid = "2", chaptertype = "0", chaptername = "锁定", islock = "1" },
|
||||
{ chapterid = "3", chaptertype = "0", chaptername = "第三章", islock = "0", isvip = 2 },
|
||||
} })
|
||||
Assert.len(toc, 2)
|
||||
Assert.eq(toc[2].uid, "3")
|
||||
Assert.eq(toc[2].idx, 2)
|
||||
Assert.is_true(toc[2].vip)
|
||||
Assert.is_nil(toc[1].vip)
|
||||
Assert.eq(toc[1].toc_version, Mapper.TOC_VERSION)
|
||||
end
|
||||
|
||||
do
|
||||
Assert.eq(Mapper.webContent('<ul class="content_ul"><li class="x">甲<br>乙&丙</li></ul>'), "甲\n乙&丙")
|
||||
Assert.is_nil(Mapper.webContent("<h1>提示</h1>"))
|
||||
Assert.eq(Mapper.webContent('<ul class="content_ul"><li>甲<script>var a = "x";</script>乙</li></ul>'), "甲乙")
|
||||
local vip = '<ul class="content_ul"><li><div id="content_1">vip内容加载中...</div><div id="contentvars">'
|
||||
.. '<input type="hidden" name="novelid" value="9942287"><input type="hidden" name="chapterid" value="23">'
|
||||
.. '<input type="hidden" name="readerid" value="85927522"><input type="hidden" name="accessKey" value="PxowDj">'
|
||||
.. '<input type="hidden" name="cryptInfo" value="UahebT8I2W5DVP5RtJTyCv1C6busic0hCivj23MPTk2HT99HFI3DvvCodX1QFhgRjU3iX1mxo8d2Gew/rq0qmDncXWCcbF7pIJ8MOhTRzV8=">'
|
||||
.. '<input type="hidden" name="content" value="Emlwl6ggvu2rApuyRLY0AEkcBQrKkbdlc4dnnXiyv2GlVkdadO7XU7ajVLp7r4yNKJsCzyUFsnFXtjXtpHOMCMWh7YMzOwF/YC/3uid37ZFyJcrWtkoot1B5mGTJYe5s0Vdy+pJl3IwBMXuHFH88vVgUfiXj+mxoaeYo/Znglqk="></div></li></ul>'
|
||||
Assert.eq(Mapper.webContent(vip), " 甲&乙\n\n 丙\238\129\132丁")
|
||||
Assert.is_nil(Mapper.webContent(vip:gsub("PxowDj", "xxxxxx")))
|
||||
end
|
||||
|
||||
do
|
||||
-- key / iv 取摘要里任意偏移的窗口,正文也可能是未编码的 UTF-8。
|
||||
local Aes, md5, Text = require("crypto.aes"), require("ffi/sha2").md5, require("utils.text")
|
||||
local function enc(plain, source, key_off, iv_off)
|
||||
local d = md5(source)
|
||||
d = d .. d
|
||||
return Text.base64Encode(Aes.cbc_encrypt(plain, d:sub(key_off + 1, key_off + 16), d:sub(iv_off + 1, iv_off + 16)))
|
||||
end
|
||||
local meta = Text.base64Encode('{"time":1792544104,"key":"HqgOwYk","ver":"20250926"}')
|
||||
local body = " 沈玄宁讪讪一笑,道:“我是路过的。”<br><br> 他转身走了,留下一句话:好自为之。"
|
||||
local page = '<div id="contentvars"><input name="novelid" value="9942287"><input name="chapterid" value="23">'
|
||||
.. '<input name="readerid" value="85927522"><input name="accessKey" value="AcsRWK">'
|
||||
.. '<input name="cryptInfo" value="' .. enc(meta, "9942287.23.85927522.AcsRWK", 27, 11) .. '">'
|
||||
.. '<input name="content" value="' .. enc(body, "HqgOwYk179254410485927522", 12, 28) .. '"></div>'
|
||||
Assert.eq(require("moonsource_jjwxc.vip").content(page), body)
|
||||
-- 书号 + 章号为奇数时官方脚本换密钥(issue #78)。密文由 Node crypto 按脚本规则生成,
|
||||
-- 不跟 Lua 实现共用派生,派生错了这里对不上。奇数章若仍是旧的点号密钥,也要能解开。
|
||||
local odd = '<div id="contentvars"><input name="novelid" value="100"><input name="chapterid" value="1">'
|
||||
.. '<input name="readerid" value="42"><input name="accessKey" value="Ab12">'
|
||||
.. '<input name="cryptInfo" value="fuO73SNX9D4tRXsRYM3+AqBEUOk/rBNxSjkep0cnWPVHs/z7E3F5Lv4aD7VMrTOr0aFEh8aQNfh5YnvP6djkUhASTVDWdyOpNHzGhYFLPfE=">'
|
||||
.. '<input name="content" value="lErz8EEQyFUYbBR62OfGFxuF2cmlnWeVhUZVe7FnX36I4WLn1A2qP2KisezEaSyHcvWsLD0HZys87HvdW/rPilJ2+znYbX2ls/Myl4wocCry6gXJjrFiENS688VyxfVezdvKwwwBVBUaY5CecSG2hrU+8W8ILu4uX31NgjgUFa0="></div>'
|
||||
Assert.eq(require("moonsource_jjwxc.vip").content(odd), body)
|
||||
local odd_old = '<div id="contentvars"><input name="novelid" value="100"><input name="chapterid" value="1">'
|
||||
.. '<input name="readerid" value="42"><input name="accessKey" value="Ab12">'
|
||||
.. '<input name="cryptInfo" value="' .. enc(meta, "100.1.42.Ab12", 3, 9) .. '">'
|
||||
.. '<input name="content" value="' .. enc(body, "HqgOwYk179254410442", 4, 18) .. '"></div>'
|
||||
Assert.eq(require("moonsource_jjwxc.vip").content(odd_old), body)
|
||||
-- 现行 jjcontent.js:cryptInfo 是 DES,正文是固定窗口 AES。密文在这里用 Des/Aes 现算,不走 Vip 内部。
|
||||
local Des = require("crypto.des")
|
||||
local function turn(source, access)
|
||||
local hex = md5(source)
|
||||
local sum = 0
|
||||
for i = 1, #access do sum = sum + access:byte(i) end
|
||||
local off = sum % #hex
|
||||
if off ~= 0 then hex = hex:sub(off + 1) .. hex:sub(1, off) end
|
||||
return hex
|
||||
end
|
||||
local access, novel, chapter, reader = "Ab12Cd", "8718162", "19", "7"
|
||||
local spun = turn(novel .. "." .. chapter .. "." .. reader .. "." .. access, access)
|
||||
local info = Des.encryptBase64('{"key":"K1","time":1700000000}', spun:sub(-16, -9), spun:sub(1, 8))
|
||||
spun = turn("K117000000007", access)
|
||||
local content = Text.base64Encode(Aes.cbc_encrypt(body, spun:sub(1, 16), spun:sub(-16)))
|
||||
local current = '<div id="contentvars"><input name="novelid" value="' .. novel .. '">'
|
||||
.. '<input name="chapterid" value="' .. chapter .. '"><input name="readerid" value="' .. reader .. '">'
|
||||
.. '<input name="accessKey" value="' .. access .. '"><input name="cryptInfo" value="' .. info .. '">'
|
||||
.. '<input name="content" value="' .. content .. '"></div>'
|
||||
Assert.eq(require("moonsource_jjwxc.vip").content(current), body)
|
||||
-- 段缝:正文切成 c_ span,缝里的字挂在同页 <style> 的 :before/:after content 上(issue #67)。
|
||||
-- .c_zz 是同规则的配对类名(不在正文里),不得重复拼;\7f1d 是 CSS 十六进制转义。
|
||||
Assert.eq(Mapper.webContent([[<style>.c_aa:before, .c_zz:after{content:'缝1';} .c_bb:after{content:'\7f1d 2';}</style>]]
|
||||
.. [[<ul class="content_ul"><li>甲<span class='c_aa'>乙</span><span class="c_bb">丙</span>丁</li></ul>]]),
|
||||
"甲缝1乙丙缝2丁")
|
||||
end
|
||||
|
||||
do
|
||||
package.loaded["moonsource_jjwxc.font"] = nil
|
||||
local Font = require("moonsource_jjwxc.font")
|
||||
local fh = assert(io.open("tests/fixtures/jjwxcfont_9eo8b.ttf", "rb"))
|
||||
local ttf = fh:read("*a")
|
||||
fh:close()
|
||||
local map = Font.mapping(ttf)
|
||||
local n = 0
|
||||
for _code in pairs(map) do n = n + 1 end
|
||||
Assert.eq(n, 200)
|
||||
Assert.eq(map[0xE044], "他")
|
||||
Assert.eq(map[0xE9BE], "已")
|
||||
-- 私有区字 → 真字;字后的零宽占位去掉;未命中的私有区字原样保留。
|
||||
Assert.eq(Font.decode("\u{E044}\u{200B}说\u{E9BE}\u{FEFF}\u{F8F0}", map), "他说已\u{F8F0}")
|
||||
Assert.is_nil(Font.mapping("not a font"))
|
||||
end
|
||||
|
||||
do
|
||||
Assert.eq(Setting.parseCookie("b=2; a=1;bad name=3; c="), "a=1; b=2")
|
||||
Assert.eq(Setting.fromPayload({ cookies = {
|
||||
{ domain = ".jjwxc.com", name = "sid", value = "v" },
|
||||
{ domain = "m.jjwxc.com", name = "JJSESS", value = "w" },
|
||||
{ domain = "evil.com", name = "x", value = "y" },
|
||||
} }), "JJSESS=w; sid=v")
|
||||
end
|
||||
|
||||
do
|
||||
local html = require("utils.text").chapterHtml("第一章", " 甲\n\n 乙〇\n")
|
||||
Assert.eq(html, "<h1>第一章</h1>\n<p>甲</p>\n<p>乙〇</p>")
|
||||
end
|
||||
|
||||
do
|
||||
local book = Mapper.book({ novelId = 1, novelName = "x", novelCover = "https://i9-static.jjwxc.net/novelimage.php?novelid=1&coverid=2&ver=abc" })
|
||||
Assert.eq(book.cover, "https://i9-static.jjwxc.net/novelimage.php?novelid=1&coverid=2")
|
||||
end
|
||||
|
||||
do
|
||||
local books = Mapper.search({ items = {
|
||||
{ novelid = 5, novelname = "甲", authorname = "乙", novelintroshort = "简介" },
|
||||
} })
|
||||
Assert.len(books, 1)
|
||||
Assert.eq(books[1].stable_id, "5")
|
||||
Assert.eq(books[1].title, "甲")
|
||||
Assert.eq(books[1].authors, "乙")
|
||||
end
|
||||
|
||||
-- 段评:统计只留有评论的真实段(-2 是章末总评),评论页的游标是累计偏移。
|
||||
do
|
||||
package.loaded["moonsource_jjwxc.reviews"] = nil
|
||||
local Reviews = require("moonsource_jjwxc.reviews")
|
||||
local hot = Reviews.hotspots({
|
||||
{ paragraph_id = "-2", comment_total = "130" },
|
||||
{ paragraph_id = "3", comment_total = "7" },
|
||||
{ paragraph_id = "1", comment_total = "24148" },
|
||||
{ paragraph_id = "2", comment_total = "0" },
|
||||
})
|
||||
Assert.len(hot, 3)
|
||||
Assert.eq(hot[1].range, "-2")
|
||||
Assert.eq(hot[2].range, "1")
|
||||
Assert.eq(hot[3].range, "3")
|
||||
Assert.eq(hot[3].total, 7)
|
||||
|
||||
local page = Reviews.page({ commentTotal = "45", commentList = {
|
||||
{ commentId = "9", commentAuthor = "甲", commentBody = "好&看<br/>真的", agreenum = "6", comment_date_time = "1792324141" },
|
||||
} }, 20)
|
||||
Assert.eq(page.total, 45)
|
||||
Assert.eq(page.max_idx, 21)
|
||||
Assert.is_true(page.more)
|
||||
Assert.eq(page.items[1].content, "好&看\n真的")
|
||||
Assert.eq(page.items[1].likes, 6)
|
||||
Assert.eq(page.items[1].time, 1792324141)
|
||||
Assert.is_false(Reviews.page({ commentTotal = "1", commentList = { { commentId = "1" } } }, 0).more)
|
||||
Assert.is_nil((Reviews.page({}, 0)))
|
||||
end
|
||||
|
||||
-- App 登录用的 DES-CBC:向量来自 openssl(des-cbc,key KW8Dvm2N,iv 1ae2c94b)。
|
||||
do
|
||||
local Des = require("crypto.des")
|
||||
local cipher = Des.encrypt("hello-世界 password 123", "KW8Dvm2N", "1ae2c94b")
|
||||
local hex = cipher:gsub(".", function(c) return string.format("%02x", c:byte()) end)
|
||||
Assert.eq(hex, "6c85a3005530ad3b2e41bb2f25eb77bb5fc29c01b2df52790e15fb89ec87c576")
|
||||
Assert.eq(Des.decrypt(cipher, "KW8Dvm2N", "1ae2c94b"), "hello-世界 password 123")
|
||||
Assert.is_nil(Des.decrypt(cipher:sub(1, 15), "KW8Dvm2N", "1ae2c94b"))
|
||||
Assert.is_nil(Des.decrypt(cipher, "WRONGKEY", "1ae2c94b"))
|
||||
|
||||
local rows = Mapper.tokenFavRows({ { novelId = 7, novelName = "甲", authorName = "乙" }, { novelname = "无号" } })
|
||||
Assert.len(rows, 1)
|
||||
Assert.eq(rows[1].id, "7")
|
||||
Assert.eq(rows[1].author, "乙")
|
||||
end
|
||||
|
||||
do
|
||||
local Des = require("crypto.des")
|
||||
local md5, Hex = require("ffi/sha2").md5, require("crypto.hex")
|
||||
package.loaded["moonsource_jjwxc.protocols.app"] = nil
|
||||
local Client = require("moonsource_jjwxc.protocols.app")
|
||||
local keystring = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
local plain = '{"content":"正文","code":"1004"}'
|
||||
-- accesskey 字节和 = 97+98+99 = 294,末字符 c(99) 为奇:盐在尾;偏移 294%62=46,长度 floor(294/65)=4
|
||||
local salt, part = "0123456789ab", keystring:sub(47, 50)
|
||||
local cipher = Hex.to_hex(Des.encrypt(plain, md5(part .. salt):sub(1, 8), md5(salt):sub(1, 8)))
|
||||
Assert.eq(Client.decryptBody(cipher .. salt, "abc", keystring), plain)
|
||||
-- 末字符为偶:盐在头
|
||||
local even_sum = 97 + 98 + 100
|
||||
local start2, count2 = even_sum % #keystring, math.floor(even_sum / 65)
|
||||
local part2 = keystring:sub(start2 + 1, start2 + count2)
|
||||
local cipher2 = Hex.to_hex(Des.encrypt(plain, md5(part2 .. salt):sub(1, 8), md5(salt):sub(1, 8)))
|
||||
Assert.eq(Client.decryptBody(salt .. cipher2, "abd", keystring), plain)
|
||||
local chapter = "甲<br>乙"
|
||||
local chapter_cipher = Des.encryptBase64(chapter, "KW8Dvm2N", "1ae2c94b")
|
||||
Assert.eq(Client.chapterText(chapter_cipher, nil), chapter)
|
||||
Assert.eq(Client.chapterText(chapter_cipher, "jj"), chapter)
|
||||
Assert.eq(Client.chapterText(chapter, nil), chapter)
|
||||
Assert.is_nil(Client.chapterText("@@@@", "jj"))
|
||||
end
|
||||
|
||||
do
|
||||
local Settings = require("utils.settings")
|
||||
local Protocols = require("moonsource_jjwxc.protocols")
|
||||
local cfg = Settings.getSource("ext.jjwxc")
|
||||
cfg.cookie, cfg.token, cfg.protocol = nil, nil, nil
|
||||
Assert.is_nil(Protocols.current())
|
||||
cfg.token = "t"
|
||||
Assert.eq(Protocols.current().id, "app")
|
||||
cfg.cookie = "c=1"
|
||||
Assert.eq(Protocols.current().id, "web")
|
||||
Protocols.select("app")
|
||||
Assert.eq(Protocols.current().id, "app")
|
||||
cfg.protocol = "web"
|
||||
cfg.cookie = nil
|
||||
Assert.eq(Protocols.current().id, "app")
|
||||
cfg.token, cfg.protocol = nil, nil
|
||||
end
|
||||
|
||||
-- 段评接口:VIP 章节要登录态,web 带 Cookie、app 带 token 查询参数,都没有就匿名。
|
||||
do
|
||||
local Settings = require("utils.settings")
|
||||
local Protocols = require("moonsource_jjwxc.protocols")
|
||||
local cfg = Settings.getSource("ext.jjwxc")
|
||||
cfg.cookie, cfg.token, cfg.protocol = nil, nil, nil
|
||||
Assert.eq(select(1, Protocols.list[1].commentAuth()), "")
|
||||
Assert.is_nil(select(2, Protocols.list[1].commentAuth()).Cookie)
|
||||
cfg.cookie, cfg.token = "c=1", "t k"
|
||||
local query, headers = Protocols.list[1].commentAuth()
|
||||
Assert.eq(query, "")
|
||||
Assert.eq(headers.Cookie, "c=1")
|
||||
query, headers = Protocols.list[2].commentAuth()
|
||||
Assert.eq(query, "&token=t%20k")
|
||||
Assert.is_nil(headers.Cookie)
|
||||
cfg.cookie, cfg.token = nil, nil
|
||||
end
|
||||
@@ -0,0 +1,102 @@
|
||||
--[[--
|
||||
晋江章评与段评分流、分页、坏响应、章节归属及取消。
|
||||
|
||||
@module tests.moonsource_jjwxc.reviews_spec
|
||||
--]]
|
||||
---@diagnostic disable: undefined-field, missing-fields, param-type-mismatch
|
||||
|
||||
local Assert = require("support.assert")
|
||||
local JSON = require("support.json_stub")
|
||||
local pending, request, called
|
||||
package.loaded["json"] = JSON
|
||||
package.loaded["moonsource_jjwxc.protocols"] = { current = function() end }
|
||||
package.loaded["http.request"] = { get = function(url, _opts, cb)
|
||||
pending = cb
|
||||
request = { url = url, cancel = function() request.cancelled = true end }
|
||||
return request
|
||||
end }
|
||||
package.loaded["moonsource_jjwxc.reviews"] = nil
|
||||
local Reviews = require("moonsource_jjwxc.reviews")
|
||||
Assert.eq(Reviews.item({ commentBody = "第一行<br>第二行<BR />第三行" }).content,
|
||||
"第一行\n第二行\n第三行", "转义换行标签不能直接显示")
|
||||
local formatted = Reviews.item({ commentBody = "<p>第一行</p><p><b>第二行</b> [紫糖]</p>" })
|
||||
Assert.eq(formatted.content, "第一行\n第二行 [紫糖]")
|
||||
Assert.is_true(formatted.inline_images["[紫糖]"] ~= nil, "清理标签后保留表情")
|
||||
local emoji_body = " [紫糖][狗头][紫糖][红心]<br>😀[未知表情] "
|
||||
local emoji_item = Reviews.item({ commentId = "emoji", commentBody = emoji_body })
|
||||
Assert.eq(emoji_item.content, "[紫糖][狗头][紫糖][红心]\n😀[未知表情]")
|
||||
Assert.matches(emoji_item.inline_images["[紫糖]"].url, "66baeed24ae82_531%.png$")
|
||||
Assert.eq(emoji_item.inline_images["[狗头]"].url, "https://i9-static.jjwxc.net/tmp/emoji/dog.png")
|
||||
Assert.eq(emoji_item.inline_images["[红心]"].headers.Referer, "https://www.jjwxc.net/")
|
||||
Assert.is_nil(emoji_item.inline_images["[未知表情]"])
|
||||
Assert.len(emoji_item.images, 0, "表情不能变成卡片配图")
|
||||
Assert.is_nil(Reviews.item({ commentBody = "普通评论 😀[未知表情]" }).inline_images)
|
||||
Assert.len(Reviews.hotspots({}), 0)
|
||||
Assert.is_nil(Reviews.hotspots({ message = "错误对象" }))
|
||||
Assert.is_nil(Reviews.hotspots({ { paragraph_id = 1 } }))
|
||||
Reviews.hotspotsAsync("9", "23", function(value, err) called = { value, err } end)
|
||||
pending(JSON.encode({ code = 200, data = { { paragraph_id = 1, comment_total = "bad" } } }))
|
||||
Assert.is_nil(called[1])
|
||||
Assert.eq(called[2], "响应无效")
|
||||
Reviews.pageAsync("9", "23", -2, 20, function(value, err) called = { value, err } end)
|
||||
Assert.matches(request.url, "novelId=9&chapterId=23¶graph_id=%-2&offset=20")
|
||||
pending(JSON.encode({ code = 200, data = { commentTotal = "21", commentList = { { commentId = "7", commentBody = "测试评论" } } } }))
|
||||
Assert.eq(called[1].max_idx, 21)
|
||||
Assert.is_false(called[1].more)
|
||||
Reviews.pageAsync("9", "23", 1, 0, function(value, err) called = { value, err } end)
|
||||
pending(JSON.encode({ code = 200, data = { commentTotal = 0, commentList = {} } }))
|
||||
Assert.len(called[1].items, 0)
|
||||
Assert.is_nil(Reviews.page({ commentTotal = 2, commentList = { "bad" } }, 0))
|
||||
Assert.is_nil(Reviews.page({ commentList = {} }, 0))
|
||||
Assert.is_nil(Reviews.page({ commentTotal = 0, commentList = { error = "bad" } }, 0))
|
||||
Reviews.pageAsync("9", "23", 1, 0, function(value, err) called = { value, err } end)
|
||||
pending(nil, "网络故障")
|
||||
Assert.eq(called[2], "网络故障")
|
||||
|
||||
local hotspots = { { range = "-2", total = 37 }, { range = "6", total = 205 } }
|
||||
package.loaded["book.review_cache"] = {
|
||||
hotspotsAsync = function(_identity, fetch, cb) return fetch(cb) end,
|
||||
pageAsync = function(_identity, _range, _offset, fetch, cb) return fetch(cb) end,
|
||||
}
|
||||
package.loaded["moonsource_jjwxc.reviews"] = {
|
||||
inlineImages = Reviews.inlineImages,
|
||||
hotspotsAsync = function(_novel, uid, cb)
|
||||
Assert.eq(uid, "23")
|
||||
cb(hotspots)
|
||||
return { cancel = function() end }
|
||||
end,
|
||||
pageAsync = function(_novel, uid, range, offset, cb)
|
||||
Assert.eq(uid, "23"); Assert.eq(range, -2); Assert.eq(offset, 0)
|
||||
pending = cb
|
||||
request = { cancel = function() request.cancelled = true end }
|
||||
return request
|
||||
end,
|
||||
}
|
||||
package.loaded["moonsource_jjwxc.source"] = nil
|
||||
local source = require("moonsource_jjwxc.source").new()
|
||||
source.loadTocAsync = function(_self, _identity, cb)
|
||||
cb({ { uid = "23" } })
|
||||
return { cancel = function() error("不应取消已完成目录请求") end }
|
||||
end
|
||||
local identity = { source_id = "ext.jjwxc", stable_id = "9", chapter_idx = 1 }
|
||||
source:paragraphHotspotsAsync(identity, function(value) called = value end)
|
||||
Assert.len(called, 1)
|
||||
Assert.eq(called[1].range, "6")
|
||||
source:chapterReviewHotspotsAsync(identity, function(value) called = value end)
|
||||
Assert.len(called, 1)
|
||||
Assert.eq(called[1].range, "-2")
|
||||
Assert.eq(called[1].anchor, "moon-chapter-reviews")
|
||||
called = nil
|
||||
local handle = source:paragraphReviewPageAsync(identity, "-2", 0, function() called = true end)
|
||||
handle.cancel()
|
||||
Assert.is_true(request.cancelled)
|
||||
pending({})
|
||||
Assert.is_nil(called, "换章取消后不得展示旧评论")
|
||||
|
||||
package.loaded["book.review_cache"].pageAsync = function(_identity, _range, _offset, _fetch, cb)
|
||||
cb({ items = { { content = "旧缓存<br>[紫糖]" } } })
|
||||
return { cancel = function() end }
|
||||
end
|
||||
source:paragraphReviewPageAsync(identity, "-2", 0, function(value) called = value end)
|
||||
Assert.matches(called.items[1].inline_images["[紫糖]"].url, "66baeed24ae82_531%.png$")
|
||||
Assert.eq(called.items[1].content, "旧缓存\n[紫糖]", "修正旧缓存中的标签,不丢弃离线评论")
|
||||
@@ -0,0 +1,83 @@
|
||||
--[[--
|
||||
晋江登录:不静默覆盖旧账号、取消迟到回包、离线立即失败。
|
||||
|
||||
@module tests.moonsource_jjwxc.setting_spec
|
||||
--]]
|
||||
---@diagnostic disable: undefined-field, missing-fields, param-type-mismatch
|
||||
|
||||
local Assert = require("support.assert")
|
||||
local beginLogin = require("source.auth").beginLogin
|
||||
local Themed = require("support.theme_stubs")
|
||||
Themed.install()
|
||||
local cfg, online, pending, cancelled, stored = {}, true, nil, false, 0
|
||||
local cleared = 0
|
||||
package.loaded["source.logout"] = { clear = function(_id, clear)
|
||||
clear(); cleared = cleared + 1; return true
|
||||
end }
|
||||
local cookie_pending, cookie_cancelled, cookie_async
|
||||
package.loaded["utils.settings"] = { getSource = function() return cfg end, saveSource = function() end }
|
||||
package.loaded["source.registry"] = { reload = function() end }
|
||||
package.loaded["source.auth"] = { beginLogin = beginLogin, ok = function() end }
|
||||
package.loaded["ui/network/manager"] = { isConnected = function() return online end }
|
||||
local App = {
|
||||
loginAsync = function(_account, password, _verify, cb)
|
||||
Assert.eq(password, " password ", "密码按原值提交")
|
||||
pending = cb
|
||||
return { cancel = function() cancelled = true end }
|
||||
end,
|
||||
save = function(_account, _password, token) stored = stored + 1; cfg.token = token end,
|
||||
}
|
||||
package.loaded["moonsource_jjwxc.protocols.app"] = App
|
||||
package.loaded["moonsource_jjwxc.protocols"] = { current = function() end, select = function() end }
|
||||
package.loaded["moonsource_jjwxc.protocols.web"] = {
|
||||
favAsync = function(_cookie, cb)
|
||||
if cookie_async then cookie_pending = cb else cb({}) end
|
||||
return { cancel = function() cookie_cancelled = true end }
|
||||
end,
|
||||
}
|
||||
package.loaded["moonsource_jjwxc.setting"] = nil
|
||||
local Setting = require("moonsource_jjwxc.setting")
|
||||
|
||||
Setting.login()
|
||||
Themed.last("input").callback("test", " password ")
|
||||
Themed.last("progress_dialog").on_cancel()
|
||||
Assert.is_true(cancelled)
|
||||
pending("late")
|
||||
Assert.eq(stored, 0)
|
||||
|
||||
Setting.login()
|
||||
Themed.last("input").callback("test", " password ")
|
||||
cfg.token = "newer"
|
||||
pending("older")
|
||||
Assert.eq(stored, 0)
|
||||
Assert.eq(cfg.token, "newer")
|
||||
Assert.eq(Themed.last("toast").text, "账号已变化,请重新登录")
|
||||
|
||||
local result, reason
|
||||
cfg.cookie = "sid=old"
|
||||
Setting.browser.apply({ cookies = { { domain = ".jjwxc.com", name = "sid", value = "new" } } },
|
||||
function(ok, err) result, reason = ok, err end)
|
||||
Assert.is_true(result)
|
||||
Assert.is_nil(reason)
|
||||
Assert.eq(cfg.cookie, "sid=new")
|
||||
Assert.eq(cleared, 1)
|
||||
Assert.is_nil(Themed.last("confirm"))
|
||||
cfg.token = nil
|
||||
Setting.browser.apply({ cookies = { { domain = ".jjwxc.com", name = "sid", value = "new" } } },
|
||||
function(ok) result = ok end)
|
||||
Assert.is_true(result, "同一 Cookie 重新校验不清库")
|
||||
|
||||
cfg, cookie_async, result = {}, true, nil
|
||||
local cookie_job = Setting.browser.apply({ cookies = { { domain = ".jjwxc.com", name = "sid", value = "new" } } },
|
||||
function(ok) result = ok end)
|
||||
cookie_job.cancel()
|
||||
Assert.is_true(cookie_cancelled, "关闭登录必须取消校验请求")
|
||||
cookie_pending({})
|
||||
Assert.is_nil(cfg.cookie)
|
||||
Assert.is_nil(result)
|
||||
|
||||
cfg, online, pending = {}, false, nil
|
||||
Setting.login()
|
||||
Themed.last("input").callback("test", " password ")
|
||||
Assert.is_nil(pending)
|
||||
Assert.eq(Themed.last("toast").text, "未联网")
|
||||
Reference in new issue
Block a user