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

[34253] - Add AuthorizationControllerWrapper & Unit Test for TwilioPasskey iOS. #21

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

AlejandroOrozco
Copy link
Collaborator

Ticket

  • [34253]

Github Issue

  • ISSUE-

Description

  • Add AuthorizationControllerWrapper & Unit Test for TwilioPasskey iOS.

Commit message

  • [34253] - Add AuthorizationControllerWrapper & Unit Test for TwilioPasskey iOS.

Screenshot

Testing

  • Added unit tests
  • Ran unit tests successfully
  • Added documentation for public APIs and/or Wiki

@AlejandroOrozco AlejandroOrozco self-assigned this Apr 17, 2024
@AlejandroOrozco AlejandroOrozco requested a review from a team as a code owner April 17, 2024 22:16
@AlejandroOrozco AlejandroOrozco force-pushed the aorozcobuiles/ACCSEC-34253/PasskeysWrappersForUnitTests branch from e80eb42 to de93987 Compare April 18, 2024 20:10
// Then
when (result) {
is CreatePasskeyResult.Success -> {
fail("It shouldn't succeed")

Choose a reason for hiding this comment

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

⚠️ Line detected, which is longer than the defined maximum line length in the code style.

Copy link
Collaborator

Choose a reason for hiding this comment

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

looks like a false positive

@AlejandroOrozco AlejandroOrozco force-pushed the aorozcobuiles/ACCSEC-34253/PasskeysWrappersForUnitTests branch from de93987 to 375997d Compare April 18, 2024 20:27
@@ -84,7 +84,7 @@ class AuthenticationManager: NSObject, ObservableObject {
) {
Task {
do {
let result = try await worker.registrationVerification(request: .init(
_ = try await worker.registrationVerification(request: .init(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there something that can be checked in the verification response?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah definitely makes sense, I added a validation to check if the response was verified by the backend. Thank you.

"name": "Example"
},
"user": {
"id": "WUU0ZmQzYWFmNGU0NTMyNGQwZjNlMTM0NjA3YjIxOTEyYg",
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be flaged as a secret, could you please change them to a placeholder?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Definitely 😅, added Placeholder prefix just to avoid any confusion. But apart from that the length must be exact. Thank you

* @property deviceUtils The utility class for device-related operations.
*/
class AuthorizationControllerWrapper : IAuthorizationControllerWrapper {
private var authController: ASAuthorizationController? = null
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could this be a lateinit var?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done, seems way clear with that one. Thank you

@authid-sdk-ci
Copy link

1 Warning
⚠️ Big PR

Generated by 🚫 Danger

@authid-sdk-ci
Copy link

1 Warning
⚠️

Size impact

ABI APK Size Impact
x86 2MB
x86_64 2MB
armeabi-v7a 2MB
arm64-v8a 2MB
universal 2MB

Generated by 🚫 Danger

@authid-sdk-ci
Copy link

🧛 shared module Code Coverage: 96.16%

Coverage of Modified Files:

File Coverage
TwilioPasskey.kt 97.38%

Modified Files Not Found In Coverage Report:

AuthenticationManager.swift
AuthorizationControllerWrapper.kt
AuthorizationControllerWrapperMock.kt
PayloadMocks.kt
TwilioPasskeyTest.kt

Codebase cunningly covered by count Shroud 🧛

Generated by 🚫 Danger

@authid-sdk-ci
Copy link

1 Warning
⚠️ IPA size: 1.9 MB
App size: 6.6 MB
TwilioPasskeys.framework: 5.5 MB, Impact: 84.2%

Generated by 🚫 Danger

*/
actual class TwilioPasskey private constructor(
actual class TwilioPasskey internal constructor(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can mapToTwilioException be part of this class instead of the wrapper? As it is a TwilioException, this could be more related to this class and the wrapper can pass the original error

"name": "Example"
},
"user": {
"id": "PLACEHOLDERIDWUU0ZmQzYWFmNGU0NTMyNGQwZjNlMTM0N",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this be something like PLACEHOLDERID without the letters? Or can the letters be ABCD.... instead of WUU0ZmQzY.....

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The size of the userId is being validated, so it requires to have the same size, maybe we can try with PLACEHOLDERID and spaces wdyt?

Copy link
Collaborator

Choose a reason for hiding this comment

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

So, we can complete the values with ABCDEFG......., so it will be added as the alphabet (known order)

"name": "user1",
"displayName": "User One"
},
"challenge": "WUYwNDhkMWE3ZWMzYTJhNjk3MDA1OWMyNzY2YmJjN2UwZg",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above, this can be flagged as a secret

const val TIMEOUT = 600000L
val keyCredential =
KeyCredential(
id = "6ySmhJd6qGUMCthiqszyb4Od4U6TFn0v3DLz-1EZrNQ",
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be flagged as a secret

Copy link
Collaborator

Choose a reason for hiding this comment

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

Same for values below RAW_ID, ATTESTATION_OBJECT, AUTHENTICATE_CHALLENGE, CLIENT_DATA_JSON_CREATE, SIGNATURE, USER_HANDLE. If we can use placeholder without letters will be better, if we need the values encoded or following a format, we should use dummy values so they are not considered secrets

controller: ASAuthorizationController,
didCompleteWithAuthorization: ASAuthorization,
) {
val credentialRegistration = didCompleteWithAuthorization.credential as ASAuthorizationPlatformPublicKeyCredentialRegistration
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a way to pass the credentialRegistration to TwilioPasskey and applying the logic below in TwilioPasskey? AuthorizationControllerWrapper could be in charge of completing the interaction / needed code for iOS authorization, but some logic can be kept in TwilioPasskey, so it can be tested

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No unfortunately that ASAuthorizationPlatformPublicKeyCredentialRegistration contains a couple of Objects that can't be initialized outside of Apple private logic. So It won't be possible to create that object from Scratch to use it as a mock.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants