Skip to content

feat(auth): enable emulator support on desktop #1423

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 23 commits into from
Aug 10, 2023
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
1 change: 1 addition & 0 deletions app/rest/request_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class RequestJson : public Request {
explicit RequestJson(const char* schema) : application_data_(new FbsTypeT()) {
flatbuffers::IDLOptions fbs_options;
fbs_options.skip_unexpected_fields_in_json = true;
fbs_options.strict_json = true;
parser_.reset(new flatbuffers::Parser(fbs_options));

bool parse_status = parser_->Parse(schema);
Expand Down
4 changes: 2 additions & 2 deletions app/rest/tests/request_json_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ TEST(RequestJsonTest, UpdatePostFields) {
request.set_token("abc");
EXPECT_EQ(
"{\n"
" token: \"abc\",\n"
" number: 123\n"
" \"token\": \"abc\",\n"
" \"number\": 123\n"
"}\n",
request.options().post_fields);
}
Expand Down
4 changes: 3 additions & 1 deletion auth/src/android/auth_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,12 @@ void CheckEmulator(AuthData* auth_data) {

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

LogInfo("Using Auth Emulator for testing.");

// Use AUTH_EMULATOR_PORT if it is set to non empty string,
// otherwise use the default port.
uint32_t port = std::stoi(kEmulatorPort);
Expand Down
7 changes: 4 additions & 3 deletions auth/src/desktop/rpcs/auth_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,23 @@ std::string AuthRequest::GetUrl() {
} else {
std::string url(kHttp);
url += emulator_url;
url += "/";
url += kServerURL;
return url;
}
}

void AuthRequest::CheckEmulator() {
if (!emulator_url.empty()) {
LogDebug("Emulator Url already set: %s", emulator_url.c_str());
LogInfo("Emulator Url already set: %s", emulator_url.c_str());
return;
}
// Use emulator as long as this env variable is set, regardless its value.
if (std::getenv("USE_AUTH_EMULATOR") == nullptr) {
LogDebug("Using Auth Prod for testing.");
LogInfo("Using Auth Prod for testing.");
return;
}

LogInfo("Using Auth Emulator.");
emulator_url.append(kEmulatorLocalHost);
emulator_url.append(":");
// Use AUTH_EMULATOR_PORT if it is set to non empty string,
Expand Down
4 changes: 2 additions & 2 deletions auth/src/ios/auth_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ void UpdateCurrentUser(AuthData *auth_data) {
void CheckEmulator(AuthData *auth_data) {
// Use emulator as long as this env variable is set, regardless its value.
if (std::getenv("USE_AUTH_EMULATOR") == nullptr) {
LogDebug("Using Auth Prod for testing.");
LogInfo("Using Auth Prod for testing.");
return;
}

LogInfo("Using Auth Emulator.");
// Use AUTH_EMULATOR_PORT if it is set to non empty string,
// otherwise use the default port.
uint32_t port = std::stoi(kEmulatorPort);
Expand Down
4 changes: 2 additions & 2 deletions auth/tests/desktop/rpcs/create_auth_uri_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ TEST(CreateAuthUriTest, TestCreateAuthUriRequest) {
request.options().url);
EXPECT_EQ(
"{\n"
" identifier: \"email\",\n"
" continueUri: \"http://localhost\"\n"
" \"identifier\": \"email\",\n"
" \"continueUri\": \"http://localhost\"\n"
"}\n",
request.options().post_fields);
}
Expand Down
2 changes: 1 addition & 1 deletion auth/tests/desktop/rpcs/delete_account_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ TEST(DeleteAccountTest, TestDeleteAccountRequest) {
request.options().url);
EXPECT_EQ(
"{\n"
" idToken: \"token\"\n"
" \"idToken\": \"token\"\n"
"}\n",
request.options().post_fields);
}
Expand Down
2 changes: 1 addition & 1 deletion auth/tests/desktop/rpcs/get_account_info_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ TEST(GetAccountInfoTest, TestGetAccountInfoRequest) {
request.options().url);
EXPECT_EQ(
"{\n"
" idToken: \"token\"\n"
" \"idToken\": \"token\"\n"
"}\n",
request.options().post_fields);
}
Expand Down
8 changes: 4 additions & 4 deletions auth/tests/desktop/rpcs/get_oob_confirmation_code_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ TEST(GetOobConfirmationCodeTest, SendVerifyEmailRequest) {
request->options().url);
EXPECT_EQ(
"{\n"
" idToken: \"token\",\n"
" requestType: \"VERIFY_EMAIL\"\n"
" \"idToken\": \"token\",\n"
" \"requestType\": \"VERIFY_EMAIL\"\n"
"}\n",
request->options().post_fields);
}
Expand All @@ -56,8 +56,8 @@ TEST(GetOobConfirmationCodeTest, SendPasswordResetEmailRequest) {
request->options().url);
EXPECT_EQ(
"{\n"
" email: \"email\",\n"
" requestType: \"PASSWORD_RESET\"\n"
" \"email\": \"email\",\n"
" \"requestType\": \"PASSWORD_RESET\"\n"
"}\n",
request->options().post_fields);
}
Expand Down
4 changes: 2 additions & 2 deletions auth/tests/desktop/rpcs/reset_password_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ TEST(ResetPasswordTest, TestResetPasswordRequest) {
request.options().url);
EXPECT_EQ(
"{\n"
" oobCode: \"oob\",\n"
" newPassword: \"password\"\n"
" \"oobCode\": \"oob\",\n"
" \"newPassword\": \"password\"\n"
"}\n",
request.options().post_fields);
}
Expand Down
4 changes: 2 additions & 2 deletions auth/tests/desktop/rpcs/secure_token_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ TEST(SecureTokenTest, TestSetRefreshRequest) {
request.options().url);
EXPECT_EQ(
"{\n"
" grantType: \"refresh_token\",\n"
" refreshToken: \"token123\"\n"
" \"grantType\": \"refresh_token\",\n"
" \"refreshToken\": \"token123\"\n"
"}\n",
request.options().post_fields);
}
Expand Down
46 changes: 23 additions & 23 deletions auth/tests/desktop/rpcs/set_account_info_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ TEST(SetAccountInfoTest, TestSetAccountInfoRequest_UpdateEmail) {
request->options().url);
EXPECT_EQ(
"{\n"
" email: \"fakeemail\",\n"
" returnSecureToken: true,\n"
" idToken: \"token\"\n"
" \"email\": \"fakeemail\",\n"
" \"returnSecureToken\": true,\n"
" \"idToken\": \"token\"\n"
"}\n",
request->options().post_fields);
}
Expand All @@ -60,9 +60,9 @@ TEST(SetAccountInfoTest, TestSetAccountInfoRequest_UpdatePassword) {
request->options().url);
EXPECT_EQ(
"{\n"
" password: \"fakepassword\",\n"
" returnSecureToken: true,\n"
" idToken: \"token\"\n"
" \"password\": \"fakepassword\",\n"
" \"returnSecureToken\": true,\n"
" \"idToken\": \"token\"\n"
"}\n",
request->options().post_fields);
}
Expand All @@ -79,10 +79,10 @@ TEST(SetAccountInfoTest, TestSetAccountInfoRequest_UpdateProfile_Full) {
request->options().url);
EXPECT_EQ(
"{\n"
" displayName: \"New Name\",\n"
" returnSecureToken: true,\n"
" idToken: \"token\",\n"
" photoUrl: \"new_url\"\n"
" \"displayName\": \"New Name\",\n"
" \"returnSecureToken\": true,\n"
" \"idToken\": \"token\",\n"
" \"photoUrl\": \"new_url\"\n"
"}\n",
request->options().post_fields);
}
Expand All @@ -99,9 +99,9 @@ TEST(SetAccountInfoTest, TestSetAccountInfoRequest_UpdateProfile_Partial) {
request->options().url);
EXPECT_EQ(
"{\n"
" returnSecureToken: true,\n"
" idToken: \"token\",\n"
" photoUrl: \"new_url\"\n"
" \"returnSecureToken\": true,\n"
" \"idToken\": \"token\",\n"
" \"photoUrl\": \"new_url\"\n"
"}\n",
request->options().post_fields);
}
Expand All @@ -117,9 +117,9 @@ TEST(SetAccountInfoTest, TestSetAccountInfoRequest_UpdateProfile_DeleteFields) {
request->options().url);
EXPECT_EQ(
"{\n"
" returnSecureToken: true,\n"
" idToken: \"token\",\n"
" deleteAttribute: [\n"
" \"returnSecureToken\": true,\n"
" \"idToken\": \"token\",\n"
" \"deleteAttribute\": [\n"
" \"DISPLAY_NAME\",\n"
" \"PHOTO_URL\"\n"
" ]\n"
Expand All @@ -140,10 +140,10 @@ TEST(SetAccountInfoTest,
request->options().url);
EXPECT_EQ(
"{\n"
" returnSecureToken: true,\n"
" idToken: \"token\",\n"
" photoUrl: \"new_url\",\n"
" deleteAttribute: [\n"
" \"returnSecureToken\": true,\n"
" \"idToken\": \"token\",\n"
" \"photoUrl\": \"new_url\",\n"
" \"deleteAttribute\": [\n"
" \"DISPLAY_NAME\"\n"
" ]\n"
"}\n",
Expand All @@ -162,9 +162,9 @@ TEST(SetAccountInfoTest, TestSetAccountInfoRequest_Unlink) {
request->options().url);
EXPECT_EQ(
"{\n"
" returnSecureToken: true,\n"
" idToken: \"token\",\n"
" deleteProvider: [\n"
" \"returnSecureToken\": true,\n"
" \"idToken\": \"token\",\n"
" \"deleteProvider\": [\n"
" \"fakeprovider\"\n"
" ]\n"
"}\n",
Expand Down
10 changes: 5 additions & 5 deletions auth/tests/desktop/rpcs/sign_up_new_user_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ TEST(SignUpNewUserTest, TestAnonymousSignInRequest) {
request.options().url);
EXPECT_EQ(
"{\n"
" returnSecureToken: true\n"
" \"returnSecureToken\": true\n"
"}\n",
request.options().post_fields);
}
Expand All @@ -50,10 +50,10 @@ TEST(SignUpNewUserTest, TestEmailPasswordSignInRequest) {
request.options().url);
EXPECT_EQ(
"{\n"
" email: \"e@mail\",\n"
" password: \"pwd\",\n"
" displayName: \"rabbit\",\n"
" returnSecureToken: true\n"
" \"email\": \"e@mail\",\n"
" \"password\": \"pwd\",\n"
" \"displayName\": \"rabbit\",\n"
" \"returnSecureToken\": true\n"
"}\n",
request.options().post_fields);
}
Expand Down
4 changes: 2 additions & 2 deletions auth/tests/desktop/rpcs/verify_custom_token_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ TEST(VerifyCustomTokenTest, TestVerifyCustomTokenRequest) {
request.options().url);
EXPECT_EQ(
"{\n"
" returnSecureToken: true,\n"
" token: \"token123\"\n"
" \"returnSecureToken\": true,\n"
" \"token\": \"token123\"\n"
"}\n",
request.options().post_fields);
}
Expand Down
6 changes: 3 additions & 3 deletions auth/tests/desktop/rpcs/verify_password_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ TEST(VerifyPasswordTest, TestVerifyPasswordRequest) {
request.options().url);
EXPECT_EQ(
"{\n"
" email: \"abc@email\",\n"
" password: \"pwd\",\n"
" returnSecureToken: true\n"
" \"email\": \"abc@email\",\n"
" \"password\": \"pwd\",\n"
" \"returnSecureToken\": true\n"
"}\n",
request.options().post_fields);
}
Expand Down
6 changes: 6 additions & 0 deletions release_build_files/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,12 @@ workflow use only during the development of your app, not for publicly shipping
code.

## Release Notes
### Next Release
- Changes
- Auth: Add Firebase Auth Emulator support. Set the environment variable
USE_AUTH_EMULATOR=yes (and optionally AUTH_EMULATOR_PORT, default 9099)
to connect to the local Firebase Auth Emulator.

### 11.4.0
- Changes
- General (Android): Update to Firebase Android BoM version 32.2.2.
Expand Down