-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Split auth api tests into multiple cases #2399
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright 2019 Google | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#import <XCTest/XCTest.h> | ||
|
||
#import "FIRAuthApiTestsBase.h" | ||
|
||
/** The testing email address for testCreateAccountWithEmailAndPassword. */ | ||
static NSString *const kOldUserEmail = @"[email protected]"; | ||
|
||
/** The testing email address for testUpdatingUsersEmail. */ | ||
static NSString *const kNewUserEmail = @"[email protected]"; | ||
|
||
@interface AccountInfoTests : FIRAuthApiTestsBase | ||
|
||
@end | ||
|
||
@implementation AccountInfoTests | ||
|
||
- (void)testUpdatingUsersEmail { | ||
SKIP_IF_ON_MOBILE_HARNESS | ||
FIRAuth *auth = [FIRAuth auth]; | ||
if (!auth) { | ||
XCTFail(@"Could not obtain auth object."); | ||
} | ||
|
||
__block NSError *apiError; | ||
XCTestExpectation *expectation = | ||
[self expectationWithDescription:@"Created account with email and password."]; | ||
[auth createUserWithEmail:kOldUserEmail | ||
password:@"password" | ||
completion:^(FIRAuthDataResult *user, NSError *error) { | ||
apiError = error; | ||
[expectation fulfill]; | ||
}]; | ||
[self waitForExpectationsWithTimeout:kExpectationsTimeout handler:nil]; | ||
expectation = [self expectationWithDescription:@"Created account with email and password."]; | ||
XCTAssertEqualObjects(auth.currentUser.email, kOldUserEmail); | ||
XCTAssertNil(apiError); | ||
|
||
[auth.currentUser updateEmail:kNewUserEmail | ||
completion:^(NSError *_Nullable error) { | ||
apiError = error; | ||
[expectation fulfill]; | ||
}]; | ||
[self waitForExpectationsWithTimeout:kExpectationsTimeout handler:nil]; | ||
XCTAssertNil(apiError); | ||
XCTAssertEqualObjects(auth.currentUser.email, kNewUserEmail); | ||
|
||
// Clean up the created Firebase user for future runs. | ||
[self deleteCurrentUser]; | ||
} | ||
|
||
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2019 Google | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#import <XCTest/XCTest.h> | ||
|
||
#import "FIRAuthApiTestsBase.h" | ||
|
||
@interface AnonymousAuthTests : FIRAuthApiTestsBase | ||
|
||
@end | ||
|
||
@implementation AnonymousAuthTests | ||
|
||
- (void)testSignInAnonymously { | ||
[self signInAnonymously]; | ||
XCTAssertTrue([FIRAuth auth].currentUser.anonymous); | ||
|
||
[self deleteCurrentUser]; | ||
} | ||
|
||
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// | ||
// Use this file to import your target's public headers that you would like to expose to Swift. | ||
// | ||
|
||
#import "FIRAuthApiTestsBase.h" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
/* | ||
* Copyright 2019 Google | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#import <XCTest/XCTest.h> | ||
|
||
#import "FIRAuthApiTestsBase.h" | ||
|
||
/** The user name string for Custom Auth testing account. */ | ||
static NSString *const kCustomAuthTestingAccountUserID = KCUSTOM_AUTH_USER_ID; | ||
|
||
/** The url for obtaining a valid custom token string used to test Custom Auth. */ | ||
static NSString *const kCustomTokenUrl = KCUSTOM_AUTH_TOKEN_URL; | ||
|
||
/** The url for obtaining an expired but valid custom token string used to test Custom Auth failure. | ||
*/ | ||
static NSString *const kExpiredCustomTokenUrl = KCUSTOM_AUTH_TOKEN_EXPIRED_URL; | ||
|
||
/** The invalid custom token string for testing Custom Auth. */ | ||
static NSString *const kInvalidCustomToken = @"invalid token."; | ||
|
||
/** Error message for invalid custom token sign in. */ | ||
NSString *kInvalidTokenErrorMessage = | ||
@"Invalid assertion format. 3 dot separated segments required."; | ||
|
||
@interface CustomAuthTests : FIRAuthApiTestsBase | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove new line. same for other files |
||
@end | ||
|
||
@implementation CustomAuthTests | ||
|
||
- (void)testSignInWithValidCustomAuthToken { | ||
FIRAuth *auth = [FIRAuth auth]; | ||
if (!auth) { | ||
XCTFail(@"Could not obtain auth object."); | ||
} | ||
|
||
NSError *error; | ||
NSString *customToken = [NSString stringWithContentsOfURL:[NSURL URLWithString:kCustomTokenUrl] | ||
encoding:NSUTF8StringEncoding | ||
error:&error]; | ||
if (!customToken) { | ||
XCTFail(@"There was an error retrieving the custom token: %@", error); | ||
} | ||
NSLog(@"The valid token is: %@", customToken); | ||
|
||
XCTestExpectation *expectation = | ||
[self expectationWithDescription:@"CustomAuthToken sign-in finished."]; | ||
|
||
[auth signInWithCustomToken:customToken | ||
completion:^(FIRAuthDataResult *_Nullable result, NSError *_Nullable error) { | ||
if (error) { | ||
NSLog(@"Valid token sign in error: %@", error); | ||
} | ||
[expectation fulfill]; | ||
}]; | ||
[self waitForExpectationsWithTimeout:kExpectationsTimeout | ||
handler:^(NSError *error) { | ||
if (error != nil) { | ||
XCTFail(@"Failed to wait for expectations " | ||
@"in CustomAuthToken sign in. Error: %@", | ||
error.localizedDescription); | ||
} | ||
}]; | ||
|
||
XCTAssertEqualObjects(auth.currentUser.uid, kCustomAuthTestingAccountUserID); | ||
} | ||
|
||
- (void)testSignInWithValidCustomAuthExpiredToken { | ||
FIRAuth *auth = [FIRAuth auth]; | ||
if (!auth) { | ||
XCTFail(@"Could not obtain auth object."); | ||
} | ||
|
||
NSError *error; | ||
NSString *customToken = | ||
[NSString stringWithContentsOfURL:[NSURL URLWithString:kExpiredCustomTokenUrl] | ||
encoding:NSUTF8StringEncoding | ||
error:&error]; | ||
if (!customToken) { | ||
XCTFail(@"There was an error retrieving the custom token: %@", error); | ||
} | ||
XCTestExpectation *expectation = | ||
[self expectationWithDescription:@"CustomAuthToken sign-in finished."]; | ||
|
||
__block NSError *apiError; | ||
[auth signInWithCustomToken:customToken | ||
completion:^(FIRAuthDataResult *_Nullable result, NSError *_Nullable error) { | ||
if (error) { | ||
apiError = error; | ||
} | ||
[expectation fulfill]; | ||
}]; | ||
[self waitForExpectationsWithTimeout:kExpectationsTimeout | ||
handler:^(NSError *error) { | ||
if (error != nil) { | ||
XCTFail(@"Failed to wait for expectations " | ||
@"in CustomAuthToken sign in. Error: %@", | ||
error.localizedDescription); | ||
} | ||
}]; | ||
|
||
XCTAssertNil(auth.currentUser); | ||
XCTAssertEqual(apiError.code, FIRAuthErrorCodeInvalidCustomToken); | ||
} | ||
|
||
- (void)testSignInWithInvalidCustomAuthToken { | ||
FIRAuth *auth = [FIRAuth auth]; | ||
if (!auth) { | ||
XCTFail(@"Could not obtain auth object."); | ||
} | ||
XCTestExpectation *expectation = | ||
[self expectationWithDescription:@"Invalid CustomAuthToken sign-in finished."]; | ||
|
||
[auth signInWithCustomToken:kInvalidCustomToken | ||
completion:^(FIRAuthDataResult *_Nullable result, NSError *_Nullable error) { | ||
XCTAssertEqualObjects(error.localizedDescription, kInvalidTokenErrorMessage); | ||
[expectation fulfill]; | ||
}]; | ||
[self waitForExpectationsWithTimeout:kExpectationsTimeout | ||
handler:^(NSError *error) { | ||
if (error != nil) { | ||
XCTFail(@"Failed to wait for expectations " | ||
@"in CustomAuthToken sign in. Error: %@", | ||
error.localizedDescription); | ||
} | ||
}]; | ||
} | ||
|
||
- (void)testInMemoryUserAfterSignOut { | ||
FIRAuth *auth = [FIRAuth auth]; | ||
if (!auth) { | ||
XCTFail(@"Could not obtain auth object."); | ||
} | ||
NSError *error; | ||
NSString *customToken = [NSString stringWithContentsOfURL:[NSURL URLWithString:kCustomTokenUrl] | ||
encoding:NSUTF8StringEncoding | ||
error:&error]; | ||
if (!customToken) { | ||
XCTFail(@"There was an error retrieving the custom token: %@", error); | ||
} | ||
XCTestExpectation *expectation = | ||
[self expectationWithDescription:@"CustomAuthToken sign-in finished."]; | ||
__block NSError *rpcError; | ||
[auth signInWithCustomToken:customToken | ||
completion:^(FIRAuthDataResult *_Nullable result, NSError *_Nullable error) { | ||
if (error) { | ||
rpcError = error; | ||
} | ||
[expectation fulfill]; | ||
}]; | ||
[self waitForExpectationsWithTimeout:kExpectationsTimeout | ||
handler:^(NSError *error) { | ||
if (error != nil) { | ||
XCTFail(@"Failed to wait for expectations " | ||
@"in CustomAuthToken sign in. Error: %@", | ||
error.localizedDescription); | ||
} | ||
}]; | ||
XCTAssertEqualObjects(auth.currentUser.uid, kCustomAuthTestingAccountUserID); | ||
XCTAssertNil(rpcError); | ||
FIRUser *inMemoryUser = auth.currentUser; | ||
XCTestExpectation *expectation1 = [self expectationWithDescription:@"Profile data change."]; | ||
[auth signOut:NULL]; | ||
rpcError = nil; | ||
NSString *newEmailAddress = [self fakeRandomEmail]; | ||
XCTAssertNotEqualObjects(newEmailAddress, inMemoryUser.email); | ||
[inMemoryUser updateEmail:newEmailAddress | ||
completion:^(NSError *_Nullable error) { | ||
rpcError = error; | ||
[expectation1 fulfill]; | ||
}]; | ||
[self waitForExpectationsWithTimeout:kExpectationsTimeout handler:nil]; | ||
XCTAssertEqualObjects(inMemoryUser.email, newEmailAddress); | ||
XCTAssertNil(rpcError); | ||
XCTAssertNil(auth.currentUser); | ||
} | ||
|
||
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright 2017 Google | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#import <XCTest/XCTest.h> | ||
|
||
#import "FIRAuthApiTestsBase.h" | ||
|
||
/** The testing email address for testCreateAccountWithEmailAndPassword. */ | ||
static NSString *const kNewEmailToCreateUser = @"[email protected]"; | ||
|
||
/** The testing email address for testSignInExistingUserWithEmailAndPassword. */ | ||
static NSString *const kExistingEmailToSignIn = @"[email protected]"; | ||
|
||
/** The testing password for testSignInExistingUserWithEmailAndPassword. */ | ||
static NSString *const kExistingPasswordToSignIn = @"password"; | ||
|
||
@interface EmailPasswordAuthTests : FIRAuthApiTestsBase | ||
|
||
@end | ||
|
||
@implementation EmailPasswordAuthTests | ||
|
||
- (void)testCreateAccountWithEmailAndPassword { | ||
SKIP_IF_ON_MOBILE_HARNESS | ||
FIRAuth *auth = [FIRAuth auth]; | ||
if (!auth) { | ||
XCTFail(@"Could not obtain auth object."); | ||
} | ||
XCTestExpectation *expectation = | ||
[self expectationWithDescription:@"Created account with email and password."]; | ||
[auth createUserWithEmail:kNewEmailToCreateUser | ||
password:@"password" | ||
completion:^(FIRAuthDataResult *result, NSError *error) { | ||
if (error) { | ||
NSLog(@"createUserWithEmail has error: %@", error); | ||
} | ||
[expectation fulfill]; | ||
}]; | ||
[self waitForExpectationsWithTimeout:kExpectationsTimeout | ||
handler:^(NSError *error) { | ||
if (error != nil) { | ||
XCTFail(@"Failed to wait for expectations " | ||
@"in creating account. Error: %@", | ||
error.localizedDescription); | ||
} | ||
}]; | ||
|
||
XCTAssertEqualObjects(auth.currentUser.email, kNewEmailToCreateUser); | ||
|
||
[self deleteCurrentUser]; | ||
} | ||
|
||
- (void)testSignInExistingUserWithEmailAndPassword { | ||
FIRAuth *auth = [FIRAuth auth]; | ||
if (!auth) { | ||
XCTFail(@"Could not obtain auth object."); | ||
} | ||
XCTestExpectation *expectation = | ||
[self expectationWithDescription:@"Signed in existing account with email and password."]; | ||
[auth signInWithEmail:kExistingEmailToSignIn | ||
password:kExistingPasswordToSignIn | ||
completion:^(FIRAuthDataResult *user, NSError *error) { | ||
if (error) { | ||
NSLog(@"Signing in existing account has error: %@", error); | ||
} | ||
[expectation fulfill]; | ||
}]; | ||
[self waitForExpectationsWithTimeout:kExpectationsTimeout | ||
handler:^(NSError *error) { | ||
if (error != nil) { | ||
XCTFail(@"Failed to wait for expectations " | ||
@"in signing in existing account. Error: %@", | ||
error.localizedDescription); | ||
} | ||
}]; | ||
|
||
XCTAssertEqualObjects(auth.currentUser.email, kExistingEmailToSignIn); | ||
} | ||
|
||
@end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the new line here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean line 22 right? I prefer keep it since it's makes the class structure clearer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the line for a simple class with 0 method is more common among Google3 code. see http://google.github.io/styleguide/objcguide.html#prefixes
It's ok if you dont remove, because I don't care much about it.