Skip to content

Commit

Permalink
Merge pull request #308 from ForgeRock/DeviceBinding-None-Simulators
Browse files Browse the repository at this point in the history
Allowing DeviceBinding `NONE` option on Simulators
  • Loading branch information
spetrov authored Oct 11, 2024
2 parents d72d6f7 + f079ea9 commit 0feb747
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,6 @@ class AA_05_DeviceBindingCallbackTest: CallbackBaseTest {
ex.fulfill()
})
waitForExpectations(timeout: 60, handler: nil)
if isSimulator {
XCTAssertEqual(bindingResult, "DeviceBinding/Signing is not supported on the iOS Simulator")
return
}

XCTAssertEqual(bindingResult, "Success")

Expand Down Expand Up @@ -301,10 +297,7 @@ class AA_05_DeviceBindingCallbackTest: CallbackBaseTest {
})
waitForExpectations(timeout: 60, handler: nil)

if isSimulator {
XCTAssertEqual(bindingResult, "DeviceBinding/Signing is not supported on the iOS Simulator")
return
}

XCTAssertEqual(bindingResult, "Success")

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,7 @@ class AA_06_DeviceSigningVerifierCallbackTest: CallbackBaseTest {
ex.fulfill()
})
waitForExpectations(timeout: 60, handler: nil)
if isSimulator {
XCTAssertEqual(singningResult, DeviceBindingStatus.clientNotRegistered.errorMessage)
return
}

XCTAssertEqual(singningResult, "Success")
}
else {
Expand Down Expand Up @@ -294,10 +291,7 @@ class AA_06_DeviceSigningVerifierCallbackTest: CallbackBaseTest {
ex.fulfill()
})
waitForExpectations(timeout: 60, handler: nil)
if isSimulator {
XCTAssertEqual(singningResult, DeviceBindingStatus.clientNotRegistered.errorMessage)
return
}

XCTAssertEqual(singningResult, "Success")
}
else {
Expand Down Expand Up @@ -370,10 +364,7 @@ class AA_06_DeviceSigningVerifierCallbackTest: CallbackBaseTest {
ex.fulfill()
})
waitForExpectations(timeout: 60, handler: nil)
if isSimulator {
XCTAssertEqual(singningResult, DeviceBindingStatus.clientNotRegistered.errorMessage)
return
}

XCTAssertEqual(singningResult, "Authentication Timeout")
}
else {
Expand Down Expand Up @@ -719,10 +710,7 @@ class AA_06_DeviceSigningVerifierCallbackTest: CallbackBaseTest {
ex.fulfill()
})
waitForExpectations(timeout: 60, handler: nil)
if isSimulator {
XCTAssertEqual(bindingResult, "DeviceBinding/Signing is not supported on the iOS Simulator")
return
}

