Skip to content

Commit f2498b5

Browse files
authored
fix(config): serialization crash (#97)
* bugfix: HCaptchaConfig serialization crash #94 * bump version 3.5.1
1 parent 367fe1f commit f2498b5

File tree

5 files changed

+66
-3
lines changed

5 files changed

+66
-3
lines changed

CHANGES.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
# 3.5.1
4+
5+
- Bugfix: Parcelable encountered IOException writing serializable object (name = com.hcaptcha.sdk.HCaptchaConfig) ([#94](https://github.com/hCaptcha/hcaptcha-android-sdk/issues/94))
6+
37
# 3.5.0
48

59
- Deprecated: `HCaptchaConfig.apiEndpoint` replaced with `HCaptchaConfig.jsSrc` option

sdk/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ android {
2222
// See https://developer.android.com/studio/publish/versioning
2323
// versionCode must be integer and be incremented by one for every new update
2424
// android system uses this to prevent downgrades
25-
versionCode 27
25+
versionCode 28
2626

2727
// version number visible to the user
2828
// should follow semantic versioning (See https://semver.org)
29-
versionName "3.5.0"
29+
versionName "3.5.1"
3030

3131
buildConfigField 'String', 'VERSION_NAME', "\"${defaultConfig.versionName}_${defaultConfig.versionCode}\""
3232

sdk/src/androidTest/java/com/hcaptcha/sdk/HCaptchaDialogFragmentTest.java

+39
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import android.util.AndroidRuntimeException;
2929
import android.view.LayoutInflater;
3030
import androidx.fragment.app.testing.FragmentScenario;
31+
import androidx.lifecycle.Lifecycle;
3132
import androidx.test.espresso.web.webdriver.DriverAtoms;
3233
import androidx.test.espresso.web.webdriver.Locator;
3334
import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -264,4 +265,42 @@ void onFailure(HCaptchaException exception) {
264265

265266
assertTrue(failureLatch.await(AWAIT_CALLBACK_MS, TimeUnit.MILLISECONDS));
266267
}
268+
269+
@Test
270+
public void testPauseResumeFragment() throws Exception {
271+
final CountDownLatch successLatch = new CountDownLatch(1);
272+
final HCaptchaStateListener listener = new HCaptchaStateTestAdapter() {
273+
274+
@Override
275+
void onSuccess(String token) {
276+
successLatch.countDown();
277+
}
278+
};
279+
280+
final FragmentScenario<HCaptchaDialogFragment> scenario = launchCaptchaFragment(config, listener);
281+
scenario.moveToState(Lifecycle.State.STARTED).moveToState(Lifecycle.State.RESUMED);
282+
283+
waitHCaptchaWebViewToken(successLatch, AWAIT_CALLBACK_MS);
284+
285+
assertTrue(successLatch.await(AWAIT_CALLBACK_MS, TimeUnit.MILLISECONDS));
286+
}
287+
288+
@Test
289+
public void testActivityRecreate() throws Exception {
290+
final CountDownLatch successLatch = new CountDownLatch(1);
291+
final HCaptchaStateListener listener = new HCaptchaStateTestAdapter() {
292+
293+
@Override
294+
void onSuccess(String token) {
295+
successLatch.countDown();
296+
}
297+
};
298+
299+
final FragmentScenario<HCaptchaDialogFragment> scenario = launchCaptchaFragment(config, listener);
300+
scenario.recreate();
301+
302+
waitHCaptchaWebViewToken(successLatch, AWAIT_CALLBACK_MS);
303+
304+
assertTrue(successLatch.await(AWAIT_CALLBACK_MS, TimeUnit.MILLISECONDS));
305+
}
267306
}

sdk/src/main/java/com/hcaptcha/sdk/IHCaptchaRetryPredicate.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.hcaptcha.sdk;
22

3+
import java.io.Serializable;
4+
35
/**
46
* On failure retry decider class
57
*/
68
@FunctionalInterface
7-
public interface IHCaptchaRetryPredicate {
9+
public interface IHCaptchaRetryPredicate extends Serializable {
810

911
/**
1012
* Allows retrying in case of verification errors.

sdk/src/test/java/com/hcaptcha/sdk/HCaptchaConfigTest.java

+18
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
import org.junit.Test;
77

8+
import java.io.ByteArrayInputStream;
9+
import java.io.ByteArrayOutputStream;
10+
import java.io.ObjectInputStream;
11+
import java.io.ObjectOutputStream;
812
import java.util.Locale;
913

1014
public class HCaptchaConfigTest {
@@ -63,5 +67,19 @@ public void custom_config() {
6367
assertEquals(customTheme, config.getCustomTheme());
6468
}
6569

70+
@Test
71+
public void serialization() throws Exception {
72+
final HCaptchaConfig config = HCaptchaConfig.builder().siteKey(MOCK_SITE_KEY).build();
73+
74+
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
75+
final ObjectOutputStream oos = new ObjectOutputStream(bos);
76+
oos.writeObject(config);
77+
final ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
78+
final ObjectInputStream ois = new ObjectInputStream(bis);
79+
final HCaptchaConfig deserializedObject = (HCaptchaConfig) ois.readObject();
80+
81+
assertEquals(config.toBuilder().retryPredicate(null).build(),
82+
deserializedObject.toBuilder().retryPredicate(null).build());
83+
}
6684

6785
}

0 commit comments

Comments
 (0)