-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.test.ts
More file actions
254 lines (212 loc) · 8.71 KB
/
Copy pathproxy.test.ts
File metadata and controls
254 lines (212 loc) · 8.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
import { describe, expect, it } from "vitest";
import { NextRequest } from "next/server";
import { proxy } from "../proxy";
describe("proxy", () => {
it("does not hard-code private hosts for HTTPS redirects", async () => {
const response = await proxy(
new NextRequest("http://app.memroos.test/login", {
headers: { host: "app.memroos.test" },
})
);
expect(response.status).toBe(200);
expect(response.headers.get("location")).toBeNull();
});
it("redirects the production app host from HTTP to HTTPS", async () => {
process.env.MEMROOS_HTTPS_APP_HOSTS = "app.memroos.test";
const response = await proxy(
new NextRequest("http://app.memroos.test/login", {
headers: { host: "app.memroos.test" },
})
);
expect(response.status).toBe(307);
expect(response.headers.get("location")).toBe("https://app.memroos.test/login");
delete process.env.MEMROOS_HTTPS_APP_HOSTS;
});
it("lets agent-authenticated API routes handle their own authorization", async () => {
const response = await proxy(
new NextRequest("http://localhost:3002/api/memory/add", {
method: "POST",
headers: { host: "localhost:3002", authorization: "Bearer agent-key" },
})
);
expect(response.status).toBe(200);
expect(await response.text()).toBe("");
});
it("lets operator-key API routes handle their own authorization", async () => {
const response = await proxy(
new NextRequest("http://localhost:3002/api/agents/register", {
method: "POST",
headers: { host: "localhost:3002", "x-memroos-operator-key": "operator-key" },
})
);
expect(response.status).toBe(200);
expect(await response.text()).toBe("");
});
it("lets SkillForge routes handle their own local/operator authorization", async () => {
const response = await proxy(
new NextRequest("http://localhost:3002/api/skillforge/status", {
method: "GET",
headers: { host: "localhost:3002", "x-memroos-operator-key": "operator-key" },
})
);
expect(response.status).toBe(200);
expect(await response.text()).toBe("");
});
it("lets agent-memory continuity routes handle their own local/operator authorization", async () => {
const response = await proxy(
new NextRequest("http://localhost:3002/api/agent-memory/capture", {
method: "POST",
headers: { host: "localhost:3002", "x-memroos-operator-key": "operator-key" },
})
);
expect(response.status).toBe(200);
expect(await response.text()).toBe("");
});
it("lets agent-context bus routes handle their own agent-key authorization", async () => {
const response = await proxy(
new NextRequest("http://localhost:3002/api/agent-context/messages", {
method: "POST",
headers: { host: "localhost:3002", authorization: "Bearer agent-key" },
})
);
expect(response.status).toBe(200);
expect(await response.text()).toBe("");
});
it("lets ChatGPT Action routes handle their own API key authorization", async () => {
const response = await proxy(
new NextRequest("https://app.memroos.test/api/chatgpt/actions/search", {
method: "POST",
headers: { host: "app.memroos.test", "x-api-key": "action-key" },
})
);
expect(response.status).toBe(200);
expect(await response.text()).toBe("");
});
it("serves research PDFs on the public marketing host", async () => {
const response = await proxy(
new NextRequest("https://memroos.com/research/memroos-governed-knowledge-architecture-paper.pdf", {
headers: { host: "memroos.com" },
})
);
expect(response.status).toBe(200);
expect(response.headers.get("location")).toBeNull();
});
it("serves public screenshot assets on the marketing host", async () => {
const response = await proxy(
new NextRequest("https://memroos.com/screenshots/memroos-floor.png", {
headers: { host: "memroos.com" },
})
);
expect(response.status).toBe(200);
expect(response.headers.get("location")).toBeNull();
});
it("serves extracted landing assets on the marketing host", async () => {
const response = await proxy(
new NextRequest("https://memroos.com/landing/assets/shots/operator-floor.png", {
headers: { host: "memroos.com" },
})
);
expect(response.status).toBe(200);
expect(response.headers.get("location")).toBeNull();
});
it("serves the SVG app icon on the marketing host", async () => {
const response = await proxy(
new NextRequest("https://memroos.com/icon.svg", {
headers: { host: "memroos.com" },
})
);
expect(response.status).toBe(200);
expect(response.headers.get("location")).toBeNull();
});
it("serves the unlinked Understand graph page on the marketing host with noindex headers", async () => {
const response = await proxy(
new NextRequest("https://memroos.com/understand?token=graph-token", {
headers: { host: "memroos.com" },
})
);
expect(response.status).toBe(200);
expect(response.headers.get("location")).toBeNull();
expect(response.headers.get("x-robots-tag")).toContain("noindex");
});
it("serves Understand dashboard static assets with same-origin frame protection", async () => {
const response = await proxy(
new NextRequest("https://memroos.com/understand-static/index.html?token=graph-token", {
headers: { host: "memroos.com" },
})
);
expect(response.status).toBe(200);
expect(response.headers.get("location")).toBeNull();
expect(response.headers.get("x-robots-tag")).toContain("noindex");
expect(response.headers.get("x-frame-options")).toBe("SAMEORIGIN");
expect(response.headers.get("content-security-policy")).toContain("frame-ancestors 'self'");
});
it("lets the Understand graph JSON route handle token authorization on the marketing host", async () => {
const response = await proxy(
new NextRequest("https://memroos.com/knowledge-graph.json?token=graph-token", {
headers: { host: "memroos.com" },
})
);
expect(response.status).toBe(200);
expect(response.headers.get("location")).toBeNull();
expect(response.headers.get("x-robots-tag")).toContain("noindex");
});
it("requires app-host session auth for the Understand page", async () => {
const response = await proxy(
new NextRequest("https://memroos.example.com/understand?token=graph-token", {
headers: { host: "memroos.example.com" },
})
);
expect(response.status).toBe(307);
expect(response.headers.get("location")).toBe("https://memroos.example.com/login");
});
it("requires app-host session auth before Understand JSON token authorization", async () => {
const response = await proxy(
new NextRequest("https://memroos.example.com/knowledge-graph.json?token=graph-token", {
headers: { host: "memroos.example.com" },
})
);
expect(response.status).toBe(307);
expect(response.headers.get("location")).toBe("https://memroos.example.com/login");
});
it("treats a custom domain as an app host", async () => {
const loginResponse = await proxy(
new NextRequest("https://memroos.example.com/login", {
headers: { host: "memroos.example.com" },
})
);
expect(loginResponse.status).toBe(200);
expect(loginResponse.headers.get("location")).toBeNull();
const appResponse = await proxy(
new NextRequest("https://memroos.example.com/dispatch", {
headers: { host: "memroos.example.com" },
})
);
expect(appResponse.status).toBe(307);
expect(appResponse.headers.get("location")).toBe("https://memroos.example.com/login");
});
it("serves the public landing on memroos.localhost for local preview", async () => {
const response = await proxy(
new NextRequest("http://memroos.localhost:3003/", {
headers: { host: "memroos.localhost:3003" },
})
);
expect(response.status).toBe(200);
expect(response.headers.get("location")).toBeNull();
expect(response.headers.get("x-middleware-rewrite")).toBe(
"http://memroos.localhost:3003/landing/index.html"
);
});
it("allows analytics and Google Fonts endpoints in the content security policy", async () => {
const response = await proxy(
new NextRequest("https://memroos.com/", {
headers: { host: "memroos.com" },
})
);
const csp = response.headers.get("Content-Security-Policy");
expect(csp).toContain("https://www.googletagmanager.com");
expect(csp).toContain("https://www.google-analytics.com");
expect(csp).toContain("https://region1.google-analytics.com");
expect(csp).toContain("https://fonts.googleapis.com");
expect(csp).toContain("https://fonts.gstatic.com");
});
});