Skip to content
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

feat: Send client key in the connect operation #118

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ class ConnectClientOperation extends ClientOperation {

private final String applicationId;
private final String sessionToken;
private final String clientKey;

ConnectClientOperation(String applicationId, String sessionToken) {
ConnectClientOperation(String applicationId, String sessionToken, String clientKey) {
this.applicationId = applicationId;
this.sessionToken = sessionToken;
this.clientKey = clientKey;
}

@Override
Expand All @@ -19,6 +21,7 @@ JSONObject getJSONObjectRepresentation() throws JSONException {
jsonObject.put("op", "connect");
jsonObject.put("applicationId", applicationId);
jsonObject.put("sessionToken", sessionToken);
jsonObject.put("clientKey", clientKey);
return jsonObject;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ public void onOpen() {
@Override
public Task<Void> then(Task<String> task) throws Exception {
String sessionToken = task.getResult();
return sendOperationAsync(new ConnectClientOperation(applicationId, sessionToken));
return sendOperationAsync(new ConnectClientOperation(applicationId, sessionToken, clientKey));
}
}).continueWith(new Continuation<Void, Void>() {
public Void then(Task<Void> task) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,13 +413,42 @@ public void testSessionTokenSentOnSubscribe() {

@Test
public void testEmptySessionTokenOnSubscribe() {
when(mockUser.getSessionToken()).thenReturn("the token");
when(webSocketClient.getState()).thenReturn(WebSocketClient.State.CONNECTED);
parseLiveQueryClient.subscribe(ParseQuery.getQuery("Test"));
verify(webSocketClient, times(1)).send(contains("\"op\":\"connect\""));
verify(webSocketClient, times(1)).send(and(
contains("\"op\":\"subscribe\""),
contains("\"sessionToken\":\"the token\"")));
not(contains("\"sessionToken\":"))));
}

@Test
public void testClientKeySentOnConnect() throws Exception {
Parse.Configuration configuration = new Parse.Configuration.Builder(null)
.applicationId("1234")
.clientKey("1234")
.build();
ParsePlugins.reset();
ParsePlugins.initialize(null, configuration);

parseLiveQueryClient = ParseLiveQueryClient.Factory.getClient(new URI(""), new WebSocketClientFactory() {
@Override
public WebSocketClient createInstance(WebSocketClient.WebSocketClientCallback webSocketClientCallback, URI hostUrl) {
TestParseLiveQueryClient.this.webSocketClientCallback = webSocketClientCallback;
webSocketClient = mock(WebSocketClient.class);
return webSocketClient;
}
}, new ImmediateExecutor());
Comment on lines +433 to +440
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason why you explicitly change the instance from @Before?

The initialization looks same to me.


parseLiveQueryClient.reconnect();
webSocketClientCallback.onOpen();
verify(webSocketClient, times(1)).send(contains("\"clientKey\":\"1234\""));
}

@Test
public void testEmptyClientKeyOnConnect() {
parseLiveQueryClient.reconnect();
webSocketClientCallback.onOpen();
verify(webSocketClient, times(1)).send(not(contains("\"clientKey\":")));
}

@Test
Expand Down