test: cover native forward request boundary

This commit is contained in:
kris
2026-03-28 08:33:08 +08:00
parent 13c67425ab
commit 200fc18210
2 changed files with 240 additions and 5 deletions

View File

@@ -33,8 +33,12 @@ public class BossApiClient {
private final String baseUrl;
public BossApiClient(Context context) {
this.prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
this.baseUrl = BuildConfig.BOSS_API_BASE_URL;
this(context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE), BuildConfig.BOSS_API_BASE_URL);
}
BossApiClient(SharedPreferences prefs, String baseUrl) {
this.prefs = prefs;
this.baseUrl = baseUrl;
}
public boolean hasSessionHints() {
@@ -264,7 +268,7 @@ public class BossApiClient {
}
private ApiResponse requestRaw(String method, String path, @Nullable String body, boolean expectProtected) throws IOException, JSONException {
HttpURLConnection connection = (HttpURLConnection) new URL(baseUrl + path).openConnection();
HttpURLConnection connection = openConnection(path);
connection.setRequestMethod(method);
connection.setConnectTimeout(12000);
connection.setReadTimeout(12000);
@@ -301,6 +305,10 @@ public class BossApiClient {
return new ApiResponse(statusCode, json == null ? new JSONObject() : json);
}
HttpURLConnection openConnection(String path) throws IOException {
return (HttpURLConnection) new URL(baseUrl + path).openConnection();
}
private JSONObject readJson(InputStream stream) throws IOException, JSONException {
if (stream == null) {
return new JSONObject();
@@ -339,7 +347,7 @@ public class BossApiClient {
}
}
private void rememberIdentity(JSONObject json) {
void rememberIdentity(JSONObject json) {
if (json == null) return;
JSONObject session = json.optJSONObject("session");
JSONObject source = session != null ? session : json;
@@ -370,7 +378,7 @@ public class BossApiClient {
.apply();
}
private String encode(String value) {
String encode(String value) {
return Uri.encode(value);
}