Skip to content

Commit

Permalink
Merge pull request #1832 from ably/fix/1177-clear-clientId
Browse files Browse the repository at this point in the history
Clear clientId after deregistration
  • Loading branch information
maratal authored Nov 13, 2023
2 parents 244dc3b + bff9205 commit f715fdc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
5 changes: 5 additions & 0 deletions Source/ARTLocalDevice.m
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,9 @@ - (BOOL)isRegistered {
return _identityTokenDetails != nil;
}

- (void)clearIdentityTokenDetailsAndClientId {
[self setAndPersistIdentityTokenDetails:nil];
self.clientId = nil;
}

@end
2 changes: 1 addition & 1 deletion Source/ARTPushActivationState.m
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ - (ARTPushActivationState *)transition:(ARTPushActivationEvent *)event {
else if ([event isKindOfClass:[ARTPushActivationEventDeregistered class]]) {
#if TARGET_OS_IOS
ARTLocalDevice *local = self.machine.rest.device_nosync;
[local setAndPersistIdentityTokenDetails:nil];
[local clearIdentityTokenDetailsAndClientId];
#endif
[self.machine callDeactivatedCallback:nil];
return [ARTPushActivationStateNotActivated newWithMachine:self.machine logger:self.logger];
Expand Down
1 change: 1 addition & 0 deletions Source/PrivateHeaders/Ably/ARTLocalDevice+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ NSString* ARTAPNSDeviceTokenKeyOfType(NSString * _Nullable tokenType);
- (void)setAndPersistAPNSDeviceToken:(nullable NSString *)deviceToken;
- (void)setAndPersistIdentityTokenDetails:(nullable ARTDeviceIdentityTokenDetails *)tokenDetails;
- (BOOL)isRegistered;
- (void)clearIdentityTokenDetailsAndClientId;

+ (NSString *)generateId;
+ (NSString *)generateSecret;
Expand Down
21 changes: 15 additions & 6 deletions Test/Tests/PushActivationStateMachineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -822,26 +822,35 @@ class PushActivationStateMachineTests: XCTestCase {

// RSH3g2
func test__054__Activation_state_machine__State_WaitingForDeregistration__on_Event_Deregistered() {
beforeEach__Activation_state_machine__State_WaitingForDeregistration()

storage = MockDeviceStorage(startWith: ARTPushActivationStateWaitingForDeregistration(machine: initialStateMachine, logger: .init(core: MockInternalLogCore())))

let options = ARTClientOptions(key: "xxxx:xxxx")
options.clientId = "client1"
let rest = ARTRest(options: options)
rest.internal.storage = storage
stateMachine = ARTPushActivationStateMachine(rest: rest.internal, delegate: StateMachineDelegate(), logger: .init(core: MockInternalLogCore()))

XCTAssertEqual(stateMachine.rest.device.clientId, "client1")

var deactivatedCallbackCalled = false
let hook = stateMachine.testSuite_injectIntoMethod(after: NSSelectorFromString("callDeactivatedCallback:")) {
deactivatedCallbackCalled = true
}
defer { hook.remove() }

var setAndPersistIdentityTokenDetailsCalled = false
let hookDevice = stateMachine.rest.device.testSuite_injectIntoMethod(after: NSSelectorFromString("setAndPersistIdentityTokenDetails:")) {
setAndPersistIdentityTokenDetailsCalled = true
var clearIdentityTokenDetailsAndClientIdCalled = false
let hookDevice = stateMachine.rest.device.testSuite_injectIntoMethod(after: NSSelectorFromString("clearIdentityTokenDetailsAndClientId")) {
clearIdentityTokenDetailsAndClientIdCalled = true
}
defer { hookDevice.remove() }

stateMachine.send(ARTPushActivationEventDeregistered())
expect(stateMachine.current).to(beAKindOf(ARTPushActivationStateNotActivated.self))
XCTAssertTrue(deactivatedCallbackCalled)
XCTAssertTrue(setAndPersistIdentityTokenDetailsCalled)
XCTAssertTrue(clearIdentityTokenDetailsAndClientIdCalled)
// RSH3g2a
XCTAssertNil(stateMachine.rest.device.identityTokenDetails)
XCTAssertNil(stateMachine.rest.device.clientId)
}

// RSH3g3
Expand Down

0 comments on commit f715fdc

Please sign in to comment.