docs(gateway): gateway 剩余文件注释改中文(逐行 1:1,代码零字节改动)
主人 2026-10-03 拍板「注释一律中文」;gateway 至此整包注释中文化完成(本会话共 3 批: 已推库 16 个文件 + 本批剩余文件)。 校验:机械校验(非注释改动行)= 空;剥注释后代码文本逐行比对全等(不一致文件数 0); 全树 go test ./... 58 包 ok / 0 FAIL;交叉编译绿。
This commit is contained in:
1 parent
91e8d7a029
commit
074ffc4ebf
73 files changed
+2529
-2529
No files matched your search
@@ -17,9 +17,9 @@ import (
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/db"
|
||||
)
|
||||
|
||||
// newRefreshEnv builds a gateway backed by a real JWT service and a real
|
||||
// SQLite-backed refresh store, returning the store and DB so a test can assert
|
||||
// what was persisted. The DB is isolated in memory per test.
|
||||
// newRefreshEnv 构建一个网关,后端是真实 JWT 服务与真实的
|
||||
// SQLite refresh 存储,并返回该存储与 DB,使测试能断言
|
||||
// 持久化了什么。DB 每个测试都隔离在内存中。
|
||||
func newRefreshEnv(t *testing.T) (*testEnv, *auth.RefreshStore, *sql.DB) {
|
||||
t.Helper()
|
||||
ctx := context.Background()
|
||||
@@ -52,7 +52,7 @@ func newRefreshEnv(t *testing.T) (*testEnv, *auth.RefreshStore, *sql.DB) {
|
||||
return &testEnv{srv: srv, ts: ts, auth: jwt, bus: b}, refresh, sqlDB
|
||||
}
|
||||
|
||||
// decodeData unmarshals the {data: ...} envelope payload into v.
|
||||
// decodeData 把 {data: ...} 信封载荷反序列化进 v。
|
||||
func decodeData(t *testing.T, body []byte, v any) {
|
||||
t.Helper()
|
||||
env := decodeBody(t, body)
|
||||
@@ -65,7 +65,7 @@ func decodeData(t *testing.T, body []byte, v any) {
|
||||
}
|
||||
}
|
||||
|
||||
// loginRefresh performs an admin login and returns the access and refresh tokens.
|
||||
// loginRefresh 执行一次管理登录并返回访问令牌与 refresh token。
|
||||
func loginRefresh(t *testing.T, ts *httptest.Server) (string, string) {
|
||||
t.Helper()
|
||||
resp, body := doReq(t, http.MethodPost, ts.URL+"/api/v1/auth/login",
|
||||
@@ -89,7 +89,7 @@ func loginRefresh(t *testing.T, ts *httptest.Server) (string, string) {
|
||||
return data.Token, data.RefreshToken
|
||||
}
|
||||
|
||||
// postRefresh calls /auth/refresh with token and returns the status and body.
|
||||
// postRefresh 用 token 调用 /auth/refresh 并返回状态与响应体。
|
||||
func postRefresh(t *testing.T, ts *httptest.Server, token string) (int, []byte) {
|
||||
t.Helper()
|
||||
resp, body := doReq(t, http.MethodPost, ts.URL+"/api/v1/auth/refresh",
|
||||
@@ -97,7 +97,7 @@ func postRefresh(t *testing.T, ts *httptest.Server, token string) (int, []byte)
|
||||
return resp.StatusCode, body
|
||||
}
|
||||
|
||||
// wantInvalidGrant asserts a 401 with the machine-readable invalid_grant code.
|
||||
// wantInvalidGrant 断言 401 与机器可读的 invalid_grant 码。
|
||||
func wantInvalidGrant(t *testing.T, status int, body []byte) {
|
||||
t.Helper()
|
||||
if status != http.StatusUnauthorized {
|
||||
@@ -165,11 +165,11 @@ func TestRefreshRotatesAccessAndRefreshTokens(t *testing.T) {
|
||||
t.Fatalf("refreshed claims = %+v, want admin/owner", claims)
|
||||
}
|
||||
|
||||
// The presented token is single-use: replay must fail.
|
||||
// 出示的 token 是一次性的:重放必须失败。
|
||||
status, body = postRefresh(t, env.ts, oldRefresh)
|
||||
wantInvalidGrant(t, status, body)
|
||||
|
||||
// The rotated token works.
|
||||
// 轮换后的 token 有效。
|
||||
if status, body = postRefresh(t, env.ts, data.RefreshToken); status != http.StatusOK {
|
||||
t.Fatalf("rotate replacement status = %d, want 200: %s", status, body)
|
||||
}
|
||||
@@ -229,7 +229,7 @@ func TestLogoutRevokesRefreshToken(t *testing.T) {
|
||||
t.Fatalf("refresh after logout status = %d, want 401: %s", status, body)
|
||||
}
|
||||
|
||||
// Logout is idempotent: a second call reports revoked=false, not an error.
|
||||
// 登出是幂等的:第二次调用报告 revoked=false,而不是错误。
|
||||
resp, body = doReq(t, http.MethodPost, env.ts.URL+"/api/v1/auth/logout",
|
||||
map[string]string{"refreshToken": refreshToken}, "")
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
|
||||
Reference in new issue
Block a user