Skip to content

Commit fb7c9ce

Browse files
rustyconoverclaude
andcommitted
Fix tests for token v3 format (4-segment state tokens with stream_id)
Update test_wrong_token_version_400, test_expired_token_400, and test_pack_unpack_roundtrip_with_base64 to build v3-format tokens with the stream_id segment. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 6d1917d commit fb7c9ce

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

tests/test_http.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,9 @@ def test_wrong_token_version_400(self, resumable_client: _SyncTestClient) -> Non
377377
from vgi_rpc.rpc import _EMPTY_SCHEMA
378378
from vgi_rpc.utils import empty_batch
379379

380-
# Build a structurally valid v2 token with a wrong version byte
380+
# Build a structurally valid v3 token with a wrong version byte
381381
bad_version = 99
382-
state_bytes = schema_bytes = input_bytes = b""
382+
state_bytes = schema_bytes = input_bytes = stream_id_bytes = b""
383383
payload = (
384384
struct.pack("B", bad_version)
385385
+ struct.pack("<Q", int(time.time()))
@@ -389,6 +389,8 @@ def test_wrong_token_version_400(self, resumable_client: _SyncTestClient) -> Non
389389
+ schema_bytes
390390
+ struct.pack("<I", len(input_bytes))
391391
+ input_bytes
392+
+ struct.pack("<I", len(stream_id_bytes))
393+
+ stream_id_bytes
392394
)
393395
mac = hmac_mod.new(b"test-key", payload, hashlib.sha256).digest()
394396
token = base64.b64encode(payload + mac)
@@ -459,9 +461,9 @@ def test_expired_token_400(self) -> None:
459461
from vgi_rpc.rpc import _EMPTY_SCHEMA
460462
from vgi_rpc.utils import empty_batch
461463

462-
# Build a valid v2 token with a timestamp 2 hours in the past
464+
# Build a valid v3 token with a timestamp 2 hours in the past
463465
old_time = int(time.time()) - 7200
464-
state_bytes = schema_bytes = input_bytes = b""
466+
state_bytes = schema_bytes = input_bytes = stream_id_bytes = b""
465467
payload = (
466468
struct.pack("B", _TOKEN_VERSION)
467469
+ struct.pack("<Q", old_time)
@@ -471,6 +473,8 @@ def test_expired_token_400(self) -> None:
471473
+ schema_bytes
472474
+ struct.pack("<I", len(input_bytes))
473475
+ input_bytes
476+
+ struct.pack("<I", len(stream_id_bytes))
477+
+ stream_id_bytes
474478
)
475479
mac = hmac_mod.new(b"test-key", payload, hashlib.sha256).digest()
476480
token = base64.b64encode(payload + mac)
@@ -511,11 +515,12 @@ def test_token_ttl_zero_disables_expiry(self) -> None:
511515
from vgi_rpc.rpc import _EMPTY_SCHEMA
512516
from vgi_rpc.utils import empty_batch
513517

514-
# Build a valid v2 token with a very old timestamp
518+
# Build a valid v3 token with a very old timestamp
515519
old_time = int(time.time()) - 86400 # 24 hours ago
516520
state_bytes = _EMPTY_SCHEMA.serialize().to_pybytes()
517521
schema_bytes = _EMPTY_SCHEMA.serialize().to_pybytes()
518522
input_bytes = _EMPTY_SCHEMA.serialize().to_pybytes()
523+
stream_id_bytes = b""
519524
payload = (
520525
struct.pack("B", _TOKEN_VERSION)
521526
+ struct.pack("<Q", old_time)
@@ -525,6 +530,8 @@ def test_token_ttl_zero_disables_expiry(self) -> None:
525530
+ schema_bytes
526531
+ struct.pack("<I", len(input_bytes))
527532
+ input_bytes
533+
+ struct.pack("<I", len(stream_id_bytes))
534+
+ stream_id_bytes
528535
)
529536
mac = hmac_mod.new(b"test-key", payload, hashlib.sha256).digest()
530537
token = base64.b64encode(payload + mac)
@@ -575,10 +582,11 @@ def test_pack_unpack_roundtrip_with_base64(self) -> None:
575582
# Verify it's valid UTF-8
576583
token.decode("utf-8")
577584

578-
s, sch, inp = _unpack_state_token(token, key)
585+
s, sch, inp, sid = _unpack_state_token(token, key)
579586
assert s == state
580587
assert sch == schema
581588
assert inp == input_schema
589+
assert sid == ""
582590

583591

584592
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)