-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_external_results_artifact.py
More file actions
646 lines (520 loc) · 24.7 KB
/
Copy pathtest_external_results_artifact.py
File metadata and controls
646 lines (520 loc) · 24.7 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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
"""Tests for the artifact upload endpoint (BGSTM#298).
Covers:
- Happy path (201, DB record, audit log, file written to local backend)
- Oversized file → 413, partial write detected, temp file cleaned up
- Bad content-type → 415
- Unknown kind → 422
- Missing case_result_id (FK violation, case not found) → 404
- Bad UUID for case_result_id → 422
- S3 stub raises NotImplementedError
"""
from __future__ import annotations
import io
import os
import tempfile
import uuid
import pytest
import pytest_asyncio
from fastapi.testclient import TestClient
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
import app.api.external_results as _api_module
from app.config import settings
from app.crud.runner_token import create_runner_token
from app.db.session import get_db
from app.main import app
from app.models.audit_log import AuditLog
from app.models.base import Base
from app.models.external_case_artifact import ExternalCaseArtifact
from app.models.project import Project
from app.models.user import User, UserRole
from app.storage.s3 import S3Backend
# ---------------------------------------------------------------------------
# Helpers
# ---------------------------------------------------------------------------
_PROJECT_ID = str(uuid.uuid4())
def _auth_header(plaintext: str) -> dict[str, str]:
return {"Authorization": f"Bearer {plaintext}"}
def _make_user(role: UserRole = UserRole.admin) -> User:
return User(
id=uuid.uuid4(),
email=f"{role.value}-{uuid.uuid4().hex[:6]}@example.com",
hashed_password="hashed",
full_name=f"{role.value.capitalize()} User",
role=role,
is_active=True,
)
# ---------------------------------------------------------------------------
# Fixtures
# ---------------------------------------------------------------------------
@pytest_asyncio.fixture
async def db_session():
engine = create_async_engine("sqlite+aiosqlite:///:memory:", echo=False)
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
factory = async_sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)
async with factory() as session:
project = Project(id=uuid.UUID(_PROJECT_ID), name=f"project-{uuid.uuid4().hex[:6]}")
session.add(project)
await session.commit()
async def _override_get_db():
yield session
app.dependency_overrides[get_db] = _override_get_db
yield session
app.dependency_overrides.clear()
await engine.dispose()
@pytest_asyncio.fixture
async def admin_user(db_session):
admin = _make_user(UserRole.admin)
db_session.add(admin)
await db_session.commit()
return admin
@pytest_asyncio.fixture
async def write_token(db_session, admin_user):
return await create_runner_token(
db_session,
label="write-token",
scopes=["external_results:write"],
created_by_user_id=admin_user.id,
)
def _session_payload() -> dict:
return {
"runner": "pytest-bgstm@1.0.0",
"project_id": _PROJECT_ID,
"git_sha": "abc123",
"git_branch": "main",
"ci_url": f"https://ci.example.com/runs/{uuid.uuid4()}",
"metadata": {},
}
def _create_session(client: TestClient, plaintext: str) -> str:
resp = client.post(
"/api/v1/external-results/session",
json=_session_payload(),
headers=_auth_header(plaintext),
)
assert resp.status_code == 201, resp.text
return resp.json()["id"]
def _create_case_result(client: TestClient, plaintext: str, session_id: str) -> str:
resp = client.post(
"/api/v1/external-results/case",
json={
"session_id": session_id,
"external_id": f"ext-{uuid.uuid4()}",
"title": "test case",
"outcome": "passed",
"duration_ms": 10,
},
headers=_auth_header(plaintext),
)
assert resp.status_code == 201, resp.text
return resp.json()["id"]
# ---------------------------------------------------------------------------
# Happy path
# ---------------------------------------------------------------------------
class TestHappyPath:
@pytest.mark.asyncio
async def test_upload_screenshot_returns_201(self, db_session, write_token, tmp_path, monkeypatch):
"""201 Created with full response body; DB record + audit log written."""
_token_model, plaintext = write_token
# Point local backend at a temp directory
monkeypatch.setattr(settings, "BGSTM_ARTIFACTS_DIR", str(tmp_path))
monkeypatch.setattr(settings, "BGSTM_ARTIFACT_URL_PREFIX", "http://testserver/artifacts")
monkeypatch.setattr(settings, "BGSTM_STORAGE_BACKEND", "local")
file_data = b"\x89PNG\r\n" + b"A" * 100
with TestClient(app) as client:
session_id = _create_session(client, plaintext)
case_result_id = _create_case_result(client, plaintext, session_id)
resp = client.post(
"/api/v1/external-results/artifact",
data={
"case_result_id": case_result_id,
"kind": "screenshot",
"filename": "failure-state.png",
},
files={"file": ("failure-state.png", io.BytesIO(file_data), "image/png")},
headers=_auth_header(plaintext),
)
assert resp.status_code == 201, resp.text
body = resp.json()
# Response fields
assert body["case_result_id"] == case_result_id
assert body["kind"] == "screenshot"
assert body["filename"] == "failure-state.png"
assert body["content_type"] == "image/png"
assert body["size_bytes"] == len(file_data)
assert "testserver/artifacts" in body["url"]
assert uuid.UUID(body["id"]) # valid UUID
# File on disk
artifact_row = await db_session.execute(
select(ExternalCaseArtifact).where(ExternalCaseArtifact.id == uuid.UUID(body["id"]))
)
artifact = artifact_row.scalar_one()
assert artifact.size_bytes == len(file_data)
stored_file = tmp_path / artifact.storage_key
assert stored_file.exists()
assert stored_file.read_bytes() == file_data
# Audit log — all five required fields
audit_rows = await db_session.execute(
select(AuditLog).where(AuditLog.action == "external_results.artifact.upload")
)
audit = audit_rows.scalar_one()
assert audit.details["case_result_id"] == case_result_id
assert audit.details["kind"] == "screenshot"
assert audit.details["size_bytes"] == len(file_data)
assert audit.details["filename"] == "failure-state.png"
assert audit.details["content_type"] == "image/png"
# ---------------------------------------------------------------------------
# Size enforcement (413 + cleanup + partial-write assertion)
# ---------------------------------------------------------------------------
class TestSizeEnforcement:
@pytest.mark.asyncio
async def test_oversized_file_returns_413_and_cleans_up(self, db_session, write_token, tmp_path, monkeypatch):
"""413 on oversized upload; streaming abort is now the actual behavior.
The handler uses streaming-form-data to parse the multipart body and raises
_SizeLimitExceeded mid-stream as soon as cumulative bytes exceed
BGSTM_ARTIFACT_MAX_BYTES — bytes past the limit are never read from the
connection.
This test exercises the cleanup / DB-row / artifact-dir guarantees post-abort:
- The handler's own temp file (bgstm_artifact_*) is cleaned up on 413.
- No artifact row is written to the DB.
- No file is left in the artifacts directory.
"""
_token_model, plaintext = write_token
monkeypatch.setattr(settings, "BGSTM_ARTIFACTS_DIR", str(tmp_path))
monkeypatch.setattr(settings, "BGSTM_ARTIFACT_URL_PREFIX", "http://testserver/artifacts")
monkeypatch.setattr(settings, "BGSTM_STORAGE_BACKEND", "local")
monkeypatch.setattr(settings, "BGSTM_ARTIFACT_MAX_BYTES", 10)
# Small chunk size so we process the 20-byte file in multiple iterations
monkeypatch.setattr(_api_module, "_ARTIFACT_CHUNK_SIZE", 8)
# Track temp files created to verify cleanup
created_temps: list[str] = []
real_mkstemp = tempfile.mkstemp
def _fake_mkstemp(*args, **kwargs):
fd, path = real_mkstemp(*args, **kwargs)
created_temps.append(path)
return fd, path
monkeypatch.setattr("tempfile.mkstemp", _fake_mkstemp)
file_data = b"X" * 20 # 20 bytes > max_bytes=10
with TestClient(app) as client:
session_id = _create_session(client, plaintext)
case_result_id = _create_case_result(client, plaintext, session_id)
resp = client.post(
"/api/v1/external-results/artifact",
data={
"case_result_id": case_result_id,
"kind": "screenshot",
"filename": "big.png",
},
files={"file": ("big.png", io.BytesIO(file_data), "image/png")},
headers=_auth_header(plaintext),
)
assert resp.status_code == 413, resp.text
assert resp.json()["detail"]["code"] == "artifact.too_large"
# Temp file must be cleaned up after 413
for path in created_temps:
assert not os.path.exists(path), f"Temp file {path!r} was not cleaned up after 413"
# No artifact row in DB
artifact_rows = await db_session.execute(select(ExternalCaseArtifact))
assert artifact_rows.scalars().all() == []
# No file in artifacts dir
artifact_files = list(tmp_path.rglob("*"))
assert artifact_files == [], f"Unexpected files in artifacts dir: {artifact_files}"
@pytest.mark.asyncio
async def test_oversized_upload_aborts_stream_without_reading_full_body(
self, db_session, write_token, tmp_path, monkeypatch
):
"""Verify that bytes past BGSTM_ARTIFACT_MAX_BYTES are NEVER read from the
request stream. This is the load-bearing test for #320 — it fails against
the old buffer-then-reject implementation and passes only when streaming
abort is correctly wired.
"""
_token_model, plaintext = write_token
monkeypatch.setattr(settings, "BGSTM_ARTIFACT_MAX_BYTES", 1024)
monkeypatch.setattr(settings, "BGSTM_ARTIFACTS_DIR", str(tmp_path))
monkeypatch.setattr(settings, "BGSTM_ARTIFACT_URL_PREFIX", "http://testserver/artifacts")
monkeypatch.setattr(settings, "BGSTM_STORAGE_BACKEND", "local")
with TestClient(app) as sync_client:
session_id = _create_session(sync_client, plaintext)
case_result_id = _create_case_result(sync_client, plaintext, session_id)
# Build a multipart body: small text fields + 100 KiB file (100x the 1024 limit).
LIMIT = 1024
FILE_SIZE = 100 * LIMIT # 100 KiB — well past the limit
boundary = b"bgstmtestboundary"
file_data = b"X" * FILE_SIZE
def _field_part(name: str, value: str) -> bytes:
return (
b"--"
+ boundary
+ b"\r\n"
+ b'Content-Disposition: form-data; name="'
+ name.encode()
+ b'"\r\n'
+ b"\r\n"
+ value.encode()
+ b"\r\n"
)
full_body = (
_field_part("case_result_id", case_result_id)
+ _field_part("kind", "screenshot")
+ _field_part("filename", "big.png")
+ b"--"
+ boundary
+ b"\r\n"
+ b'Content-Disposition: form-data; name="file"; filename="big.png"\r\n'
+ b"Content-Type: image/png\r\n"
+ b"\r\n"
+ file_data
+ b"\r\n"
+ b"--"
+ boundary
+ b"--\r\n"
)
body_size = len(full_body)
# Track how many bytes our generator has yielded — each yield corresponds
# to one receive() call from the ASGI server (via ASGITransport).
bytes_yielded = 0
CHUNK_SIZE = 4096
async def streaming_body():
nonlocal bytes_yielded
for i in range(0, len(full_body), CHUNK_SIZE):
chunk = full_body[i : i + CHUNK_SIZE]
bytes_yielded += len(chunk)
yield chunk
from httpx import ASGITransport, AsyncClient
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://testserver") as client:
resp = await client.post(
"/api/v1/external-results/artifact",
content=streaming_body(),
headers={
"Authorization": f"Bearer {plaintext}",
"Content-Type": f"multipart/form-data; boundary={boundary.decode()}",
},
)
assert resp.status_code == 413, resp.text
assert resp.json()["detail"]["code"] == "artifact.too_large"
# The server must have stopped reading well before the full body was sent.
# Allow generous slack (limit + 256 KiB for framing + chunks), but assert
# well below total body size (100 KiB file ≫ slack).
assert bytes_yielded < body_size // 2, (
f"Server read {bytes_yielded} of {body_size} body bytes — "
"streaming abort is not actually aborting; bytes past the limit are still being read."
)
# ---------------------------------------------------------------------------
# Malformed multipart body (422 + code=validation_error)
# ---------------------------------------------------------------------------
class TestMalformedMultipart:
@pytest.mark.asyncio
async def test_malformed_multipart_returns_422(self, db_session, write_token, tmp_path, monkeypatch):
"""Posting a body that is not valid multipart must return 422 with
code=validation_error, never 500.
"""
_token_model, plaintext = write_token
monkeypatch.setattr(settings, "BGSTM_ARTIFACTS_DIR", str(tmp_path))
monkeypatch.setattr(settings, "BGSTM_STORAGE_BACKEND", "local")
from httpx import ASGITransport, AsyncClient
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://testserver") as client:
resp = await client.post(
"/api/v1/external-results/artifact",
content=b"this is not multipart data at all \x00\x01\x02",
headers={
"Authorization": f"Bearer {plaintext}",
# Valid multipart content-type but body is garbage
"Content-Type": "multipart/form-data; boundary=correctboundary",
},
)
assert resp.status_code == 422, resp.text
assert resp.json()["detail"]["code"] == "validation_error"
class TestContentTypeEnforcement:
@pytest.mark.asyncio
async def test_disallowed_content_type_returns_415(self, db_session, write_token, tmp_path, monkeypatch):
_token_model, plaintext = write_token
monkeypatch.setattr(settings, "BGSTM_ARTIFACTS_DIR", str(tmp_path))
monkeypatch.setattr(settings, "BGSTM_STORAGE_BACKEND", "local")
with TestClient(app) as client:
session_id = _create_session(client, plaintext)
case_result_id = _create_case_result(client, plaintext, session_id)
resp = client.post(
"/api/v1/external-results/artifact",
data={
"case_result_id": case_result_id,
"kind": "screenshot",
"filename": "attack.exe",
},
files={"file": ("attack.exe", io.BytesIO(b"MZ\x00"), "application/x-msdownload")},
headers=_auth_header(plaintext),
)
assert resp.status_code == 415, resp.text
assert resp.json()["detail"]["code"] == "artifact.unsupported_type"
@pytest.mark.asyncio
async def test_other_kind_bypasses_content_type_check(self, db_session, write_token, tmp_path, monkeypatch):
"""kind=other accepts any content-type."""
_token_model, plaintext = write_token
monkeypatch.setattr(settings, "BGSTM_ARTIFACTS_DIR", str(tmp_path))
monkeypatch.setattr(settings, "BGSTM_ARTIFACT_URL_PREFIX", "http://testserver/artifacts")
monkeypatch.setattr(settings, "BGSTM_STORAGE_BACKEND", "local")
with TestClient(app) as client:
session_id = _create_session(client, plaintext)
case_result_id = _create_case_result(client, plaintext, session_id)
resp = client.post(
"/api/v1/external-results/artifact",
data={
"case_result_id": case_result_id,
"kind": "other",
"filename": "dump.bin",
},
files={"file": ("dump.bin", io.BytesIO(b"\x00\x01\x02"), "application/x-custom-binary")},
headers=_auth_header(plaintext),
)
assert resp.status_code == 201, resp.text
assert resp.json()["kind"] == "other"
# ---------------------------------------------------------------------------
# Path traversal (filename sanitization)
# ---------------------------------------------------------------------------
class TestFilenameValidation:
"""Verify that malicious filenames are rejected before any file is written."""
@pytest.mark.asyncio
@pytest.mark.parametrize(
"bad_filename",
[
"../etc/passwd",
"../../tmp/pwned.png",
"/etc/shadow",
"subdir/file.png",
"file\x00.png", # null byte
"file\\path.png", # backslash (also disallowed by regex)
"a" * 256, # too long
".", # current directory
"..", # parent directory traversal
"...", # dots-only
],
)
async def test_unsafe_filename_returns_422_and_writes_nothing(
self, db_session, write_token, tmp_path, monkeypatch, bad_filename
):
_token_model, plaintext = write_token
monkeypatch.setattr(settings, "BGSTM_ARTIFACTS_DIR", str(tmp_path))
monkeypatch.setattr(settings, "BGSTM_STORAGE_BACKEND", "local")
with TestClient(app) as client:
session_id = _create_session(client, plaintext)
case_result_id = _create_case_result(client, plaintext, session_id)
resp = client.post(
"/api/v1/external-results/artifact",
data={
"case_result_id": case_result_id,
"kind": "screenshot",
"filename": bad_filename,
},
files={"file": ("payload", io.BytesIO(b"\x89PNG"), "image/png")},
headers=_auth_header(plaintext),
)
assert resp.status_code == 422, f"Expected 422 for filename={bad_filename!r}, got {resp.status_code}"
assert resp.json()["detail"]["code"] == "validation_error"
# Nothing should be written to the artifacts directory
written = list(tmp_path.rglob("*"))
assert written == [], f"Files written for malicious filename {bad_filename!r}: {written}"
@pytest.mark.asyncio
async def test_local_backend_rejects_escaped_key_directly(self, tmp_path):
"""LocalFsBackend second-line defense: ValueError if key escapes root."""
from app.storage.local import LocalFsBackend
backend = LocalFsBackend(root=tmp_path, url_prefix="http://testserver/artifacts")
with pytest.raises(ValueError, match="escapes artifact root"):
backend.save(io.BytesIO(b"data"), key="../outside/file.txt", content_type="text/plain")
# ---------------------------------------------------------------------------
# Validation errors (422)
# ---------------------------------------------------------------------------
class TestValidationErrors:
@pytest.mark.asyncio
async def test_unknown_kind_returns_422(self, db_session, write_token, tmp_path, monkeypatch):
_token_model, plaintext = write_token
monkeypatch.setattr(settings, "BGSTM_ARTIFACTS_DIR", str(tmp_path))
monkeypatch.setattr(settings, "BGSTM_STORAGE_BACKEND", "local")
with TestClient(app) as client:
session_id = _create_session(client, plaintext)
case_result_id = _create_case_result(client, plaintext, session_id)
resp = client.post(
"/api/v1/external-results/artifact",
data={
"case_result_id": case_result_id,
"kind": "totally_unknown",
"filename": "file.png",
},
files={"file": ("file.png", io.BytesIO(b"PNG"), "image/png")},
headers=_auth_header(plaintext),
)
assert resp.status_code == 422
assert resp.json()["detail"]["code"] == "validation_error"
@pytest.mark.asyncio
async def test_invalid_case_result_id_uuid_returns_422(self, db_session, write_token, tmp_path, monkeypatch):
_token_model, plaintext = write_token
monkeypatch.setattr(settings, "BGSTM_ARTIFACTS_DIR", str(tmp_path))
monkeypatch.setattr(settings, "BGSTM_STORAGE_BACKEND", "local")
with TestClient(app) as client:
resp = client.post(
"/api/v1/external-results/artifact",
data={
"case_result_id": "not-a-uuid",
"kind": "screenshot",
"filename": "file.png",
},
files={"file": ("file.png", io.BytesIO(b"PNG"), "image/png")},
headers=_auth_header(plaintext),
)
assert resp.status_code == 422
assert resp.json()["detail"]["code"] == "validation_error"
# ---------------------------------------------------------------------------
# FK violation — case_result_id not found (404)
# ---------------------------------------------------------------------------
class TestFKViolation:
@pytest.mark.asyncio
async def test_unknown_case_result_id_returns_404(self, db_session, write_token, tmp_path, monkeypatch):
_token_model, plaintext = write_token
monkeypatch.setattr(settings, "BGSTM_ARTIFACTS_DIR", str(tmp_path))
monkeypatch.setattr(settings, "BGSTM_STORAGE_BACKEND", "local")
with TestClient(app) as client:
resp = client.post(
"/api/v1/external-results/artifact",
data={
"case_result_id": str(uuid.uuid4()),
"kind": "screenshot",
"filename": "file.png",
},
files={"file": ("file.png", io.BytesIO(b"PNG"), "image/png")},
headers=_auth_header(plaintext),
)
assert resp.status_code == 404
assert resp.json()["detail"]["code"] == "case_result.not_found"
# ---------------------------------------------------------------------------
# Auth
# ---------------------------------------------------------------------------
class TestAuth:
@pytest.mark.asyncio
async def test_missing_auth_returns_401(self, db_session, write_token, tmp_path, monkeypatch):
monkeypatch.setattr(settings, "BGSTM_ARTIFACTS_DIR", str(tmp_path))
monkeypatch.setattr(settings, "BGSTM_STORAGE_BACKEND", "local")
_token_model, plaintext = write_token
with TestClient(app) as client:
session_id = _create_session(client, plaintext)
case_result_id = _create_case_result(client, plaintext, session_id)
resp = client.post(
"/api/v1/external-results/artifact",
data={
"case_result_id": case_result_id,
"kind": "screenshot",
"filename": "file.png",
},
files={"file": ("file.png", io.BytesIO(b"PNG"), "image/png")},
# No auth header
)
assert resp.status_code == 401
# ---------------------------------------------------------------------------
# S3 stub
# ---------------------------------------------------------------------------
class TestS3Stub:
def test_s3_backend_raises_not_implemented(self):
backend = S3Backend()
with pytest.raises(NotImplementedError, match="S3 backend not yet implemented"):
backend.save(io.BytesIO(b"data"), key="test/key", content_type="image/png")
def test_s3_url_for_raises_not_implemented(self):
backend = S3Backend()
with pytest.raises(NotImplementedError, match="S3 backend not yet implemented"):
backend.url_for("test/key")