test: tighten gateway auth path assertions · openclaw/openclaw@7a6dbff
steipete
·
2026-05-11
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -108,16 +108,16 @@ describe("authorizeGatewayHttpRequestOrReply", () => {
|
108 | 108 | trustedProxies: ["127.0.0.1"], |
109 | 109 | }); |
110 | 110 | |
111 | | -expect(vi.mocked(authorizeHttpGatewayConnect)).toHaveBeenCalledWith( |
112 | | - expect.objectContaining({ |
113 | | - browserOriginPolicy: { |
114 | | - requestHost: "gateway.example.com", |
115 | | - origin: "https://evil.example", |
116 | | - allowedOrigins: ["https://control.example.com"], |
117 | | - allowHostHeaderOriginFallback: false, |
118 | | - }, |
119 | | -}), |
120 | | -); |
| 111 | +const [authParams] = vi.mocked(authorizeHttpGatewayConnect).mock.calls.at(-1) ?? []; |
| 112 | +if (authParams === undefined) { |
| 113 | +throw new Error("Expected HTTP gateway auth to be called"); |
| 114 | +} |
| 115 | +expect(authParams.browserOriginPolicy).toEqual({ |
| 116 | +requestHost: "gateway.example.com", |
| 117 | +origin: "https://evil.example", |
| 118 | +allowedOrigins: ["https://control.example.com"], |
| 119 | +allowHostHeaderOriginFallback: false, |
| 120 | +}); |
121 | 121 | }); |
122 | 122 | |
123 | 123 | it("replies with auth failure and returns null when auth fails", async () => { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -17,16 +17,14 @@ function buildRepeatedEncodedSlashPath(depth: number): string {
|
17 | 17 | |
18 | 18 | describe("security-path canonicalization", () => { |
19 | 19 | it("canonicalizes decoded case/slash variants", () => { |
20 | | -expect(canonicalizePathForSecurity("/API/channels//nostr/default/profile/")).toEqual( |
21 | | -expect.objectContaining({ |
22 | | -canonicalPath: "/api/channels/nostr/default/profile", |
23 | | -candidates: ["/api/channels/nostr/default/profile"], |
24 | | -malformedEncoding: false, |
25 | | -decodePasses: 0, |
26 | | -decodePassLimitReached: false, |
27 | | -rawNormalizedPath: "/api/channels/nostr/default/profile", |
28 | | -}), |
29 | | -); |
| 20 | +expect(canonicalizePathForSecurity("/API/channels//nostr/default/profile/")).toEqual({ |
| 21 | +canonicalPath: "/api/channels/nostr/default/profile", |
| 22 | +candidates: ["/api/channels/nostr/default/profile"], |
| 23 | +malformedEncoding: false, |
| 24 | +decodePasses: 0, |
| 25 | +decodePassLimitReached: false, |
| 26 | +rawNormalizedPath: "/api/channels/nostr/default/profile", |
| 27 | +}); |
30 | 28 | const encoded = canonicalizePathForSecurity("/api/%63hannels%2Fnostr%2Fdefault%2Fprofile"); |
31 | 29 | expect(encoded.canonicalPath).toBe("/api/channels/nostr/default/profile"); |
32 | 30 | expect(encoded.candidates).toContain("/api/%63hannels%2fnostr%2fdefault%2fprofile"); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。