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

SDKS-3373 - ReCaptcha e2e test cases #452

Merged
merged 1 commit into from
Oct 1, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,20 @@ class ReCaptchaEnterpriseCallback : AbstractCallback {
lateinit var reCaptchaSiteKey: String
private set

/**
* Retrieves the token result.
*
* @return the token result.
*/
lateinit var tokenResult: String
private set

companion object {
private val TAG = ReCaptchaEnterpriseCallback::class.java.simpleName
private const val INVALID_CAPTCHA_TOKEN = "INVALID_CAPTCHA_TOKEN"
private const val UNKNOWN_ERROR = "UNKNOWN_ERROR"
}


@Keep
@JvmOverloads
constructor()
Expand All @@ -59,15 +66,6 @@ class ReCaptchaEnterpriseCallback : AbstractCallback {
super.setValue(value, 0)
}

/**
* Set the Action for the ReCAPTCHA
*
* @param value The Action
*/
fun setAction(value: String) {
super.setValue(value, 1)
}

/**
* Input the Client Error to the server
* @param value Error String.
Expand All @@ -85,6 +83,15 @@ class ReCaptchaEnterpriseCallback : AbstractCallback {
super.setValue(value.toString(), 3)
}

/**
* Set the Action for the ReCAPTCHA
*
* @param value The Action
*/
private fun setAction(value: String) {
super.setValue(value, 1)
}

override fun getType(): String {
return "ReCaptchaEnterpriseCallback"
}
Expand All @@ -111,7 +118,9 @@ class ReCaptchaEnterpriseCallback : AbstractCallback {
if (token == null) {
throw Exception(INVALID_CAPTCHA_TOKEN)
}
tokenResult = token
setValue(token)
setAction(action)
}
catch (e: Exception) {
Logger.error(TAG, e.message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import org.mockito.kotlin.whenever
@RunWith(AndroidJUnit4::class)
class ReCaptchaEnterpriseCallbackTest {

val application: Application = ApplicationProvider.getApplicationContext()
private val application: Application = ApplicationProvider.getApplicationContext()

private lateinit var callback: ReCaptchaEnterpriseCallback

Expand Down Expand Up @@ -98,7 +98,7 @@ class ReCaptchaEnterpriseCallbackTest {
verify(recaptchaClientProvider).execute(recaptchaClient, RecaptchaAction.custom("login"), 15000L)

assert(callback.content.contains("test-token"))

assert(callback.tokenResult == "test-token")
}

@Test
Expand Down Expand Up @@ -153,16 +153,15 @@ class ReCaptchaEnterpriseCallbackTest {
)
whenever(recaptchaClientProvider.execute(any(), any<RecaptchaAction>(), anyLong())).thenReturn("test-token")

callback.execute(application, "login", 15000L, recaptchaClientProvider)
callback.execute(application, "custom-action", 15000L, recaptchaClientProvider)

callback.setPayload(JSONObject().put("key", "value"))
callback.setAction("custom-action")

verify(recaptchaClientProvider).fetchClient(
application,
"6Lf3tbYUAAAAAEm78fAOFRKb-n1M67FDtmpczIBK"
)
verify(recaptchaClientProvider).execute(recaptchaClient, RecaptchaAction.custom("login"), 15000L)
verify(recaptchaClientProvider).execute(recaptchaClient, RecaptchaAction.custom("custom-action"), 15000L)

assert(callback.content.contains("test-token"))
assert(callback.content.contains("key"))
Expand Down
5 changes: 5 additions & 0 deletions forgerock-integration-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,16 @@ dependencies {
androidTestImplementation(libs.androidx.biometric.ktx)
androidTestImplementation(libs.nimbus.jose.jwt)
androidTestImplementation(libs.okhttp)
androidTestImplementation(libs.kotlinx.coroutines.test)

//For Application Pin
androidTestImplementation(libs.bcpkix.jdk15on)
androidTestImplementation(libs.androidx.security.crypto)

//App Integrity
androidTestImplementation(libs.integrity)

// Captcha
androidTestImplementation(libs.play.services.safetynet)
androidTestImplementation(libs.recaptchaEnterprise)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (c) 2024 ForgeRock. All rights reserved.
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
package org.forgerock.android.auth.callback

import android.app.Application
import android.content.Context
import androidx.test.core.app.ApplicationProvider
import org.forgerock.android.auth.FRAuth
import org.forgerock.android.auth.FROptionsBuilder
import org.forgerock.android.auth.FRSession
import org.forgerock.android.auth.Logger
import org.forgerock.android.auth.Logger.Companion.set
import org.junit.After
import org.junit.BeforeClass

/**
* e2e tests for [ReCaptchaEnterpriseCallback]
*/
open class ReCaptchaEnterpriseCallbackBaseTest {
@After
fun logoutSession() {
if (FRSession.getCurrentSession() != null) {
FRSession.getCurrentSession().logout()
}
}

companion object {
val context: Context = ApplicationProvider.getApplicationContext()
val application: Application = ApplicationProvider.getApplicationContext()

protected const val AM_URL: String = "https://openam-recaptcha.forgeblocks.com/am"
protected const val REALM: String = "alpha"
protected const val OAUTH_CLIENT: String = "AndroidTest"
protected const val OAUTH_REDIRECT_URI: String = "org.forgerock.demo:/oauth2redirect"
protected const val SCOPE: String = "openid profile email address phone"
const val TREE: String = "TEST-e2e-recaptcha-enterprise"
const val USERNAME: String = "sdkuser"
const val RECAPTCHA_SITE_KEY: String = "6LfAykUqAAAAAE6aZOg9pNiS3XduyGZ5y-8U-z8B"

@JvmStatic
@BeforeClass
fun setUpSDK(): Unit {
set(Logger.Level.DEBUG)

val options = FROptionsBuilder.build {
server {
url = AM_URL
cookieName = "b431aeda2ba0e98"
realm = REALM
}
oauth {
oauthClientId = OAUTH_CLIENT
oauthRedirectUri = OAUTH_REDIRECT_URI
oauthCacheSeconds = 0
oauthScope = SCOPE
}
service {
authServiceName = TREE
}
}

FRAuth.start(context, options)
}
}
}




Loading
Loading