Skip to content
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
18 changes: 9 additions & 9 deletions Example/Auth/ApiTests/AccountInfoTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ - (void)testUpdatingUsersEmail {
[auth createUserWithEmail:kOldUserEmail
password:@"password"
completion:^(FIRAuthDataResult *user, NSError *error) {
if (error.code != FIRAuthErrorCodeEmailAlreadyInUse) {
apiError = error;
}
[expectation fulfill];
}];
if (error.code != FIRAuthErrorCodeEmailAlreadyInUse) {
apiError = error;
}
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:kExpectationsTimeout handler:nil];

expectation = [self expectationWithDescription:@"Sign in with email and password."];
[auth signInWithEmail:kOldUserEmail
password:@"password"
completion:^(FIRAuthDataResult * _Nullable authResult, NSError * _Nullable error) {
apiError = error;
[expectation fulfill];
}];
completion:^(FIRAuthDataResult *_Nullable authResult, NSError *_Nullable error) {
apiError = error;
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:kExpectationsTimeout handler:nil];

XCTAssertEqualObjects(auth.currentUser.email, kOldUserEmail);
Expand Down
3 changes: 1 addition & 2 deletions Example/Auth/ApiTests/FIRAuthApiTestsBase.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ - (void)signInAnonymously {
XCTFail(@"Could not obtain auth object.");
}

