Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
LouiseHsu committed May 13, 2024
1 parent 1412041 commit 3f22950
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
4 changes: 4 additions & 0 deletions packages/local_auth/local_auth_darwin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.3.1

* Fixes an issue where biometrics are shown as unavailable rather than disabled when turned off in settings.

## 1.3.0

* Adds Swift Package Manager compatibility.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ - (void)setUp {
self.continueAfterFailure = NO;
}

- (void)testSuccessfullAuthWithBiometrics {
- (void)testSuccessfulAuthWithBiometrics {
id mockAuthContext = OCMClassMock([LAContext class]);
FLALocalAuthPlugin *plugin = [[FLALocalAuthPlugin alloc]
initWithContextFactory:[[StubAuthContextFactory alloc]
Expand Down Expand Up @@ -446,6 +446,45 @@ - (void)testGetEnrolledBiometricsWithFaceID {
XCTAssertNil(error);
}

- (void)testGetEnrolledBiometricsWithFaceID_NotEnrolled {
id mockAuthContext = OCMClassMock([LAContext class]);
FLALocalAuthPlugin *plugin = [[FLALocalAuthPlugin alloc]
initWithContextFactory:[[StubAuthContextFactory alloc]
initWithContexts:@[ mockAuthContext ]]];

const LAPolicy policy = LAPolicyDeviceOwnerAuthenticationWithBiometrics;
FLADAuthStrings *strings = [self createAuthStrings];

OCMStub([mockAuthContext biometryType]).andReturn(LABiometryTypeFaceID);
void (^canEvaluatePolicyHandler)(NSInvocation *) = ^(NSInvocation *invocation) {
// Write error
NSError *__autoreleasing *authError;
[invocation getArgument:&authError atIndex:3];
*authError = [NSError errorWithDomain:@"error" code:LAErrorBiometryNotAvailable userInfo:nil];
// Write return value
BOOL returnValue = NO;
NSValue *nsReturnValue = [NSValue valueWithBytes:&returnValue objCType:@encode(BOOL)];
[invocation setReturnValue:&nsReturnValue];
};
OCMStub([mockAuthContext canEvaluatePolicy:policy
error:(NSError * __autoreleasing *)[OCMArg anyPointer]])
.andDo(canEvaluatePolicyHandler);

XCTestExpectation *expectation = [self expectationWithDescription:@"Result is called"];
[plugin authenticateWithOptions:[FLADAuthOptions makeWithBiometricOnly:YES
sticky:NO
useErrorDialogs:NO]
strings:strings
completion:^(FLADAuthResultDetails *_Nullable resultDetails,
FlutterError *_Nullable error) {
XCTAssertTrue([NSThread isMainThread]);
XCTAssertEqual(resultDetails.result, FLADAuthResultErrorNotAvailable);
XCTAssertNil(error);
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:kTimeout handler:nil];
}

- (void)testGetEnrolledBiometricsWithTouchID {
id mockAuthContext = OCMClassMock([LAContext class]);
FLALocalAuthPlugin *plugin = [[FLALocalAuthPlugin alloc]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,21 @@ - (void)handleError:(NSError *)authError
switch (authError.code) {
case LAErrorPasscodeNotSet:
case LAErrorBiometryNotEnrolled:
case LAErrorBiometryNotAvailable:
if (options.useErrorDialogs) {
[self showAlertWithMessage:strings.goToSettingsDescription
dismissButtonTitle:strings.cancelButton
openSettingsButtonTitle:strings.goToSettingsButton
completion:completion];
return;
}
result = authError.code == LAErrorPasscodeNotSet ? FLADAuthResultErrorPasscodeNotSet
: FLADAuthResultErrorNotEnrolled;
if (authError.code == LAErrorPasscodeNotSet) {
result = FLADAuthResultErrorPasscodeNotSet;
} else if (authError.code == LAErrorBiometryNotEnrolled) {
result = FLADAuthResultErrorNotEnrolled;
} else if (authError.code == LAErrorBiometryNotAvailable) {
result = FLADAuthResultErrorNotAvailable;
}
break;
case LAErrorBiometryLockout:
[self showAlertWithMessage:strings.lockOut
Expand Down
2 changes: 1 addition & 1 deletion packages/local_auth/local_auth_darwin/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: local_auth_darwin
description: iOS implementation of the local_auth plugin.
repository: https://github.com/flutter/packages/tree/main/packages/local_auth/local_auth_darwin
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+local_auth%22
version: 1.3.0
version: 1.3.1

environment:
sdk: ^3.2.3
Expand Down

0 comments on commit 3f22950

Please sign in to comment.