Skip to content

Commit

Permalink
SDKS-3372 - ReCaptcha e2e test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
spetrov committed Sep 25, 2024
1 parent 56d157e commit 2ad0d30
Show file tree
Hide file tree
Showing 8 changed files with 687 additions and 12 deletions.
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 @@ -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
6 changes: 6 additions & 0 deletions forgerock-integration-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,17 @@ dependencies {
androidTestImplementation(libs.androidx.biometric.ktx)
androidTestImplementation(libs.nimbus.jose.jwt)
androidTestImplementation(libs.okhttp)
androidTestImplementation(libs.kotlinx.coroutines.test)
testImplementation(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,81 @@
/*
* 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 kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runTest
import org.assertj.core.api.Assertions
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.forgerock.android.auth.Node
import org.forgerock.android.auth.NodeListener
import org.json.JSONObject
import org.junit.After
import org.junit.Assert
import org.junit.BeforeClass
import org.junit.Test
import java.util.concurrent.ExecutionException

/**
* 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://localam.petrov.ca/openam"
protected const val REALM: String = "root"
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
realm = REALM
}
oauth {
oauthClientId = OAUTH_CLIENT
oauthRedirectUri = OAUTH_REDIRECT_URI
oauthCacheSeconds = 0
oauthScope = SCOPE
}
service {
authServiceName = TREE
}
}

FRAuth.start(context, options)
}
}
}




Loading

0 comments on commit 2ad0d30

Please sign in to comment.