OLD | NEW |
| (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/attestation/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 MOCK_METHOD1(MockHandleAsyncMethodCallback, void(int)); | |
37 MOCK_METHOD3(MockHandleAsyncMethodResultResponse, void(int, bool, int)); | |
38 MOCK_METHOD3(MockHandleAsyncMethodDataResponse, | |
39 void(int, bool, const std::string&)); | |
40 | |
41 protected: | |
42 base::MessageLoop message_loop_; | |
43 | |
44 FakeCryptohomeClient fake_cryptohome_client_; | |
45 CryptohomeClient::AsyncMethodCallback async_method_callback_; | |
46 | |
47 base::WeakPtrFactory<FakeCryptohomeClientTest> weak_ptr_factory_; | |
48 | |
49 DISALLOW_COPY_AND_ASSIGN(FakeCryptohomeClientTest); | |
50 }; | |
51 | |
52 TEST_F(FakeCryptohomeClientTest, SignSimpleChallenge) { | |
53 const std::string challenge{"challenge"}; | |
54 | |
55 EXPECT_CALL(*this, MockHandleAsyncMethodCallback(_)); | |
56 | |
57 std::string return_data; | |
58 EXPECT_CALL(*this, MockHandleAsyncMethodDataResponse(_, true, _)) | |
59 .WillOnce(SaveArg<2>(&return_data)); | |
60 | |
61 cryptohome::Identification cryptohome_id; | |
62 fake_cryptohome_client_.TpmAttestationSignSimpleChallenge( | |
63 attestation::AttestationKeyType::KEY_DEVICE, cryptohome_id, "key_name", | |
64 challenge, async_method_callback_); | |
65 | |
66 base::RunLoop().RunUntilIdle(); | |
67 | |
68 chromeos::attestation::SignedData signed_data; | |
69 ASSERT_TRUE(signed_data.ParseFromString(return_data)); | |
70 ASSERT_EQ(static_cast<size_t>(20), | |
71 signed_data.data().size() - challenge.size()); | |
72 ASSERT_EQ(challenge, | |
73 signed_data.data().substr(0, signed_data.data().size() - 20)); | |
74 } | |
75 | |
76 } // namespace cryptohome | |
OLD | NEW |