Skip to content

Commit 94b61d5

Browse files
committed
docs: enable encryption examples by setting CACHEKIT_MASTER_KEY in test fixtures
- Add os.environ["CACHEKIT_MASTER_KEY"] = secret_key to conftest.py - Convert encryption examples in api-reference.md to testable - 134 doc tests now pass (up from 133)
1 parent a6eb44a commit 94b61d5

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

docs/api-reference.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -658,8 +658,8 @@ def default_function():
658658
}
659659
```
660660

661-
**Encryption examples** (require `CACHEKIT_MASTER_KEY` env var):
662-
```python notest
661+
**Encryption examples** (env var `CACHEKIT_MASTER_KEY` set in test fixtures):
662+
```python
663663
from cachekit import cache
664664
from cachekit.serializers import EncryptionWrapper, OrjsonSerializer
665665

@@ -669,7 +669,7 @@ def get_user_ssn(user_id: int):
669669
return {"ssn": "123-45-6789", "dob": "1990-01-01"}
670670

671671
# Encrypted JSON (zero-knowledge API caching)
672-
@cache(serializer=EncryptionWrapper(serializer=OrjsonSerializer()), backend=None)
672+
@cache(serializer=EncryptionWrapper(serializer=OrjsonSerializer(), master_key=bytes.fromhex(secret_key)), backend=None)
673673
def get_api_keys(tenant_id: str):
674674
return {"api_key": "sk_live_...", "webhook_secret": "whsec_..."}
675675
```

docs/conftest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77

88
import logging
9+
import os
910
import time
1011

1112
try:
@@ -92,6 +93,8 @@ def expensive_computation():
9293

9394
# Secret key for encryption examples (test value only)
9495
secret_key = "a" * 64 # 32 bytes in hex
96+
# Set env var so @cache.secure validation passes
97+
os.environ["CACHEKIT_MASTER_KEY"] = secret_key
9598

9699
globals_dict = {
97100
"cache": cache,

0 commit comments

Comments
 (0)