Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "chromeos/attestation/mock_attestation_flow.h" | 8 #include "chromeos/attestation/mock_attestation_flow.h" |
| 9 #include "chromeos/cryptohome/mock_async_method_caller.h" | 9 #include "chromeos/cryptohome/mock_async_method_caller.h" |
| 10 #include "chromeos/dbus/mock_cryptohome_client.h" | 10 #include "chromeos/dbus/mock_cryptohome_client.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 using testing::_; | 14 using testing::_; |
| 15 using testing::Invoke; | 15 using testing::Invoke; |
| 16 using testing::NiceMock; | |
|
Mattias Nissler (ping if slow)
2013/04/24 12:57:53
unused?
dkrahn
2013/04/25 01:06:52
Done.
| |
| 16 using testing::Sequence; | 17 using testing::Sequence; |
| 17 using testing::StrictMock; | 18 using testing::StrictMock; |
| 18 using testing::WithArgs; | 19 using testing::WithArgs; |
| 19 | 20 |
| 20 namespace chromeos { | 21 namespace chromeos { |
| 21 namespace attestation { | 22 namespace attestation { |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 void DBusCallbackFalse(const BoolDBusMethodCallback& callback) { | 26 void DBusCallbackFalse(const BoolDBusMethodCallback& callback) { |
| 26 MessageLoop::current()->PostTask( | 27 MessageLoop::current()->PostTask( |
| 27 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false)); | 28 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false)); |
| 28 } | 29 } |
| 29 | 30 |
| 30 void DBusCallbackTrue(const BoolDBusMethodCallback& callback) { | 31 void DBusCallbackTrue(const BoolDBusMethodCallback& callback) { |
| 31 MessageLoop::current()->PostTask( | 32 MessageLoop::current()->PostTask( |
| 32 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true)); | 33 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true)); |
| 33 } | 34 } |
| 34 | 35 |
| 35 void DBusCallbackFail(const BoolDBusMethodCallback& callback) { | 36 void DBusCallbackFail(const BoolDBusMethodCallback& callback) { |
| 36 MessageLoop::current()->PostTask( | 37 MessageLoop::current()->PostTask( |
| 37 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_FAILURE, false)); | 38 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_FAILURE, false)); |
| 38 } | 39 } |
| 39 | 40 |
| 40 void AsyncCallbackFalse(cryptohome::AsyncMethodCaller::Callback callback) { | 41 void AsyncCallbackFalse(cryptohome::AsyncMethodCaller::Callback callback) { |
| 41 callback.Run(false, cryptohome::MOUNT_ERROR_NONE); | 42 callback.Run(false, cryptohome::MOUNT_ERROR_NONE); |
| 42 } | 43 } |
| 43 | 44 |
| 45 class FakeDBusData { | |
| 46 public: | |
| 47 explicit FakeDBusData(const std::string& data) : data_(data) {} | |
| 48 | |
| 49 void operator() (const CryptohomeClient::DataMethodCallback& callback) { | |
| 50 MessageLoop::current()->PostTask( | |
| 51 FROM_HERE, | |
| 52 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true, data_)); | |
| 53 } | |
| 54 | |
| 55 private: | |
| 56 std::string data_; | |
| 57 }; | |
| 58 | |
| 44 } // namespace | 59 } // namespace |
| 45 | 60 |
| 46 class AttestationFlowTest : public testing::Test { | 61 class AttestationFlowTest : public testing::Test { |
| 47 protected: | 62 protected: |
| 48 void Run() { | 63 void Run() { |
| 49 base::RunLoop run_loop; | 64 base::RunLoop run_loop; |
| 50 run_loop.RunUntilIdle(); | 65 run_loop.RunUntilIdle(); |
| 51 } | 66 } |
| 52 MessageLoop message_loop_; | 67 MessageLoop message_loop_; |
| 53 }; | 68 }; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 76 _)).Times(1) | 91 _)).Times(1) |
| 77 .InSequence(flow_order); | 92 .InSequence(flow_order); |
| 78 | 93 |
| 79 std::string fake_enroll_response = | 94 std::string fake_enroll_response = |
| 80 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest; | 95 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest; |
| 81 fake_enroll_response += "_response"; | 96 fake_enroll_response += "_response"; |
| 82 EXPECT_CALL(async_caller, AsyncTpmAttestationEnroll(fake_enroll_response, _)) | 97 EXPECT_CALL(async_caller, AsyncTpmAttestationEnroll(fake_enroll_response, _)) |
| 83 .Times(1) | 98 .Times(1) |
| 84 .InSequence(flow_order); | 99 .InSequence(flow_order); |
| 85 | 100 |
| 86 int options = CryptohomeClient::INCLUDE_DEVICE_STATE; | |
| 87 EXPECT_CALL(async_caller, | 101 EXPECT_CALL(async_caller, |
| 88 AsyncTpmAttestationCreateCertRequest(options, _)) | 102 AsyncTpmAttestationCreateCertRequest(INCLUDE_DEVICE_STATE, _)) |
| 89 .Times(1) | 103 .Times(1) |
| 90 .InSequence(flow_order); | 104 .InSequence(flow_order); |
| 91 | 105 |
| 92 EXPECT_CALL(*proxy, SendCertificateRequest( | 106 EXPECT_CALL(*proxy, SendCertificateRequest( |
| 93 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest, | 107 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest, |
| 94 _)).Times(1) | 108 _)).Times(1) |
| 95 .InSequence(flow_order); | 109 .InSequence(flow_order); |
| 96 | 110 |
| 97 std::string fake_cert_response = | 111 std::string fake_cert_response = |
| 98 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest; | 112 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest; |
| 99 fake_cert_response += "_response"; | 113 fake_cert_response += "_response"; |
| 100 EXPECT_CALL(async_caller, | 114 EXPECT_CALL(async_caller, |
| 101 AsyncTpmAttestationFinishCertRequest(fake_cert_response, | 115 AsyncTpmAttestationFinishCertRequest(fake_cert_response, |
| 102 CryptohomeClient::USER_KEY, | 116 USER_KEY, |
| 103 "test", | 117 kEnterpriseUserKey, |
| 104 _)) | 118 _)) |
| 105 .Times(1) | 119 .Times(1) |
| 106 .InSequence(flow_order); | 120 .InSequence(flow_order); |
| 107 | 121 |
| 108 StrictMock<MockObserver> observer; | 122 StrictMock<MockObserver> observer; |
| 109 EXPECT_CALL(observer, MockCertificateCallback( | 123 EXPECT_CALL(observer, MockCertificateCallback( |
| 110 true, | 124 true, |
| 111 cryptohome::MockAsyncMethodCaller::kFakeAttestationCert)) | 125 cryptohome::MockAsyncMethodCaller::kFakeAttestationCert)) |
| 112 .Times(1) | 126 .Times(1) |
| 113 .InSequence(flow_order); | 127 .InSequence(flow_order); |
| 114 AttestationFlow::CertificateCallback mock_callback = base::Bind( | 128 AttestationFlow::CertificateCallback mock_callback = base::Bind( |
| 115 &MockObserver::MockCertificateCallback, | 129 &MockObserver::MockCertificateCallback, |
| 116 base::Unretained(&observer)); | 130 base::Unretained(&observer)); |
| 117 | 131 |
| 118 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); | 132 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); |
| 119 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); | 133 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); |
| 120 flow.GetCertificate("test", mock_callback); | 134 flow.GetCertificate(ENTERPRISE_USER_CERTIFICATE, true, mock_callback); |
| 121 Run(); | 135 Run(); |
| 122 } | 136 } |
| 123 | 137 |
| 124 TEST_F(AttestationFlowTest, GetCertificate_NoEK) { | 138 TEST_F(AttestationFlowTest, GetCertificate_NoEK) { |
| 125 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; | 139 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; |
| 126 async_caller.SetUp(false, cryptohome::MOUNT_ERROR_NONE); | 140 async_caller.SetUp(false, cryptohome::MOUNT_ERROR_NONE); |
| 127 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_)) | 141 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_)) |
| 128 .Times(1); | 142 .Times(1); |
| 129 | 143 |
| 130 chromeos::MockCryptohomeClient client; | 144 chromeos::MockCryptohomeClient client; |
| 131 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) | 145 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) |
| 132 .WillRepeatedly(Invoke(DBusCallbackFalse)); | 146 .WillRepeatedly(Invoke(DBusCallbackFalse)); |
| 133 | 147 |
| 134 // We're not expecting any server calls in this case; StrictMock will verify. | 148 // We're not expecting any server calls in this case; StrictMock will verify. |
| 135 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); | 149 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); |
| 136 | 150 |
| 137 StrictMock<MockObserver> observer; | 151 StrictMock<MockObserver> observer; |
| 138 EXPECT_CALL(observer, MockCertificateCallback(false, "")) | 152 EXPECT_CALL(observer, MockCertificateCallback(false, "")) |
| 139 .Times(1); | 153 .Times(1); |
| 140 AttestationFlow::CertificateCallback mock_callback = base::Bind( | 154 AttestationFlow::CertificateCallback mock_callback = base::Bind( |
| 141 &MockObserver::MockCertificateCallback, | 155 &MockObserver::MockCertificateCallback, |
| 142 base::Unretained(&observer)); | 156 base::Unretained(&observer)); |
| 143 | 157 |
| 144 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); | 158 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); |
| 145 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); | 159 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); |
| 146 flow.GetCertificate("test", mock_callback); | 160 flow.GetCertificate(ENTERPRISE_USER_CERTIFICATE, true, mock_callback); |
| 147 Run(); | 161 Run(); |
| 148 } | 162 } |
| 149 | 163 |
| 150 TEST_F(AttestationFlowTest, GetCertificate_EKRejected) { | 164 TEST_F(AttestationFlowTest, GetCertificate_EKRejected) { |
| 151 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; | 165 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; |
| 152 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); | 166 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); |
| 153 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_)) | 167 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_)) |
| 154 .Times(1); | 168 .Times(1); |
| 155 | 169 |
| 156 chromeos::MockCryptohomeClient client; | 170 chromeos::MockCryptohomeClient client; |
| 157 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) | 171 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) |
| 158 .WillRepeatedly(Invoke(DBusCallbackFalse)); | 172 .WillRepeatedly(Invoke(DBusCallbackFalse)); |
| 159 | 173 |
| 160 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); | 174 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); |
| 161 proxy->DeferToFake(false); | 175 proxy->DeferToFake(false); |
| 162 EXPECT_CALL(*proxy, SendEnrollRequest( | 176 EXPECT_CALL(*proxy, SendEnrollRequest( |
| 163 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest, | 177 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest, |
| 164 _)).Times(1); | 178 _)).Times(1); |
| 165 | 179 |
| 166 StrictMock<MockObserver> observer; | 180 StrictMock<MockObserver> observer; |
| 167 EXPECT_CALL(observer, MockCertificateCallback(false, "")) | 181 EXPECT_CALL(observer, MockCertificateCallback(false, "")) |
| 168 .Times(1); | 182 .Times(1); |
| 169 AttestationFlow::CertificateCallback mock_callback = base::Bind( | 183 AttestationFlow::CertificateCallback mock_callback = base::Bind( |
| 170 &MockObserver::MockCertificateCallback, | 184 &MockObserver::MockCertificateCallback, |
| 171 base::Unretained(&observer)); | 185 base::Unretained(&observer)); |
| 172 | 186 |
| 173 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); | 187 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); |
| 174 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); | 188 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); |
| 175 flow.GetCertificate("test", mock_callback); | 189 flow.GetCertificate(ENTERPRISE_USER_CERTIFICATE, true, mock_callback); |
| 176 Run(); | 190 Run(); |
| 177 } | 191 } |
| 178 | 192 |
| 179 TEST_F(AttestationFlowTest, GetCertificate_FailEnroll) { | 193 TEST_F(AttestationFlowTest, GetCertificate_FailEnroll) { |
| 180 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; | 194 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; |
| 181 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); | 195 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); |
| 182 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_)) | 196 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateEnrollRequest(_)) |
| 183 .Times(1); | 197 .Times(1); |
| 184 std::string fake_enroll_response = | 198 std::string fake_enroll_response = |
| 185 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest; | 199 cryptohome::MockAsyncMethodCaller::kFakeAttestationEnrollRequest; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 198 _)).Times(1); | 212 _)).Times(1); |
| 199 | 213 |
| 200 StrictMock<MockObserver> observer; | 214 StrictMock<MockObserver> observer; |
| 201 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1); | 215 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1); |
| 202 AttestationFlow::CertificateCallback mock_callback = base::Bind( | 216 AttestationFlow::CertificateCallback mock_callback = base::Bind( |
| 203 &MockObserver::MockCertificateCallback, | 217 &MockObserver::MockCertificateCallback, |
| 204 base::Unretained(&observer)); | 218 base::Unretained(&observer)); |
| 205 | 219 |
| 206 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); | 220 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); |
| 207 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); | 221 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); |
| 208 flow.GetCertificate("test", mock_callback); | 222 flow.GetCertificate(ENTERPRISE_USER_CERTIFICATE, true, mock_callback); |
| 209 Run(); | 223 Run(); |
| 210 } | 224 } |
| 211 | 225 |
| 212 TEST_F(AttestationFlowTest, GetOwnerCertificateAlreadyEnrolled) { | 226 TEST_F(AttestationFlowTest, GetMachineCertificateAlreadyEnrolled) { |
| 213 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; | 227 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; |
| 214 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); | 228 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); |
| 215 int options = CryptohomeClient::INCLUDE_DEVICE_STATE | | 229 int options = INCLUDE_DEVICE_STATE | |
| 216 CryptohomeClient::INCLUDE_STABLE_ID; | 230 INCLUDE_STABLE_ID; |
| 217 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateCertRequest(options, _)) | 231 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateCertRequest(options, _)) |
| 218 .Times(1); | 232 .Times(1); |
| 219 std::string fake_cert_response = | 233 std::string fake_cert_response = |
| 220 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest; | 234 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest; |
| 221 fake_cert_response += "_response"; | 235 fake_cert_response += "_response"; |
| 222 EXPECT_CALL(async_caller, | 236 EXPECT_CALL(async_caller, |
| 223 AsyncTpmAttestationFinishCertRequest(fake_cert_response, | 237 AsyncTpmAttestationFinishCertRequest(fake_cert_response, |
| 224 CryptohomeClient::DEVICE_KEY, | 238 DEVICE_KEY, |
| 225 "attest-ent-machine", | 239 kEnterpriseMachineKey, |
| 226 _)) | 240 _)) |
| 227 .Times(1); | 241 .Times(1); |
| 228 | 242 |
| 229 chromeos::MockCryptohomeClient client; | 243 chromeos::MockCryptohomeClient client; |
| 230 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) | 244 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) |
| 231 .WillRepeatedly(Invoke(DBusCallbackTrue)); | 245 .WillRepeatedly(Invoke(DBusCallbackTrue)); |
| 232 | 246 |
| 233 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); | 247 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); |
| 234 proxy->DeferToFake(true); | 248 proxy->DeferToFake(true); |
| 235 EXPECT_CALL(*proxy, SendCertificateRequest( | 249 EXPECT_CALL(*proxy, SendCertificateRequest( |
| 236 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest, | 250 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest, |
| 237 _)).Times(1); | 251 _)).Times(1); |
| 238 | 252 |
| 239 StrictMock<MockObserver> observer; | 253 StrictMock<MockObserver> observer; |
| 240 EXPECT_CALL(observer, MockCertificateCallback( | 254 EXPECT_CALL(observer, MockCertificateCallback( |
| 241 true, | 255 true, |
| 242 cryptohome::MockAsyncMethodCaller::kFakeAttestationCert)).Times(1); | 256 cryptohome::MockAsyncMethodCaller::kFakeAttestationCert)).Times(1); |
| 243 AttestationFlow::CertificateCallback mock_callback = base::Bind( | 257 AttestationFlow::CertificateCallback mock_callback = base::Bind( |
| 244 &MockObserver::MockCertificateCallback, | 258 &MockObserver::MockCertificateCallback, |
| 245 base::Unretained(&observer)); | 259 base::Unretained(&observer)); |
| 246 | 260 |
| 247 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); | 261 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); |
| 248 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); | 262 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); |
| 249 flow.GetCertificate("attest-ent-machine", mock_callback); | 263 flow.GetCertificate(ENTERPRISE_MACHINE_CERTIFICATE, true, mock_callback); |
| 250 Run(); | 264 Run(); |
| 251 } | 265 } |
| 252 | 266 |
| 253 TEST_F(AttestationFlowTest, GetCertificate_FailCreateCertRequest) { | 267 TEST_F(AttestationFlowTest, GetCertificate_FailCreateCertRequest) { |
| 254 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; | 268 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; |
| 255 async_caller.SetUp(false, cryptohome::MOUNT_ERROR_NONE); | 269 async_caller.SetUp(false, cryptohome::MOUNT_ERROR_NONE); |
| 256 int options = CryptohomeClient::INCLUDE_DEVICE_STATE; | 270 int options = INCLUDE_DEVICE_STATE; |
| 257 EXPECT_CALL(async_caller, | 271 EXPECT_CALL(async_caller, |
| 258 AsyncTpmAttestationCreateCertRequest(options, _)) | 272 AsyncTpmAttestationCreateCertRequest(options, _)) |
| 259 .Times(1); | 273 .Times(1); |
| 260 | 274 |
| 261 chromeos::MockCryptohomeClient client; | 275 chromeos::MockCryptohomeClient client; |
| 262 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) | 276 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) |
| 263 .WillRepeatedly(Invoke(DBusCallbackTrue)); | 277 .WillRepeatedly(Invoke(DBusCallbackTrue)); |
| 264 | 278 |
| 265 // We're not expecting any server calls in this case; StrictMock will verify. | 279 // We're not expecting any server calls in this case; StrictMock will verify. |
| 266 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); | 280 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); |
| 267 | 281 |
| 268 StrictMock<MockObserver> observer; | 282 StrictMock<MockObserver> observer; |
| 269 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1); | 283 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1); |
| 270 AttestationFlow::CertificateCallback mock_callback = base::Bind( | 284 AttestationFlow::CertificateCallback mock_callback = base::Bind( |
| 271 &MockObserver::MockCertificateCallback, | 285 &MockObserver::MockCertificateCallback, |
| 272 base::Unretained(&observer)); | 286 base::Unretained(&observer)); |
| 273 | 287 |
| 274 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); | 288 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); |
| 275 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); | 289 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); |
| 276 flow.GetCertificate("test", mock_callback); | 290 flow.GetCertificate(ENTERPRISE_USER_CERTIFICATE, true, mock_callback); |
| 277 Run(); | 291 Run(); |
| 278 } | 292 } |
| 279 | 293 |
| 280 TEST_F(AttestationFlowTest, GetCertificate_CertRequestRejected) { | 294 TEST_F(AttestationFlowTest, GetCertificate_CertRequestRejected) { |
| 281 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; | 295 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; |
| 282 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); | 296 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); |
| 283 int options = CryptohomeClient::INCLUDE_DEVICE_STATE; | 297 int options = INCLUDE_DEVICE_STATE; |
| 284 EXPECT_CALL(async_caller, | 298 EXPECT_CALL(async_caller, |
| 285 AsyncTpmAttestationCreateCertRequest(options, _)) | 299 AsyncTpmAttestationCreateCertRequest(options, _)) |
| 286 .Times(1); | 300 .Times(1); |
| 287 | 301 |
| 288 chromeos::MockCryptohomeClient client; | 302 chromeos::MockCryptohomeClient client; |
| 289 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) | 303 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) |
| 290 .WillRepeatedly(Invoke(DBusCallbackTrue)); | 304 .WillRepeatedly(Invoke(DBusCallbackTrue)); |
| 291 | 305 |
| 292 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); | 306 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); |
| 293 proxy->DeferToFake(false); | 307 proxy->DeferToFake(false); |
| 294 EXPECT_CALL(*proxy, SendCertificateRequest( | 308 EXPECT_CALL(*proxy, SendCertificateRequest( |
| 295 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest, | 309 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest, |
| 296 _)).Times(1); | 310 _)).Times(1); |
| 297 | 311 |
| 298 StrictMock<MockObserver> observer; | 312 StrictMock<MockObserver> observer; |
| 299 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1); | 313 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1); |
| 300 AttestationFlow::CertificateCallback mock_callback = base::Bind( | 314 AttestationFlow::CertificateCallback mock_callback = base::Bind( |
| 301 &MockObserver::MockCertificateCallback, | 315 &MockObserver::MockCertificateCallback, |
| 302 base::Unretained(&observer)); | 316 base::Unretained(&observer)); |
| 303 | 317 |
| 304 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); | 318 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); |
| 305 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); | 319 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); |
| 306 flow.GetCertificate("test", mock_callback); | 320 flow.GetCertificate(ENTERPRISE_USER_CERTIFICATE, true, mock_callback); |
| 307 Run(); | 321 Run(); |
| 308 } | 322 } |
| 309 | 323 |
| 310 TEST_F(AttestationFlowTest, GetCertificate_FailIsEnrolled) { | 324 TEST_F(AttestationFlowTest, GetCertificate_FailIsEnrolled) { |
| 311 // We're not expecting any server calls in this case; StrictMock will verify. | 325 // We're not expecting any async calls in this case; StrictMock will verify. |
| 312 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; | 326 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; |
| 313 | 327 |
| 314 chromeos::MockCryptohomeClient client; | 328 chromeos::MockCryptohomeClient client; |
| 315 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) | 329 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) |
| 316 .WillRepeatedly(Invoke(DBusCallbackFail)); | 330 .WillRepeatedly(Invoke(DBusCallbackFail)); |
| 317 | 331 |
| 318 // We're not expecting any server calls in this case; StrictMock will verify. | 332 // We're not expecting any server calls in this case; StrictMock will verify. |
| 319 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); | 333 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); |
| 320 | 334 |
| 321 StrictMock<MockObserver> observer; | 335 StrictMock<MockObserver> observer; |
| 322 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1); | 336 EXPECT_CALL(observer, MockCertificateCallback(false, "")).Times(1); |
| 323 AttestationFlow::CertificateCallback mock_callback = base::Bind( | 337 AttestationFlow::CertificateCallback mock_callback = base::Bind( |
| 324 &MockObserver::MockCertificateCallback, | 338 &MockObserver::MockCertificateCallback, |
| 325 base::Unretained(&observer)); | 339 base::Unretained(&observer)); |
| 326 | 340 |
| 327 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); | 341 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); |
| 328 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); | 342 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); |
| 329 flow.GetCertificate("test", mock_callback); | 343 flow.GetCertificate(ENTERPRISE_USER_CERTIFICATE, true, mock_callback); |
| 330 Run(); | 344 Run(); |
| 331 } | 345 } |
| 332 | 346 |
| 347 TEST_F(AttestationFlowTest, GetCertificate_CheckExisting) { | |
| 348 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; | |
| 349 async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); | |
| 350 int options = INCLUDE_DEVICE_STATE; | |
| 351 EXPECT_CALL(async_caller, AsyncTpmAttestationCreateCertRequest(options, _)) | |
| 352 .Times(1); | |
| 353 std::string fake_cert_response = | |
| 354 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest; | |
| 355 fake_cert_response += "_response"; | |
| 356 EXPECT_CALL(async_caller, | |
| 357 AsyncTpmAttestationFinishCertRequest(fake_cert_response, | |
| 358 USER_KEY, | |
| 359 kEnterpriseUserKey, | |
| 360 _)) | |
| 361 .Times(1); | |
| 362 | |
| 363 chromeos::MockCryptohomeClient client; | |
| 364 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) | |
| 365 .WillRepeatedly(Invoke(DBusCallbackTrue)); | |
| 366 EXPECT_CALL(client, | |
| 367 TpmAttestationDoesKeyExist(USER_KEY, kEnterpriseUserKey, _)) | |
| 368 .WillRepeatedly(WithArgs<2>(Invoke(DBusCallbackFalse))); | |
| 369 | |
| 370 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); | |
| 371 proxy->DeferToFake(true); | |
| 372 EXPECT_CALL(*proxy, SendCertificateRequest( | |
| 373 cryptohome::MockAsyncMethodCaller::kFakeAttestationCertRequest, | |
| 374 _)).Times(1); | |
| 375 | |
| 376 StrictMock<MockObserver> observer; | |
| 377 EXPECT_CALL(observer, MockCertificateCallback( | |
| 378 true, | |
| 379 cryptohome::MockAsyncMethodCaller::kFakeAttestationCert)).Times(1); | |
| 380 AttestationFlow::CertificateCallback mock_callback = base::Bind( | |
| 381 &MockObserver::MockCertificateCallback, | |
| 382 base::Unretained(&observer)); | |
| 383 | |
| 384 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); | |
| 385 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); | |
| 386 flow.GetCertificate(ENTERPRISE_USER_CERTIFICATE, false, mock_callback); | |
| 387 Run(); | |
| 388 } | |
| 389 | |
| 390 TEST_F(AttestationFlowTest, GetCertificate_AlreadyExists) { | |
| 391 // We're not expecting any async calls in this case; StrictMock will verify. | |
| 392 StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; | |
| 393 | |
| 394 chromeos::MockCryptohomeClient client; | |
| 395 EXPECT_CALL(client, TpmAttestationIsEnrolled(_)) | |
| 396 .WillRepeatedly(Invoke(DBusCallbackTrue)); | |
| 397 EXPECT_CALL(client, | |
| 398 TpmAttestationDoesKeyExist(USER_KEY, kEnterpriseUserKey, _)) | |
| 399 .WillRepeatedly(WithArgs<2>(Invoke(DBusCallbackTrue))); | |
| 400 EXPECT_CALL(client, | |
| 401 TpmAttestationGetCertificate(USER_KEY, kEnterpriseUserKey, _)) | |
| 402 .WillRepeatedly(WithArgs<2>(Invoke(FakeDBusData("fake_cert")))); | |
| 403 | |
| 404 // We're not expecting any server calls in this case; StrictMock will verify. | |
| 405 scoped_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); | |
| 406 | |
| 407 StrictMock<MockObserver> observer; | |
| 408 EXPECT_CALL(observer, MockCertificateCallback(true, "fake_cert")).Times(1); | |
| 409 AttestationFlow::CertificateCallback mock_callback = base::Bind( | |
| 410 &MockObserver::MockCertificateCallback, | |
| 411 base::Unretained(&observer)); | |
| 412 | |
| 413 scoped_ptr<ServerProxy> proxy_interface(proxy.release()); | |
| 414 AttestationFlow flow(&async_caller, &client, proxy_interface.Pass()); | |
| 415 flow.GetCertificate(ENTERPRISE_USER_CERTIFICATE, false, mock_callback); | |
| 416 Run(); | |
|
Mattias Nissler (ping if slow)
2013/04/24 12:57:53
Ugh, even more hard-to-read gmock setup. To repeat
dkrahn
2013/04/25 01:06:52
For testing this flow I believe I have a legitimat
Mattias Nissler (ping if slow)
2013/04/25 12:05:26
Yes, these seem reasonable.
| |
| 417 } | |
| 418 | |
| 333 } // namespace attestation | 419 } // namespace attestation |
| 334 } // namespace chromeos | 420 } // namespace chromeos |
| OLD | NEW |