-
Notifications
You must be signed in to change notification settings - Fork 36
[SDK-369] no push reregister on token refresh #1003
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
Open
franco-zalamena-iterable
wants to merge
11
commits into
master
Choose a base branch
from
bugfix/no-push-reregister-on-token-refresh
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ce61333
Fixed retrigger of completeUserLogin on new auth token
franco-zalamena-iterable affca7b
On same email login also complete the login flow
franco-zalamena-iterable 6d3a0b7
Fix for auto retry on 401 error
franco-zalamena-iterable 636a5d4
Merge branch 'master' into bugfix/no-push-reregister-on-token-refresh
joaodordio 2dbb142
Fixes flow so that reregister and fetch messages gets called after re…
davidtruong 348bc50
removed unnecessary test check
davidtruong 30fd5f2
Removed unnecessary check and regeneration of token
franco-zalamena-iterable 1283f94
When online api call fails, set JWT state to failed, When it goes bac…
franco-zalamena-iterable 92da9fd
Remove unused code
franco-zalamena-iterable 98da40b
Preserve setAuthToken() guard: only trigger login when token changes
franco-zalamena-iterable 30b6943
Merge branch 'master' into bugfix/no-push-reregister-on-token-refresh
franco-zalamena-iterable File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
iterableapi/src/main/java/com/iterable/iterableapi/AuthRecoverySyncManager.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package com.iterable.iterableapi; | ||
|
|
||
| /** | ||
| * Syncs in-app and embedded messages when the auth token recovers from a 401 JWT rejection. | ||
| * Registered as an {@link IterableAuthManager.AuthTokenReadyListener}, which only fires on | ||
| * INVALID → UNKNOWN/VALID transitions (i.e., after a 401, not on routine token refreshes). | ||
| * | ||
| * Also triggers push re-registration when autoPushRegistration is enabled. | ||
| */ | ||
| class AuthRecoverySyncManager implements IterableAuthManager.AuthTokenReadyListener { | ||
| private static final String TAG = "AuthRecoverySyncMgr"; | ||
|
|
||
| private final IterableApi api; | ||
|
|
||
| AuthRecoverySyncManager(IterableApi api) { | ||
| this.api = api; | ||
| } | ||
|
|
||
| @Override | ||
| public void onAuthTokenReady() { | ||
| IterableLogger.d(TAG, "Auth token ready after recovery - syncing messages"); | ||
|
|
||
| if (api.config.autoPushRegistration) { | ||
| api.registerForPush(); | ||
| } | ||
|
|
||
| api.getInAppManager().syncInApp(); | ||
| api.getEmbeddedManager().syncMessages(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
iterableapi/src/test/java/com/iterable/iterableapi/AuthRecoverySyncManagerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| package com.iterable.iterableapi; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.never; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| public class AuthRecoverySyncManagerTest { | ||
|
|
||
| private IterableApi createMockApi(boolean autoPushRegistration) { | ||
| IterableApi mockApi = mock(IterableApi.class); | ||
| mockApi.config = new IterableConfig.Builder() | ||
| .setAutoPushRegistration(autoPushRegistration) | ||
| .build(); | ||
| IterableInAppManager mockInApp = mock(IterableInAppManager.class); | ||
| IterableEmbeddedManager mockEmbedded = mock(IterableEmbeddedManager.class); | ||
| when(mockApi.getInAppManager()).thenReturn(mockInApp); | ||
| when(mockApi.getEmbeddedManager()).thenReturn(mockEmbedded); | ||
| return mockApi; | ||
| } | ||
|
|
||
| @Test | ||
| public void testOnAuthTokenReadySyncsInApp() { | ||
| IterableApi mockApi = createMockApi(false); | ||
| AuthRecoverySyncManager manager = new AuthRecoverySyncManager(mockApi); | ||
|
|
||
| manager.onAuthTokenReady(); | ||
|
|
||
| verify(mockApi.getInAppManager()).syncInApp(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testOnAuthTokenReadySyncsEmbeddedMessages() { | ||
| IterableApi mockApi = createMockApi(false); | ||
| AuthRecoverySyncManager manager = new AuthRecoverySyncManager(mockApi); | ||
|
|
||
| manager.onAuthTokenReady(); | ||
|
|
||
| verify(mockApi.getEmbeddedManager()).syncMessages(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testOnAuthTokenReadyRegistersForPushWhenEnabled() { | ||
| IterableApi mockApi = createMockApi(true); | ||
| AuthRecoverySyncManager manager = new AuthRecoverySyncManager(mockApi); | ||
|
|
||
| manager.onAuthTokenReady(); | ||
|
|
||
| verify(mockApi).registerForPush(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testOnAuthTokenReadySkipsPushWhenDisabled() { | ||
| IterableApi mockApi = createMockApi(false); | ||
| AuthRecoverySyncManager manager = new AuthRecoverySyncManager(mockApi); | ||
|
|
||
| manager.onAuthTokenReady(); | ||
|
|
||
| verify(mockApi, never()).registerForPush(); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.