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 "chrome/browser/chromeos/settings/owner_key_util.h" | 5 #include "chrome/browser/chromeos/settings/owner_key_util.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/files/scoped_temp_dir.h" |
13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
14 #include "base/scoped_temp_dir.h" | |
15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
16 #include "crypto/rsa_private_key.h" | 16 #include "crypto/rsa_private_key.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 | 18 |
19 namespace chromeos { | 19 namespace chromeos { |
20 | 20 |
21 // 2048-bit RSA public key for testing. | 21 // 2048-bit RSA public key for testing. |
22 const uint8 kTestKeyData[] = { | 22 const uint8 kTestKeyData[] = { |
23 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, | 23 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, |
24 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, | 24 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, |
(...skipping 26 matching lines...) Expand all Loading... |
51 protected: | 51 protected: |
52 OwnerKeyUtilTest() {} | 52 OwnerKeyUtilTest() {} |
53 virtual ~OwnerKeyUtilTest() {} | 53 virtual ~OwnerKeyUtilTest() {} |
54 | 54 |
55 virtual void SetUp() OVERRIDE { | 55 virtual void SetUp() OVERRIDE { |
56 ASSERT_TRUE(tmpdir_.CreateUniqueTempDir()); | 56 ASSERT_TRUE(tmpdir_.CreateUniqueTempDir()); |
57 key_file_ = tmpdir_.path().Append("key"); | 57 key_file_ = tmpdir_.path().Append("key"); |
58 util_ = new OwnerKeyUtilImpl(key_file_); | 58 util_ = new OwnerKeyUtilImpl(key_file_); |
59 } | 59 } |
60 | 60 |
61 ScopedTempDir tmpdir_; | 61 base::ScopedTempDir tmpdir_; |
62 FilePath key_file_; | 62 FilePath key_file_; |
63 scoped_refptr<OwnerKeyUtil> util_; | 63 scoped_refptr<OwnerKeyUtil> util_; |
64 | 64 |
65 private: | 65 private: |
66 DISALLOW_COPY_AND_ASSIGN(OwnerKeyUtilTest); | 66 DISALLOW_COPY_AND_ASSIGN(OwnerKeyUtilTest); |
67 }; | 67 }; |
68 | 68 |
69 TEST_F(OwnerKeyUtilTest, ImportPublicKey) { | 69 TEST_F(OwnerKeyUtilTest, ImportPublicKey) { |
70 // Export public key, so that we can compare it to the one we get off disk. | 70 // Export public key, so that we can compare it to the one we get off disk. |
71 std::vector<uint8> public_key(kTestKeyData, | 71 std::vector<uint8> public_key(kTestKeyData, |
(...skipping 19 matching lines...) Expand all Loading... |
91 | 91 |
92 // Next try empty file. This should fail and the array should be empty. | 92 // Next try empty file. This should fail and the array should be empty. |
93 from_disk.resize(10); | 93 from_disk.resize(10); |
94 ASSERT_EQ(0, file_util::WriteFile(key_file_, "", 0)); | 94 ASSERT_EQ(0, file_util::WriteFile(key_file_, "", 0)); |
95 EXPECT_TRUE(util_->IsPublicKeyPresent()); | 95 EXPECT_TRUE(util_->IsPublicKeyPresent()); |
96 EXPECT_FALSE(util_->ImportPublicKey(&from_disk)); | 96 EXPECT_FALSE(util_->ImportPublicKey(&from_disk)); |
97 EXPECT_FALSE(from_disk.size()); | 97 EXPECT_FALSE(from_disk.size()); |
98 } | 98 } |
99 | 99 |
100 } // namespace chromeos | 100 } // namespace chromeos |
OLD | NEW |