如何使用 KIWI-tcms api 注销

问题描述

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

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

我可以这样登录

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

这将返回一个会话 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"}';

我希望在我注销后,会话 ID 将不再起作用,但我仍然可以使用它来访问 Kiwi-tcms 中的数据

解决方法

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

我希望在我注销后,会话 ID 将不再起作用,但我仍然可以使用它来访问 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