-
-
Notifications
You must be signed in to change notification settings - Fork 735
Fixed: ParseUser.getCurrentUser() returns a non authenticated user when local datastore is used #3
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -500,6 +500,16 @@ public Task<Void> then(Task<Void> task) throws Exception { | |
} | ||
} | ||
|
||
@Override | ||
/* package */ void setState(ParseObject.State newState) { | ||
// Avoid clearing sessionToken when updating the current user's State via ParseQuery result | ||
if (isCurrentUser() && getSessionToken() != null | ||
&& newState.get("sessionToken") == null) { | ||
newState = newState.newBuilder().put("sessionToken", getSessionToken()).build(); | ||
} | ||
super.setState(newState); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like we'd be creating unnecessary |
||
|
||
@Override | ||
/* package */ void validateDelete() { | ||
synchronized (mutex) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1059,6 +1059,41 @@ public void testUpgradeToRevocableSessionAsync() throws Exception { | |
verify(currentUserController, times(1)).setAsync(user); | ||
} | ||
|
||
@Test | ||
public void testDontOverwriteSessionTokenForCurrentUser() throws Exception { | ||
ParseUser.State sessionTokenState = new ParseUser.State.Builder() | ||
.sessionToken("sessionToken") | ||
.put("key0", "value0") | ||
.put("key1", "value1") | ||
.isComplete(true) | ||
.build(); | ||
ParseUser.State newState = new ParseUser.State.Builder() | ||
.put("key0", "newValue0") | ||
.put("key2", "value2") | ||
.isComplete(true) | ||
.build(); | ||
ParseUser.State emptyState = new ParseUser.State.Builder().isComplete(true).build(); | ||
|
||
ParseUser user = ParseObject.from(sessionTokenState); | ||
user.setIsCurrentUser(true); | ||
assertEquals(user.getSessionToken(), "sessionToken"); | ||
assertEquals(user.getString("key0"), "value0"); | ||
assertEquals(user.getString("key1"), "value1"); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: whitespace |
||
user.setState(newState); | ||
assertEquals(user.getSessionToken(), "sessionToken"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we add some data in |
||
assertEquals(user.getString("key0"), "newValue0"); | ||
assertNull(user.getString("key1")); | ||
assertEquals(user.getString("key2"), "value2"); | ||
|
||
user.setIsCurrentUser(false); | ||
user.setState(emptyState); | ||
assertNull(user.getSessionToken()); | ||
assertNull(user.getString("key0")); | ||
assertNull(user.getString("key1")); | ||
assertNull(user.getString("key2")); | ||
} | ||
|
||
//endregion | ||
|
||
//region testUnlinkFromAsync | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic seems a tad messy, could we simplify it to the following?