Skip to content

Commit

Permalink
Merge pull request #306 from ForgeRock/SDKS-3373
Browse files Browse the repository at this point in the history
SDKS-3373 - ReCaptcha e2e test cases
  • Loading branch information
spetrov authored Oct 2, 2024
2 parents 68b7749 + db44623 commit 08ec08d
Show file tree
Hide file tree
Showing 8 changed files with 480 additions and 29 deletions.
4 changes: 4 additions & 0 deletions FRAuth/FRAuth.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
3A67B8832AD83946003331C5 /* FRAppIntegrityKeys.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A67B8822AD83946003331C5 /* FRAppIntegrityKeys.swift */; };
3A6D26672A1345400099D877 /* PolicyAdviceCreator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A6D26662A1345400099D877 /* PolicyAdviceCreator.swift */; };
3AB062FA2AE6224D00C4B47C /* FRAppIntegrityKeysTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AB062F92AE6224D00C4B47C /* FRAppIntegrityKeysTests.swift */; };
9527F63F2CA32942008475B7 /* AA_12_ReCaptchaEnterpriseCallbackTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9527F63E2CA32942008475B7 /* AA_12_ReCaptchaEnterpriseCallbackTest.swift */; };
9536C56C2B865DD600B2DFDD /* AA_08_TextInputCallbackTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9536C56B2B865DD600B2DFDD /* AA_08_TextInputCallbackTest.swift */; };
959D7D98290B4B9200A1F22F /* AA-05-DeviceBindingCallbackTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 959D7D97290B4B9200A1F22F /* AA-05-DeviceBindingCallbackTest.swift */; };
95A812F02C516FC4001CDFCB /* AA_11_TextOutputCallbackTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95A812EF2C516FC4001CDFCB /* AA_11_TextOutputCallbackTest.swift */; };
Expand Down Expand Up @@ -363,6 +364,7 @@
3A67B8822AD83946003331C5 /* FRAppIntegrityKeys.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FRAppIntegrityKeys.swift; sourceTree = "<group>"; };
3A6D26662A1345400099D877 /* PolicyAdviceCreator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PolicyAdviceCreator.swift; sourceTree = "<group>"; };
3AB062F92AE6224D00C4B47C /* FRAppIntegrityKeysTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FRAppIntegrityKeysTests.swift; sourceTree = "<group>"; };
9527F63E2CA32942008475B7 /* AA_12_ReCaptchaEnterpriseCallbackTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AA_12_ReCaptchaEnterpriseCallbackTest.swift; sourceTree = "<group>"; };
9536C56B2B865DD600B2DFDD /* AA_08_TextInputCallbackTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AA_08_TextInputCallbackTest.swift; sourceTree = "<group>"; };
959D7D97290B4B9200A1F22F /* AA-05-DeviceBindingCallbackTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AA-05-DeviceBindingCallbackTest.swift"; sourceTree = "<group>"; };
95A812EF2C516FC4001CDFCB /* AA_11_TextOutputCallbackTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AA_11_TextOutputCallbackTest.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1223,6 +1225,7 @@
95EB7E4C2B8D010B00B59CD6 /* AA_09_PingOneProtectInitializeCallbackTest.swift */,
95EB7E522B8D5F6100B59CD6 /* AA_10_PingOneProtectEvaluateCallbackTest.swift */,
95A812EF2C516FC4001CDFCB /* AA_11_TextOutputCallbackTest.swift */,
9527F63E2CA32942008475B7 /* AA_12_ReCaptchaEnterpriseCallbackTest.swift */,
);
path = "Callback-Live";
sourceTree = "<group>";
Expand Down Expand Up @@ -1975,6 +1978,7 @@
D5791BD125F87DE8004B487A /* FRDeviceCollectorTests.swift in Sources */,
D5791BD225F87DE8004B487A /* AuthErrorTests.swift in Sources */,
D5791BD325F87DE8004B487A /* ConfigErrorTests.swift in Sources */,
9527F63F2CA32942008475B7 /* AA_12_ReCaptchaEnterpriseCallbackTest.swift in Sources */,
D5791BD425F87DE8004B487A /* TokenErrorTests.swift in Sources */,
D5791BD525F87DE8004B487A /* AuthApiErrorTests.swift in Sources */,
D5791BD625F87DE8004B487A /* BrowserErrorTests.swift in Sources */,
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/* Begin PBXBuildFile section */
1BA9F00B2C755B390033651D /* FRCaptchaEnterprise.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1BA9F0002C755B390033651D /* FRCaptchaEnterprise.framework */; };
1BA9F0102C755B390033651D /* FRCaptchaEnterpriseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1BA9F00F2C755B390033651D /* FRCaptchaEnterpriseTests.swift */; };
1BA9F0102C755B390033651D /* ReCaptchaEnterpriseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1BA9F00F2C755B390033651D /* ReCaptchaEnterpriseTests.swift */; };
1BA9F0112C755B390033651D /* FRCaptchaEnterprise.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BA9F0032C755B390033651D /* FRCaptchaEnterprise.h */; settings = {ATTRIBUTES = (Public, ); }; };
1BA9F02F2C755EB90033651D /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 1BA9F02E2C755EAD0033651D /* PrivacyInfo.xcprivacy */; };
1BE1B7AF2C767C5800B12207 /* ReCaptchaEnterpriseCallback.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1BE1B7AE2C767C5800B12207 /* ReCaptchaEnterpriseCallback.swift */; };
Expand Down Expand Up @@ -121,7 +121,7 @@
1BA9F0002C755B390033651D /* FRCaptchaEnterprise.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = FRCaptchaEnterprise.framework; sourceTree = BUILT_PRODUCTS_DIR; };
1BA9F0032C755B390033651D /* FRCaptchaEnterprise.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FRCaptchaEnterprise.h; sourceTree = "<group>"; };
1BA9F00A2C755B390033651D /* FRCaptchaEnterpriseTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = FRCaptchaEnterpriseTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
1BA9F00F2C755B390033651D /* FRCaptchaEnterpriseTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FRCaptchaEnterpriseTests.swift; sourceTree = "<group>"; };
1BA9F00F2C755B390033651D /* ReCaptchaEnterpriseTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReCaptchaEnterpriseTests.swift; sourceTree = "<group>"; };
1BA9F02E2C755EAD0033651D /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
1BE1B7AE2C767C5800B12207 /* ReCaptchaEnterpriseCallback.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReCaptchaEnterpriseCallback.swift; sourceTree = "<group>"; };
1BE1B7B12C767EB400B12207 /* FRAuth.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = FRAuth.xcodeproj; path = ../FRAuth/FRAuth.xcodeproj; sourceTree = "<group>"; };
Expand Down Expand Up @@ -246,7 +246,7 @@
isa = PBXGroup;
children = (
1BE1B8212C76B9BE00B12207 /* SharedTestFiles */,
1BA9F00F2C755B390033651D /* FRCaptchaEnterpriseTests.swift */,
1BA9F00F2C755B390033651D /* ReCaptchaEnterpriseTests.swift */,
);
path = FRCaptchaEnterpriseTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -674,7 +674,7 @@
1BE1B85D2C76B9BF00B12207 /* FRTestNetworkStubProtocol.swift in Sources */,
1BE1B85F2C76B9BF00B12207 /* FRTestUtils.swift in Sources */,
1BE1B8222C76B9BE00B12207 /* FRAuthBaseTest.swift in Sources */,
1BA9F0102C755B390033651D /* FRCaptchaEnterpriseTests.swift in Sources */,
1BA9F0102C755B390033651D /* ReCaptchaEnterpriseTests.swift in Sources */,
1BE1B85E2C76B9BF00B12207 /* FRTestStubResponseParser.swift in Sources */,
1BE1B82C2C76B9BE00B12207 /* CustomCallback.swift in Sources */,
);
Expand Down Expand Up @@ -964,7 +964,7 @@
repositoryURL = "https://github.com/GoogleCloudPlatform/recaptcha-enterprise-mobile-sdk";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 18.5.1;
minimumVersion = 18.6.0;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class ReCaptchaEnterpriseCallback: MultipleValuesCallback {
public private(set) var recaptchaSiteKey: String = String()
/// Token input key in callback response
public private(set) var tokenKey: String = String()
/// Token result
public private(set) var tokenResult: String = String()
/// Action input key in callback response
public private(set) var actionKey: String = String()
/// Client Error input key in callback response
Expand Down Expand Up @@ -99,12 +101,14 @@ public class ReCaptchaEnterpriseCallback: MultipleValuesCallback {
public func execute(action: String = "login",
timeoutInMillis: Double = 15000, recaptchaProvider: RecaptchaClientProvider = DefaultRecaptchaClientProvider()) async throws {
do {
let recaptchaClient: RecaptchaClient? = try await recaptchaProvider.getClient(withSiteKey: recaptchaSiteKey, withTimeout: timeoutInMillis)
let action = RecaptchaAction(customAction: action)
let token: String? = try await recaptchaProvider.execute(recaptchaClient: recaptchaClient, action: action, timeout: timeoutInMillis)
let recaptchaClient: RecaptchaClient? = try await recaptchaProvider.fetchClient(withSiteKey: recaptchaSiteKey)
let recaptchaAction = RecaptchaAction(customAction: action)
let token: String? = try await recaptchaProvider.execute(recaptchaClient: recaptchaClient, action: recaptchaAction, timeout: timeoutInMillis)
guard let result = token else {
throw NSError(domain: CaptchaConstant.domain, code: 1, userInfo: [NSLocalizedDescriptionKey: CaptchaConstant.invalidToken])
}
self.setAction(action)
self.tokenResult = result
self.setToken(result)
}
catch {
Expand Down Expand Up @@ -137,7 +141,7 @@ public class ReCaptchaEnterpriseCallback: MultipleValuesCallback {

/// Sets `action` value for the ReCAPTCHA in callback response
/// - Parameter value: String value of `action`
public func setAction(_ value: String) {
internal func setAction(_ value: String) {
self.inputValues[self.actionKey] = value
}

Expand All @@ -147,9 +151,9 @@ public class ReCaptchaEnterpriseCallback: MultipleValuesCallback {
self.inputValues[self.clientErrorKey] = value
}

/// Sets `additionalJson` value for the ReCAPTCHA in callback response
/// Sets additional payload value for the ReCAPTCHA in callback response
/// - Parameter value: Dictionary value of `additionalJson`
public func setAdditionalJson(_ value: [String: Any]? = nil) {
public func setPayload(_ value: [String: Any]? = nil) {
if let payload = value, !payload.isEmpty {
self.inputValues[self.payloadKey] = JSONStringify(value: payload)
}
Expand All @@ -160,10 +164,9 @@ public class ReCaptchaEnterpriseCallback: MultipleValuesCallback {
// MARK: - RecaptchaClientProvider
@available(iOS 13, *)
public protocol RecaptchaClientProvider {
/// Get RecaptchaClient with given siteKey and timeout
/// Fetch RecaptchaClient with given siteKey
/// - Parameter siteKey: String value of siteKey
/// - Parameter timeout: Double value of timeout
func getClient(withSiteKey siteKey: String, withTimeout timeout: Double) async throws -> RecaptchaClient?
func fetchClient(withSiteKey siteKey: String) async throws -> RecaptchaClient?

/// Execute RecaptchaClient with given action and timeout
/// - Parameter recaptchaClient: RecaptchaClient instance
Expand All @@ -175,11 +178,10 @@ public protocol RecaptchaClientProvider {
@available(iOS 13, *)
public struct DefaultRecaptchaClientProvider: RecaptchaClientProvider {
public init(){}
/// Get RecaptchaClient with given siteKey and timeout
/// Fetch RecaptchaClient with given siteKey and timeout
/// - Parameter siteKey: String value of siteKey
/// - Parameter timeout: Double value of timeout
public func getClient(withSiteKey siteKey: String, withTimeout timeout: Double) async throws -> RecaptchaClient? {
return try await Recaptcha.getClient(withSiteKey: siteKey, withTimeout: timeout)
public func fetchClient(withSiteKey siteKey: String) async throws -> RecaptchaClient? {
return try await Recaptcha.fetchClient(withSiteKey: siteKey)
}

/// Execute RecaptchaClient with given action and timeout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import XCTest
@testable import FRAuth

@available(iOS 13, *)
final class FRCaptchaEnterpriseTests: FRAuthBaseTest {
final class ReCaptchaEnterpriseTests: FRAuthBaseTest {

var mockProvider: MockRecaptchaClientProvider!

Expand Down Expand Up @@ -183,7 +183,6 @@ final class FRCaptchaEnterpriseTests: FRAuthBaseTest {

// Verify captured parameters
XCTAssertEqual(mockProvider.capturedSiteKey, "siteKey")
XCTAssertEqual(mockProvider.capturedClientTimeout, 15000)
XCTAssertEqual(mockProvider.capturedAction?.action, nil)
}

Expand Down Expand Up @@ -268,7 +267,7 @@ final class FRCaptchaEnterpriseTests: FRAuthBaseTest {

// Test case 1: Set valid JSON payload
let validJson: [String: Any] = ["key": "value"]
callback.setAdditionalJson(validJson)
callback.setPayload(validJson)
XCTAssertTrue((callback.inputValues[callback.payloadKey] as! String).contains("value"))

}
Expand All @@ -280,15 +279,13 @@ final class FRCaptchaEnterpriseTests: FRAuthBaseTest {
let callbackResponse = self.parseStringToDictionary(jsonStr)
let callback = try ReCaptchaEnterpriseCallback(json: callbackResponse)


// Test case 1: Set valid JSON payload
let action = "login_test"
callback.setAction(action)
callback.setClientError("customClientError")

XCTAssertEqual(callback.inputValues[callback.actionKey] as? String, "login_test")
XCTAssertEqual(callback.inputValues[callback.clientErrorKey] as? String, "customClientError")

}

}
Expand All @@ -307,10 +304,9 @@ class MockRecaptchaClientProvider: RecaptchaClientProvider {
var capturedClientTimeout: Double?
var capturedAction: RecaptchaAction?

func getClient(withSiteKey siteKey: String, withTimeout timeout: Double) async throws -> RecaptchaClient? {
func fetchClient(withSiteKey siteKey: String) async throws -> RecaptchaClient? {

capturedSiteKey = siteKey
capturedClientTimeout = timeout

if let error = shouldThrowErrorIntialization {
throw error
Expand All @@ -320,6 +316,7 @@ class MockRecaptchaClientProvider: RecaptchaClientProvider {

func execute(recaptchaClient: RecaptchaClient?, action: RecaptchaAction, timeout: Double) async throws -> String? {
capturedAction = action
capturedClientTimeout = timeout
if let shouldthrowError = shouldthrowError {
throw shouldthrowError
}
Expand Down
2 changes: 1 addition & 1 deletion FRTestHost/FRTestHost/FRAuthConfigPKHash.plist
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<string>signUp</string>
<key>forgerock_ssl_pinning_public_key_hashes</key>
<array>
<string>IFG+z/oQKXfpUYOHgWHy5axgkT9B01XSxwb2AHDyN34=</string>
<string>C5+lpZ7tcVwmwQIMcRtPbsQtWLABXhQzejna0wHFr8M=</string>
<string>7wkd0YUvyMiF/H74I7FLGYVcIsb8eFDhjA8Aqq0S2+U=</string>
<string>QqdOOH5lPT79vRggY1h13mgwQ1CJTaAi8oLkuKZnk74=</string>
</array>
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let package = Package (
.package(name: "GoogleSignIn", url: "https://github.com/google/GoogleSignIn-iOS.git", .upToNextMinor(from: "7.1.0")),
.package(name: "JOSESwift", url: "https://github.com/airsidemobile/JOSESwift.git", .upToNextMinor(from: "2.4.0")),
.package(name: "PingOneSignals", url: "https://github.com/pingidentity/pingone-signals-sdk-ios.git", .upToNextMinor(from: "5.2.3")),
.package(name: "RecaptchaEnterprise", url: "https://github.com/GoogleCloudPlatform/recaptcha-enterprise-mobile-sdk.git", .upToNextMinor(from: "18.5.1"))
.package(name: "RecaptchaEnterprise", url: "https://github.com/GoogleCloudPlatform/recaptcha-enterprise-mobile-sdk.git", .upToNextMinor(from: "18.6.0"))
],
targets: [
.target(name: "cFRCore", dependencies: [], path: "FRCore/FRCore/SharedC/Sources"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/GoogleCloudPlatform/recaptcha-enterprise-mobile-sdk",
"state" : {
"revision" : "742de2369422c0e5395205b9215b6b7228dc206a",
"version" : "18.5.1"
"revision" : "e1890d87d0aa0780baa38f46bf09db3630bd0beb",
"version" : "18.6.0"
}
}
],
Expand Down

0 comments on commit 08ec08d

Please sign in to comment.