Skip to content

Commit e393eb0

Browse files
committed
Merge branch 'master' into bs-gullogger
* master: E2e tests split (#2401) Split auth api tests into multiple cases (#2399) Add a ToString function to create human-readable debug descriptions (#2384) Split Auth unit tests (#2396) Create umbrella header for FIAM (#2392) Deprecate setMinimumSessionInterval (#2305) Forbid queries endAt an uncommitted server timestamp. (#2382) update changelog for release (#2383) Fix FIAM Travic CI issues (#2380) Remove swift sample for Auth (#2371) C++ migration: port `FSTTransaction` (#2362) Fix a bug where unlinking emailpassword doesn’t remove provider data (#2370) Fix a bug where sign in with Game Center doesn’t return additional user info (#2368) Firebase In-app messaging callbacks (#2354) Fix a bug where sign in with email link always return isNewUser as false (#2363) C++ migration: eliminate `FSTRemoteStore` (#2338)
2 parents 29e7510 + 593774b commit e393eb0

File tree

107 files changed

+3417
-3945
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+3417
-3945
lines changed
+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright 2019 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import <XCTest/XCTest.h>
18+
19+
#import "FIRAuthApiTestsBase.h"
20+
21+
/** The testing email address for testCreateAccountWithEmailAndPassword. */
22+
static NSString *const kOldUserEmail = @"[email protected]";
23+
24+
/** The testing email address for testUpdatingUsersEmail. */
25+
static NSString *const kNewUserEmail = @"[email protected]";
26+
27+
@interface AccountInfoTests : FIRAuthApiTestsBase
28+
29+
@end
30+
31+
@implementation AccountInfoTests
32+
33+
- (void)testUpdatingUsersEmail {
34+
SKIP_IF_ON_MOBILE_HARNESS
35+
FIRAuth *auth = [FIRAuth auth];
36+
if (!auth) {
37+
XCTFail(@"Could not obtain auth object.");
38+
}
39+
40+
__block NSError *apiError;
41+
XCTestExpectation *expectation =
42+
[self expectationWithDescription:@"Created account with email and password."];
43+
[auth createUserWithEmail:kOldUserEmail
44+
password:@"password"
45+
completion:^(FIRAuthDataResult *user, NSError *error) {
46+
apiError = error;
47+
[expectation fulfill];
48+
}];
49+
[self waitForExpectationsWithTimeout:kExpectationsTimeout handler:nil];
50+
expectation = [self expectationWithDescription:@"Created account with email and password."];
51+
XCTAssertEqualObjects(auth.currentUser.email, kOldUserEmail);
52+
XCTAssertNil(apiError);
53+
54+
[auth.currentUser updateEmail:kNewUserEmail
55+
completion:^(NSError *_Nullable error) {
56+
apiError = error;
57+
[expectation fulfill];
58+
}];
59+
[self waitForExpectationsWithTimeout:kExpectationsTimeout handler:nil];
60+
XCTAssertNil(apiError);
61+
XCTAssertEqualObjects(auth.currentUser.email, kNewUserEmail);
62+
63+
// Clean up the created Firebase user for future runs.
64+
[self deleteCurrentUser];
65+
}
66+
67+
@end
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2019 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import <XCTest/XCTest.h>
18+
19+
#import "FIRAuthApiTestsBase.h"
20+
21+
@interface AnonymousAuthTests : FIRAuthApiTestsBase
22+
23+
@end
24+
25+
@implementation AnonymousAuthTests
26+
27+
- (void)testSignInAnonymously {
28+
[self signInAnonymously];
29+
XCTAssertTrue([FIRAuth auth].currentUser.anonymous);
30+
31+
[self deleteCurrentUser];
32+
}
33+
34+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright 2019 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import "FIRAuthApiTestsBase.h"
+191
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
/*
2+
* Copyright 2019 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import <XCTest/XCTest.h>
18+
19+
#import "FIRAuthApiTestsBase.h"
20+
21+
/** The user name string for Custom Auth testing account. */
22+
static NSString *const kCustomAuthTestingAccountUserID = KCUSTOM_AUTH_USER_ID;
23+
24+
/** The url for obtaining a valid custom token string used to test Custom Auth. */
25+
static NSString *const kCustomTokenUrl = KCUSTOM_AUTH_TOKEN_URL;
26+
27+
/** The url for obtaining an expired but valid custom token string used to test Custom Auth failure.
28+
*/
29+
static NSString *const kExpiredCustomTokenUrl = KCUSTOM_AUTH_TOKEN_EXPIRED_URL;
30+
31+
/** The invalid custom token string for testing Custom Auth. */
32+
static NSString *const kInvalidCustomToken = @"invalid token.";
33+
34+
/** Error message for invalid custom token sign in. */
35+
NSString *kInvalidTokenErrorMessage =
36+
@"Invalid assertion format. 3 dot separated segments required.";
37+
38+
@interface CustomAuthTests : FIRAuthApiTestsBase
39+
40+
@end
41+
42+
@implementation CustomAuthTests
43+
44+
- (void)testSignInWithValidCustomAuthToken {
45+
FIRAuth *auth = [FIRAuth auth];
46+
if (!auth) {
47+
XCTFail(@"Could not obtain auth object.");
48+
}
49+
50+
NSError *error;
51+
NSString *customToken = [NSString stringWithContentsOfURL:[NSURL URLWithString:kCustomTokenUrl]
52+
encoding:NSUTF8StringEncoding
53+
error:&error];
54+
if (!customToken) {
55+
XCTFail(@"There was an error retrieving the custom token: %@", error);
56+
}
57+
NSLog(@"The valid token is: %@", customToken);
58+
59+
XCTestExpectation *expectation =
60+
[self expectationWithDescription:@"CustomAuthToken sign-in finished."];
61+
62+
[auth signInWithCustomToken:customToken
63+
completion:^(FIRAuthDataResult *_Nullable result, NSError *_Nullable error) {
64+
if (error) {
65+
NSLog(@"Valid token sign in error: %@", error);
66+
}
67+
[expectation fulfill];
68+
}];
69+
[self waitForExpectationsWithTimeout:kExpectationsTimeout
70+
handler:^(NSError *error) {
71+
if (error != nil) {
72+
XCTFail(@"Failed to wait for expectations "
73+
@"in CustomAuthToken sign in. Error: %@",
74+
error.localizedDescription);
75+
}
76+
}];
77+
78+
XCTAssertEqualObjects(auth.currentUser.uid, kCustomAuthTestingAccountUserID);
79+
}
80+
81+
- (void)testSignInWithValidCustomAuthExpiredToken {
82+
FIRAuth *auth = [FIRAuth auth];
83+
if (!auth) {
84+
XCTFail(@"Could not obtain auth object.");
85+
}
86+
87+
NSError *error;
88+
NSString *customToken =
89+
[NSString stringWithContentsOfURL:[NSURL URLWithString:kExpiredCustomTokenUrl]
90+
encoding:NSUTF8StringEncoding
91+
error:&error];
92+
if (!customToken) {
93+
XCTFail(@"There was an error retrieving the custom token: %@", error);
94+
}
95+
XCTestExpectation *expectation =
96+
[self expectationWithDescription:@"CustomAuthToken sign-in finished."];
97+
98+
__block NSError *apiError;
99+
[auth signInWithCustomToken:customToken
100+
completion:^(FIRAuthDataResult *_Nullable result, NSError *_Nullable error) {
101+
if (error) {
102+
apiError = error;
103+
}
104+
[expectation fulfill];
105+
}];
106+
[self waitForExpectationsWithTimeout:kExpectationsTimeout
107+
handler:^(NSError *error) {
108+
if (error != nil) {
109+
XCTFail(@"Failed to wait for expectations "
110+
@"in CustomAuthToken sign in. Error: %@",
111+
error.localizedDescription);
112+
}
113+
}];
114+
115+
XCTAssertNil(auth.currentUser);
116+
XCTAssertEqual(apiError.code, FIRAuthErrorCodeInvalidCustomToken);
117+
}
118+
119+
- (void)testSignInWithInvalidCustomAuthToken {
120+
FIRAuth *auth = [FIRAuth auth];
121+
if (!auth) {
122+
XCTFail(@"Could not obtain auth object.");
123+
}
124+
XCTestExpectation *expectation =
125+
[self expectationWithDescription:@"Invalid CustomAuthToken sign-in finished."];
126+
127+
[auth signInWithCustomToken:kInvalidCustomToken
128+
completion:^(FIRAuthDataResult *_Nullable result, NSError *_Nullable error) {
129+
XCTAssertEqualObjects(error.localizedDescription, kInvalidTokenErrorMessage);
130+
[expectation fulfill];
131+
}];
132+
[self waitForExpectationsWithTimeout:kExpectationsTimeout
133+
handler:^(NSError *error) {
134+
if (error != nil) {
135+
XCTFail(@"Failed to wait for expectations "
136+
@"in CustomAuthToken sign in. Error: %@",
137+
error.localizedDescription);
138+
}
139+
}];
140+
}
141+
142+
- (void)testInMemoryUserAfterSignOut {
143+
FIRAuth *auth = [FIRAuth auth];
144+
if (!auth) {
145+
XCTFail(@"Could not obtain auth object.");
146+
}
147+
NSError *error;
148+
NSString *customToken = [NSString stringWithContentsOfURL:[NSURL URLWithString:kCustomTokenUrl]
149+
encoding:NSUTF8StringEncoding
150+
error:&error];
151+
if (!customToken) {
152+
XCTFail(@"There was an error retrieving the custom token: %@", error);
153+
}
154+
XCTestExpectation *expectation =
155+
[self expectationWithDescription:@"CustomAuthToken sign-in finished."];
156+
__block NSError *rpcError;
157+
[auth signInWithCustomToken:customToken
158+
completion:^(FIRAuthDataResult *_Nullable result, NSError *_Nullable error) {
159+
if (error) {
160+
rpcError = error;
161+
}
162+
[expectation fulfill];
163+
}];
164+
[self waitForExpectationsWithTimeout:kExpectationsTimeout
165+
handler:^(NSError *error) {
166+
if (error != nil) {
167+
XCTFail(@"Failed to wait for expectations "
168+
@"in CustomAuthToken sign in. Error: %@",
169+
error.localizedDescription);
170+
}
171+
}];
172+
XCTAssertEqualObjects(auth.currentUser.uid, kCustomAuthTestingAccountUserID);
173+
XCTAssertNil(rpcError);
174+
FIRUser *inMemoryUser = auth.currentUser;
175+
XCTestExpectation *expectation1 = [self expectationWithDescription:@"Profile data change."];
176+
[auth signOut:NULL];
177+
rpcError = nil;
178+
NSString *newEmailAddress = [self fakeRandomEmail];
179+
XCTAssertNotEqualObjects(newEmailAddress, inMemoryUser.email);
180+
[inMemoryUser updateEmail:newEmailAddress
181+
completion:^(NSError *_Nullable error) {
182+
rpcError = error;
183+
[expectation1 fulfill];
184+
}];
185+
[self waitForExpectationsWithTimeout:kExpectationsTimeout handler:nil];
186+
XCTAssertEqualObjects(inMemoryUser.email, newEmailAddress);
187+
XCTAssertNil(rpcError);
188+
XCTAssertNil(auth.currentUser);
189+
}
190+
191+
@end

0 commit comments

Comments
 (0)