XCTestExpectation *expectation =
[self expectationWithDescription:@"Anonymous sign-in finished."];
XCTestExpectation *expectation = [self expectationWithDescription:@"Anonymous sign-in finished."];
[auth signInAnonymouslyWithCompletion:^(FIRAuthDataResult *result, NSError *error) {
if (error) {
NSLog(@"Anonymous sign in error: %@", error);
Expand Down
79 changes: 41 additions & 38 deletions Example/Auth/ApiTests/PhoneMultiFactorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,53 +27,54 @@ let kOneSecondFactorUserEmail = "iosapitests+one_phone_second_factor@gmail.com"
let kOneSecondFactorUserPassword = "aaaaaa"

class PhoneMultiFactorTests: FIRAuthApiTestsBase {

func testEnrollUnenroll() {
let enrollExpectation = self.expectation(description: "Enroll phone multi factor finished.")
let unenrollExpectation = self.expectation(description: "Unenroll phone multi factor finished.")
Auth.auth().signIn(withEmail: kNoSecondFactorUserEmail, password: kNoSecondFactorUserPassword) { (result, error) in
let enrollExpectation = expectation(description: "Enroll phone multi factor finished.")
let unenrollExpectation = expectation(description: "Unenroll phone multi factor finished.")
Auth.auth().signIn(withEmail: kNoSecondFactorUserEmail, password: kNoSecondFactorUserPassword) { result, error in
XCTAssertNil(error, "User normal sign in failed. Error: \(error!.localizedDescription)")

// Enroll
guard let user = result?.user else {
XCTFail("No valid user after attempted sign-in.")
}
user.multiFactor.getSessionWithCompletion({ (session, error) in
user.multiFactor.getSessionWithCompletion { session, error in
XCTAssertNil(error, "Get multi factor session failed. Error: \(error!.localizedDescription)")
PhoneAuthProvider.provider().verifyPhoneNumber(
kPhoneSecondFactorPhoneNumber,
uiDelegate: nil,
multiFactorSession: session) { (verificationId, error) in
XCTAssertNil(error, "Verify phone number failed. Error: \(error!.localizedDescription)")
let credential = PhoneAuthProvider.provider().credential(
withVerificationID: verificationId!,
verificationCode: kPhoneSecondFactorVerificationCode)
let assertion = PhoneMultiFactorGenerator.assertion(with: credential);
user?.multiFactor.enroll(with: assertion, displayName: kPhoneSecondFactorDisplayName) { (error) in
XCTAssertNil(error, "Phone multi factor enroll failed. Error: \(error!.localizedDescription)")
XCTAssertEqual(Auth.auth().currentUser?.multiFactor.enrolledFactors.first?.displayName, kPhoneSecondFactorDisplayName)
enrollExpectation.fulfill()
multiFactorSession: session
) { verificationId, error in
XCTAssertNil(error, "Verify phone number failed. Error: \(error!.localizedDescription)")
let credential = PhoneAuthProvider.provider().credential(
withVerificationID: verificationId!,
verificationCode: kPhoneSecondFactorVerificationCode
)
let assertion = PhoneMultiFactorGenerator.assertion(with: credential)
user?.multiFactor.enroll(with: assertion, displayName: kPhoneSecondFactorDisplayName) { error in
XCTAssertNil(error, "Phone multi factor enroll failed. Error: \(error!.localizedDescription)")
XCTAssertEqual(Auth.auth().currentUser?.multiFactor.enrolledFactors.first?.displayName, kPhoneSecondFactorDisplayName)
enrollExpectation.fulfill()

// Unenroll
user = Auth.auth().currentUser
user?.multiFactor.unenroll(with: (user?.multiFactor.enrolledFactors.first)!, completion: { (error) in
XCTAssertNil(error, "Phone multi factor unenroll failed. Error: \(error!.localizedDescription)")
XCTAssertEqual(Auth.auth().currentUser?.multiFactor.enrolledFactors.count, 0)
unenrollExpectation.fulfill()
})
}
// Unenroll
user = Auth.auth().currentUser
user?.multiFactor.unenroll(with: (user?.multiFactor.enrolledFactors.first)!, completion: { error in
XCTAssertNil(error, "Phone multi factor unenroll failed. Error: \(error!.localizedDescription)")
XCTAssertEqual(Auth.auth().currentUser?.multiFactor.enrolledFactors.count, 0)
unenrollExpectation.fulfill()
})
}
}
})
}
}

self.waitForExpectations(timeout: 30) { error in
waitForExpectations(timeout: 30) { error in
XCTAssertNil(error, "Failed to wait for enroll and unenroll phone multi factor finished. Error: \(error!.localizedDescription)")
}
}

func testSignInWithSecondFactor() {
let signInExpectation = self.expectation(description: "Sign in with phone multi factor finished.")
Auth.auth().signIn(withEmail: kOneSecondFactorUserEmail, password: kOneSecondFactorUserPassword) { (result, error) in
let signInExpectation = expectation(description: "Sign in with phone multi factor finished.")
Auth.auth().signIn(withEmail: kOneSecondFactorUserEmail, password: kOneSecondFactorUserPassword) { result, error in
// SignIn
guard let error = error, error.code == AuthErrorCode.secondFactorRequired.rawValue else {
XCTFail("User sign in returns wrong error. Error: \(error!.localizedDescription)")
Expand All @@ -83,20 +84,22 @@ class PhoneMultiFactorTests: FIRAuthApiTestsBase {
PhoneAuthProvider.provider().verifyPhoneNumber(
with: hint,
uiDelegate: nil,
multiFactorSession: resolver.session) { (verificationId, error) in
XCTAssertNil(error, "Failed to verify phone number. Error: \(error!.localizedDescription)")
let credential = PhoneAuthProvider.provider().credential(
withVerificationID: verificationId!,
verificationCode: kPhoneSecondFactorVerificationCode)
let assertion = PhoneMultiFactorGenerator.assertion(with: credential);
resolver.resolveSignIn(with: assertion) { (authResult, error) in
XCTAssertNil(error, "Failed to sign in with phone multi factor. Error: \(error!.localizedDescription)")
signInExpectation.fulfill()
}
multiFactorSession: resolver.session
) { verificationId, error in
XCTAssertNil(error, "Failed to verify phone number. Error: \(error!.localizedDescription)")
let credential = PhoneAuthProvider.provider().credential(
withVerificationID: verificationId!,
verificationCode: kPhoneSecondFactorVerificationCode
)
let assertion = PhoneMultiFactorGenerator.assertion(with: credential)
resolver.resolveSignIn(with: assertion) { authResult, error in
XCTAssertNil(error, "Failed to sign in with phone multi factor. Error: \(error!.localizedDescription)")
signInExpectation.fulfill()
}
}
}

self.waitForExpectations(timeout: 300) { error in
waitForExpectations(timeout: 300) { error in
XCTAssertNil(error, "Failed to wait for enroll and unenroll phone multi factor finished. Error: \(error!.localizedDescription)")
}
}
Expand Down
2 changes: 1 addition & 1 deletion Example/Auth/App/iOS/FIRAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

@interface FIRAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property(strong, nonatomic) UIWindow *window;

@end
45 changes: 24 additions & 21 deletions Example/Auth/App/iOS/FIRAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,40 @@

@implementation FIRAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
return YES;
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
- (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for
// certain types of temporary interruptions (such as an incoming phone call or SMS message) or
// when the user quits the application and it begins the transition to the background state. Use
// this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates.
// Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store
// enough application state information to restore your application to its current state in case
// it is terminated later. If your application supports background execution, this method is
// called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the inactive state; here you can undo
// many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If
// the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also
// applicationDidEnterBackground:.
}

@end
14 changes: 6 additions & 8 deletions Example/Auth/App/iOS/FIRViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@ @interface FIRViewController ()

@implementation FIRViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end
9 changes: 4 additions & 5 deletions Example/Auth/App/iOS/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
@import UIKit;
#import "FIRAppDelegate.h"

int main(int argc, char * argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([FIRAppDelegate class]));
}
int main(int argc, char* argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([FIRAppDelegate class]));
}
}
2 changes: 0 additions & 2 deletions Example/Auth/App/macOS/FIRAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,4 @@

@interface FIRAppDelegate : NSObject <NSApplicationDelegate>


@end

6 changes: 2 additions & 4 deletions Example/Auth/App/macOS/FIRAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ @interface FIRAppDelegate ()
@implementation FIRAppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
// Insert code here to initialize your application
}


- (void)applicationWillTerminate:(NSNotification *)aNotification {
// Insert code here to tear down your application
// Insert code here to tear down your application
}


@end
2 changes: 0 additions & 2 deletions Example/Auth/App/macOS/FIRViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,4 @@

@interface FIRViewController : NSViewController


@end

10 changes: 4 additions & 6 deletions Example/Auth/App/macOS/FIRViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@
@implementation FIRViewController

- (void)viewDidLoad {
[super viewDidLoad];
[super viewDidLoad];

// Do any additional setup after loading the view.
// Do any additional setup after loading the view.
}


- (void)setRepresentedObject:(id)representedObject {
[super setRepresentedObject:representedObject];
[super setRepresentedObject:representedObject];

// Update the view, if already loaded.
// Update the view, if already loaded.
}


@end
4 changes: 2 additions & 2 deletions Example/Auth/App/macOS/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@

#import <Cocoa/Cocoa.h>

int main(int argc, const char * argv[]) {
return NSApplicationMain(argc, argv);
int main(int argc, const char* argv[]) {
return NSApplicationMain(argc, argv);
}
2 changes: 1 addition & 1 deletion Example/Auth/E2eTests/FIRAuthE2eTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ - (void)testSignInExistingUser {
grey_allOf(grey_kindOfClass([UILabel class]), grey_accessibilityLabel(@"OK"), nil);

[[EarlGrey selectElementWithMatcher:
// TODO: Add accessibilityIdentifiers for the elements.
// TODO: Add accessibilityIdentifiers for the elements.
grey_kindOfClass(NSClassFromString(@"_UIAlertControllerView"))]
performAction:grey_typeText(email)];

Expand Down
8 changes: 2 additions & 6 deletions Example/Auth/Tests/FIRAdditionalUserInfoTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

#import <XCTest/XCTest.h>

#import <OCMock/OCMock.h>
#import "FIRAdditionalUserInfo_Internal.h"
#import "FIRVerifyAssertionResponse.h"
#import <OCMock/OCMock.h>

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -52,11 +52,7 @@ + (NSDictionary *)profile {
static NSDictionary *kProfile = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
kProfile = @{
@"email": @"user@mail.com",
@"given_name": @"User",
@"family_name": @"Doe"
};
kProfile = @{@"email" : @"user@mail.com", @"given_name" : @"User", @"family_name" : @"Doe"};
});
return kProfile;
}
Expand Down
3 changes: 1 addition & 2 deletions Example/Auth/Tests/FIRApp+FIRAuthUnitTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ + (FIROptions *)appOptions {
return [[FIROptions alloc] initInternalWithOptionsDictionary:@{
@"GOOGLE_APP_ID" : @"1:1085102361755:ios:f790a919483d5bdf",
@"API_KEY" : @"FAKE_API_KEY",
@"GCM_SENDER_ID": @"217397612173",
@"GCM_SENDER_ID" : @"217397612173",
@"CLIENT_ID" : @"123456.apps.googleusercontent.com",
}];
}
Expand All @@ -42,5 +42,4 @@ + (FIRApp *)appForAuthUnitTestsWithName:(NSString *)name {
return [[FIRApp alloc] initInstanceWithName:name options:[self appOptions]];
}


@end
2 changes: 1 addition & 1 deletion Example/Auth/Tests/FIRAuthAPNSTokenManagerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

#import <XCTest/XCTest.h>

#import <OCMock/OCMock.h>
#import "FIRAuthAPNSToken.h"
#import "FIRAuthAPNSTokenManager.h"
#import <OCMock/OCMock.h>

NS_ASSUME_NONNULL_BEGIN

Expand Down
Loading