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

Allowing DeviceBinding NONE option on Simulators #308

Merged
merged 3 commits into from
Oct 11, 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 @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add some tests for this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests were failing and fixed based on that

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add some tests for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests were failing and fixed based on that

Copy link
Contributor

@jeyanthanperiyasamy jeyanthanperiyasamy Oct 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry didnt notice this test class update, when I add my comment, and at the same time u pushed.

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
Loading