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: MLIBZ-2448 Fix setting client app version #165
The head ref may contain hidden characters: "feature/MLIBZ-2448_Android_doesn't_send_\"X-Kinvey-Client-App-Version\"_before_user_is_authorized"
Changes from 4 commits
96dbe79
c3a000e
f5aff09
1b05e52
f426caa
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 |
---|---|---|
|
@@ -16,11 +16,15 @@ | |
package com.kinvey.java; | ||
|
||
import java.io.IOException; | ||
import java.lang.reflect.Field; | ||
import java.util.Hashtable; | ||
|
||
import com.google.api.client.json.GenericJson; | ||
import com.google.api.client.json.gson.GsonFactory; | ||
import com.kinvey.java.auth.KinveyAuthRequest; | ||
import com.kinvey.java.auth.ThirdPartyIdentity; | ||
import com.kinvey.java.core.KinveyClientRequestInitializer; | ||
import com.kinvey.java.core.KinveyHeaders; | ||
import com.kinvey.java.core.KinveyMockUnitTest; | ||
import com.kinvey.java.dto.BaseUser; | ||
import com.kinvey.java.store.UserStoreRequestManager; | ||
|
@@ -314,5 +318,28 @@ public void testMICAPIVersionAppendsV() throws IOException{ | |
assertEquals(getClient().getMICApiVersion(), "v2"); | ||
} | ||
|
||
public void testClientAppVersionHeader() throws IOException, NoSuchFieldException, IllegalAccessException { | ||
String clientAppVersion = "1.2.3"; | ||
getClient().setClientAppVersion(clientAppVersion); | ||
UserStoreRequestManager user = new UserStoreRequestManager(getClient(), createBuilder(getClient())); | ||
assertNotNull(user); | ||
UserStoreRequestManager.LoginRequest loginRequest = user.createBlocking("test_name", "test_login").buildAuthRequest(); | ||
Field kinveyAuthRequestField = loginRequest.getClass().getDeclaredField("request"); //NoSuchFieldException | ||
kinveyAuthRequestField.setAccessible(true); | ||
KinveyAuthRequest request = (KinveyAuthRequest) kinveyAuthRequestField.get(loginRequest); | ||
Field kinveyHeadersField = request.getClass().getDeclaredField("kinveyHeaders"); //NoSuchFieldException | ||
kinveyHeadersField.setAccessible(true); | ||
KinveyHeaders kinveyHeaders = (KinveyHeaders) kinveyHeadersField.get(request); | ||
String clientAppVersionHeader = (String) kinveyHeaders.get("X-Kinvey-Client-App-Version"); | ||
assertEquals(clientAppVersion, clientAppVersionHeader); | ||
} | ||
|
||
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. Please also add a test case to verify that if clientAppVersion is not set, that the X-Kinvey-Client-App-Version header is not added to the request. 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. Added |
||
private KinveyAuthRequest.Builder createBuilder(AbstractClient client) { | ||
String appKey = ((KinveyClientRequestInitializer) client.getKinveyRequestInitializer()).getAppKey(); | ||
String appSecret = ((KinveyClientRequestInitializer) client.getKinveyRequestInitializer()).getAppSecret(); | ||
|
||
return new KinveyAuthRequest.Builder(client.getRequestFactory().getTransport(), | ||
client.getJsonFactory(), client.getBaseUrl(), appKey, appSecret, null); | ||
} | ||
|
||
} |
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.
We should only be setting the X-Kinvey-Client-App-Version header if the clientAppVersion has been set by the developer. If the clientAppVersion is null or empty, the header should not be added.
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.
Updated