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

Side by Side Diff: chrome/browser/managed_mode/managed_user_passphrase_unittest.cc

Issue 11783008: Add a lock to the managed user settings page and require authentication for unlocking. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add browser test for ManagedUserSetPassphraseOverlay Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
Pam (message me for reviews) 2013/01/28 13:53:27 2013
Adrian Kuegel 2013/01/28 15:41:44 Done.
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 "chrome/browser/managed_mode/managed_user_passphrase.h"
6
7 #include <string>
8
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 // This test checks the class ManagedUserPassphraseTest when providing a salt
Pam (message me for reviews) 2013/01/28 13:53:27 It actually checks the ManagedUserPassphrase class
Adrian Kuegel 2013/01/28 15:41:44 Right, I fixed that now.
12 // as parameter of the constructor.
13 TEST(ManagedUserPassphraseTest, WithSaltProvided) {
Pam (message me for reviews) 2013/01/28 13:53:27 Please add blank lines to make all these tests eas
Adrian Kuegel 2013/01/28 15:41:44 Done.
14 std::string salt = "my special salt";
15 std::string salt2 = "my other special salt";
16 ManagedUserPassphrase instance_with_provided_salt(salt);
17 ManagedUserPassphrase other_instance_with_provided_salt(salt2);
18 // We expect that the provided salt is used internally as well.
19 EXPECT_STREQ(salt.c_str(), instance_with_provided_salt.GetSalt().c_str());
20 std::string passphrase_hash;
21 std::string passphrase = "some_passphrase123";
22 instance_with_provided_salt.GenerateHashFromPassphrase(passphrase,
23 &passphrase_hash);
24 // As the method generates a Base64 encoded 128 bit key, we expect the
25 // passphrase hash to have length at least 7 bytes.
26 EXPECT_GE(passphrase_hash.size(), 7u);
27 // When calling the function with a (slightly) different parameter, we
28 // expect to get a different result.
29 std::string passphrase2 = passphrase + "4";
30 std::string passphrase_hash2;
31 instance_with_provided_salt.GenerateHashFromPassphrase(passphrase2,
32 &passphrase_hash2);
33 EXPECT_GE(passphrase_hash2.size(), 7u);
34 EXPECT_STRNE(passphrase_hash.c_str(), passphrase_hash2.c_str());
35 // When calling the function again with the first parameter, we expect to
36 // get the same result as in the first call.
37 instance_with_provided_salt.GenerateHashFromPassphrase(passphrase,
38 &passphrase_hash2);
39 EXPECT_STREQ(passphrase_hash.c_str(), passphrase_hash2.c_str());
40 // When calling the function on the instance with the other salt, but
41 // with the same passphrase, we expect to get a different result.
42 other_instance_with_provided_salt.GenerateHashFromPassphrase(
43 passphrase,
44 &passphrase_hash2);
45 EXPECT_STRNE(passphrase_hash.c_str(), passphrase_hash2.c_str());
46 }
47
48 // This test checks the class ManagedUserPassphraseTest when no salt is
49 // provided as parameter of the constructor.
50 TEST(ManagedUserPassphraseTest, WithEmptySalt) {
51 ManagedUserPassphrase instance_with_empty_salt((std::string()));
52 ManagedUserPassphrase other_instance_with_empty_salt((std::string()));
53 std::string salt = instance_with_empty_salt.GetSalt();
54 std::string salt2 = other_instance_with_empty_salt.GetSalt();
55 // We expect that the class will generate a salt randomly, and for different
56 // instances a different salt is calculated.
57 EXPECT_GT(salt.size(), 0u);
58 EXPECT_GT(salt2.size(), 0u);
59 EXPECT_STRNE(salt.c_str(), salt2.c_str());
60 std::string passphrase_hash;
Pam (message me for reviews) 2013/01/28 13:53:27 Once you've verified the presence of two different
Adrian Kuegel 2013/01/28 15:41:44 True. It was actually just copy/paste, so it is de
61 std::string passphrase = "some_passphrase123";
62 instance_with_empty_salt.GenerateHashFromPassphrase(passphrase,
63 &passphrase_hash);
64 // As the method generates a Base64 encoded 128 bit key, we expect the
65 // passphrase hash to have length at least 7 bytes.
66 EXPECT_GE(passphrase_hash.size(), 7u);
67 // When calling the function with a (slightly) different parameter, we
68 // expect to get a different result.
69 std::string passphrase2 = passphrase + "4";
70 std::string passphrase_hash2;
71 instance_with_empty_salt.GenerateHashFromPassphrase(passphrase2,
72 &passphrase_hash2);
73 EXPECT_GE(passphrase_hash2.size(), 7u);
74 EXPECT_STRNE(passphrase_hash.c_str(), passphrase_hash2.c_str());
75 // When calling the function again with the first parameter, we expect to
76 // get the same result as in the first call.
77 instance_with_empty_salt.GenerateHashFromPassphrase(passphrase,
78 &passphrase_hash2);
79 EXPECT_STREQ(passphrase_hash.c_str(), passphrase_hash2.c_str());
80 // When calling the function on the instance with the other salt, but
81 // with the same passphrase, we expect to get a different result.
82 other_instance_with_empty_salt.GenerateHashFromPassphrase(
83 passphrase,
84 &passphrase_hash2);
85 EXPECT_STRNE(passphrase_hash.c_str(), passphrase_hash2.c_str());
86 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698