|
39 | 39 | #import "FirebaseAuth/Sources/Backend/RPC/FIRCreateAuthURIResponse.h"
|
40 | 40 | #import "FirebaseAuth/Sources/Backend/RPC/FIREmailLinkSignInRequest.h"
|
41 | 41 | #import "FirebaseAuth/Sources/Backend/RPC/FIREmailLinkSignInResponse.h"
|
| 42 | +#import "FirebaseAuth/Sources/Backend/RPC/FIRFinalizePasskeySignInRequest.h" |
| 43 | +#import "FirebaseAuth/Sources/Backend/RPC/FIRFinalizePasskeySignInResponse.h" |
42 | 44 | #import "FirebaseAuth/Sources/Backend/RPC/FIRGetAccountInfoRequest.h"
|
43 | 45 | #import "FirebaseAuth/Sources/Backend/RPC/FIRGetAccountInfoResponse.h"
|
44 | 46 | #import "FirebaseAuth/Sources/Backend/RPC/FIRGetOOBConfirmationCodeRequest.h"
|
|
53 | 55 | #import "FirebaseAuth/Sources/Backend/RPC/FIRSetAccountInfoResponse.h"
|
54 | 56 | #import "FirebaseAuth/Sources/Backend/RPC/FIRSignUpNewUserRequest.h"
|
55 | 57 | #import "FirebaseAuth/Sources/Backend/RPC/FIRSignUpNewUserResponse.h"
|
| 58 | +#import "FirebaseAuth/Sources/Backend/RPC/FIRStartPasskeySignInRequest.h" |
| 59 | +#import "FirebaseAuth/Sources/Backend/RPC/FIRStartPasskeySignInResponse.h" |
56 | 60 | #import "FirebaseAuth/Sources/Backend/RPC/FIRVerifyAssertionRequest.h"
|
57 | 61 | #import "FirebaseAuth/Sources/Backend/RPC/FIRVerifyAssertionResponse.h"
|
58 | 62 | #import "FirebaseAuth/Sources/Backend/RPC/FIRVerifyCustomTokenRequest.h"
|
|
78 | 82 | #import "FirebaseAuth/Sources/Utilities/FIRAuthURLPresenter.h"
|
79 | 83 | #endif // TARGET_OS_IOS
|
80 | 84 |
|
| 85 | +#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_OSX || TARGET_OS_MACCATALYST |
| 86 | +#import <AuthenticationServices/AuthenticationServices.h> |
| 87 | +#endif |
| 88 | + |
81 | 89 | /** @var kAPIKey
|
82 | 90 | @brief The fake API key.
|
83 | 91 | */
|
|
278 | 286 | */
|
279 | 287 | static NSString *const kFakeRecaptchaVersion = @"RecaptchaVersion";
|
280 | 288 |
|
| 289 | +/** @var kRpId |
| 290 | + @brief The fake passkey relying party identifier. |
| 291 | + */ |
| 292 | +static NSString *const kRpId = @"fake.rp.id"; |
| 293 | + |
| 294 | +/** @var kChallenge |
| 295 | + @brief The fake passkey challenge. |
| 296 | + */ |
| 297 | +static NSString *const kChallenge = @"Y2hhbGxlbmdl"; // decode to "challenge" |
| 298 | + |
| 299 | +/** @var kCredentialID |
| 300 | + @brief The fake passkey credentialID. |
| 301 | + */ |
| 302 | +static NSString *const kCredentialID = @"Y3JlZGVudGlhbGlk"; // decode to "credentialid" |
| 303 | + |
| 304 | +/** @var kClientDataJson |
| 305 | + @brief The fake clientDataJson object |
| 306 | + */ |
| 307 | +static NSString *const kClientDataJson = @"Y2xpZW50ZGF0YWpzb24="; // decode to "clientdatajson" |
| 308 | + |
| 309 | +/** @var kAuthenticatorData |
| 310 | + @brief The fake authenticatorData object |
| 311 | + */ |
| 312 | +static NSString *const kAuthenticatorData = |
| 313 | + @"YXV0aGVudGljYXRvcmRhdGE="; // decode to "authenticatordata" |
| 314 | + |
| 315 | +/** @var kSignature |
| 316 | + @brief The fake signature |
| 317 | + */ |
| 318 | +static NSString *const kSignature = @"c2lnbmF0dXJl"; // decode to "signature" |
| 319 | + |
| 320 | +/** @var kUserID |
| 321 | + @brief The fake user ID / user handle |
| 322 | + */ |
| 323 | +static NSString *const kUserID = @"dXNlcmlk"; // decode to "userid" |
| 324 | + |
281 | 325 | #if TARGET_OS_IOS
|
282 | 326 | /** @class FIRAuthAppDelegate
|
283 | 327 | @brief Application delegate implementation to test the app delegate proxying
|
@@ -1805,6 +1849,106 @@ - (void)testSignInAndRetrieveDataWithCustomTokenFailure {
|
1805 | 1849 | OCMVerifyAll(_mockBackend);
|
1806 | 1850 | }
|
1807 | 1851 |
|
| 1852 | +#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_OSX || TARGET_OS_MACCATALYST |
| 1853 | +/** @fn testStartPasskeySignInSuccess |
| 1854 | + @brief Tests the flow of a successful @c startPasskeySignInWithCompletion: call. |
| 1855 | + */ |
| 1856 | +- (void)testStartPasskeySignInSuccess { |
| 1857 | + if (@available(iOS 15.0, tvOS 16.0, macOS 12.0, *)) { |
| 1858 | + OCMExpect([_mockBackend startPasskeySignIn:[OCMArg any] callback:[OCMArg any]]) |
| 1859 | + .andCallBlock2(^(FIRStartPasskeySignInRequest *_Nullable request, |
| 1860 | + FIRStartPasskeySignInResponseCallback callback) { |
| 1861 | + XCTAssertEqualObjects(request.APIKey, kAPIKey); |
| 1862 | + dispatch_async(FIRAuthGlobalWorkQueue(), ^() { |
| 1863 | + id mockStartPasskeySignInResponse = OCMClassMock([FIRStartPasskeySignInResponse class]); |
| 1864 | + OCMStub([mockStartPasskeySignInResponse rpID]).andReturn(kRpId); |
| 1865 | + OCMStub([mockStartPasskeySignInResponse challenge]).andReturn(kChallenge); |
| 1866 | + callback(mockStartPasskeySignInResponse, nil); |
| 1867 | + }); |
| 1868 | + }); |
| 1869 | + XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; |
| 1870 | + [[FIRAuth auth] signOut:NULL]; |
| 1871 | + [[FIRAuth auth] |
| 1872 | + startPasskeySignInWithCompletion:^( |
| 1873 | + ASAuthorizationPlatformPublicKeyCredentialAssertionRequest *_Nullable request, |
| 1874 | + NSError *_Nullable error) { |
| 1875 | + XCTAssertNil(error); |
| 1876 | + XCTAssertEqualObjects([[request challenge] base64EncodedStringWithOptions:0], kChallenge); |
| 1877 | + ASAuthorizationPlatformPublicKeyCredentialProvider *provider = |
| 1878 | + (ASAuthorizationPlatformPublicKeyCredentialProvider *)[request provider]; |
| 1879 | + XCTAssertEqualObjects([provider relyingPartyIdentifier], kRpId); |
| 1880 | + [expectation fulfill]; |
| 1881 | + }]; |
| 1882 | + |
| 1883 | + [self waitForExpectationsWithTimeout:kExpectationTimeout handler:nil]; |
| 1884 | + OCMVerifyAll(_mockBackend); |
| 1885 | + } |
| 1886 | +} |
| 1887 | + |
| 1888 | +/** @fn testStartPasskeySignInFailure |
| 1889 | + @brief Tests the flow of a failed @c startPasskeySignInWithCompletion: call. |
| 1890 | + */ |
| 1891 | +- (void)testStartPasskeySignInFailure { |
| 1892 | + if (@available(iOS 15.0, tvOS 16.0, macOS 12.0, *)) { |
| 1893 | + OCMExpect([_mockBackend startPasskeySignIn:[OCMArg any] callback:[OCMArg any]]) |
| 1894 | + .andDispatchError2([FIRAuthErrorUtils operationNotAllowedErrorWithMessage:nil]); |
| 1895 | + XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; |
| 1896 | + [[FIRAuth auth] signOut:NULL]; |
| 1897 | + [[FIRAuth auth] |
| 1898 | + startPasskeySignInWithCompletion:^( |
| 1899 | + ASAuthorizationPlatformPublicKeyCredentialAssertionRequest *_Nullable request, |
| 1900 | + NSError *_Nullable error) { |
| 1901 | + XCTAssertNil(request); |
| 1902 | + XCTAssertEqual(error.code, FIRAuthErrorCodeOperationNotAllowed); |
| 1903 | + XCTAssertNotNil(error.userInfo[NSLocalizedDescriptionKey]); |
| 1904 | + [expectation fulfill]; |
| 1905 | + }]; |
| 1906 | + [self waitForExpectationsWithTimeout:kExpectationTimeout handler:nil]; |
| 1907 | + OCMVerifyAll(_mockBackend); |
| 1908 | + } |
| 1909 | +} |
| 1910 | + |
| 1911 | +/** @fn testFinalizePasskeySignInFailure |
| 1912 | + @brief Tests the flow of a failed @c finalizePasskeySignInWithCompletion: call. |
| 1913 | + */ |
| 1914 | + |
| 1915 | +- (void)testFinalizePasskeySignInFailure { |
| 1916 | + if (@available(iOS 15.0, tvOS 16.0, macOS 12.0, *)) { |
| 1917 | + OCMExpect([_mockBackend finalizePasskeySignIn:[OCMArg any] callback:[OCMArg any]]) |
| 1918 | + .andDispatchError2([FIRAuthErrorUtils operationNotAllowedErrorWithMessage:nil]); |
| 1919 | + XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; |
| 1920 | + id mockPlatfromCredential = |
| 1921 | + OCMClassMock([ASAuthorizationPlatformPublicKeyCredentialAssertion class]); |
| 1922 | + OCMStub([mockPlatfromCredential credentialID]) |
| 1923 | + .andReturn([[NSData alloc] initWithBase64EncodedString:kCredentialID options:0]); |
| 1924 | + OCMStub([mockPlatfromCredential rawClientDataJSON]) |
| 1925 | + .andReturn([[NSData alloc] initWithBase64EncodedString:kClientDataJson options:0]); |
| 1926 | + OCMStub([mockPlatfromCredential signature]) |
| 1927 | + .andReturn([[NSData alloc] initWithBase64EncodedString:kSignature options:0]); |
| 1928 | + OCMStub([mockPlatfromCredential userID]) |
| 1929 | + .andReturn([[NSData alloc] initWithBase64EncodedString:kUserID options:0]); |
| 1930 | + OCMStub([mockPlatfromCredential rawAuthenticatorData]) |
| 1931 | + .andReturn([[NSData alloc] initWithBase64EncodedString:kAuthenticatorData options:0]); |
| 1932 | + [[FIRAuth auth] signOut:NULL]; |
| 1933 | + [[FIRAuth auth] |
| 1934 | + finalizePasskeySignInWithPlatformCredential:mockPlatfromCredential |
| 1935 | + completion:^(FIRAuthDataResult *_Nullable authResult, |
| 1936 | + NSError *_Nullable error) { |
| 1937 | + XCTAssertTrue([NSThread isMainThread]); |
| 1938 | + XCTAssertNil(authResult.user); |
| 1939 | + XCTAssertEqual(error.code, |
| 1940 | + FIRAuthErrorCodeOperationNotAllowed); |
| 1941 | + XCTAssertNotNil( |
| 1942 | + error.userInfo[NSLocalizedDescriptionKey]); |
| 1943 | + [expectation fulfill]; |
| 1944 | + }]; |
| 1945 | + [self waitForExpectationsWithTimeout:kExpectationTimeout handler:nil]; |
| 1946 | + OCMVerifyAll(_mockBackend); |
| 1947 | + } |
| 1948 | +} |
| 1949 | + |
| 1950 | +#endif // #if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_OSX || TARGET_OS_MACCATALYST |
| 1951 | + |
1808 | 1952 | #if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
|
1809 | 1953 | /** @fn testCreateUserWithEmailPasswordWithRecaptchaVerificationSuccess
|
1810 | 1954 | @brief Tests the flow of a successful @c createUserWithEmail:password:completion: call.
|
|
0 commit comments