'
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("请登录"))
end
do
local html = ' 【言情排行】
'
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 = " 沈玄宁讪讪一笑,道:“我是路过的。”
'
Assert.eq(require("moonsource_jjwxc.vip").content(odd), body)
local odd_old = '
'
.. ''
.. ''
.. '
'
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 = '
]]),
"甲缝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, "
第一章
\n
甲
\n
乙〇
")
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 = "好&看 真的", 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 = "甲 乙"
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