Commit f363b1dd authored by Colin Blundell's avatar Colin Blundell Committed by Commit Bot

IdentityTestEnvironment: Sharpen APIs for interacting with refresh token

This CL follows the motivations of
https://chromium-review.googlesource.com/c/chromium/src/+/1095108 to
make the same change for the SetInvalidRefreshTokenForAccount() and
RemoveRefreshTokenForAccount() APIs as that CL made for the
SetRefreshTokenForAccount() API.

Bug: 798699
Change-Id: If3701f0d42fd0129ed324dc8b9f7ac7402c1cb3d
Reviewed-on: https://chromium-review.googlesource.com/1097087Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Commit-Queue: Colin Blundell <blundell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#566765}
parent 2f96cd9f
......@@ -173,7 +173,7 @@ TEST_F(SyncAuthManagerTest, ForwardsCredentialsEvents) {
// Revoking the refresh token should also cause the access token to get
// dropped.
EXPECT_CALL(credentials_changed, Run());
identity_env()->RemoveRefreshTokenForAccount(account_id);
identity_env()->RemoveRefreshTokenForPrimaryAccount();
EXPECT_TRUE(auth_manager->GetCredentials().sync_token.empty());
}
......@@ -419,7 +419,7 @@ TEST_F(SyncAuthManagerTest, ClearsCredentialsOnRefreshTokenRemoval) {
EXPECT_CALL(access_token_requested, Run()).Times(0);
identity_env()->SetCallbackForNextAccessTokenRequest(
access_token_requested.Get());
identity_env()->RemoveRefreshTokenForAccount(account_id);
identity_env()->RemoveRefreshTokenForPrimaryAccount();
// Should immediately drop the access token and expose an auth error.
EXPECT_TRUE(auth_manager->GetCredentials().sync_token.empty());
......@@ -459,7 +459,7 @@ TEST_F(SyncAuthManagerTest, ClearsCredentialsOnInvalidRefreshToken) {
EXPECT_CALL(access_token_requested, Run()).Times(0);
identity_env()->SetCallbackForNextAccessTokenRequest(
access_token_requested.Get());
identity_env()->SetInvalidRefreshTokenForAccount(account_id);
identity_env()->SetInvalidRefreshTokenForPrimaryAccount();
// Should immediately drop the access token and expose a special auth error.
EXPECT_TRUE(auth_manager->GetCredentials().sync_token.empty());
......
......@@ -108,16 +108,14 @@ void IdentityTestEnvironment::SetRefreshTokenForPrimaryAccount() {
internals_->identity_manager());
}
void IdentityTestEnvironment::SetInvalidRefreshTokenForAccount(
const std::string& account_id) {
identity::SetInvalidRefreshTokenForAccount(
internals_->token_service(), internals_->identity_manager(), account_id);
void IdentityTestEnvironment::SetInvalidRefreshTokenForPrimaryAccount() {
identity::SetInvalidRefreshTokenForPrimaryAccount(
internals_->token_service(), internals_->identity_manager());
}
void IdentityTestEnvironment::RemoveRefreshTokenForAccount(
const std::string& account_id) {
identity::RemoveRefreshTokenForAccount(
internals_->token_service(), internals_->identity_manager(), account_id);
void IdentityTestEnvironment::RemoveRefreshTokenForPrimaryAccount() {
identity::RemoveRefreshTokenForPrimaryAccount(internals_->token_service(),
internals_->identity_manager());
}
std::string IdentityTestEnvironment::MakePrimaryAccountAvailable(
......
......@@ -34,13 +34,13 @@ class IdentityTestEnvironment : public IdentityManager::DiagnosticsObserver {
// Blocks until the refresh token is set.
void SetRefreshTokenForPrimaryAccount();
// Sets a special invalid refresh token that corresponds uniquely to
// |account_id|. Blocks until the refresh token is set.
void SetInvalidRefreshTokenForAccount(const std::string& account_id);
// Sets a special invalid refresh token for the primary account (which must
// already be set). Blocks until the refresh token is set.
void SetInvalidRefreshTokenForPrimaryAccount();
// Removes the refresh token that corresponds uniquely to |account_id|.
// Blocks until the refresh token is cleared.
void RemoveRefreshTokenForAccount(const std::string& account_id);
// Removes any refresh token for the primary account (which must already be
// set). Blocks until the refresh token is removed.
void RemoveRefreshTokenForPrimaryAccount();
// Makes the primary account available for the given email address, generating
// a GAIA ID and refresh token that correspond uniquely to that email address.
......
......@@ -107,16 +107,20 @@ void SetRefreshTokenForPrimaryAccount(ProfileOAuth2TokenService* token_service,
token_service->UpdateCredentials(account_id, refresh_token);
}
void SetInvalidRefreshTokenForAccount(ProfileOAuth2TokenService* token_service,
IdentityManager* identity_manager,
const std::string& account_id) {
void SetInvalidRefreshTokenForPrimaryAccount(
ProfileOAuth2TokenService* token_service,
IdentityManager* identity_manager) {
DCHECK(identity_manager->HasPrimaryAccount());
std::string account_id = identity_manager->GetPrimaryAccountInfo().account_id;
token_service->UpdateCredentials(
account_id, OAuth2TokenServiceDelegate::kInvalidRefreshToken);
}
void RemoveRefreshTokenForAccount(ProfileOAuth2TokenService* token_service,
IdentityManager* identity_manager,
const std::string& account_id) {
void RemoveRefreshTokenForPrimaryAccount(
ProfileOAuth2TokenService* token_service,
IdentityManager* identity_manager) {
DCHECK(identity_manager->HasPrimaryAccount());
std::string account_id = identity_manager->GetPrimaryAccountInfo().account_id;
token_service->RevokeCredentials(account_id);
}
......
......@@ -48,18 +48,19 @@ std::string SetPrimaryAccount(SigninManagerBase* signin_manager,
void SetRefreshTokenForPrimaryAccount(ProfileOAuth2TokenService* token_service,
IdentityManager* identity_manager);
// Sets a special invalid refresh token. Blocks until the refresh token is set.
// NOTE: See disclaimer at top of file re: direct usage.
void SetInvalidRefreshTokenForAccount(ProfileOAuth2TokenService* token_service,
IdentityManager* identity_manager,
const std::string& account_id);
// Sets a special invalid refresh token for the primary account (which must
// already be set). Blocks until the refresh token is set. NOTE: See disclaimer
// at top of file re: direct usage.
void SetInvalidRefreshTokenForPrimaryAccount(
ProfileOAuth2TokenService* token_service,
IdentityManager* identity_manager);
// Removes the refresh token for |account_id|, if ones exists. Blocks until the
// refresh token is cleared.
// NOTE: See disclaimer at top of file re: direct usage.
void RemoveRefreshTokenForAccount(ProfileOAuth2TokenService* token_service,
IdentityManager* identity_manager,
const std::string& account_id);
// Removes any refresh token for the primary account (which must already be
// set). Blocks until the refresh token is removed. NOTE: See disclaimer at top
// of file re: direct usage.
void RemoveRefreshTokenForPrimaryAccount(
ProfileOAuth2TokenService* token_service,
IdentityManager* identity_manager);
// Makes the primary account available for the given email address, generating a
// GAIA ID and refresh token that correspond uniquely to that email address. On
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment