✨ 迁移到现行 Web 协议:签名请求、浏览器登录与分类书城
GetImageIndex / ImageToken 等接口走 ultra_sign 签名并解 bytesData; 登录改为浏览器授权或完整 Cookie,校验通过才保存。
This commit is contained in:
1 parent
430962a5d0
commit
455891353c
8 files changed
+1012
-143
No files matched your search
@@ -0,0 +1,74 @@
|
||||
--[[--
|
||||
哔哩漫画账号校验,以及已解锁话不被本机标成未购买。
|
||||
|
||||
@module tests.moonsource_bilimanga.account_spec
|
||||
--]]
|
||||
|
||||
local Assert = require("support.assert")
|
||||
local Stubs = require("support.stubs")
|
||||
local Json = require("support.json_stub")
|
||||
|
||||
local Mapper = require("moonsource_bilimanga.mapper")
|
||||
local chapters = Mapper.chapters({ ep_list = {
|
||||
{ id = 1, title = "已解锁", is_locked = false, pay_type = 1, is_pay = true },
|
||||
{ id = 2, title = "未解锁", is_locked = true, pay_type = 0 },
|
||||
} })
|
||||
Assert.eq(chapters[1].vip, false)
|
||||
Assert.eq(chapters[2].vip, true)
|
||||
|
||||
local fetched = false
|
||||
package.loaded["moonsource_bilimanga.client"] = {
|
||||
imageIndexAsync = function() fetched = true end,
|
||||
}
|
||||
local Chapter = require("moonsource_bilimanga.chapter")
|
||||
local reason
|
||||
Chapter.materializeAsync(
|
||||
{ source_id = "bilimanga", stable_id = "1" },
|
||||
{ uid = "9", vip = true },
|
||||
nil,
|
||||
function(_path, err) reason = err end)
|
||||
Stubs.flush()
|
||||
Assert.eq(reason, "本章未购买")
|
||||
Assert.is_false(fetched)
|
||||
|
||||
package.loaded["moonsource_bilimanga.client"] = nil
|
||||
package.loaded["moonsource_bilimanga.chapter"] = nil
|
||||
package.loaded["json"] = { encode = Json.encode, decode = Json.decode }
|
||||
|
||||
local sent
|
||||
local reply
|
||||
package.loaded["http.request"] = {
|
||||
ok = function(code) return code and code >= 200 and code < 300 end,
|
||||
request = function(opts, cb)
|
||||
sent = opts
|
||||
local job = { cancel = function() reply = nil end }
|
||||
if reply then cb(reply.body, reply.err) end
|
||||
return job
|
||||
end,
|
||||
}
|
||||
local Client = require("moonsource_bilimanga.client")
|
||||
|
||||
local function check(body)
|
||||
reply = { body = { code = 200, body = body } }
|
||||
local ok, err, account
|
||||
Client.loginCheckAsync("SESSDATA=fixture", function(a, b, c)
|
||||
ok, err, account = a, b, c
|
||||
end)
|
||||
return ok, err, account
|
||||
end
|
||||
|
||||
local ok, err = check(Json.encode({ code = -101, data = { isLogin = false } }))
|
||||
Assert.eq(ok, false)
|
||||
Assert.eq(err, "登录校验失败,请确认已经登录哔哩哔哩")
|
||||
Assert.eq(sent.headers.Cookie, "SESSDATA=fixture")
|
||||
Assert.eq(sent.url, "https://api.bilibili.com/x/web-interface/nav")
|
||||
|
||||
ok, err, account = check(Json.encode({ code = 0, data = { isLogin = true, mid = 42 } }))
|
||||
Assert.eq(ok, true)
|
||||
Assert.is_nil(err)
|
||||
Assert.eq(account.id, "42")
|
||||
|
||||
local empty_ok, empty_err
|
||||
Client.loginCheckAsync("", function(a, b) empty_ok, empty_err = a, b end)
|
||||
Assert.eq(empty_ok, false)
|
||||
Assert.eq(empty_err, "没有读到 Cookie")
|
||||
Reference in new issue
Block a user