Commit 7c3707a7 authored by Thomas Tangl's avatar Thomas Tangl Committed by Commit Bot

[unified-consent] Revoke unified consent when user has custom passphrase

When a custom passphrase is detected in the unified consent service,
unified consent is revoked.

Bug: 872221
Change-Id: I5c571e38a8752973f8b393f570c6a2e11b56183b
Reviewed-on: https://chromium-review.googlesource.com/1170694
Commit-Queue: Thomas Tangl <tangltom@chromium.org>
Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582476}
parent 89099d7d
...@@ -235,6 +235,14 @@ void UnifiedConsentService::OnPrimaryAccountCleared( ...@@ -235,6 +235,14 @@ void UnifiedConsentService::OnPrimaryAccountCleared(
} }
void UnifiedConsentService::OnStateChanged(syncer::SyncService* sync) { void UnifiedConsentService::OnStateChanged(syncer::SyncService* sync) {
if (!sync_service_->IsEngineInitialized())
return;
if (sync_service_->IsUsingSecondaryPassphrase() && IsUnifiedConsentGiven()) {
// Force off unified consent given when the user sets a custom passphrase.
SetUnifiedConsentGiven(false);
}
syncer::SyncPrefs sync_prefs(pref_service_); syncer::SyncPrefs sync_prefs(pref_service_);
if (IsUnifiedConsentGiven() != sync_prefs.HasKeepEverythingSynced()) { if (IsUnifiedConsentGiven() != sync_prefs.HasKeepEverythingSynced()) {
// Make sync-everything consistent with the |kUnifiedConsentGiven| pref. // Make sync-everything consistent with the |kUnifiedConsentGiven| pref.
......
...@@ -40,8 +40,15 @@ class TestSyncService : public syncer::FakeSyncService { ...@@ -40,8 +40,15 @@ class TestSyncService : public syncer::FakeSyncService {
syncer::ModelTypeSet GetPreferredDataTypes() const override { syncer::ModelTypeSet GetPreferredDataTypes() const override {
return chosen_types_; return chosen_types_;
} }
bool IsUsingSecondaryPassphrase() const override {
return is_using_passphrase_;
}
void SetTransportState(TransportState state) { state_ = state; } void SetTransportState(TransportState state) { state_ = state; }
void SetIsUsingPassphrase(bool using_passphrase) {
is_using_passphrase_ = using_passphrase;
}
void FireStateChanged() { void FireStateChanged() {
if (observer_) if (observer_)
observer_->OnStateChanged(this); observer_->OnStateChanged(this);
...@@ -51,6 +58,7 @@ class TestSyncService : public syncer::FakeSyncService { ...@@ -51,6 +58,7 @@ class TestSyncService : public syncer::FakeSyncService {
syncer::SyncServiceObserver* observer_ = nullptr; syncer::SyncServiceObserver* observer_ = nullptr;
TransportState state_ = TransportState::ACTIVE; TransportState state_ = TransportState::ACTIVE;
syncer::ModelTypeSet chosen_types_ = syncer::UserSelectableTypes(); syncer::ModelTypeSet chosen_types_ = syncer::UserSelectableTypes();
bool is_using_passphrase_ = false;
PrefService* pref_service_; PrefService* pref_service_;
}; };
...@@ -243,6 +251,25 @@ TEST_F(UnifiedConsentServiceTest, EnableUnfiedConsent_SyncNotActive) { ...@@ -243,6 +251,25 @@ TEST_F(UnifiedConsentServiceTest, EnableUnfiedConsent_SyncNotActive) {
EXPECT_TRUE(sync_prefs.HasKeepEverythingSynced()); EXPECT_TRUE(sync_prefs.HasKeepEverythingSynced());
} }
TEST_F(UnifiedConsentServiceTest, EnableUnfiedConsent_WithCustomPassphrase) {
CreateConsentService();
identity_test_environment_.SetPrimaryAccount("testaccount");
EXPECT_FALSE(consent_service_->IsUnifiedConsentGiven());
EXPECT_FALSE(AreAllNonPersonalizedServicesEnabled());
// Enable Unified Consent.
consent_service_->SetUnifiedConsentGiven(true);
EXPECT_TRUE(consent_service_->IsUnifiedConsentGiven());
EXPECT_TRUE(AreAllNonPersonalizedServicesEnabled());
// Set custom passphrase.
sync_service_.SetIsUsingPassphrase(true);
sync_service_.FireStateChanged();
// Setting a custom passphrase forces off unified consent given.
EXPECT_FALSE(consent_service_->IsUnifiedConsentGiven());
}
// Test whether unified consent is disabled when any of its dependent services // Test whether unified consent is disabled when any of its dependent services
// gets disabled. // gets disabled.
TEST_F(UnifiedConsentServiceTest, DisableUnfiedConsentWhenServiceIsDisabled) { TEST_F(UnifiedConsentServiceTest, DisableUnfiedConsentWhenServiceIsDisabled) {
......
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