Index: chrome/browser/extensions/api/enterprise_platform_keys_private/enterprise_platform_keys_private_api_unittest.cc |
diff --git a/chrome/browser/extensions/api/enterprise_platform_keys_private/enterprise_platform_keys_private_api_unittest.cc b/chrome/browser/extensions/api/enterprise_platform_keys_private/enterprise_platform_keys_private_api_unittest.cc |
index 2bb3c4350d17ede8931e39ba6a15a9080e71fdea..054c1830b8243ae60e653fe5fb7a28fa018857e1 100644 |
--- a/chrome/browser/extensions/api/enterprise_platform_keys_private/enterprise_platform_keys_private_api_unittest.cc |
+++ b/chrome/browser/extensions/api/enterprise_platform_keys_private/enterprise_platform_keys_private_api_unittest.cc |
@@ -15,6 +15,7 @@ |
#include "chrome/browser/chromeos/policy/stub_enterprise_install_attributes.h" |
#include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" |
#include "chrome/browser/extensions/extension_function_test_utils.h" |
+#include "chrome/browser/signin/signin_manager_factory.h" |
#include "chrome/common/pref_names.h" |
#include "chrome/test/base/browser_with_test_window_test.h" |
#include "chromeos/attestation/attestation_constants.h" |
@@ -25,6 +26,7 @@ |
#include "chromeos/dbus/mock_cryptohome_client.h" |
#include "chromeos/settings/cros_settings_provider.h" |
#include "components/policy/core/common/cloud/cloud_policy_constants.h" |
+#include "components/signin/core/browser/signin_manager.h" |
#include "extensions/common/test_util.h" |
#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -187,7 +189,6 @@ class EPKPChallengeKeyTestBase : public BrowserWithTestWindowTest { |
// Set the user preferences. |
prefs_ = browser()->profile()->GetPrefs(); |
- prefs_->SetString(prefs::kGoogleServicesUsername, "test@google.com"); |
base::ListValue whitelist; |
whitelist.AppendString(extension_->id()); |
prefs_->Set(prefs::kAttestationExtensionWhitelist, whitelist); |
@@ -229,12 +230,16 @@ class EPKPChallengeMachineKeyTest : public EPKPChallengeKeyTestBase { |
const char EPKPChallengeMachineKeyTest::kArgs[] = "[\"Y2hhbGxlbmdl\"]"; |
TEST_F(EPKPChallengeMachineKeyTest, ChallengeBadBase64) { |
+ SigninManagerFactory::GetForProfile(browser()->profile())-> |
not at google - send to devlin
2014/12/04 16:32:31
Is there any harm in doing this in a SetUp for eve
Roger Tawa OOO till Jul 10th
2014/12/04 16:35:58
See my comment at line 261 below :-)
|
+ SetAuthenticatedUsername("test@google.com"); |
EXPECT_EQ(EPKPChallengeKeyBase::kChallengeBadBase64Error, |
utils::RunFunctionAndReturnError( |
func_.get(), "[\"****\"]", browser())); |
} |
TEST_F(EPKPChallengeMachineKeyTest, NonEnterpriseDevice) { |
+ SigninManagerFactory::GetForProfile(browser()->profile())-> |
+ SetAuthenticatedUsername("test@google.com"); |
stub_install_attributes_.SetRegistrationUser(""); |
EXPECT_EQ(EPKPChallengeMachineKey::kNonEnterpriseDeviceError, |
@@ -242,6 +247,8 @@ TEST_F(EPKPChallengeMachineKeyTest, NonEnterpriseDevice) { |
} |
TEST_F(EPKPChallengeMachineKeyTest, ExtensionNotWhitelisted) { |
+ SigninManagerFactory::GetForProfile(browser()->profile())-> |
+ SetAuthenticatedUsername("test@google.com"); |
base::ListValue empty_whitelist; |
prefs_->Set(prefs::kAttestationExtensionWhitelist, empty_whitelist); |
@@ -250,13 +257,16 @@ TEST_F(EPKPChallengeMachineKeyTest, ExtensionNotWhitelisted) { |
} |
TEST_F(EPKPChallengeMachineKeyTest, UserNotManaged) { |
- prefs_->SetString(prefs::kGoogleServicesUsername, "test@chromium.org"); |
+ SigninManagerFactory::GetForProfile(browser()->profile())-> |
+ SetAuthenticatedUsername("test@chromium.org"); |
Roger Tawa OOO till Jul 10th
2014/12/04 16:27:57
On cros, you can only call SetAuthenticatedUsernam
not at google - send to devlin
2014/12/04 16:37:26
Well... bummer.
pneubeck (no reviews)
2014/12/04 17:06:47
How about a separate test-fixture that again overr
Roger Tawa OOO till Jul 10th
2014/12/04 22:26:47
Yeah, actually that is a lot better. Done.
|
EXPECT_EQ(EPKPChallengeKeyBase::kUserNotManaged, |
utils::RunFunctionAndReturnError(func_.get(), kArgs, browser())); |
} |
TEST_F(EPKPChallengeMachineKeyTest, DevicePolicyDisabled) { |
+ SigninManagerFactory::GetForProfile(browser()->profile())-> |
+ SetAuthenticatedUsername("test@google.com"); |
stub_settings_provider_.Set(chromeos::kDeviceAttestationEnabled, |
base::FundamentalValue(false)); |
@@ -265,6 +275,8 @@ TEST_F(EPKPChallengeMachineKeyTest, DevicePolicyDisabled) { |
} |
TEST_F(EPKPChallengeMachineKeyTest, DoesKeyExistDbusFailed) { |
+ SigninManagerFactory::GetForProfile(browser()->profile())-> |
+ SetAuthenticatedUsername("test@google.com"); |
EXPECT_CALL(mock_cryptohome_client_, TpmAttestationDoesKeyExist(_, _, _, _)) |
.WillRepeatedly(WithArgs<3>(Invoke(FakeBoolDBusMethod( |
chromeos::DBUS_METHOD_CALL_FAILURE, false)))); |
@@ -274,6 +286,8 @@ TEST_F(EPKPChallengeMachineKeyTest, DoesKeyExistDbusFailed) { |
} |
TEST_F(EPKPChallengeMachineKeyTest, GetCertificateFailed) { |
+ SigninManagerFactory::GetForProfile(browser()->profile())-> |
+ SetAuthenticatedUsername("test@google.com"); |
EXPECT_CALL(mock_attestation_flow_, GetCertificate(_, _, _, _, _)) |
.WillRepeatedly(Invoke(GetCertificateCallbackFalse)); |
@@ -282,6 +296,8 @@ TEST_F(EPKPChallengeMachineKeyTest, GetCertificateFailed) { |
} |
TEST_F(EPKPChallengeMachineKeyTest, SignChallengeFailed) { |
+ SigninManagerFactory::GetForProfile(browser()->profile())-> |
+ SetAuthenticatedUsername("test@google.com"); |
EXPECT_CALL(mock_async_method_caller_, |
TpmAttestationSignEnterpriseChallenge(_, _, _, _, _, _, _, _)) |
.WillRepeatedly(Invoke(SignChallengeCallbackFalse)); |
@@ -291,6 +307,8 @@ TEST_F(EPKPChallengeMachineKeyTest, SignChallengeFailed) { |
} |
TEST_F(EPKPChallengeMachineKeyTest, KeyExists) { |
+ SigninManagerFactory::GetForProfile(browser()->profile())-> |
+ SetAuthenticatedUsername("test@google.com"); |
EXPECT_CALL(mock_cryptohome_client_, TpmAttestationDoesKeyExist(_, _, _, _)) |
.WillRepeatedly(WithArgs<3>(Invoke(FakeBoolDBusMethod( |
chromeos::DBUS_METHOD_CALL_SUCCESS, true)))); |
@@ -302,6 +320,8 @@ TEST_F(EPKPChallengeMachineKeyTest, KeyExists) { |
} |
TEST_F(EPKPChallengeMachineKeyTest, Success) { |
+ SigninManagerFactory::GetForProfile(browser()->profile())-> |
+ SetAuthenticatedUsername("test@google.com"); |
// GetCertificate must be called exactly once. |
EXPECT_CALL(mock_attestation_flow_, |
GetCertificate( |
@@ -324,6 +344,8 @@ TEST_F(EPKPChallengeMachineKeyTest, Success) { |
} |
TEST_F(EPKPChallengeMachineKeyTest, AttestationNotPrepared) { |
+ SigninManagerFactory::GetForProfile(browser()->profile())-> |
+ SetAuthenticatedUsername("test@google.com"); |
EXPECT_CALL(mock_cryptohome_client_, TpmAttestationIsPrepared(_)) |
.WillRepeatedly(Invoke(FakeBoolDBusMethod( |
chromeos::DBUS_METHOD_CALL_SUCCESS, false))); |
@@ -333,6 +355,8 @@ TEST_F(EPKPChallengeMachineKeyTest, AttestationNotPrepared) { |
} |
TEST_F(EPKPChallengeMachineKeyTest, AttestationPreparedDbusFailed) { |
+ SigninManagerFactory::GetForProfile(browser()->profile())-> |
+ SetAuthenticatedUsername("test@google.com"); |
EXPECT_CALL(mock_cryptohome_client_, TpmAttestationIsPrepared(_)) |
.WillRepeatedly(Invoke(FakeBoolDBusMethod( |
chromeos::DBUS_METHOD_CALL_FAILURE, true))); |
@@ -373,12 +397,16 @@ class EPKPChallengeUserKeyTest : public EPKPChallengeKeyTestBase { |
const char EPKPChallengeUserKeyTest::kArgs[] = "[\"Y2hhbGxlbmdl\", true]"; |
TEST_F(EPKPChallengeUserKeyTest, ChallengeBadBase64) { |
+ SigninManagerFactory::GetForProfile(browser()->profile())-> |
+ SetAuthenticatedUsername("test@google.com"); |
EXPECT_EQ(EPKPChallengeKeyBase::kChallengeBadBase64Error, |
utils::RunFunctionAndReturnError( |
func_.get(), "[\"****\", true]", browser())); |
} |
TEST_F(EPKPChallengeUserKeyTest, UserPolicyDisabled) { |
+ SigninManagerFactory::GetForProfile(browser()->profile())-> |
+ SetAuthenticatedUsername("test@google.com"); |
prefs_->SetBoolean(prefs::kAttestationEnabled, false); |
EXPECT_EQ(EPKPChallengeUserKey::kUserPolicyDisabledError, |
@@ -386,6 +414,8 @@ TEST_F(EPKPChallengeUserKeyTest, UserPolicyDisabled) { |
} |
TEST_F(EPKPChallengeUserKeyTest, ExtensionNotWhitelisted) { |
+ SigninManagerFactory::GetForProfile(browser()->profile())-> |
+ SetAuthenticatedUsername("test@google.com"); |
base::ListValue empty_whitelist; |
prefs_->Set(prefs::kAttestationExtensionWhitelist, empty_whitelist); |
@@ -394,13 +424,16 @@ TEST_F(EPKPChallengeUserKeyTest, ExtensionNotWhitelisted) { |
} |
TEST_F(EPKPChallengeUserKeyTest, UserNotManaged) { |
- prefs_->SetString(prefs::kGoogleServicesUsername, "test@chromium.org"); |
+ SigninManagerFactory::GetForProfile(browser()->profile())-> |
+ SetAuthenticatedUsername("test@chromium.org"); |
EXPECT_EQ(EPKPChallengeKeyBase::kUserNotManaged, |
utils::RunFunctionAndReturnError(func_.get(), kArgs, browser())); |
} |
TEST_F(EPKPChallengeUserKeyTest, DevicePolicyDisabled) { |
+ SigninManagerFactory::GetForProfile(browser()->profile())-> |
+ SetAuthenticatedUsername("test@google.com"); |
stub_settings_provider_.Set(chromeos::kDeviceAttestationEnabled, |
base::FundamentalValue(false)); |
@@ -409,6 +442,8 @@ TEST_F(EPKPChallengeUserKeyTest, DevicePolicyDisabled) { |
} |
TEST_F(EPKPChallengeUserKeyTest, DoesKeyExistDbusFailed) { |
+ SigninManagerFactory::GetForProfile(browser()->profile())-> |
+ SetAuthenticatedUsername("test@google.com"); |
EXPECT_CALL(mock_cryptohome_client_, TpmAttestationDoesKeyExist(_, _, _, _)) |
.WillRepeatedly(WithArgs<3>(Invoke(FakeBoolDBusMethod( |
chromeos::DBUS_METHOD_CALL_FAILURE, false)))); |
@@ -418,6 +453,8 @@ TEST_F(EPKPChallengeUserKeyTest, DoesKeyExistDbusFailed) { |
} |
TEST_F(EPKPChallengeUserKeyTest, GetCertificateFailed) { |
+ SigninManagerFactory::GetForProfile(browser()->profile())-> |
+ SetAuthenticatedUsername("test@google.com"); |
EXPECT_CALL(mock_attestation_flow_, GetCertificate(_, _, _, _, _)) |
.WillRepeatedly(Invoke(GetCertificateCallbackFalse)); |
@@ -426,6 +463,8 @@ TEST_F(EPKPChallengeUserKeyTest, GetCertificateFailed) { |
} |
TEST_F(EPKPChallengeUserKeyTest, SignChallengeFailed) { |
+ SigninManagerFactory::GetForProfile(browser()->profile())-> |
+ SetAuthenticatedUsername("test@google.com"); |
EXPECT_CALL(mock_async_method_caller_, |
TpmAttestationSignEnterpriseChallenge(_, _, _, _, _, _, _, _)) |
.WillRepeatedly(Invoke(SignChallengeCallbackFalse)); |
@@ -435,6 +474,8 @@ TEST_F(EPKPChallengeUserKeyTest, SignChallengeFailed) { |
} |
TEST_F(EPKPChallengeUserKeyTest, KeyRegistrationFailed) { |
+ SigninManagerFactory::GetForProfile(browser()->profile())-> |
+ SetAuthenticatedUsername("test@google.com"); |
EXPECT_CALL(mock_async_method_caller_, TpmAttestationRegisterKey(_, _, _, _)) |
.WillRepeatedly(Invoke(RegisterKeyCallbackFalse)); |
@@ -443,6 +484,8 @@ TEST_F(EPKPChallengeUserKeyTest, KeyRegistrationFailed) { |
} |
TEST_F(EPKPChallengeUserKeyTest, KeyExists) { |
+ SigninManagerFactory::GetForProfile(browser()->profile())-> |
+ SetAuthenticatedUsername("test@google.com"); |
EXPECT_CALL(mock_cryptohome_client_, TpmAttestationDoesKeyExist(_, _, _, _)) |
.WillRepeatedly(WithArgs<3>(Invoke(FakeBoolDBusMethod( |
chromeos::DBUS_METHOD_CALL_SUCCESS, true)))); |
@@ -454,6 +497,8 @@ TEST_F(EPKPChallengeUserKeyTest, KeyExists) { |
} |
TEST_F(EPKPChallengeUserKeyTest, KeyNotRegistered) { |
+ SigninManagerFactory::GetForProfile(browser()->profile())-> |
+ SetAuthenticatedUsername("test@google.com"); |
EXPECT_CALL(mock_async_method_caller_, TpmAttestationRegisterKey(_, _, _, _)) |
.Times(0); |
@@ -462,6 +507,8 @@ TEST_F(EPKPChallengeUserKeyTest, KeyNotRegistered) { |
} |
TEST_F(EPKPChallengeUserKeyTest, PersonalDevice) { |
+ SigninManagerFactory::GetForProfile(browser()->profile())-> |
+ SetAuthenticatedUsername("test@google.com"); |
stub_install_attributes_.SetRegistrationUser(""); |
// Currently personal devices are not supported. |
@@ -470,6 +517,8 @@ TEST_F(EPKPChallengeUserKeyTest, PersonalDevice) { |
} |
TEST_F(EPKPChallengeUserKeyTest, Success) { |
+ SigninManagerFactory::GetForProfile(browser()->profile())-> |
+ SetAuthenticatedUsername("test@google.com"); |
// GetCertificate must be called exactly once. |
EXPECT_CALL(mock_attestation_flow_, |
GetCertificate( |
@@ -499,6 +548,8 @@ TEST_F(EPKPChallengeUserKeyTest, Success) { |
} |
TEST_F(EPKPChallengeUserKeyTest, AttestationNotPrepared) { |
+ SigninManagerFactory::GetForProfile(browser()->profile())-> |
+ SetAuthenticatedUsername("test@google.com"); |
EXPECT_CALL(mock_cryptohome_client_, TpmAttestationIsPrepared(_)) |
.WillRepeatedly(Invoke(FakeBoolDBusMethod( |
chromeos::DBUS_METHOD_CALL_SUCCESS, false))); |
@@ -508,6 +559,8 @@ TEST_F(EPKPChallengeUserKeyTest, AttestationNotPrepared) { |
} |
TEST_F(EPKPChallengeUserKeyTest, AttestationPreparedDbusFailed) { |
+ SigninManagerFactory::GetForProfile(browser()->profile())-> |
+ SetAuthenticatedUsername("test@google.com"); |
EXPECT_CALL(mock_cryptohome_client_, TpmAttestationIsPrepared(_)) |
.WillRepeatedly(Invoke(FakeBoolDBusMethod( |
chromeos::DBUS_METHOD_CALL_FAILURE, true))); |