mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Support 3P oauth flow.
PiperOrigin-RevId: 663964316
This commit is contained in:
committed by
Copybara-Service
parent
f1a1c39177
commit
a81ce57879
@@ -55,7 +55,7 @@ class AccountManager {
|
||||
// Gets current active account. If no login user, return std::nullopt.
|
||||
virtual std::optional<Account> GetCurrentAccount() = 0;
|
||||
|
||||
// Initializes the login process for a Google account.
|
||||
// Initializes the login process for a Google account from 1P client.
|
||||
// |login_success_callback| is called when the login succeeded. Account
|
||||
// information is passed to callback.
|
||||
// |login_failure_callback| is called when the login fails.
|
||||
@@ -63,6 +63,17 @@ class AccountManager {
|
||||
absl::AnyInvocable<void(Account)> login_success_callback,
|
||||
absl::AnyInvocable<void(absl::Status)> login_failure_callback) = 0;
|
||||
|
||||
// Initializes the login process for a Google account from an oauth client.
|
||||
// |client_id| GCP client_id of the client
|
||||
// |client_secret| GCP client_secret of the client
|
||||
// |login_success_callback| is called when the login succeeded. Account
|
||||
// information is passed to callback.
|
||||
// |login_failure_callback| is called when the login fails.
|
||||
virtual void Login(
|
||||
absl::string_view client_id, absl::string_view client_secret,
|
||||
absl::AnyInvocable<void(Account)> login_success_callback,
|
||||
absl::AnyInvocable<void(absl::Status)> login_failure_callback) = 0;
|
||||
|
||||
// Logs out current active account. |logout_callback| is called when logout is
|
||||
// completed.
|
||||
virtual void Logout(
|
||||
|
||||
@@ -46,6 +46,22 @@ void FakeAccountManager::Login(
|
||||
login_failure_callback(absl::InternalError("No account."));
|
||||
}
|
||||
|
||||
void FakeAccountManager::Login(
|
||||
absl::string_view client_id, absl::string_view client_secret,
|
||||
absl::AnyInvocable<void(Account)> login_success_callback,
|
||||
absl::AnyInvocable<void(absl::Status)> login_failure_callback) {
|
||||
if (account_.has_value()) {
|
||||
UpdateCurrentUser(account_->id);
|
||||
NotifyLogin(account_->id);
|
||||
// Invoke callback after all operations have been performed since test cases
|
||||
// may rely on the callback for synchronization.
|
||||
login_success_callback(*account_);
|
||||
return;
|
||||
}
|
||||
|
||||
login_failure_callback(absl::InternalError("No account."));
|
||||
}
|
||||
|
||||
void FakeAccountManager::Logout(
|
||||
absl::AnyInvocable<void(absl::Status)> logout_callback) {
|
||||
if (is_logout_success_) {
|
||||
|
||||
@@ -39,6 +39,11 @@ class FakeAccountManager : public AccountManager {
|
||||
absl::AnyInvocable<void(Account)> login_success_callback,
|
||||
absl::AnyInvocable<void(absl::Status)> login_failure_callback) override;
|
||||
|
||||
void Login(
|
||||
absl::string_view client_id, absl::string_view client_secret,
|
||||
absl::AnyInvocable<void(Account)> login_success_callback,
|
||||
absl::AnyInvocable<void(absl::Status)> login_failure_callback) override;
|
||||
|
||||
void Logout(absl::AnyInvocable<void(absl::Status)> logout_callback) override;
|
||||
|
||||
bool GetAccessToken(
|
||||
|
||||
@@ -32,6 +32,11 @@ class MockAccountManager : public AccountManager {
|
||||
(absl::AnyInvocable<void(Account)> login_success_callback,
|
||||
absl::AnyInvocable<void(absl::Status)> login_failure_callback),
|
||||
(override));
|
||||
MOCK_METHOD(void, Login,
|
||||
(absl::string_view client_id, absl::string_view client_secret,
|
||||
absl::AnyInvocable<void(Account)> login_success_callback,
|
||||
absl::AnyInvocable<void(absl::Status)> login_failure_callback),
|
||||
(override));
|
||||
MOCK_METHOD(void, Logout,
|
||||
(absl::AnyInvocable<void(absl::Status)> logout_callback),
|
||||
(override));
|
||||
|
||||
@@ -117,8 +117,9 @@ class NearbyShareCertificateManagerImplTest
|
||||
|
||||
fake_account_manager_.SetAccount(account);
|
||||
|
||||
fake_account_manager_.Login([](AccountManager::Account account) {},
|
||||
[](absl::Status status) {});
|
||||
fake_account_manager_.Login(
|
||||
"test_client_id", "test_client_secret",
|
||||
[](AccountManager::Account account) {}, [](absl::Status status) {});
|
||||
|
||||
NearbyShareSchedulerFactory::SetFactoryForTesting(&scheduler_factory_);
|
||||
NearbyShareCertificateStorageImpl::Factory::SetFactoryForTesting(
|
||||
@@ -511,10 +512,10 @@ TEST_F(NearbyShareCertificateManagerImplTest,
|
||||
FastForward(GetNearbyShareTestNotBefore() +
|
||||
kNearbyShareCertificateValidityPeriod * 0.5 - Now());
|
||||
|
||||
std::optional<NearbyShareEncryptedMetadataKey> encrypted_metadata_key_everyone
|
||||
=
|
||||
cert_manager_->EncryptPrivateCertificateMetadataKey(
|
||||
DeviceVisibility::DEVICE_VISIBILITY_EVERYONE);
|
||||
std::optional<NearbyShareEncryptedMetadataKey>
|
||||
encrypted_metadata_key_everyone =
|
||||
cert_manager_->EncryptPrivateCertificateMetadataKey(
|
||||
DeviceVisibility::DEVICE_VISIBILITY_EVERYONE);
|
||||
EXPECT_EQ(GetNearbyShareTestEncryptedMetadataKey().encrypted_key(),
|
||||
encrypted_metadata_key_everyone->encrypted_key());
|
||||
EXPECT_EQ(GetNearbyShareTestEncryptedMetadataKey().salt(),
|
||||
|
||||
@@ -2174,6 +2174,7 @@ TEST_F(NearbySharingServiceImplTest, ValidateLoginStateWhenSettingVisibility) {
|
||||
absl::Notification login_notification;
|
||||
account_manager().SetAccount(account);
|
||||
service_->GetAccountManager()->Login(
|
||||
"test_client_id", "test_client_secret",
|
||||
[&](AccountManager::Account account) {
|
||||
EXPECT_EQ(account.id, kTestAccountId);
|
||||
login_notification.Notify();
|
||||
@@ -4467,6 +4468,7 @@ TEST_F(NearbySharingServiceImplTest, ObserveAccountLoginAndLogout) {
|
||||
account.id = kTestAccountId;
|
||||
account_manager().SetAccount(account);
|
||||
service_->GetAccountManager()->Login(
|
||||
"test_client_id", "test_client_secret",
|
||||
[&](AccountManager::Account account) {
|
||||
EXPECT_EQ(account.id, kTestAccountId);
|
||||
notification.Notify();
|
||||
@@ -4499,6 +4501,7 @@ TEST_F(NearbySharingServiceImplTest, LoginAndLogoutShouldResetSettings) {
|
||||
absl::Notification login_notification;
|
||||
account_manager().SetAccount(account);
|
||||
service_->GetAccountManager()->Login(
|
||||
"test_client_id", "test_client_secret",
|
||||
[&](AccountManager::Account account) {
|
||||
EXPECT_EQ(account.id, kTestAccountId);
|
||||
login_notification.Notify();
|
||||
@@ -4536,6 +4539,7 @@ TEST_F(NearbySharingServiceImplTest, LogoutShouldSetValidVisibility) {
|
||||
absl::Notification login_notification;
|
||||
account_manager().SetAccount(account);
|
||||
service_->GetAccountManager()->Login(
|
||||
"test_client_id", "test_client_secret",
|
||||
[&](AccountManager::Account account) {
|
||||
EXPECT_EQ(account.id, kTestAccountId);
|
||||
login_notification.Notify();
|
||||
@@ -4563,6 +4567,7 @@ TEST_F(NearbySharingServiceImplTest, LogoutShouldSetValidVisibility) {
|
||||
absl::Notification login2_notification;
|
||||
account_manager().SetAccount(account);
|
||||
service_->GetAccountManager()->Login(
|
||||
"test_client_id", "test_client_secret",
|
||||
[&](AccountManager::Account account) {
|
||||
EXPECT_EQ(account.id, kTestAccountId);
|
||||
login2_notification.Notify();
|
||||
@@ -4605,6 +4610,7 @@ TEST_F(NearbySharingServiceImplTest, LoginAndLogoutNoStopRunningSurfaces) {
|
||||
account.id = kTestAccountId;
|
||||
account_manager().SetAccount(account);
|
||||
service_->GetAccountManager()->Login(
|
||||
"test_client_id", "test_client_secret",
|
||||
[&](AccountManager::Account account) {
|
||||
EXPECT_EQ(account.id, kTestAccountId);
|
||||
notification.Notify();
|
||||
|
||||
Reference in New Issue
Block a user