Skip to content

Commit f6845a9

Browse files
Add edge case unit tests for OAuth2TokenManager
- Introduced new test cases in `OAuth2TokenManager` to handle edge cases for negative, zero, and very small expiry dates, ensuring the `isTokenValid` method correctly identifies invalid token data. - These tests enhance the robustness of the token validation logic by covering additional scenarios that could lead to incorrect token handling. This update improves the overall reliability of the OAuth2 token management implementation by validating critical edge cases in token expiry handling.
1 parent 8881bea commit f6845a9

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

workers/main/src/services/OAuth2/OAuth2TokenManager.errors.test.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ describe('OAuth2TokenManager - Error Handling', () => {
3636

3737
beforeEach(async () => {
3838
tokenManager = new OAuth2TokenManager('qbo', 'test-refresh-token');
39-
// Wait for async initialization to complete
4039
await new Promise((resolve) => setTimeout(resolve, 0));
4140
});
4241

@@ -113,4 +112,42 @@ describe('OAuth2TokenManager - Error Handling', () => {
113112
);
114113
});
115114
});
115+
116+
describe('edge cases', () => {
117+
it('should handle negative expiry date', () => {
118+
const tokenData: TokenData = {
119+
access_token: 'valid-token',
120+
refresh_token: 'refresh-token',
121+
expires_at: -1000,
122+
token_type: 'Bearer',
123+
};
124+
125+
tokenManager.setTokenDataForTesting(tokenData);
126+
expect(tokenManager.isTokenValid()).toBe(false);
127+
});
128+
129+
it('should handle zero expiry date', () => {
130+
const tokenData: TokenData = {
131+
access_token: 'valid-token',
132+
refresh_token: 'refresh-token',
133+
expires_at: 0,
134+
token_type: 'Bearer',
135+
};
136+
137+
tokenManager.setTokenDataForTesting(tokenData);
138+
expect(tokenManager.isTokenValid()).toBe(false);
139+
});
140+
141+
it('should handle very small expiry date', () => {
142+
const tokenData: TokenData = {
143+
access_token: 'valid-token',
144+
refresh_token: 'refresh-token',
145+
expires_at: Number.MIN_SAFE_INTEGER,
146+
token_type: 'Bearer',
147+
};
148+
149+
tokenManager.setTokenDataForTesting(tokenData);
150+
expect(tokenManager.isTokenValid()).toBe(false);
151+
});
152+
});
116153
});

0 commit comments

Comments
 (0)