Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
9 changes: 1 addition & 8 deletions Source/ARTAuth.m
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ - (void)storeOptions:(ARTAuthOptions *)customOptions {
self.options.authMethod = customOptions.authMethod;
self.options.authParams = [customOptions.authParams copy];
self.options.useTokenAuth = customOptions.useTokenAuth;
self.options.queryTime = NO;
}

- (ARTTokenParams *)mergeParams:(ARTTokenParams *)customParams {
Expand Down Expand Up @@ -701,7 +700,7 @@ - (void)createTokenRequest:(ARTTokenParams *)tokenParams options:(ARTAuthOptions
return nil;
}

if ([self hasTimeOffsetWithValue] && !replacedOptions.queryTime) {
if ([self hasTimeOffset]) {
currentTokenParams.timestamp = [self currentDate];
callback([currentTokenParams sign:replacedOptions.key], nil);
return nil;
Expand Down Expand Up @@ -766,10 +765,6 @@ - (BOOL)hasTimeOffset {
return _timeOffset != nil;
}

- (BOOL)hasTimeOffsetWithValue {
return _timeOffset != nil && _timeOffset.doubleValue > 0;
}

- (void)discardTimeOffset {
// This may run after dealloc has been called in _rest. I've seen this
// happen when rest.auth is put in a variable, even if (apparently) that
Expand Down Expand Up @@ -804,8 +799,6 @@ - (void)clearTimeOffset; {
}

- (void)fetchServerTimeWithCompletion:(void (^)(NSDate * _Nullable, ARTErrorInfo * _Nullable))completion {
// TODO: I don't know why elsewhere we use hasTimeOffsetWithValue; it's causing us to ignore the offset in the case where the stored time offset indicates that the local clock is ahead of the server clock. See https://github.com/ably/ably-cocoa/issues/2148

if ([self hasTimeOffset]) {
NSDate *serverTime = [self currentDate];
ARTLogDebug(self.logger, @"Server time fetch calculated time %@ from offset", serverTime);
Expand Down
16 changes: 12 additions & 4 deletions Test/AblyTests/Tests/AuthTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3438,13 +3438,13 @@ class AuthTests: XCTestCase {
}

// RSA10k

func test__115__authorize__server_time_offset__should_obtain_server_time_once_and_persist_the_offset_from_the_local_clock() throws {
func _test__115__authorize__server_time_offset__should_obtain_server_time_once_and_persist_the_offset_from_the_local_clock(_ offset: TimeInterval) throws {
let test = Test()
let options = try AblyTests.commonAppSetup(for: test)
let rest = ARTRest(options: options)

let mockServerDate = Date().addingTimeInterval(120)
let mockServerDate = Date().addingTimeInterval(offset)
rest.auth.internal.testSuite_returnValue(for: NSSelectorFromString("handleServerTime:"), with: mockServerDate)
let currentDate = Date()

Expand Down Expand Up @@ -3479,7 +3479,7 @@ class AuthTests: XCTestCase {
rest.auth.internal.testSuite_forceTokenToExpire()

waitUntil(timeout: testTimeout) { done in
rest.auth.authorize(nil, options: nil) { tokenDetails, error in
rest.auth.authorize(nil, options: authOptions) { tokenDetails, error in
XCTAssertNil(error)
guard tokenDetails != nil else {
fail("TokenDetails is nil"); done(); return
Expand All @@ -3496,6 +3496,14 @@ class AuthTests: XCTestCase {
}
}

func test__115__authorize__server_time_offset__should_obtain_server_time_once_and_persist_the_offset_from_the_local_clock() throws {
try _test__115__authorize__server_time_offset__should_obtain_server_time_once_and_persist_the_offset_from_the_local_clock(120)
}

func test__115b__authorize__server_time_offset__should_obtain_server_time_once_and_persist_the_offset_from_the_local_clock() throws {
try _test__115__authorize__server_time_offset__should_obtain_server_time_once_and_persist_the_offset_from_the_local_clock(-119) // looks like 120 is out of range in server side comparison
}

func test__116__authorize__server_time_offset__should_be_consistent_the_timestamp_request_with_the_server_time() throws {
let test = Test()
let options = try AblyTests.commonAppSetup(for: test)
Expand Down
Loading