Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(core): unit validating clockskew offset is updated when client clock back and forth #12495

Merged
merged 2 commits into from
Nov 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ describe('getUpdatedSystemClockOffset', () => {
Date.now = jest.fn(() => signingDate.valueOf());
});

test('returns the current offset if not skewed', () => {
it('should return the current offset if not skewed', () => {
mockIsClockSkewed.mockReturnValue(false);
const offset = 1500;
expect(getUpdatedSystemClockOffset(signingDate.getTime(), offset)).toBe(
offset
);
});

test('returns the updated offset if system clock is behind', () => {
it('should return the updated offset if system clock is behind', () => {
mockIsClockSkewed.mockReturnValue(true);
const clockTime = new Date(signingDate);
clockTime.setMinutes(signingDate.getMinutes() + 15);
Expand All @@ -32,12 +32,25 @@ describe('getUpdatedSystemClockOffset', () => {
);
});

test('returns the updated offset if system clock is ahead', () => {
it('should return the updated offset if system clock is ahead', () => {
mockIsClockSkewed.mockReturnValue(true);
const clockTime = new Date(signingDate);
clockTime.setMinutes(signingDate.getMinutes() - 15);
expect(getUpdatedSystemClockOffset(clockTime.getTime(), 0)).toBe(
-15 * 60 * 1000
);
});

// Addresses: https://github.com/aws-amplify/amplify-js/issues/12450#issuecomment-1787945008
it('should return the updated offset if system clock is back and forth', () => {
// initialize client clock skew to be 15 mins behind
mockIsClockSkewed.mockReturnValue(true);
const clockTime = new Date(signingDate);
clockTime.setMinutes(signingDate.getMinutes() - 15);
let offset = getUpdatedSystemClockOffset(clockTime.getTime(), 0);
// client clock skew is now 15 mins ahead, making is sync with server clock
clockTime.setMinutes(signingDate.getMinutes() + 15);
offset = getUpdatedSystemClockOffset(clockTime.getTime(), offset);
expect(offset).toBe(0);
});
});
Loading