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

Side by Side Diff: chromeos/dbus/fake_cryptohome_client_unittest.cc

Issue 2297193006: Do a better job at faking simple challenge signatures. (Closed)
Patch Set: Added missing attestation.proto file. 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chromeos/dbus/fake_cryptohome_client.h"
6
7 #include <string>
8
9 #include "base/bind.h"
10 #include "base/bind_helpers.h"
11 #include "base/run_loop.h"
12 #include "chromeos/cryptohome/attestation.pb.h"
13 #include "chromeos/cryptohome/cryptohome_parameters.h"
14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 using ::testing::_;
18 using ::testing::SaveArg;
19
20 namespace chromeos {
21
22 class FakeCryptohomeClientTest : public ::testing::Test {
23 public:
24 FakeCryptohomeClientTest() : weak_ptr_factory_(this) {
25 async_method_callback_ =
26 base::Bind(&FakeCryptohomeClientTest::MockHandleAsyncMethodCallback,
27 weak_ptr_factory_.GetWeakPtr());
28 fake_cryptohome_client_.SetAsyncCallStatusHandlers(
29 base::Bind(
30 &FakeCryptohomeClientTest::MockHandleAsyncMethodResultResponse,
31 weak_ptr_factory_.GetWeakPtr()),
32 base::Bind(&FakeCryptohomeClientTest::MockHandleAsyncMethodDataResponse,
33 weak_ptr_factory_.GetWeakPtr()));
34 }
35
36 void Run() {
xiyuan 2016/09/06 22:32:32 nit: We probably can get rid of this method and ju
The one and only Dr. Crash 2016/09/07 02:43:47 Sure.
37 base::RunLoop run_loop;
38 run_loop.RunUntilIdle();
39 }
40
41 MOCK_METHOD1(MockHandleAsyncMethodCallback, void(int));
42 MOCK_METHOD3(MockHandleAsyncMethodResultResponse, void(int, bool, int));
43 MOCK_METHOD3(MockHandleAsyncMethodDataResponse,
44 void(int, bool, const std::string&));
45
46 protected:
47 base::MessageLoop message_loop_;
48
49 FakeCryptohomeClient fake_cryptohome_client_;
50 CryptohomeClient::AsyncMethodCallback async_method_callback_;
51
52 base::WeakPtrFactory<FakeCryptohomeClientTest> weak_ptr_factory_;
53
54 DISALLOW_COPY_AND_ASSIGN(FakeCryptohomeClientTest);
55 };
56
57 TEST_F(FakeCryptohomeClientTest, SignSimpleChallenge) {
58 const std::string challenge{"challenge"};
59
60 EXPECT_CALL(*this, MockHandleAsyncMethodCallback(_));
61
62 std::string return_data;
63 EXPECT_CALL(*this, MockHandleAsyncMethodDataResponse(_, true, _))
64 .WillOnce(SaveArg<2>(&return_data));
65
66 cryptohome::Identification cryptohome_id;
67 fake_cryptohome_client_.TpmAttestationSignSimpleChallenge(
68 attestation::AttestationKeyType::KEY_DEVICE, cryptohome_id, "key_name",
69 challenge, async_method_callback_);
70
71 Run();
72
73 cryptohome::SignedData signed_data;
74 ASSERT_TRUE(signed_data.ParseFromString(return_data));
75 ASSERT_EQ(static_cast<size_t>(20),
76 signed_data.data().size() - challenge.size());
77 ASSERT_EQ(challenge,
78 signed_data.data().substr(0, signed_data.data().size() - 20));
79 }
80
81 } // namespace cryptohome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698