Skip to content
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
9 changes: 6 additions & 3 deletions auth/src/desktop/rpcs/auth_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,24 @@ AuthRequest::AuthRequest(::firebase::App& app, const char* schema,
}
}

std::string AuthRequest::GetUrl() {
std::string AuthRequest::GetUrl(const char* server_url) {
if (server_url == nullptr) {
return "";
}
Auth* auth_ptr = Auth::GetAuth(&app);
Comment on lines +76 to 80

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The server_url parameter is a raw pointer (const char*) and is not checked for nullptr before being appended to std::string on lines 84 and 90. Appending a null pointer to a std::string results in undefined behavior (typically a crash). Consider adding a defensive check at the beginning of the function to handle a null server_url gracefully.

std::string AuthRequest::GetUrl(const char* server_url) {\n  if (server_url == nullptr) {\n    return "";\n  }\n  Auth* auth_ptr = Auth::GetAuth(&app);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure Done

std::string assigned_emulator_url =
static_cast<AuthImpl*>(auth_ptr->auth_data_->auth_impl)
->assigned_emulator_url;

if (assigned_emulator_url.empty()) {
std::string url(kHttps);
url += kServerURL;
url += server_url;
return url;
} else {
std::string url(kHttp);
url += assigned_emulator_url;
url += "/";
url += kServerURL;
url += server_url;
return url;
}
}
Expand Down
2 changes: 1 addition & 1 deletion auth/src/desktop/rpcs/auth_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class AuthRequest
: AuthRequest(app, reinterpret_cast<const char*>(schema),
deliver_heartbeat) {}

std::string GetUrl();
std::string GetUrl(const char* server_url = kServerURL);

private:
::firebase::App& app;
Expand Down
8 changes: 3 additions & 5 deletions auth/src/desktop/rpcs/secure_token_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "auth/src/desktop/rpcs/secure_token_request.h"

#include <cassert>
#include <cstring>
#include <string>

#include "app/src/assert.h"
#include "app/src/include/firebase/app.h"
Expand All @@ -30,10 +30,8 @@ SecureTokenRequest::SecureTokenRequest(::firebase::App& app,
: AuthRequest(app, request_resource_data, false) {
FIREBASE_ASSERT_RETURN_VOID(api_key);

const char api_host[] = "https://securetoken.googleapis.com/v1/token?key=";
std::string url;
url.reserve(strlen(api_host) + strlen(api_key));
url.append(api_host);
const char api_host[] = "securetoken.googleapis.com/v1/token?key=";
std::string url = GetUrl(api_host);
url.append(api_key);
set_url(url.c_str());

Expand Down
5 changes: 3 additions & 2 deletions auth/src/desktop/rpcs/sign_up_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ SignUpRequest::SignUpRequest(::firebase::App& app, const char* api_key)
: AuthRequest(app, request_resource_data, true) {
FIREBASE_ASSERT_RETURN_VOID(api_key);

std::string url(
"https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=");
const char api_host[] =
"identitytoolkit.googleapis.com/v1/accounts:signUp?key=";
std::string url = GetUrl(api_host);
url.append(api_key);
set_url(url.c_str());

Expand Down
11 changes: 11 additions & 0 deletions auth/tests/desktop/rpcs/create_auth_uri_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "app/tests/include/firebase/app_for_testing.h"
#include "auth/src/desktop/rpcs/create_auth_uri_request.h"
#include "auth/src/desktop/rpcs/create_auth_uri_response.h"
#include "auth/src/include/firebase/auth.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"

Expand All @@ -42,6 +43,16 @@ TEST(CreateAuthUriTest, TestCreateAuthUriRequest) {
request.options().post_fields);
}

TEST(CreateAuthUriTest, TestCreateAuthUriRequestWithEmulator) {
std::unique_ptr<App> app(testing::CreateApp());
Auth::GetAuth(app.get())->UseEmulator("localhost", 9099);
CreateAuthUriRequest request(*app, "APIKEY", "email");
EXPECT_EQ(
"http://localhost:9099/www.googleapis.com/identitytoolkit/v3/"
"relyingparty/createAuthUri?key=APIKEY",
request.options().url);
}

// Test CreateAuthUriResponse
TEST(CreateAuthUriTest, TestCreateAuthUriResponse) {
std::unique_ptr<App> app(testing::CreateApp());
Expand Down
11 changes: 11 additions & 0 deletions auth/tests/desktop/rpcs/delete_account_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "app/tests/include/firebase/app_for_testing.h"
#include "auth/src/desktop/rpcs/delete_account_request.h"
#include "auth/src/desktop/rpcs/delete_account_response.h"
#include "auth/src/include/firebase/auth.h"
#include "auth/tests/desktop/rpcs/test_util.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
Expand All @@ -42,6 +43,16 @@ TEST(DeleteAccountTest, TestDeleteAccountRequest) {
request.options().post_fields);
}

TEST(DeleteAccountTest, TestDeleteAccountRequestWithEmulator) {
std::unique_ptr<App> app(testing::CreateApp());
Auth::GetAuth(app.get())->UseEmulator("localhost", 9099);
DeleteAccountRequest request(*app, "APIKEY");
EXPECT_EQ(
"http://localhost:9099/www.googleapis.com/identitytoolkit/v3/"
"relyingparty/deleteAccount?key=APIKEY",
request.options().url);
}

// Test DeleteAccountResponse
TEST(DeleteAccountTest, TestDeleteAccountResponse) {
std::unique_ptr<App> app(testing::CreateApp());
Expand Down
11 changes: 11 additions & 0 deletions auth/tests/desktop/rpcs/get_account_info_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "app/tests/include/firebase/app_for_testing.h"
#include "auth/src/desktop/rpcs/get_account_info_request.h"
#include "auth/src/desktop/rpcs/get_account_info_response.h"
#include "auth/src/include/firebase/auth.h"
#include "auth/tests/desktop/rpcs/test_util.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
Expand All @@ -41,6 +42,16 @@ TEST(GetAccountInfoTest, TestGetAccountInfoRequest) {
request.options().post_fields);
}

TEST(GetAccountInfoTest, TestGetAccountInfoRequestWithEmulator) {
std::unique_ptr<App> app(testing::CreateApp());
Auth::GetAuth(app.get())->UseEmulator("localhost", 9099);
GetAccountInfoRequest request(*app, "APIKEY", "token");
EXPECT_EQ(
"http://localhost:9099/www.googleapis.com/identitytoolkit/v3/"
"relyingparty/getAccountInfo?key=APIKEY",
request.options().url);
}

// Test GetAccountInfoResponse
TEST(GetAccountInfoTest, TestGetAccountInfoResponse) {
std::unique_ptr<App> app(App::Create(AppOptions()));
Expand Down
11 changes: 11 additions & 0 deletions auth/tests/desktop/rpcs/get_oob_confirmation_code_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "app/tests/include/firebase/app_for_testing.h"
#include "auth/src/desktop/rpcs/get_oob_confirmation_code_request.h"
#include "auth/src/desktop/rpcs/get_oob_confirmation_code_response.h"
#include "auth/src/include/firebase/auth.h"
#include "auth/tests/desktop/rpcs/test_util.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
Expand Down Expand Up @@ -46,6 +47,16 @@ TEST(GetOobConfirmationCodeTest, SendVerifyEmailRequest) {
request->options().post_fields);
}

TEST(GetOobConfirmationCodeTest, SendVerifyEmailRequestWithEmulator) {
std::unique_ptr<App> app(testing::CreateApp());
Auth::GetAuth(app.get())->UseEmulator("localhost", 9099);
auto request = RequestT::CreateSendEmailVerificationRequest(*app, "APIKEY");
EXPECT_EQ(
"http://localhost:9099/www.googleapis.com/identitytoolkit/v3/"
"relyingparty/getOobConfirmationCode?key=APIKEY",
request->options().url);
}

TEST(GetOobConfirmationCodeTest, SendPasswordResetEmailRequest) {
std::unique_ptr<App> app(testing::CreateApp());
auto request =
Expand Down
11 changes: 11 additions & 0 deletions auth/tests/desktop/rpcs/reset_password_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "app/tests/include/firebase/app_for_testing.h"
#include "auth/src/desktop/rpcs/reset_password_request.h"
#include "auth/src/desktop/rpcs/reset_password_response.h"
#include "auth/src/include/firebase/auth.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"

Expand All @@ -41,6 +42,16 @@ TEST(ResetPasswordTest, TestResetPasswordRequest) {
request.options().post_fields);
}

TEST(ResetPasswordTest, TestResetPasswordRequestWithEmulator) {
std::unique_ptr<App> app(testing::CreateApp());
Auth::GetAuth(app.get())->UseEmulator("localhost", 9099);
ResetPasswordRequest request(*app, "APIKEY", "oob", "password");
EXPECT_EQ(
"http://localhost:9099/www.googleapis.com/identitytoolkit/v3/"
"relyingparty/resetPassword?key=APIKEY",
request.options().url);
}

// Test ResetPasswordResponse
TEST(ResetPasswordTest, TestResetPasswordResponse) {
std::unique_ptr<App> app(testing::CreateApp());
Expand Down
11 changes: 11 additions & 0 deletions auth/tests/desktop/rpcs/secure_token_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "app/tests/include/firebase/app_for_testing.h"
#include "auth/src/desktop/rpcs/secure_token_request.h"
#include "auth/src/desktop/rpcs/secure_token_response.h"
#include "auth/src/include/firebase/auth.h"
#include "auth/tests/desktop/rpcs/test_util.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
Expand All @@ -40,6 +41,16 @@ TEST(SecureTokenTest, TestSetRefreshRequest) {
request.options().post_fields);
}

TEST(SecureTokenTest, TestSetRefreshRequestWithEmulator) {
std::unique_ptr<App> app(testing::CreateApp());
Auth* auth = Auth::GetAuth(app.get());
auth->UseEmulator("localhost", 9099);
SecureTokenRequest request(*app, "APIKEY", "token123");
EXPECT_EQ(
"http://localhost:9099/securetoken.googleapis.com/v1/token?key=APIKEY",
request.options().url);
}

// Test SecureTokenResponse
TEST(SecureTokenTest, TestSecureTokenResponse) {
std::unique_ptr<App> app(testing::CreateApp());
Expand Down
12 changes: 12 additions & 0 deletions auth/tests/desktop/rpcs/set_account_info_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "app/tests/include/firebase/app_for_testing.h"
#include "auth/src/desktop/rpcs/set_account_info_request.h"
#include "auth/src/desktop/rpcs/set_account_info_response.h"
#include "auth/src/include/firebase/auth.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"

Expand Down Expand Up @@ -48,6 +49,17 @@ TEST(SetAccountInfoTest, TestSetAccountInfoRequest_UpdateEmail) {
request->options().post_fields);
}

TEST(SetAccountInfoTest, TestSetAccountInfoRequestWithEmulator) {
std::unique_ptr<App> app(testing::CreateApp());
Auth::GetAuth(app.get())->UseEmulator("localhost", 9099);
auto request =
RequestT::CreateUpdateEmailRequest(*app, "APIKEY", "fakeemail");
EXPECT_EQ(
"http://localhost:9099/www.googleapis.com/identitytoolkit/v3/"
"relyingparty/setAccountInfo?key=APIKEY",
request->options().url);
}

TEST(SetAccountInfoTest, TestSetAccountInfoRequest_UpdatePassword) {
std::unique_ptr<App> app(testing::CreateApp());
auto request =
Expand Down
39 changes: 39 additions & 0 deletions auth/tests/desktop/rpcs/sign_up_new_user_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "app/tests/include/firebase/app_for_testing.h"
#include "auth/src/desktop/rpcs/sign_up_new_user_request.h"
#include "auth/src/desktop/rpcs/sign_up_new_user_response.h"
#include "auth/src/desktop/rpcs/sign_up_request.h"
#include "auth/src/include/firebase/auth.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"

Expand All @@ -40,6 +42,16 @@ TEST(SignUpNewUserTest, TestAnonymousSignInRequest) {
request.options().post_fields);
}

TEST(SignUpNewUserTest, TestAnonymousSignInRequestWithEmulator) {
std::unique_ptr<App> app(testing::CreateApp());
Auth::GetAuth(app.get())->UseEmulator("localhost", 9099);
SignUpNewUserRequest request(*app, "APIKEY");
EXPECT_EQ(
"http://localhost:9099/www.googleapis.com/identitytoolkit/v3/"
"relyingparty/signupNewUser?key=APIKEY",
request.options().url);
}

// Test SignUpNewUserRequest for using password signin
TEST(SignUpNewUserTest, TestEmailPasswordSignInRequest) {
std::unique_ptr<App> app(testing::CreateApp());
Expand All @@ -58,6 +70,33 @@ TEST(SignUpNewUserTest, TestEmailPasswordSignInRequest) {
request.options().post_fields);
}

TEST(SignUpNewUserTest, TestSignUpRequestLinkWithEmailAndPassword) {
std::unique_ptr<App> app(testing::CreateApp());
auto request = SignUpRequest::CreateLinkWithEmailAndPasswordRequest(
*app, "APIKEY", "e@mail", "pwd");
EXPECT_EQ(
"https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=APIKEY",
request->options().url);
EXPECT_EQ(
"{\n"
" \"email\": \"e@mail\",\n"
" \"password\": \"pwd\",\n"
" \"returnSecureToken\": true\n"
"}\n",
request->options().post_fields);
}

TEST(SignUpNewUserTest, TestSignUpRequestLinkWithEmailAndPasswordWithEmulator) {
std::unique_ptr<App> app(testing::CreateApp());
Auth::GetAuth(app.get())->UseEmulator("localhost", 9099);
auto request = SignUpRequest::CreateLinkWithEmailAndPasswordRequest(
*app, "APIKEY", "e@mail", "pwd");
EXPECT_EQ(
"http://localhost:9099/identitytoolkit.googleapis.com/v1/"
"accounts:signUp?key=APIKEY",
request->options().url);
}

// Test SignUpNewUserResponse
TEST(SignUpNewUserTest, TestSignUpNewUserResponse) {
std::unique_ptr<App> app(testing::CreateApp());
Expand Down
12 changes: 12 additions & 0 deletions auth/tests/desktop/rpcs/verify_assertion_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "app/tests/include/firebase/app_for_testing.h"
#include "auth/src/desktop/rpcs/verify_assertion_request.h"
#include "auth/src/desktop/rpcs/verify_assertion_response.h"
#include "auth/src/include/firebase/auth.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"

Expand All @@ -42,6 +43,17 @@ TEST(VerifyAssertionTest, TestVerifyAssertionRequest_FromIdToken) {
CheckUrl(*request);
}

TEST(VerifyAssertionTest, TestVerifyAssertionRequestWithEmulator) {
std::unique_ptr<App> app(testing::CreateApp());
Auth::GetAuth(app.get())->UseEmulator("localhost", 9099);
auto request = VerifyAssertionRequest::FromIdToken(*app, "APIKEY", "provider",
"id_token");
EXPECT_EQ(
"http://localhost:9099/www.googleapis.com/identitytoolkit/v3/"
"relyingparty/verifyAssertion?key=APIKEY",
request->options().url);
}

TEST(VerifyAssertionTest, TestVerifyAssertionRequest_FromAccessToken) {
std::unique_ptr<App> app(testing::CreateApp());
auto request = VerifyAssertionRequest::FromAccessToken(
Expand Down
11 changes: 11 additions & 0 deletions auth/tests/desktop/rpcs/verify_custom_token_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "app/tests/include/firebase/app_for_testing.h"
#include "auth/src/desktop/rpcs/verify_custom_token_request.h"
#include "auth/src/desktop/rpcs/verify_custom_token_response.h"
#include "auth/src/include/firebase/auth.h"
#include "auth/tests/desktop/rpcs/test_util.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
Expand All @@ -42,6 +43,16 @@ TEST(VerifyCustomTokenTest, TestVerifyCustomTokenRequest) {
request.options().post_fields);
}

TEST(VerifyCustomTokenTest, TestVerifyCustomTokenRequestWithEmulator) {
std::unique_ptr<App> app(testing::CreateApp());
Auth::GetAuth(app.get())->UseEmulator("localhost", 9099);
VerifyCustomTokenRequest request(*app, "APIKEY", "token123");
EXPECT_EQ(
"http://localhost:9099/www.googleapis.com/identitytoolkit/v3/"
"relyingparty/verifyCustomToken?key=APIKEY",
request.options().url);
}

// Test VerifyCustomTokenResponse
TEST(VerifyCustomTokenTest, TestVerifyCustomTokenResponse) {
std::unique_ptr<App> app(testing::CreateApp());
Expand Down
11 changes: 11 additions & 0 deletions auth/tests/desktop/rpcs/verify_password_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "app/tests/include/firebase/app_for_testing.h"
#include "auth/src/desktop/rpcs/verify_password_request.h"
#include "auth/src/desktop/rpcs/verify_password_response.h"
#include "auth/src/include/firebase/auth.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"

Expand All @@ -42,6 +43,16 @@ TEST(VerifyPasswordTest, TestVerifyPasswordRequest) {
request.options().post_fields);
}

TEST(VerifyPasswordTest, TestVerifyPasswordRequestWithEmulator) {
std::unique_ptr<App> app(testing::CreateApp());
Auth::GetAuth(app.get())->UseEmulator("localhost", 9099);
VerifyPasswordRequest request(*app, "APIKEY", "abc@email", "pwd");
EXPECT_EQ(
"http://localhost:9099/www.googleapis.com/identitytoolkit/v3/"
"relyingparty/verifyPassword?key=APIKEY",
request.options().url);
}

// Test VerifyPasswordResponse
TEST(VerifyPasswordTest, TestVerifyPasswordResponse) {
std::unique_ptr<App> app(testing::CreateApp());
Expand Down
7 changes: 7 additions & 0 deletions release_build_files/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,13 @@ workflow use only during the development of your app, not for publicly shipping
code.

## Release Notes
### Upcoming
- Changes
- Auth (Desktop): Fixed an issue where refreshing or fetching an ID token
(`GetToken`) or linking an email/password credential to an anonymous
account failed when using the Auth Emulator, because `SecureTokenRequest`
and `SignUpRequest` were always sent to production endpoints.

### 14.0.0
- Changes
- General (Android): Update to Firebase Android BoM version 35.0.0.
Expand Down
Loading