From 821d7e4791e29d30b3bbe9ae76a0a9e8824c26a4 Mon Sep 17 00:00:00 2001 From: Marat Al Date: Sun, 12 Nov 2023 18:05:50 +0100 Subject: [PATCH] This partially fixes issue #1177 (deregistration does not clear device details) and only resets clientId, since it affects push device registration with a different clientId (after deregistration with previous clientId). This only affects clients that do not restart their apps after deregistration, since clientId is loaded into deviceId once per app launch. This commit resets clientId after deregistration. --- Source/ARTLocalDevice.m | 3 +++ Test/Tests/PushActivationStateMachineTests.swift | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Source/ARTLocalDevice.m b/Source/ARTLocalDevice.m index 4083ff4d6..aded00ba3 100644 --- a/Source/ARTLocalDevice.m +++ b/Source/ARTLocalDevice.m @@ -147,6 +147,9 @@ - (void)setAndPersistIdentityTokenDetails:(ARTDeviceIdentityTokenDetails *)token if (self.clientId == nil) { self.clientId = tokenDetails.clientId; } + if (tokenDetails == nil) { + self.clientId = nil; + } } - (BOOL)isRegistered { diff --git a/Test/Tests/PushActivationStateMachineTests.swift b/Test/Tests/PushActivationStateMachineTests.swift index 105cf240b..66799d4c7 100644 --- a/Test/Tests/PushActivationStateMachineTests.swift +++ b/Test/Tests/PushActivationStateMachineTests.swift @@ -822,8 +822,16 @@ 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 @@ -841,6 +849,7 @@ class PushActivationStateMachineTests: XCTestCase { XCTAssertTrue(deactivatedCallbackCalled) XCTAssertTrue(setAndPersistIdentityTokenDetailsCalled) // RSH3g2a + XCTAssertNil(stateMachine.rest.device.clientId) XCTAssertNil(stateMachine.rest.device.identityTokenDetails) }