XCTAssertEqual(bindingResult, "Success")
}
else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//
//
// DeviceBindingCallback.swift
// FRDeviceBinding
//
Expand Down Expand Up @@ -170,11 +170,14 @@ open class DeviceBindingCallback: MultipleValuesCallback, Binding {
deviceRepository: DeviceBindingRepository = LocalDeviceBindingRepository(),
prompt: Prompt? = nil,
_ completion: @escaping DeviceBindingResultCallback) {
if deviceBindingAuthenticationType != .none {
#if targetEnvironment(simulator)
// DeviceBinding/Signing is not supported on the iOS Simulator
handleException(status: .unsupported(errorMessage: "DeviceBinding/Signing is not supported on the iOS Simulator"), completion: completion)
return
// DeviceBinding/Signing other than `.NONE` type is not supported on the iOS Simulator
handleException(status: .unsupported(errorMessage: "DeviceBinding/Signing is not supported on the iOS Simulator"), completion: completion)
return
#endif
}

let authInterface = authInterface ?? getDeviceAuthenticator(type: deviceBindingAuthenticationType)
authInterface.initialize(userId: userId, prompt: prompt ?? Prompt(title: title, subtitle: subtitle, description: promptDescription))
let deviceId = deviceId ?? FRDevice.currentDevice?.identifier.getIdentifier()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,15 @@ open class DeviceSigningVerifierCallback: MultipleValuesCallback, Binding {
customClaims: [String: Any] = [:],
prompt: Prompt? = nil,
_ completion: @escaping DeviceSigningResultCallback) {

if userKey.authType != .none {
#if targetEnvironment(simulator)
// DeviceBinding/Signing is not supported on the iOS Simulator
handleException(status: .unsupported(errorMessage: "DeviceBinding/Signing is not supported on the iOS Simulator"), completion: completion)
return
// DeviceBinding/Signing other than `.NONE` type is not supported on the iOS Simulator
handleException(status: .unsupported(errorMessage: "DeviceBinding/Signing is not supported on the iOS Simulator"), completion: completion)
return
#endif
}

authInterface.initialize(userId: userKey.userId, prompt: prompt ?? Prompt(title: title, subtitle: subtitle, description: promptDescription))
guard authInterface.isSupported() else {
handleException(status: .unsupported(errorMessage: nil), completion: completion)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,10 +625,7 @@ class DeviceBindingCallbackTests: FRAuthBaseTest {
case .success:
XCTFail("Callback Execute succeeded instead of timeout")
case .failure(let error):
if self.isSimulator {
XCTAssertEqual(error.errorMessage, "DeviceBinding/Signing is not supported on the iOS Simulator")
return
}

XCTAssertEqual(error.clientError, DeviceBindingStatus.timeout.clientError)
XCTAssertTrue(callback.inputValues.count == 1)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,11 +538,7 @@ class DeviceSigningVerifierCallbackTests: FRAuthBaseTest {
case .success:
XCTAssertTrue(callback.inputValues.count == 1)
case .failure(let error):
if self.isSimulator {
XCTAssertEqual(error.errorMessage, "DeviceBinding/Signing is not supported on the iOS Simulator")
} else {
XCTFail("Callback Execute failed: \(error.errorMessage)")
}
XCTFail("Callback Execute failed: \(error.errorMessage)")
}
}
}
Expand Down Expand Up @@ -578,12 +574,8 @@ class DeviceSigningVerifierCallbackTests: FRAuthBaseTest {
case .success:
XCTFail("Callback Execute succeeded instead of timeout")
case .failure(let error):
if self.isSimulator {
XCTAssertEqual(error.errorMessage, "DeviceBinding/Signing is not supported on the iOS Simulator")
} else {
XCTAssertEqual(error.clientError, DeviceBindingStatus.timeout.clientError)
XCTAssertTrue(callback.inputValues.count == 1)
}
XCTAssertEqual(error.clientError, DeviceBindingStatus.timeout.clientError)
XCTAssertTrue(callback.inputValues.count == 1)
}
}
}
Expand Down Expand Up @@ -670,11 +662,7 @@ class DeviceSigningVerifierCallbackTests: FRAuthBaseTest {
case .success:
XCTAssertTrue(callback.inputValues.count == 1)
case .failure(let error):
if self.isSimulator {
XCTAssertEqual(error.errorMessage, "DeviceBinding/Signing is not supported on the iOS Simulator")
} else {
XCTFail("Callback Execute failed: \(error.errorMessage)")
}
XCTFail("Callback Execute failed: \(error.errorMessage)")
}
}
}
Expand Down Expand Up @@ -713,12 +701,8 @@ class DeviceSigningVerifierCallbackTests: FRAuthBaseTest {
case .success:
XCTFail("Callback bind succeeded instead of unsupported (invalid custom cliams)")
case .failure(let error):
if self.isSimulator {
XCTAssertEqual(error.errorMessage, "DeviceBinding/Signing is not supported on the iOS Simulator")
} else {
XCTAssertEqual(error.clientError, DeviceBindingStatus.invalidCustomClaims.clientError)
XCTAssertTrue(callback.inputValues.count == 1)
}
XCTAssertEqual(error.clientError, DeviceBindingStatus.invalidCustomClaims.clientError)
XCTAssertTrue(callback.inputValues.count == 1)
}
}
}
Expand Down Expand Up @@ -860,12 +844,8 @@ class DeviceSigningVerifierCallbackTests: FRAuthBaseTest {
XCTFail("Callback bind succeeded instead of unsupported (invalid custom cliams)")
case .failure(let error):
// even though we don't overrid any of the existing claims, it fails as validateCustomClaims method always returns false
if self.isSimulator {
XCTAssertEqual(error.errorMessage, "DeviceBinding/Signing is not supported on the iOS Simulator")
} else {
XCTAssertEqual(error, DeviceBindingStatus.invalidCustomClaims)
XCTAssertTrue(callback.inputValues.count == 1)
}
XCTAssertEqual(error, DeviceBindingStatus.invalidCustomClaims)
XCTAssertTrue(callback.inputValues.count == 1)
}
expectation.fulfill()
}
Expand Down

0 comments on commit 0feb747

Please sign in to comment.