Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Unified Diff: chromeos/dbus/fake_cryptohome_client_unittest.cc

Issue 2324793003: Do a better job at faking simple challenge signatures. (Closed)
Patch Set: A bit too quick on that private: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chromeos/dbus/fake_cryptohome_client.cc ('k') | chromeos/dbus/proto/attestation.proto » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/dbus/fake_cryptohome_client_unittest.cc
diff --git a/chromeos/dbus/fake_cryptohome_client_unittest.cc b/chromeos/dbus/fake_cryptohome_client_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..bd527107160ff8f1bb89926fc7aae8bdaa343dd3
--- /dev/null
+++ b/chromeos/dbus/fake_cryptohome_client_unittest.cc
@@ -0,0 +1,77 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chromeos/dbus/fake_cryptohome_client.h"
+
+#include <string>
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/run_loop.h"
+#include "chromeos/attestation/attestation.pb.h"
+#include "chromeos/cryptohome/cryptohome_parameters.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using ::testing::_;
+using ::testing::SaveArg;
+
+namespace chromeos {
+
+class FakeCryptohomeClientTest : public ::testing::Test {
+ public:
+ FakeCryptohomeClientTest() : weak_ptr_factory_(this) {
+ async_method_callback_ =
+ base::Bind(&FakeCryptohomeClientTest::MockHandleAsyncMethodCallback,
+ weak_ptr_factory_.GetWeakPtr());
+ fake_cryptohome_client_.SetAsyncCallStatusHandlers(
+ base::Bind(
+ &FakeCryptohomeClientTest::MockHandleAsyncMethodResultResponse,
+ weak_ptr_factory_.GetWeakPtr()),
+ base::Bind(&FakeCryptohomeClientTest::MockHandleAsyncMethodDataResponse,
+ weak_ptr_factory_.GetWeakPtr()));
+ }
+
+ MOCK_METHOD1(MockHandleAsyncMethodCallback, void(int));
+ MOCK_METHOD3(MockHandleAsyncMethodResultResponse, void(int, bool, int));
+ MOCK_METHOD3(MockHandleAsyncMethodDataResponse,
+ void(int, bool, const std::string&));
+
+ protected:
+ base::MessageLoop message_loop_;
+
+ FakeCryptohomeClient fake_cryptohome_client_;
+ CryptohomeClient::AsyncMethodCallback async_method_callback_;
+
+ base::WeakPtrFactory<FakeCryptohomeClientTest> weak_ptr_factory_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(FakeCryptohomeClientTest);
+};
+
+TEST_F(FakeCryptohomeClientTest, SignSimpleChallenge) {
+ const std::string challenge{"challenge"};
+
+ EXPECT_CALL(*this, MockHandleAsyncMethodCallback(_));
+
+ std::string return_data;
+ EXPECT_CALL(*this, MockHandleAsyncMethodDataResponse(_, true, _))
+ .WillOnce(SaveArg<2>(&return_data));
+
+ cryptohome::Identification cryptohome_id;
+ fake_cryptohome_client_.TpmAttestationSignSimpleChallenge(
+ attestation::AttestationKeyType::KEY_DEVICE, cryptohome_id, "key_name",
+ challenge, async_method_callback_);
+
+ base::RunLoop().RunUntilIdle();
+
+ chromeos::attestation::SignedData signed_data;
+ ASSERT_TRUE(signed_data.ParseFromString(return_data));
+ ASSERT_EQ(static_cast<size_t>(20),
+ signed_data.data().size() - challenge.size());
+ ASSERT_EQ(challenge,
+ signed_data.data().substr(0, signed_data.data().size() - 20));
+}
+
+} // namespace chromeos
« no previous file with comments | « chromeos/dbus/fake_cryptohome_client.cc ('k') | chromeos/dbus/proto/attestation.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698