Skip to content

Commit

Permalink
fix(config): serialization crash (#97)
Browse files Browse the repository at this point in the history
* bugfix: HCaptchaConfig serialization crash #94

* bump version 3.5.1
  • Loading branch information
CAMOBAP committed Mar 7, 2023
1 parent 367fe1f commit f2498b5
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

# 3.5.1

- Bugfix: Parcelable encountered IOException writing serializable object (name = com.hcaptcha.sdk.HCaptchaConfig) ([#94](https://github.com/hCaptcha/hcaptcha-android-sdk/issues/94))

# 3.5.0

- Deprecated: `HCaptchaConfig.apiEndpoint` replaced with `HCaptchaConfig.jsSrc` option
Expand Down
4 changes: 2 additions & 2 deletions sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ android {
// See https://developer.android.com/studio/publish/versioning
// versionCode must be integer and be incremented by one for every new update
// android system uses this to prevent downgrades
versionCode 27
versionCode 28

// version number visible to the user
// should follow semantic versioning (See https://semver.org)
versionName "3.5.0"
versionName "3.5.1"

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import android.util.AndroidRuntimeException;
import android.view.LayoutInflater;
import androidx.fragment.app.testing.FragmentScenario;
import androidx.lifecycle.Lifecycle;
import androidx.test.espresso.web.webdriver.DriverAtoms;
import androidx.test.espresso.web.webdriver.Locator;
import androidx.test.ext.junit.runners.AndroidJUnit4;
Expand Down Expand Up @@ -264,4 +265,42 @@ void onFailure(HCaptchaException exception) {

assertTrue(failureLatch.await(AWAIT_CALLBACK_MS, TimeUnit.MILLISECONDS));
}

@Test
public void testPauseResumeFragment() throws Exception {
final CountDownLatch successLatch = new CountDownLatch(1);
final HCaptchaStateListener listener = new HCaptchaStateTestAdapter() {

@Override
void onSuccess(String token) {
successLatch.countDown();
}
};

final FragmentScenario<HCaptchaDialogFragment> scenario = launchCaptchaFragment(config, listener);
scenario.moveToState(Lifecycle.State.STARTED).moveToState(Lifecycle.State.RESUMED);

waitHCaptchaWebViewToken(successLatch, AWAIT_CALLBACK_MS);

assertTrue(successLatch.await(AWAIT_CALLBACK_MS, TimeUnit.MILLISECONDS));
}

@Test
public void testActivityRecreate() throws Exception {
final CountDownLatch successLatch = new CountDownLatch(1);
final HCaptchaStateListener listener = new HCaptchaStateTestAdapter() {

@Override
void onSuccess(String token) {
successLatch.countDown();
}
};

final FragmentScenario<HCaptchaDialogFragment> scenario = launchCaptchaFragment(config, listener);
scenario.recreate();

waitHCaptchaWebViewToken(successLatch, AWAIT_CALLBACK_MS);

assertTrue(successLatch.await(AWAIT_CALLBACK_MS, TimeUnit.MILLISECONDS));
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.hcaptcha.sdk;

import java.io.Serializable;

/**
* On failure retry decider class
*/
@FunctionalInterface
public interface IHCaptchaRetryPredicate {
public interface IHCaptchaRetryPredicate extends Serializable {

/**
* Allows retrying in case of verification errors.
Expand Down
18 changes: 18 additions & 0 deletions sdk/src/test/java/com/hcaptcha/sdk/HCaptchaConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

import org.junit.Test;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Locale;

public class HCaptchaConfigTest {
Expand Down Expand Up @@ -63,5 +67,19 @@ public void custom_config() {
assertEquals(customTheme, config.getCustomTheme());
}

@Test
public void serialization() throws Exception {
final HCaptchaConfig config = HCaptchaConfig.builder().siteKey(MOCK_SITE_KEY).build();

final ByteArrayOutputStream bos = new ByteArrayOutputStream();
final ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(config);
final ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
final ObjectInputStream ois = new ObjectInputStream(bis);
final HCaptchaConfig deserializedObject = (HCaptchaConfig) ois.readObject();

assertEquals(config.toBuilder().retryPredicate(null).build(),
deserializedObject.toBuilder().retryPredicate(null).build());
}

}

0 comments on commit f2498b5

Please sign in to comment.