Skip to content

Commit 669b0fb

Browse files
cynthiajoanCynthia Jiang
and
Cynthia Jiang
authored
feat(auth): enable emulator support on desktop (#1423)
* add auth emulator support * fix ios number parse * update the documentation part * reduce lint warning * more lint warnings * code format * use environment to decide using emulator or not * fix a typo * add readme entry for FirebaseApp.GetApps() * update for review comment * add missing ` * make json request always do restrict json * add readme info * prepare for review * some minor tweak * code format * update review comments * update the unit test after request json change --------- Co-authored-by: Cynthia Jiang <cynthiajiang@google.com>
1 parent 64d5d42 commit 669b0fb

16 files changed

+63
-53
lines changed

app/rest/request_json.h

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class RequestJson : public Request {
4141
explicit RequestJson(const char* schema) : application_data_(new FbsTypeT()) {
4242
flatbuffers::IDLOptions fbs_options;
4343
fbs_options.skip_unexpected_fields_in_json = true;
44+
fbs_options.strict_json = true;
4445
parser_.reset(new flatbuffers::Parser(fbs_options));
4546

4647
bool parse_status = parser_->Parse(schema);

app/rest/tests/request_json_test.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ TEST(RequestJsonTest, UpdatePostFields) {
6464
request.set_token("abc");
6565
EXPECT_EQ(
6666
"{\n"
67-
" token: \"abc\",\n"
68-
" number: 123\n"
67+
" \"token\": \"abc\",\n"
68+
" \"number\": 123\n"
6969
"}\n",
7070
request.options().post_fields);
7171
}

auth/src/android/auth_android.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,12 @@ void CheckEmulator(AuthData* auth_data) {
195195

196196
// Use emulator as long as this env variable is set, regardless its value.
197197
if (std::getenv("USE_AUTH_EMULATOR") == nullptr) {
198-
LogDebug("Using Auth Prod for testing.");
198+
LogInfo("Using Auth Prod for testing.");
199199
return;
200200
}
201201

202+
LogInfo("Using Auth Emulator for testing.");
203+
202204
// Use AUTH_EMULATOR_PORT if it is set to non empty string,
203205
// otherwise use the default port.
204206
uint32_t port = std::stoi(kEmulatorPort);

auth/src/desktop/rpcs/auth_request.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -88,22 +88,23 @@ std::string AuthRequest::GetUrl() {
8888
} else {
8989
std::string url(kHttp);
9090
url += emulator_url;
91+
url += "/";
9192
url += kServerURL;
9293
return url;
9394
}
9495
}
9596

9697
void AuthRequest::CheckEmulator() {
9798
if (!emulator_url.empty()) {
98-
LogDebug("Emulator Url already set: %s", emulator_url.c_str());
99+
LogInfo("Emulator Url already set: %s", emulator_url.c_str());
99100
return;
100101
}
101102
// Use emulator as long as this env variable is set, regardless its value.
102103
if (std::getenv("USE_AUTH_EMULATOR") == nullptr) {
103-
LogDebug("Using Auth Prod for testing.");
104+
LogInfo("Using Auth Prod for testing.");
104105
return;
105106
}
106-
107+
LogInfo("Using Auth Emulator.");
107108
emulator_url.append(kEmulatorLocalHost);
108109
emulator_url.append(":");
109110
// Use AUTH_EMULATOR_PORT if it is set to non empty string,

auth/src/ios/auth_ios.mm

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ void UpdateCurrentUser(AuthData *auth_data) {
160160
void CheckEmulator(AuthData *auth_data) {
161161
// Use emulator as long as this env variable is set, regardless its value.
162162
if (std::getenv("USE_AUTH_EMULATOR") == nullptr) {
163-
LogDebug("Using Auth Prod for testing.");
163+
LogInfo("Using Auth Prod for testing.");
164164
return;
165165
}
166-
166+
LogInfo("Using Auth Emulator.");
167167
// Use AUTH_EMULATOR_PORT if it is set to non empty string,
168168
// otherwise use the default port.
169169
uint32_t port = std::stoi(kEmulatorPort);

auth/tests/desktop/rpcs/create_auth_uri_test.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ TEST(CreateAuthUriTest, TestCreateAuthUriRequest) {
3636
request.options().url);
3737
EXPECT_EQ(
3838
"{\n"
39-
" identifier: \"email\",\n"
40-
" continueUri: \"http://localhost\"\n"
39+
" \"identifier\": \"email\",\n"
40+
" \"continueUri\": \"http://localhost\"\n"
4141
"}\n",
4242
request.options().post_fields);
4343
}

auth/tests/desktop/rpcs/delete_account_test.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ TEST(DeleteAccountTest, TestDeleteAccountRequest) {
3737
request.options().url);
3838
EXPECT_EQ(
3939
"{\n"
40-
" idToken: \"token\"\n"
40+
" \"idToken\": \"token\"\n"
4141
"}\n",
4242
request.options().post_fields);
4343
}

auth/tests/desktop/rpcs/get_account_info_test.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ TEST(GetAccountInfoTest, TestGetAccountInfoRequest) {
3636
request.options().url);
3737
EXPECT_EQ(
3838
"{\n"
39-
" idToken: \"token\"\n"
39+
" \"idToken\": \"token\"\n"
4040
"}\n",
4141
request.options().post_fields);
4242
}

auth/tests/desktop/rpcs/get_oob_confirmation_code_test.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ TEST(GetOobConfirmationCodeTest, SendVerifyEmailRequest) {
4040
request->options().url);
4141
EXPECT_EQ(
4242
"{\n"
43-
" idToken: \"token\",\n"
44-
" requestType: \"VERIFY_EMAIL\"\n"
43+
" \"idToken\": \"token\",\n"
44+
" \"requestType\": \"VERIFY_EMAIL\"\n"
4545
"}\n",
4646
request->options().post_fields);
4747
}
@@ -56,8 +56,8 @@ TEST(GetOobConfirmationCodeTest, SendPasswordResetEmailRequest) {
5656
request->options().url);
5757
EXPECT_EQ(
5858
"{\n"
59-
" email: \"email\",\n"
60-
" requestType: \"PASSWORD_RESET\"\n"
59+
" \"email\": \"email\",\n"
60+
" \"requestType\": \"PASSWORD_RESET\"\n"
6161
"}\n",
6262
request->options().post_fields);
6363
}

auth/tests/desktop/rpcs/reset_password_test.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ TEST(ResetPasswordTest, TestResetPasswordRequest) {
3535
request.options().url);
3636
EXPECT_EQ(
3737
"{\n"
38-
" oobCode: \"oob\",\n"
39-
" newPassword: \"password\"\n"
38+
" \"oobCode\": \"oob\",\n"
39+
" \"newPassword\": \"password\"\n"
4040
"}\n",
4141
request.options().post_fields);
4242
}

auth/tests/desktop/rpcs/secure_token_test.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ TEST(SecureTokenTest, TestSetRefreshRequest) {
3434
request.options().url);
3535
EXPECT_EQ(
3636
"{\n"
37-
" grantType: \"refresh_token\",\n"
38-
" refreshToken: \"token123\"\n"
37+
" \"grantType\": \"refresh_token\",\n"
38+
" \"refreshToken\": \"token123\"\n"
3939
"}\n",
4040
request.options().post_fields);
4141
}

auth/tests/desktop/rpcs/set_account_info_test.cc

+23-23
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ TEST(SetAccountInfoTest, TestSetAccountInfoRequest_UpdateEmail) {
4141
request->options().url);
4242
EXPECT_EQ(
4343
"{\n"
44-
" email: \"fakeemail\",\n"
45-
" returnSecureToken: true,\n"
46-
" idToken: \"token\"\n"
44+
" \"email\": \"fakeemail\",\n"
45+
" \"returnSecureToken\": true,\n"
46+
" \"idToken\": \"token\"\n"
4747
"}\n",
4848
request->options().post_fields);
4949
}
@@ -60,9 +60,9 @@ TEST(SetAccountInfoTest, TestSetAccountInfoRequest_UpdatePassword) {
6060
request->options().url);
6161
EXPECT_EQ(
6262
"{\n"
63-
" password: \"fakepassword\",\n"
64-
" returnSecureToken: true,\n"
65-
" idToken: \"token\"\n"
63+
" \"password\": \"fakepassword\",\n"
64+
" \"returnSecureToken\": true,\n"
65+
" \"idToken\": \"token\"\n"
6666
"}\n",
6767
request->options().post_fields);
6868
}
@@ -79,10 +79,10 @@ TEST(SetAccountInfoTest, TestSetAccountInfoRequest_UpdateProfile_Full) {
7979
request->options().url);
8080
EXPECT_EQ(
8181
"{\n"
82-
" displayName: \"New Name\",\n"
83-
" returnSecureToken: true,\n"
84-
" idToken: \"token\",\n"
85-
" photoUrl: \"new_url\"\n"
82+
" \"displayName\": \"New Name\",\n"
83+
" \"returnSecureToken\": true,\n"
84+
" \"idToken\": \"token\",\n"
85+
" \"photoUrl\": \"new_url\"\n"
8686
"}\n",
8787
request->options().post_fields);
8888
}
@@ -99,9 +99,9 @@ TEST(SetAccountInfoTest, TestSetAccountInfoRequest_UpdateProfile_Partial) {
9999
request->options().url);
100100
EXPECT_EQ(
101101
"{\n"
102-
" returnSecureToken: true,\n"
103-
" idToken: \"token\",\n"
104-
" photoUrl: \"new_url\"\n"
102+
" \"returnSecureToken\": true,\n"
103+
" \"idToken\": \"token\",\n"
104+
" \"photoUrl\": \"new_url\"\n"
105105
"}\n",
106106
request->options().post_fields);
107107
}
@@ -117,9 +117,9 @@ TEST(SetAccountInfoTest, TestSetAccountInfoRequest_UpdateProfile_DeleteFields) {
117117
request->options().url);
118118
EXPECT_EQ(
119119
"{\n"
120-
" returnSecureToken: true,\n"
121-
" idToken: \"token\",\n"
122-
" deleteAttribute: [\n"
120+
" \"returnSecureToken\": true,\n"
121+
" \"idToken\": \"token\",\n"
122+
" \"deleteAttribute\": [\n"
123123
" \"DISPLAY_NAME\",\n"
124124
" \"PHOTO_URL\"\n"
125125
" ]\n"
@@ -140,10 +140,10 @@ TEST(SetAccountInfoTest,
140140
request->options().url);
141141
EXPECT_EQ(
142142
"{\n"
143-
" returnSecureToken: true,\n"
144-
" idToken: \"token\",\n"
145-
" photoUrl: \"new_url\",\n"
146-
" deleteAttribute: [\n"
143+
" \"returnSecureToken\": true,\n"
144+
" \"idToken\": \"token\",\n"
145+
" \"photoUrl\": \"new_url\",\n"
146+
" \"deleteAttribute\": [\n"
147147
" \"DISPLAY_NAME\"\n"
148148
" ]\n"
149149
"}\n",
@@ -162,9 +162,9 @@ TEST(SetAccountInfoTest, TestSetAccountInfoRequest_Unlink) {
162162
request->options().url);
163163
EXPECT_EQ(
164164
"{\n"
165-
" returnSecureToken: true,\n"
166-
" idToken: \"token\",\n"
167-
" deleteProvider: [\n"
165+
" \"returnSecureToken\": true,\n"
166+
" \"idToken\": \"token\",\n"
167+
" \"deleteProvider\": [\n"
168168
" \"fakeprovider\"\n"
169169
" ]\n"
170170
"}\n",

auth/tests/desktop/rpcs/sign_up_new_user_test.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ TEST(SignUpNewUserTest, TestAnonymousSignInRequest) {
3535
request.options().url);
3636
EXPECT_EQ(
3737
"{\n"
38-
" returnSecureToken: true\n"
38+
" \"returnSecureToken\": true\n"
3939
"}\n",
4040
request.options().post_fields);
4141
}
@@ -50,10 +50,10 @@ TEST(SignUpNewUserTest, TestEmailPasswordSignInRequest) {
5050
request.options().url);
5151
EXPECT_EQ(
5252
"{\n"
53-
" email: \"e@mail\",\n"
54-
" password: \"pwd\",\n"
55-
" displayName: \"rabbit\",\n"
56-
" returnSecureToken: true\n"
53+
" \"email\": \"e@mail\",\n"
54+
" \"password\": \"pwd\",\n"
55+
" \"displayName\": \"rabbit\",\n"
56+
" \"returnSecureToken\": true\n"
5757
"}\n",
5858
request.options().post_fields);
5959
}

auth/tests/desktop/rpcs/verify_custom_token_test.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ TEST(VerifyCustomTokenTest, TestVerifyCustomTokenRequest) {
3636
request.options().url);
3737
EXPECT_EQ(
3838
"{\n"
39-
" returnSecureToken: true,\n"
40-
" token: \"token123\"\n"
39+
" \"returnSecureToken\": true,\n"
40+
" \"token\": \"token123\"\n"
4141
"}\n",
4242
request.options().post_fields);
4343
}

auth/tests/desktop/rpcs/verify_password_test.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ TEST(VerifyPasswordTest, TestVerifyPasswordRequest) {
3535
request.options().url);
3636
EXPECT_EQ(
3737
"{\n"
38-
" email: \"abc@email\",\n"
39-
" password: \"pwd\",\n"
40-
" returnSecureToken: true\n"
38+
" \"email\": \"abc@email\",\n"
39+
" \"password\": \"pwd\",\n"
40+
" \"returnSecureToken\": true\n"
4141
"}\n",
4242
request.options().post_fields);
4343
}

release_build_files/readme.md

+6
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,12 @@ workflow use only during the development of your app, not for publicly shipping
627627
code.
628628

629629
## Release Notes
630+
### Next Release
631+
- Changes
632+
- Auth: Add Firebase Auth Emulator support. Set the environment variable
633+
USE_AUTH_EMULATOR=yes (and optionally AUTH_EMULATOR_PORT, default 9099)
634+
to connect to the local Firebase Auth Emulator.
635+
630636
### 11.4.0
631637
- Changes
632638
- General (Android): Update to Firebase Android BoM version 32.2.2.

0 commit comments

Comments
 (0)