Index: chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos_unittest.cc |
diff --git a/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos_unittest.cc b/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos_unittest.cc |
index 4f7089dd8f286c31b826b628ada406b2ba387a38..904c8583abdd6312b4717eafc874e6107f26084b 100644 |
--- a/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos_unittest.cc |
+++ b/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos_unittest.cc |
@@ -46,6 +46,7 @@ |
#include "components/policy/core/common/cloud/cloud_policy_constants.h" |
#include "components/policy/core/common/cloud/cloud_policy_core.h" |
#include "components/policy/core/common/cloud/mock_device_management_service.h" |
+#include "components/policy/core/common/cloud/mock_signing_service.h" |
#include "components/policy/core/common/external_data_fetcher.h" |
#include "components/policy/core/common/policy_types.h" |
#include "components/policy/core/common/schema_registry.h" |
@@ -124,7 +125,7 @@ class DeviceCloudPolicyManagerChromeOSTest |
chromeos::system::StatisticsProvider::SetTestProvider(NULL); |
} |
- virtual bool ShouldRegisterWitCert() const { return false; } |
+ virtual bool ShouldRegisterWithCert() const { return false; } |
void SetUp() override { |
DeviceSettingsTestBase::SetUp(); |
@@ -168,7 +169,7 @@ class DeviceCloudPolicyManagerChromeOSTest |
CreateAttestationFlow() { |
StrictMock<chromeos::attestation::MockAttestationFlow>* mock = |
new StrictMock<chromeos::attestation::MockAttestationFlow>(); |
- if (ShouldRegisterWitCert()) { |
+ if (ShouldRegisterWithCert()) { |
EXPECT_CALL(*mock, GetCertificate(_, _, _, _, _)) |
.WillOnce(WithArgs<4>(Invoke(CertCallbackSuccess))); |
} |
@@ -211,6 +212,8 @@ class DeviceCloudPolicyManagerChromeOSTest |
base::ThreadTaskRunnerHandle::Get(), install_attributes_.get(), |
&state_keys_broker_, store_, manager_.get(), |
cryptohome::AsyncMethodCaller::GetInstance(), std::move(unique_flow))); |
+ initializer_->SetSigningServiceForTesting( |
+ base::MakeUnique<FakeSigningService>()); |
initializer_->Init(); |
} |
@@ -394,7 +397,8 @@ TEST_F(DeviceCloudPolicyManagerChromeOSTest, ConnectAndDisconnect) { |
} |
class DeviceCloudPolicyManagerChromeOSEnrollmentTest |
- : public DeviceCloudPolicyManagerChromeOSTest { |
+ : public DeviceCloudPolicyManagerChromeOSTest, |
+ public testing::WithParamInterface<bool> { |
public: |
void Done(EnrollmentStatus status) { |
status_ = status; |
@@ -459,7 +463,7 @@ class DeviceCloudPolicyManagerChromeOSEnrollmentTest |
} |
void RunTest() { |
- const bool with_cert = ShouldRegisterWitCert(); |
+ const bool with_cert = ShouldRegisterWithCert(); |
// Trigger enrollment. |
MockDeviceManagementJob* register_job = NULL; |
EXPECT_CALL( |
@@ -598,6 +602,25 @@ class DeviceCloudPolicyManagerChromeOSEnrollmentTest |
ReloadDeviceSettings(); |
} |
+ bool ShouldRegisterWithCert() const override { return GetParam(); } |
+ |
+ const em::DeviceRegisterRequest& GetDeviceRegisterRequest() { |
+ if (ShouldRegisterWithCert()) { |
+ const em::SignedData& signed_request = |
+ register_request_.cert_based_register_request().signed_request(); |
+ em::CertificateBasedDeviceRegistrationData data; |
+ EXPECT_TRUE(data.ParseFromString(signed_request.data().substr( |
+ 0, |
+ signed_request.data().size() - signed_request.extra_data_bytes()))); |
+ EXPECT_EQ(em::CertificateBasedDeviceRegistrationData:: |
+ ENTERPRISE_ENROLLMENT_CERTIFICATE, |
+ data.certificate_type()); |
+ return data.device_register_request(); |
+ } else { |
+ return register_request_.register_request(); |
+ } |
+ } |
+ |
DeviceManagementStatus register_status_; |
em::DeviceManagementResponse register_response_; |
@@ -620,43 +643,34 @@ class DeviceCloudPolicyManagerChromeOSEnrollmentTest |
DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyManagerChromeOSEnrollmentTest); |
}; |
-// TODO(drcrash): Handle cert-based tests (http://crbug.com/641447). |
-TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentTest, Reenrollment) { |
- LockDevice(); |
+TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, Success) { |
RunTest(); |
ExpectSuccessfulEnrollment(); |
- EXPECT_TRUE(register_request_.register_request().reregister()); |
- EXPECT_EQ(PolicyBuilder::kFakeDeviceId, client_id_); |
} |
-class ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest |
- : public DeviceCloudPolicyManagerChromeOSEnrollmentTest, |
- public testing::WithParamInterface<bool> { |
- protected: |
- bool ShouldRegisterWitCert() const override { return GetParam(); } |
-}; |
- |
-TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, Success) { |
+TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, Reenrollment) { |
+ LockDevice(); |
RunTest(); |
ExpectSuccessfulEnrollment(); |
+ EXPECT_TRUE(GetDeviceRegisterRequest().reregister()); |
+ EXPECT_EQ(PolicyBuilder::kFakeDeviceId, client_id_); |
} |
-TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, |
- RegistrationFailed) { |
+TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, RegistrationFailed) { |
register_status_ = DM_STATUS_REQUEST_FAILED; |
RunTest(); |
ExpectFailedEnrollment(EnrollmentStatus::STATUS_REGISTRATION_FAILED); |
EXPECT_EQ(DM_STATUS_REQUEST_FAILED, status_.client_status()); |
} |
-TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, |
+TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, |
RobotAuthCodeFetchFailed) { |
robot_auth_fetch_status_ = DM_STATUS_REQUEST_FAILED; |
RunTest(); |
ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_AUTH_FETCH_FAILED); |
} |
-TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, |
+TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, |
RobotRefreshTokenFetchResponseCodeFailed) { |
url_fetcher_response_code_ = 400; |
RunTest(); |
@@ -664,14 +678,14 @@ TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, |
EXPECT_EQ(400, status_.http_status()); |
} |
-TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, |
+TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, |
RobotRefreshTokenFetchResponseStringFailed) { |
url_fetcher_response_string_ = "invalid response json"; |
RunTest(); |
ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_FETCH_FAILED); |
} |
-TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, |
+TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, |
RobotRefreshEncryptionFailed) { |
// The encryption lib is a noop for tests, but empty results from encryption |
// is an error, so we simulate an encryption error by returning an empty |
@@ -683,16 +697,14 @@ TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, |
ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED); |
} |
-TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, |
- PolicyFetchFailed) { |
+TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, PolicyFetchFailed) { |
policy_fetch_status_ = DM_STATUS_REQUEST_FAILED; |
RunTest(); |
ExpectFailedEnrollment(EnrollmentStatus::STATUS_POLICY_FETCH_FAILED); |
EXPECT_EQ(DM_STATUS_REQUEST_FAILED, status_.client_status()); |
} |
-TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, |
- ValidationFailed) { |
+TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, ValidationFailed) { |
device_policy_.policy().set_policy_data_signature("bad"); |
policy_fetch_response_.clear_policy_response(); |
policy_fetch_response_.mutable_policy_response()->add_response()->CopyFrom( |
@@ -703,8 +715,7 @@ TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, |
status_.validation_status()); |
} |
-TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, |
- StoreError) { |
+TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, StoreError) { |
store_result_ = false; |
RunTest(); |
ExpectFailedEnrollment(EnrollmentStatus::STATUS_STORE_ERROR); |
@@ -712,7 +723,7 @@ TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, |
status_.store_status()); |
} |
-TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, LoadError) { |
+TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, LoadError) { |
loaded_blob_.clear(); |
RunTest(); |
ExpectFailedEnrollment(EnrollmentStatus::STATUS_STORE_ERROR); |
@@ -720,8 +731,7 @@ TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, LoadError) { |
status_.store_status()); |
} |
-TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, |
- UnregisterSucceeds) { |
+TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, UnregisterSucceeds) { |
// Enroll first. |
RunTest(); |
ExpectSuccessfulEnrollment(); |
@@ -741,8 +751,7 @@ TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, |
base::Unretained(this))); |
} |
-TEST_P(ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, |
- UnregisterFails) { |
+TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, UnregisterFails) { |
// Enroll first. |
RunTest(); |
ExpectSuccessfulEnrollment(); |
@@ -770,16 +779,20 @@ class DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest |
} |
}; |
-TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest, |
+TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest, |
RobotRefreshSaveFailed) { |
// Without the system salt, the robot token can't be stored. |
RunTest(); |
ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED); |
} |
+INSTANTIATE_TEST_CASE_P(Cert, |
+ DeviceCloudPolicyManagerChromeOSEnrollmentTest, |
+ ::testing::Values(false, true)); |
+ |
INSTANTIATE_TEST_CASE_P( |
Cert, |
- ParameterizedDeviceCloudPolicyManagerChromeOSEnrollmentTest, |
+ DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest, |
::testing::Values(false, true)); |
} // namespace |