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

E2e tests split #2401

Merged
merged 15 commits into from
Feb 19, 2019
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
67 changes: 67 additions & 0 deletions Example/Auth/ApiTests/AccountInfoTests.m
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
34 changes: 34 additions & 0 deletions Example/Auth/ApiTests/AnonymousAuthTests.m
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
17 changes: 17 additions & 0 deletions Example/Auth/ApiTests/Auth_ApiTests-Bridging-Header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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 "FIRAuthApiTestsBase.h"
191 changes: 191 additions & 0 deletions Example/Auth/ApiTests/CustomAuthTests.m
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

@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
Loading