feat(protobuf): add unified state helpers for oauth payloads
This commit is contained in:
1 parent
fce38ec6f0
commit
f970ccb2ed
2 files changed
+237
-34
No files matched your search
@@ -30,4 +30,36 @@ describe('ProtobufUtils Unified OAuth', () => {
|
||||
refreshToken,
|
||||
});
|
||||
});
|
||||
|
||||
it('should round-trip unified state entry with topic/row structure', () => {
|
||||
const payload = new Uint8Array([1, 2, 3, 4, 5]);
|
||||
const entry = ProtobufUtils.createUnifiedStateEntry('userStatusSentinelKey', payload);
|
||||
const decoded = ProtobufUtils.decodeUnifiedStateEntry(entry);
|
||||
|
||||
expect(decoded.sentinelKey).toBe('userStatusSentinelKey');
|
||||
expect(Array.from(decoded.payload)).toEqual([1, 2, 3, 4, 5]);
|
||||
});
|
||||
|
||||
it('should parse legacy nested unified oauth payload', () => {
|
||||
const accessToken = 'legacy-access';
|
||||
const refreshToken = 'legacy-refresh';
|
||||
const oauthInfo = ProtobufUtils.createOAuthInfo(accessToken, refreshToken, 1700000000);
|
||||
const oauthInfoB64 = Buffer.from(oauthInfo).toString('base64');
|
||||
|
||||
// Legacy nested structure:
|
||||
// Outer(F1) -> Inner(F1 sentinel, F2 Inner2), Inner2(F1 base64(oauthInfo))
|
||||
const inner2 = ProtobufUtils.encodeStringField(1, oauthInfoB64);
|
||||
const inner = new Uint8Array(
|
||||
ProtobufUtils.encodeStringField(1, 'oauthTokenInfoSentinelKey').length +
|
||||
ProtobufUtils.encodeLenDelimField(2, inner2).length,
|
||||
);
|
||||
const innerField1 = ProtobufUtils.encodeStringField(1, 'oauthTokenInfoSentinelKey');
|
||||
const innerField2 = ProtobufUtils.encodeLenDelimField(2, inner2);
|
||||
inner.set(innerField1, 0);
|
||||
inner.set(innerField2, innerField1.length);
|
||||
const legacyOuter = ProtobufUtils.encodeLenDelimField(1, inner);
|
||||
|
||||
const parsed = ProtobufUtils.extractOAuthTokenInfoFromUnifiedState(legacyOuter);
|
||||
expect(parsed).toEqual({ accessToken, refreshToken });
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user