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

fix: missleading missing sitekey message #137

Merged
merged 3 commits into from
Dec 22, 2023
Merged
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
8 changes: 4 additions & 4 deletions sdk/src/main/java/com/hcaptcha/sdk/HCaptcha.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

public final class HCaptcha extends Task<HCaptchaTokenResponse> implements IHCaptcha {
public static final String META_SITE_KEY = "com.hcaptcha.sdk.site-key";
public static final String TAG = "hCaptcha";

@NonNull
private final FragmentActivity activity;
Expand Down Expand Up @@ -57,8 +56,9 @@ public HCaptcha setup() {
throw new IllegalStateException(e);
}
if (siteKey == null) {
throw new IllegalStateException("Add missing " + META_SITE_KEY + " meta-data to AndroidManifest.xml"
+ " or call getClient(context, siteKey) method");
throw new IllegalStateException("The site-key is missing. You can pass it by adding "
+ META_SITE_KEY + " as meta-data to AndroidManifest.xml "
+ "or as an argument for setup/verifyWithHCaptcha methods.");
}
return setup(siteKey);
}
Expand Down Expand Up @@ -93,7 +93,7 @@ void onFailure(final HCaptchaException exception) {
}
};
try {
if (inputConfig.getHideDialog()) {
if (Boolean.TRUE.equals(inputConfig.getHideDialog())) {
// Overwrite certain config values in case the dialog is hidden to avoid behavior collision
this.config = inputConfig.toBuilder()
.size(HCaptchaSize.INVISIBLE)
Expand Down
12 changes: 12 additions & 0 deletions sdk/src/test/java/com/hcaptcha/sdk/HCaptchaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ public void test_fragment_creation_via_activity() {
any(HCaptchaStateListener.class)));
}

@Test(expected = IllegalStateException.class)
public void test_exception_on_missing_site_key() throws Exception {
final ApplicationInfo applicationInfo = mock(ApplicationInfo.class);
applicationInfo.metaData = mock(Bundle.class);

when(fragmentActivity.getPackageName()).thenReturn(TEST_PACKAGE_NAME);
when(fragmentActivity.getPackageManager()).thenReturn(packageManager);
when(packageManager.getApplicationInfo(TEST_PACKAGE_NAME, PackageManager.GET_META_DATA))
.thenReturn(applicationInfo);
HCaptcha.getClient(fragmentActivity).setup();
}

@Test
public void test_site_key_from_metadata() throws Exception {
final ApplicationInfo applicationInfo = mock(ApplicationInfo.class);
Expand Down