chore: format
This commit is contained in:
@@ -56,7 +56,9 @@ describe('CredentialStore', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
vi.mocked(fs.existsSync).mockReturnValue(true);
|
vi.mocked(fs.existsSync).mockReturnValue(true);
|
||||||
vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(mockCredentials));
|
vi.mocked(fs.readFileSync).mockReturnValue(
|
||||||
|
JSON.stringify(mockCredentials)
|
||||||
|
);
|
||||||
|
|
||||||
const result = store.getCredentials();
|
const result = store.getCredentials();
|
||||||
|
|
||||||
@@ -79,7 +81,9 @@ describe('CredentialStore', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
vi.mocked(fs.existsSync).mockReturnValue(true);
|
vi.mocked(fs.existsSync).mockReturnValue(true);
|
||||||
vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(mockCredentials));
|
vi.mocked(fs.readFileSync).mockReturnValue(
|
||||||
|
JSON.stringify(mockCredentials)
|
||||||
|
);
|
||||||
|
|
||||||
const result = store.getCredentials();
|
const result = store.getCredentials();
|
||||||
|
|
||||||
@@ -100,7 +104,9 @@ describe('CredentialStore', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
vi.mocked(fs.existsSync).mockReturnValue(true);
|
vi.mocked(fs.existsSync).mockReturnValue(true);
|
||||||
vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(mockCredentials));
|
vi.mocked(fs.readFileSync).mockReturnValue(
|
||||||
|
JSON.stringify(mockCredentials)
|
||||||
|
);
|
||||||
|
|
||||||
const result = store.getCredentials();
|
const result = store.getCredentials();
|
||||||
|
|
||||||
@@ -120,7 +126,9 @@ describe('CredentialStore', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
vi.mocked(fs.existsSync).mockReturnValue(true);
|
vi.mocked(fs.existsSync).mockReturnValue(true);
|
||||||
vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(mockCredentials));
|
vi.mocked(fs.readFileSync).mockReturnValue(
|
||||||
|
JSON.stringify(mockCredentials)
|
||||||
|
);
|
||||||
|
|
||||||
const result = store.getCredentials();
|
const result = store.getCredentials();
|
||||||
|
|
||||||
@@ -140,7 +148,9 @@ describe('CredentialStore', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
vi.mocked(fs.existsSync).mockReturnValue(true);
|
vi.mocked(fs.existsSync).mockReturnValue(true);
|
||||||
vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(mockCredentials));
|
vi.mocked(fs.readFileSync).mockReturnValue(
|
||||||
|
JSON.stringify(mockCredentials)
|
||||||
|
);
|
||||||
|
|
||||||
const result = store.getCredentials();
|
const result = store.getCredentials();
|
||||||
|
|
||||||
@@ -160,7 +170,9 @@ describe('CredentialStore', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
vi.mocked(fs.existsSync).mockReturnValue(true);
|
vi.mocked(fs.existsSync).mockReturnValue(true);
|
||||||
vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(mockCredentials));
|
vi.mocked(fs.readFileSync).mockReturnValue(
|
||||||
|
JSON.stringify(mockCredentials)
|
||||||
|
);
|
||||||
|
|
||||||
const result = store.getCredentials();
|
const result = store.getCredentials();
|
||||||
|
|
||||||
@@ -181,7 +193,9 @@ describe('CredentialStore', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
vi.mocked(fs.existsSync).mockReturnValue(true);
|
vi.mocked(fs.existsSync).mockReturnValue(true);
|
||||||
vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(mockCredentials));
|
vi.mocked(fs.readFileSync).mockReturnValue(
|
||||||
|
JSON.stringify(mockCredentials)
|
||||||
|
);
|
||||||
|
|
||||||
const result = store.getCredentials();
|
const result = store.getCredentials();
|
||||||
|
|
||||||
@@ -203,7 +217,9 @@ describe('CredentialStore', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
vi.mocked(fs.existsSync).mockReturnValue(true);
|
vi.mocked(fs.existsSync).mockReturnValue(true);
|
||||||
vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(mockCredentials));
|
vi.mocked(fs.readFileSync).mockReturnValue(
|
||||||
|
JSON.stringify(mockCredentials)
|
||||||
|
);
|
||||||
|
|
||||||
const result = store.getCredentials({ allowExpired: true });
|
const result = store.getCredentials({ allowExpired: true });
|
||||||
|
|
||||||
@@ -239,7 +255,8 @@ describe('CredentialStore', () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Check that the written data contains a valid ISO string
|
// Check that the written data contains a valid ISO string
|
||||||
const writtenData = vi.mocked(fs.writeFileSync).mock.calls[0][1] as string;
|
const writtenData = vi.mocked(fs.writeFileSync).mock
|
||||||
|
.calls[0][1] as string;
|
||||||
const parsed = JSON.parse(writtenData);
|
const parsed = JSON.parse(writtenData);
|
||||||
expect(typeof parsed.expiresAt).toBe('string');
|
expect(typeof parsed.expiresAt).toBe('string');
|
||||||
expect(new Date(parsed.expiresAt).toISOString()).toBe(parsed.expiresAt);
|
expect(new Date(parsed.expiresAt).toISOString()).toBe(parsed.expiresAt);
|
||||||
@@ -257,7 +274,8 @@ describe('CredentialStore', () => {
|
|||||||
|
|
||||||
store.saveCredentials(credentials);
|
store.saveCredentials(credentials);
|
||||||
|
|
||||||
const writtenData = vi.mocked(fs.writeFileSync).mock.calls[0][1] as string;
|
const writtenData = vi.mocked(fs.writeFileSync).mock
|
||||||
|
.calls[0][1] as string;
|
||||||
const parsed = JSON.parse(writtenData);
|
const parsed = JSON.parse(writtenData);
|
||||||
expect(typeof parsed.expiresAt).toBe('string');
|
expect(typeof parsed.expiresAt).toBe('string');
|
||||||
expect(new Date(parsed.expiresAt).getTime()).toBe(futureTimestamp);
|
expect(new Date(parsed.expiresAt).getTime()).toBe(futureTimestamp);
|
||||||
@@ -272,8 +290,12 @@ describe('CredentialStore', () => {
|
|||||||
savedAt: new Date().toISOString()
|
savedAt: new Date().toISOString()
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(() => store.saveCredentials(credentials)).toThrow(AuthenticationError);
|
expect(() => store.saveCredentials(credentials)).toThrow(
|
||||||
expect(() => store.saveCredentials(credentials)).toThrow('Invalid expiresAt format');
|
AuthenticationError
|
||||||
|
);
|
||||||
|
expect(() => store.saveCredentials(credentials)).toThrow(
|
||||||
|
'Invalid expiresAt format'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reject NaN timestamp when saving', () => {
|
it('should reject NaN timestamp when saving', () => {
|
||||||
@@ -285,8 +307,12 @@ describe('CredentialStore', () => {
|
|||||||
savedAt: new Date().toISOString()
|
savedAt: new Date().toISOString()
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(() => store.saveCredentials(credentials)).toThrow(AuthenticationError);
|
expect(() => store.saveCredentials(credentials)).toThrow(
|
||||||
expect(() => store.saveCredentials(credentials)).toThrow('Invalid expiresAt format');
|
AuthenticationError
|
||||||
|
);
|
||||||
|
expect(() => store.saveCredentials(credentials)).toThrow(
|
||||||
|
'Invalid expiresAt format'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reject Infinity timestamp when saving', () => {
|
it('should reject Infinity timestamp when saving', () => {
|
||||||
@@ -298,8 +324,12 @@ describe('CredentialStore', () => {
|
|||||||
savedAt: new Date().toISOString()
|
savedAt: new Date().toISOString()
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(() => store.saveCredentials(credentials)).toThrow(AuthenticationError);
|
expect(() => store.saveCredentials(credentials)).toThrow(
|
||||||
expect(() => store.saveCredentials(credentials)).toThrow('Invalid expiresAt format');
|
AuthenticationError
|
||||||
|
);
|
||||||
|
expect(() => store.saveCredentials(credentials)).toThrow(
|
||||||
|
'Invalid expiresAt format'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle missing expiresAt when saving', () => {
|
it('should handle missing expiresAt when saving', () => {
|
||||||
@@ -313,7 +343,8 @@ describe('CredentialStore', () => {
|
|||||||
|
|
||||||
store.saveCredentials(credentials);
|
store.saveCredentials(credentials);
|
||||||
|
|
||||||
const writtenData = vi.mocked(fs.writeFileSync).mock.calls[0][1] as string;
|
const writtenData = vi.mocked(fs.writeFileSync).mock
|
||||||
|
.calls[0][1] as string;
|
||||||
const parsed = JSON.parse(writtenData);
|
const parsed = JSON.parse(writtenData);
|
||||||
expect(parsed.expiresAt).toBeUndefined();
|
expect(parsed.expiresAt).toBeUndefined();
|
||||||
});
|
});
|
||||||
@@ -394,8 +425,12 @@ describe('CredentialStore', () => {
|
|||||||
|
|
||||||
store.cleanupCorruptFiles();
|
store.cleanupCorruptFiles();
|
||||||
|
|
||||||
expect(fs.unlinkSync).toHaveBeenCalledWith(expect.stringContaining(oldFile));
|
expect(fs.unlinkSync).toHaveBeenCalledWith(
|
||||||
expect(fs.unlinkSync).not.toHaveBeenCalledWith(expect.stringContaining(newFile));
|
expect.stringContaining(oldFile)
|
||||||
|
);
|
||||||
|
expect(fs.unlinkSync).not.toHaveBeenCalledWith(
|
||||||
|
expect.stringContaining(newFile)
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle cleanup errors gracefully', () => {
|
it('should handle cleanup errors gracefully', () => {
|
||||||
|
|||||||
@@ -32,7 +32,9 @@ export class CredentialStore {
|
|||||||
// Normalize/migrate timestamps to numeric (handles both number and ISO string)
|
// Normalize/migrate timestamps to numeric (handles both number and ISO string)
|
||||||
let expiresAtMs: number | undefined;
|
let expiresAtMs: number | undefined;
|
||||||
if (typeof authData.expiresAt === 'number') {
|
if (typeof authData.expiresAt === 'number') {
|
||||||
expiresAtMs = Number.isFinite(authData.expiresAt) ? authData.expiresAt : undefined;
|
expiresAtMs = Number.isFinite(authData.expiresAt)
|
||||||
|
? authData.expiresAt
|
||||||
|
: undefined;
|
||||||
} else if (typeof authData.expiresAt === 'string') {
|
} else if (typeof authData.expiresAt === 'string') {
|
||||||
const parsed = Date.parse(authData.expiresAt);
|
const parsed = Date.parse(authData.expiresAt);
|
||||||
expiresAtMs = Number.isNaN(parsed) ? undefined : parsed;
|
expiresAtMs = Number.isNaN(parsed) ? undefined : parsed;
|
||||||
@@ -103,7 +105,9 @@ export class CredentialStore {
|
|||||||
let validTimestamp: number | undefined;
|
let validTimestamp: number | undefined;
|
||||||
|
|
||||||
if (typeof authData.expiresAt === 'number') {
|
if (typeof authData.expiresAt === 'number') {
|
||||||
validTimestamp = Number.isFinite(authData.expiresAt) ? authData.expiresAt : undefined;
|
validTimestamp = Number.isFinite(authData.expiresAt)
|
||||||
|
? authData.expiresAt
|
||||||
|
: undefined;
|
||||||
} else if (typeof authData.expiresAt === 'string') {
|
} else if (typeof authData.expiresAt === 'string') {
|
||||||
const parsed = Date.parse(authData.expiresAt);
|
const parsed = Date.parse(authData.expiresAt);
|
||||||
validTimestamp = Number.isNaN(parsed) ? undefined : parsed;
|
validTimestamp = Number.isNaN(parsed) ? undefined : parsed;
|
||||||
|
|||||||
Reference in New Issue
Block a user