Skip to content

Commit

Permalink
This partially fixes issue #1177 (deregistration does not clear devic…
Browse files Browse the repository at this point in the history
…e 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.
  • Loading branch information
maratal committed Nov 12, 2023
1 parent 244dc3b commit 821d7e4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Source/ARTLocalDevice.m
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ - (void)setAndPersistIdentityTokenDetails:(ARTDeviceIdentityTokenDetails *)token
if (self.clientId == nil) {
self.clientId = tokenDetails.clientId;
}
if (tokenDetails == nil) {
self.clientId = nil;
}
}

- (BOOL)isRegistered {
Expand Down
13 changes: 11 additions & 2 deletions Test/Tests/PushActivationStateMachineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -841,6 +849,7 @@ class PushActivationStateMachineTests: XCTestCase {
XCTAssertTrue(deactivatedCallbackCalled)
XCTAssertTrue(setAndPersistIdentityTokenDetailsCalled)
// RSH3g2a
XCTAssertNil(stateMachine.rest.device.clientId)
XCTAssertNil(stateMachine.rest.device.identityTokenDetails)
}

Expand Down

0 comments on commit 821d7e4

Please sign in to comment.