Replace crypto tests with comprehensive unit tests for authStore, storage, and configuration modules
- Removed outdated `crypto` tests; added dedicated and structured tests for `authStore`, `storage`, and `app.config`. - Enhanced test coverage for user and token validation, secure persistence, state management, and configuration parsing. - Consolidated encryption and storage error handling with thorough validation to ensure SSR-safety and resilience. - Improved runtime validations for tokens and configuration with stricter type checks and fallback mechanisms.
This commit is contained in:
@@ -134,14 +134,17 @@ export async function getTokens(): Promise<TokenStorage | null> {
|
||||
}
|
||||
|
||||
const decrypted = await decryptData(encrypted);
|
||||
const tokens = JSON.parse(decrypted) as TokenStorage;
|
||||
const parsed = JSON.parse(decrypted);
|
||||
|
||||
// Validate structure
|
||||
if (!tokens || typeof tokens !== 'object') {
|
||||
// Validate structure - must have required fields
|
||||
if (!parsed || typeof parsed !== 'object' ||
|
||||
!('accessToken' in parsed) || !('refreshToken' in parsed) ||
|
||||
(parsed.accessToken !== null && typeof parsed.accessToken !== 'string') ||
|
||||
(parsed.refreshToken !== null && typeof parsed.refreshToken !== 'string')) {
|
||||
throw new Error('Invalid token structure');
|
||||
}
|
||||
|
||||
return tokens;
|
||||
return parsed as TokenStorage;
|
||||
} catch (error) {
|
||||
console.error('Failed to retrieve tokens:', error);
|
||||
// If decryption fails, clear invalid data
|
||||
|
||||
Reference in New Issue
Block a user