如何使用 KIWI-tcms 注销 api

How to log out using KIWI-tcms api

我使用 CURL 的目的是使这个示例尽可能简单。我没有在 CURL 中实现最终版本,但我能够将 curl 示例转换为最终形式。

我使用的是 api 的 jsonrpc 版本。实际凭据和 URL 替换为虚假信息

我可以这样登录:

curl 'http://kiwi.example.com/json-rpc/' \
  -H 'Content-Type: application/json' \
  --data-binary '{"jsonrpc":"2.0","method":"Auth.login", "params":{"username":"me@example.com", "password" : "PASSWORD"}, "id":"jsonrpc"}';

这个 returns 一个会话 ID,出于这些目的,假定它是下面使用的“123456789abcdefghijklmnopqrstyvw”

然后我可以使用该会话 ID 执行以下操作:(只是任意 API 调用)

curl 'http://kiwi.example.com/json-rpc/' \
  -H 'Content-Type: application/json' \
  -H 'Cookie: sessionid=123456789abcdefghijklmnopqrstyvw' \
  --data-binary '{"jsonrpc":"2.0","method":"TestPlan.filter", "params":[{"is_active":true}],"id":"jsonrpc"}';

那为什么这行不通呢?或者,如果您愿意,我应该怎样做才能注销?

curl 'http://kiwi.example.com/json-rpc/' \
  -H 'Content-Type: application/json' \
  -H 'Cookie: sessionid=123456789abcdefghijklmnopqrstyvw' \
 --data-binary '{"jsonrpc":"2.0","method":"Auth.logout",  "id":"jsonrpc"}';

我预计在我注销后,session id 将不再起作用,但我仍然可以使用它来访问 Kiwi-tcms 中的数据

Auth.logout() 调用 django.contrib.auth.logout(request),后者又调用 request.session.flush()

I expect that after I log out, the session id wouldn't work anymore, but I can still use it to access the data in Kiwi-tcms

事实上,这就是发生在我身上的事情:

$ curl 'http://127.0.0.1:8000/json-rpc/' \
     -H 'Content-Type: application/json' \
     -H 'Cookie: sessionid=xyz' \
     --data-binary '{"jsonrpc":"2.0","method":"TestPlan.filter", "params":{"is_active":true}],"id":"jsonrpc"}';

{"id": "jsonrpc", "jsonrpc": "2.0", "error": {"code": -32603, "message": "Internal error: Authentication failed when calling \"TestPlan.filter\""}}

您可能使用的是旧版本的 Kiwi TCMS,它无法正确检查 API 凭据:https://kiwitcms.readthedocs.io/en/latest/changelog.html#kiwi-tcms-8-6-23-aug-2020 <-- 这也是一个安全漏洞,因此请立即升级。