-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into workflow/auto-update-deps-195-20231213-090113
- Loading branch information
Showing
8 changed files
with
239 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* 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. | ||
*/ | ||
|
||
#include "auth/src/desktop/rpcs/sign_up_request.h" | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include "app/src/assert.h" | ||
#include "app/src/include/firebase/app.h" | ||
|
||
namespace firebase { | ||
namespace auth { | ||
|
||
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="); | ||
url.append(api_key); | ||
set_url(url.c_str()); | ||
|
||
application_data_->returnSecureToken = true; | ||
} | ||
|
||
std::unique_ptr<SignUpRequest> | ||
SignUpRequest::CreateLinkWithEmailAndPasswordRequest(::firebase::App& app, | ||
const char* api_key, | ||
const char* email, | ||
const char* password) { | ||
auto request = | ||
std::unique_ptr<SignUpRequest>(new SignUpRequest(app, api_key)); | ||
|
||
if (email) { | ||
request->application_data_->email = email; | ||
} else { | ||
LogError("No email given"); | ||
} | ||
if (password) { | ||
request->application_data_->password = password; | ||
} else { | ||
LogError("No password given"); | ||
} | ||
request->UpdatePostFields(); | ||
return request; | ||
} | ||
|
||
} // namespace auth | ||
} // namespace firebase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* 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. | ||
*/ | ||
|
||
#ifndef FIREBASE_AUTH_SRC_DESKTOP_RPCS_SIGN_UP_REQUEST_H_ | ||
#define FIREBASE_AUTH_SRC_DESKTOP_RPCS_SIGN_UP_REQUEST_H_ | ||
|
||
#include <memory> | ||
|
||
#include "app/src/include/firebase/app.h" | ||
#include "auth/request_generated.h" | ||
#include "auth/request_resource.h" | ||
#include "auth/src/desktop/rpcs/auth_request.h" | ||
|
||
namespace firebase { | ||
namespace auth { | ||
|
||
// Represents the request payload for the signUp HTTP API. Use this to | ||
// upgrade anonymous accounts with email and password. The full specification of | ||
// the HTTP API can be found at | ||
// https://cloud.google.com/identity-platform/docs/reference/rest/v1/accounts/signUp | ||
class SignUpRequest : public AuthRequest { | ||
private: | ||
explicit SignUpRequest(::firebase::App& app, const char* api_key); | ||
static std::unique_ptr<SignUpRequest> CreateRequest(::firebase::App& app, | ||
const char* api_key); | ||
|
||
public: | ||
// Initializer for linking an email and password to an account. | ||
static std::unique_ptr<SignUpRequest> CreateLinkWithEmailAndPasswordRequest( | ||
::firebase::App& app, const char* api_key, const char* email, | ||
const char* password); | ||
|
||
void SetIdToken(const char* id_token) { | ||
if (id_token) { | ||
application_data_->idToken = id_token; | ||
UpdatePostFields(); | ||
} else { | ||
LogError("No id token given."); | ||
} | ||
} | ||
}; | ||
|
||
} // namespace auth | ||
} // namespace firebase | ||
|
||
#endif // FIREBASE_AUTH_SRC_DESKTOP_RPCS_SIGN_UP_REQUEST_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -567,8 +567,32 @@ TEST_F(UserDesktopTest, TestLinkWithCredential_OauthCredential) { | |
} | ||
|
||
TEST_F(UserDesktopTest, TestLinkWithCredential_EmailCredential) { | ||
InitializeConfigWithAFake(GetUrlForApi(API_KEY, "setAccountInfo"), | ||
FakeSetAccountInfoResponse()); | ||
FakeSetT fakes; | ||
const auto api_url = | ||
std::string( | ||
"https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=") + | ||
API_KEY; | ||
fakes[api_url] = | ||
FakeSuccessfulResponse("SignupNewUserResponse", | ||
" \"idToken\": \"idtoken123\"," | ||
" \"refreshToken\": \"refreshtoken123\"," | ||
" \"expiresIn\": \"3600\"," | ||
" \"localId\": \"localid123\""); | ||
fakes[GetUrlForApi(API_KEY, "getAccountInfo")] = | ||
FakeSuccessfulResponse("GetAccountInfoResponse", | ||
" \"users\": [" | ||
" {" | ||
" \"localId\": \"localid123\"," | ||
" \"lastLoginAt\": \"123\"," | ||
" \"createdAt\": \"456\"," | ||
" \"email\": \"[email protected]\"," | ||
" \"idToken\": \"new_fake_token\"," | ||
" \"passwordHash\": \"new_fake_hash\"," | ||
" \"emailVerified\": false," + | ||
GetFakeProviderInfo() + | ||
" }" | ||
" ]"); | ||
InitializeConfigWithFakes(fakes); | ||
|
||
// Response contains a new ID token, but user should have stayed the same. | ||
id_token_listener.ExpectChanges(1); | ||
|
@@ -844,18 +868,6 @@ TEST_F(UserDesktopTestSignOutOnError, Unlink) { | |
sem_.Wait(); | ||
} | ||
|
||
TEST_F(UserDesktopTestSignOutOnError, LinkWithEmail) { | ||
CheckSignOutIfUserIsInvalid( | ||
GetUrlForApi(API_KEY, "setAccountInfo"), "USER_NOT_FOUND", | ||
kAuthErrorUserNotFound, [&] { | ||
sem_.Post(); | ||
return firebase_user_->LinkWithCredential_DEPRECATED( | ||
EmailAuthProvider::GetCredential("[email protected]", | ||
"fake_password")); | ||
}); | ||
sem_.Wait(); | ||
} | ||
|
||
TEST_F(UserDesktopTestSignOutOnError, LinkWithOauthCredential) { | ||
CheckSignOutIfUserIsInvalid( | ||
GetUrlForApi(API_KEY, "verifyAssertion"), "USER_NOT_FOUND", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -402,18 +402,42 @@ TEST_F(UserTest, TestSendEmailVerification) { | |
} | ||
|
||
TEST_F(UserTest, TestLinkWithCredential) { | ||
const std::string config = | ||
std::string( | ||
"{" | ||
" config:[" | ||
" {fake:'FirebaseUser.linkWithCredential', " | ||
"futuregeneric:{ticker:1}}," | ||
" {fake:'FIRUser.linkWithCredential:completion:'," | ||
" futuregeneric:{ticker:1}},") + | ||
SET_ACCOUNT_INFO_SUCCESSFUL_RESPONSE + | ||
// Under the hood, since this is linking an email/password, | ||
// it is expecting a signUp call, followed by a getAccountInfo. | ||
firebase::testing::cppsdk::ConfigSet( | ||
"{" | ||
" config:[" | ||
" {fake:'FirebaseUser.linkWithCredential', " | ||
"futuregeneric:{ticker:1}}," | ||
" {fake:'FIRUser.linkWithCredential:completion:'," | ||
" futuregeneric:{ticker:1}}," | ||
" " | ||
"{fake:'https://identitytoolkit.googleapis.com/v1/" | ||
"accounts:signUp?key=not_a_real_api_key'," | ||
" httpresponse: {" | ||
" header: ['HTTP/1.1 200 Ok','Server:mock server 101']," | ||
" body: ['{" | ||
" \"kind\": \"identitytoolkit#SignupNewUserResponse\"," | ||
" \"idToken\": \"idtoken123\"," | ||
" \"refreshToken\": \"refreshtoken123\"," | ||
" \"expiresIn\": \"3600\"," | ||
" \"localId\": \"localid123\"" | ||
"}',]" | ||
" }" | ||
" }," | ||
" {fake:'https://www.googleapis.com/identitytoolkit/v3/relyingparty/" | ||
"getAccountInfo?key=not_a_real_api_key'," | ||
" httpresponse: {" | ||
" header: ['HTTP/1.1 200 Ok','Server:mock server 101']," | ||
" body: ['{" | ||
" \"users\": [{" | ||
" \"localId\": \"localid123\"" | ||
" }]}'," | ||
" ]" | ||
" }" | ||
" }" | ||
" ]" | ||
"}"; | ||
firebase::testing::cppsdk::ConfigSet(config.c_str()); | ||
"}"); | ||
|
||
Future<User*> result = firebase_user_->LinkWithCredential_DEPRECATED( | ||
EmailAuthProvider::GetCredential("[email protected]", "pw")); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters