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

Side by Side Diff: components/gcm_driver/crypto/gcm_key_store_unittest.cc

Issue 1701973003: Remove associated keying material when unregistering from GCM (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/gcm_driver/crypto/gcm_key_store.h" 5 #include "components/gcm_driver/crypto/gcm_key_store.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
8 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
9 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 11 #include "base/run_loop.h"
11 #include "base/thread_task_runner_handle.h" 12 #include "base/thread_task_runner_handle.h"
12 #include "components/gcm_driver/crypto/p256_key_util.h" 13 #include "components/gcm_driver/crypto/p256_key_util.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
15 namespace gcm { 16 namespace gcm {
16 17
17 namespace { 18 namespace {
(...skipping 26 matching lines...) Expand all
44 new GCMKeyStore(scoped_temp_dir_.path(), message_loop_.task_runner())); 45 new GCMKeyStore(scoped_temp_dir_.path(), message_loop_.task_runner()));
45 } 46 }
46 47
47 // Callback to use with GCMKeyStore::{GetKeys, CreateKeys} calls. 48 // Callback to use with GCMKeyStore::{GetKeys, CreateKeys} calls.
48 void GotKeys(KeyPair* pair_out, std::string* auth_secret_out, 49 void GotKeys(KeyPair* pair_out, std::string* auth_secret_out,
49 const KeyPair& pair, const std::string& auth_secret) { 50 const KeyPair& pair, const std::string& auth_secret) {
50 *pair_out = pair; 51 *pair_out = pair;
51 *auth_secret_out = auth_secret; 52 *auth_secret_out = auth_secret;
52 } 53 }
53 54
54 // Callback to use with GCMKeyStore::DeleteKeys calls.
55 void DeletedKeys(bool* success_out, bool success) {
56 DCHECK(success_out);
57
58 *success_out = success;
59 }
60
61 protected: 55 protected:
62 GCMKeyStore* gcm_key_store() { return gcm_key_store_.get(); } 56 GCMKeyStore* gcm_key_store() { return gcm_key_store_.get(); }
63 57
64 private: 58 private:
65 base::MessageLoop message_loop_; 59 base::MessageLoop message_loop_;
66 base::ScopedTempDir scoped_temp_dir_; 60 base::ScopedTempDir scoped_temp_dir_;
67 61
68 scoped_ptr<GCMKeyStore> gcm_key_store_; 62 scoped_ptr<GCMKeyStore> gcm_key_store_;
69 }; 63 };
70 64
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 base::Unretained(this), &read_pair, 136 base::Unretained(this), &read_pair,
143 &read_auth_secret)); 137 &read_auth_secret));
144 138
145 base::RunLoop().RunUntilIdle(); 139 base::RunLoop().RunUntilIdle();
146 140
147 ASSERT_TRUE(read_pair.IsInitialized()); 141 ASSERT_TRUE(read_pair.IsInitialized());
148 EXPECT_TRUE(read_pair.has_type()); 142 EXPECT_TRUE(read_pair.has_type());
149 EXPECT_GT(read_auth_secret.size(), 0u); 143 EXPECT_GT(read_auth_secret.size(), 0u);
150 } 144 }
151 145
152 TEST_F(GCMKeyStoreTest, CreateAndDeleteKeys) { 146 TEST_F(GCMKeyStoreTest, CreateAndRemoveKeys) {
153 KeyPair pair; 147 KeyPair pair;
154 std::string auth_secret; 148 std::string auth_secret;
155 gcm_key_store()->CreateKeys(kFakeAppId, 149 gcm_key_store()->CreateKeys(kFakeAppId,
156 base::Bind(&GCMKeyStoreTest::GotKeys, 150 base::Bind(&GCMKeyStoreTest::GotKeys,
157 base::Unretained(this), &pair, 151 base::Unretained(this), &pair,
158 &auth_secret)); 152 &auth_secret));
159 153
160 base::RunLoop().RunUntilIdle(); 154 base::RunLoop().RunUntilIdle();
161 155
162 ASSERT_TRUE(pair.IsInitialized()); 156 ASSERT_TRUE(pair.IsInitialized());
163 157
164 KeyPair read_pair; 158 KeyPair read_pair;
165 std::string read_auth_secret; 159 std::string read_auth_secret;
166 gcm_key_store()->GetKeys(kFakeAppId, 160 gcm_key_store()->GetKeys(kFakeAppId,
167 base::Bind(&GCMKeyStoreTest::GotKeys, 161 base::Bind(&GCMKeyStoreTest::GotKeys,
168 base::Unretained(this), &read_pair, 162 base::Unretained(this), &read_pair,
169 &read_auth_secret)); 163 &read_auth_secret));
170 164
171 base::RunLoop().RunUntilIdle(); 165 base::RunLoop().RunUntilIdle();
172 166
173 ASSERT_TRUE(read_pair.IsInitialized()); 167 ASSERT_TRUE(read_pair.IsInitialized());
174 EXPECT_TRUE(read_pair.has_type()); 168 EXPECT_TRUE(read_pair.has_type());
175 169
176 bool success = false; 170 gcm_key_store()->RemoveKeys(kFakeAppId, base::Bind(&base::DoNothing));
177 gcm_key_store()->DeleteKeys(kFakeAppId,
178 base::Bind(&GCMKeyStoreTest::DeletedKeys,
179 base::Unretained(this), &success));
180 171
181 base::RunLoop().RunUntilIdle(); 172 base::RunLoop().RunUntilIdle();
182 173
183 ASSERT_TRUE(success);
184
185 gcm_key_store()->GetKeys(kFakeAppId, 174 gcm_key_store()->GetKeys(kFakeAppId,
186 base::Bind(&GCMKeyStoreTest::GotKeys, 175 base::Bind(&GCMKeyStoreTest::GotKeys,
187 base::Unretained(this), &read_pair, 176 base::Unretained(this), &read_pair,
188 &read_auth_secret)); 177 &read_auth_secret));
189 178
190 base::RunLoop().RunUntilIdle(); 179 base::RunLoop().RunUntilIdle();
191 180
192 ASSERT_FALSE(read_pair.IsInitialized()); 181 ASSERT_FALSE(read_pair.IsInitialized());
193 } 182 }
194 183
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 // to the asynchronous nature of operations, however, we can't rely on the 240 // to the asynchronous nature of operations, however, we can't rely on the
252 // write to have finished before the read begins. 241 // write to have finished before the read begins.
253 base::RunLoop().RunUntilIdle(); 242 base::RunLoop().RunUntilIdle();
254 243
255 EXPECT_TRUE(pair.IsInitialized()); 244 EXPECT_TRUE(pair.IsInitialized());
256 } 245 }
257 246
258 } // namespace 247 } // namespace
259 248
260 } // namespace gcm 249 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698