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

Side by Side Diff: chrome/browser/chromeos/policy/network_configuration_updater_impl_cros_unittest.cc

Issue 16946002: Resolve certificate references in ONC by PEM. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clean up Created 7 years, 5 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
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/policy/network_configuration_updater_impl_cros .h" 5 #include "chrome/browser/chromeos/policy/network_configuration_updater_impl_cros .h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 policy.Set(key::kOpenNetworkConfiguration, POLICY_LEVEL_MANDATORY, 168 policy.Set(key::kOpenNetworkConfiguration, POLICY_LEVEL_MANDATORY,
169 POLICY_SCOPE_USER, Value::CreateStringValue(onc_policy)); 169 POLICY_SCOPE_USER, Value::CreateStringValue(onc_policy));
170 UpdateProviderPolicy(policy); 170 UpdateProviderPolicy(policy);
171 171
172 EXPECT_CALL(network_library_, AddNetworkProfileObserver(_)); 172 EXPECT_CALL(network_library_, AddNetworkProfileObserver(_));
173 173
174 // Ignore the device policy update. 174 // Ignore the device policy update.
175 EXPECT_CALL(network_library_, LoadOncNetworks(_, _)); 175 EXPECT_CALL(network_library_, LoadOncNetworks(_, _));
176 StrictMock<chromeos::MockCertificateHandler>* certificate_handler = 176 StrictMock<chromeos::MockCertificateHandler>* certificate_handler =
177 new StrictMock<chromeos::MockCertificateHandler>(); 177 new StrictMock<chromeos::MockCertificateHandler>();
178 EXPECT_CALL(*certificate_handler, ImportCertificates(_, _, _)); 178 EXPECT_CALL(*certificate_handler, ImportCertificates(_, _, _, _));
179 179
180 NetworkConfigurationUpdaterImplCros updater( 180 NetworkConfigurationUpdaterImplCros updater(
181 policy_service_.get(), 181 policy_service_.get(),
182 &network_library_, 182 &network_library_,
183 make_scoped_ptr<chromeos::CertificateHandler>(certificate_handler)); 183 make_scoped_ptr<chromeos::CertificateHandler>(certificate_handler));
184 Mock::VerifyAndClearExpectations(&network_library_); 184 Mock::VerifyAndClearExpectations(&network_library_);
185 Mock::VerifyAndClearExpectations(&certificate_handler); 185 Mock::VerifyAndClearExpectations(&certificate_handler);
186 186
187 // After the user policy is initialized, we always push both policies to the 187 // After the user policy is initialized, we always push both policies to the
188 // NetworkLibrary. Ignore the device policy. 188 // NetworkLibrary. Ignore the device policy.
189 EXPECT_CALL(network_library_, LoadOncNetworks( 189 EXPECT_CALL(network_library_, LoadOncNetworks(
190 _, onc::ONC_SOURCE_DEVICE_POLICY)); 190 _, onc::ONC_SOURCE_DEVICE_POLICY));
191 EXPECT_CALL(network_library_, LoadOncNetworks( 191 EXPECT_CALL(network_library_, LoadOncNetworks(
192 IsEqualTo(network_configs_repaired), 192 IsEqualTo(network_configs_repaired),
193 onc::ONC_SOURCE_USER_POLICY)); 193 onc::ONC_SOURCE_USER_POLICY));
194 EXPECT_CALL(*certificate_handler, ImportCertificates(_, _, _)).Times(2); 194 EXPECT_CALL(*certificate_handler, ImportCertificates(_, _, _, _)).Times(2);
195 195
196 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_)); 196 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_));
197 197
198 updater.SetUserPolicyService(false, "hash", policy_service_.get()); 198 updater.SetUserPolicyService(false, "hash", policy_service_.get());
199 updater.UnsetUserPolicyService(); 199 updater.UnsetUserPolicyService();
200 } 200 }
201 201
202 class NetworkConfigurationUpdaterTestWithParam 202 class NetworkConfigurationUpdaterTestWithParam
203 : public NetworkConfigurationUpdaterTest, 203 : public NetworkConfigurationUpdaterTest,
204 public testing::WithParamInterface<const char*> { 204 public testing::WithParamInterface<const char*> {
(...skipping 23 matching lines...) Expand all
228 device_certs = empty_certificates_.get(); 228 device_certs = empty_certificates_.get();
229 user_networks = fake_network_configs_.get(); 229 user_networks = fake_network_configs_.get();
230 user_certs = fake_certificates_.get(); 230 user_certs = fake_certificates_.get();
231 } 231 }
232 232
233 EXPECT_CALL(network_library_, LoadOncNetworks( 233 EXPECT_CALL(network_library_, LoadOncNetworks(
234 IsEqualTo(device_networks), onc::ONC_SOURCE_DEVICE_POLICY)); 234 IsEqualTo(device_networks), onc::ONC_SOURCE_DEVICE_POLICY));
235 StrictMock<chromeos::MockCertificateHandler>* certificate_handler = 235 StrictMock<chromeos::MockCertificateHandler>* certificate_handler =
236 new StrictMock<chromeos::MockCertificateHandler>(); 236 new StrictMock<chromeos::MockCertificateHandler>();
237 EXPECT_CALL(*certificate_handler, ImportCertificates( 237 EXPECT_CALL(*certificate_handler, ImportCertificates(
238 IsEqualTo(device_certs), onc::ONC_SOURCE_DEVICE_POLICY, _)); 238 IsEqualTo(device_certs), onc::ONC_SOURCE_DEVICE_POLICY, _, _));
239 239
240 NetworkConfigurationUpdaterImplCros updater( 240 NetworkConfigurationUpdaterImplCros updater(
241 policy_service_.get(), 241 policy_service_.get(),
242 &network_library_, 242 &network_library_,
243 make_scoped_ptr<chromeos::CertificateHandler>(certificate_handler)); 243 make_scoped_ptr<chromeos::CertificateHandler>(certificate_handler));
244 Mock::VerifyAndClearExpectations(&network_library_); 244 Mock::VerifyAndClearExpectations(&network_library_);
245 Mock::VerifyAndClearExpectations(&certificate_handler); 245 Mock::VerifyAndClearExpectations(&certificate_handler);
246 246
247 // After the user policy is initialized, we always push both policies to the 247 // After the user policy is initialized, we always push both policies to the
248 // NetworkLibrary. 248 // NetworkLibrary.
249 EXPECT_CALL(network_library_, LoadOncNetworks( 249 EXPECT_CALL(network_library_, LoadOncNetworks(
250 IsEqualTo(device_networks), onc::ONC_SOURCE_DEVICE_POLICY)); 250 IsEqualTo(device_networks), onc::ONC_SOURCE_DEVICE_POLICY));
251 EXPECT_CALL(*certificate_handler, ImportCertificates( 251 EXPECT_CALL(*certificate_handler, ImportCertificates(
252 IsEqualTo(device_certs), onc::ONC_SOURCE_DEVICE_POLICY, _)); 252 IsEqualTo(device_certs), onc::ONC_SOURCE_DEVICE_POLICY, _, _));
253 253
254 EXPECT_CALL(network_library_, LoadOncNetworks( 254 EXPECT_CALL(network_library_, LoadOncNetworks(
255 IsEqualTo(user_networks), onc::ONC_SOURCE_USER_POLICY)); 255 IsEqualTo(user_networks), onc::ONC_SOURCE_USER_POLICY));
256 EXPECT_CALL(*certificate_handler, ImportCertificates( 256 EXPECT_CALL(*certificate_handler, ImportCertificates(
257 IsEqualTo(user_certs), onc::ONC_SOURCE_USER_POLICY, _)); 257 IsEqualTo(user_certs), onc::ONC_SOURCE_USER_POLICY, _, _));
258 258
259 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_)); 259 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_));
260 260
261 // We just need an initialized PolicyService, so we can reuse 261 // We just need an initialized PolicyService, so we can reuse
262 // |policy_service_|. 262 // |policy_service_|.
263 updater.SetUserPolicyService(false, "hash", policy_service_.get()); 263 updater.SetUserPolicyService(false, "hash", policy_service_.get());
264 updater.UnsetUserPolicyService(); 264 updater.UnsetUserPolicyService();
265 } 265 }
266 266
267 TEST_P(NetworkConfigurationUpdaterTestWithParam, 267 TEST_P(NetworkConfigurationUpdaterTestWithParam,
268 AllowTrustedCertificatesFromPolicy) { 268 AllowTrustedCertificatesFromPolicy) {
269 EXPECT_CALL(network_library_, AddNetworkProfileObserver(_)); 269 EXPECT_CALL(network_library_, AddNetworkProfileObserver(_));
270 270
271 const net::CertificateList empty_cert_list; 271 const net::CertificateList empty_cert_list;
272 272
273 const net::CertificateList cert_list = 273 const net::CertificateList cert_list =
274 net::CreateCertificateListFromFile(net::GetTestCertsDirectory(), 274 net::CreateCertificateListFromFile(net::GetTestCertsDirectory(),
275 "ok_cert.pem", 275 "ok_cert.pem",
276 net::X509Certificate::FORMAT_AUTO); 276 net::X509Certificate::FORMAT_AUTO);
277 ASSERT_EQ(1u, cert_list.size()); 277 ASSERT_EQ(1u, cert_list.size());
278 278
279 EXPECT_CALL(network_library_, LoadOncNetworks(_, _)).Times(AnyNumber()); 279 EXPECT_CALL(network_library_, LoadOncNetworks(_, _)).Times(AnyNumber());
280 StrictMock<chromeos::MockCertificateHandler>* certificate_handler = 280 StrictMock<chromeos::MockCertificateHandler>* certificate_handler =
281 new StrictMock<chromeos::MockCertificateHandler>(); 281 new StrictMock<chromeos::MockCertificateHandler>();
282 EXPECT_CALL(*certificate_handler, ImportCertificates(_, _, _)) 282 EXPECT_CALL(*certificate_handler, ImportCertificates(_, _, _, _))
283 .WillRepeatedly(SetCertificateList(empty_cert_list)); 283 .WillRepeatedly(SetCertificateList(empty_cert_list));
284 NetworkConfigurationUpdaterImplCros updater( 284 NetworkConfigurationUpdaterImplCros updater(
285 policy_service_.get(), 285 policy_service_.get(),
286 &network_library_, 286 &network_library_,
287 make_scoped_ptr<chromeos::CertificateHandler>(certificate_handler)); 287 make_scoped_ptr<chromeos::CertificateHandler>(certificate_handler));
288 net::CertTrustAnchorProvider* trust_provider = 288 net::CertTrustAnchorProvider* trust_provider =
289 updater.GetCertTrustAnchorProvider(); 289 updater.GetCertTrustAnchorProvider();
290 ASSERT_TRUE(trust_provider); 290 ASSERT_TRUE(trust_provider);
291 // The initial list of trust anchors is empty. 291 // The initial list of trust anchors is empty.
292 content::RunAllPendingInMessageLoop(content::BrowserThread::IO); 292 content::RunAllPendingInMessageLoop(content::BrowserThread::IO);
293 EXPECT_TRUE(trust_provider->GetAdditionalTrustAnchors().empty()); 293 EXPECT_TRUE(trust_provider->GetAdditionalTrustAnchors().empty());
294 294
295 // Initially, certificates imported from policy don't have trust flags. 295 // Initially, certificates imported from policy don't have trust flags.
296 updater.SetUserPolicyService(false, "hash", policy_service_.get()); 296 updater.SetUserPolicyService(false, "hash", policy_service_.get());
297 content::RunAllPendingInMessageLoop(content::BrowserThread::IO); 297 content::RunAllPendingInMessageLoop(content::BrowserThread::IO);
298 Mock::VerifyAndClearExpectations(&network_library_); 298 Mock::VerifyAndClearExpectations(&network_library_);
299 Mock::VerifyAndClearExpectations(&certificate_handler); 299 Mock::VerifyAndClearExpectations(&certificate_handler);
300 EXPECT_TRUE(trust_provider->GetAdditionalTrustAnchors().empty()); 300 EXPECT_TRUE(trust_provider->GetAdditionalTrustAnchors().empty());
301 301
302 // Certificates with the "Web" trust flag set should be forwarded to the 302 // Certificates with the "Web" trust flag set should be forwarded to the
303 // trust provider. 303 // trust provider.
304 EXPECT_CALL(network_library_, LoadOncNetworks(_, _)); 304 EXPECT_CALL(network_library_, LoadOncNetworks(_, _));
305 EXPECT_CALL(*certificate_handler, ImportCertificates(_, _, _)) 305 EXPECT_CALL(*certificate_handler, ImportCertificates(_, _, _, _))
306 .WillRepeatedly(SetCertificateList(empty_cert_list)); 306 .WillRepeatedly(SetCertificateList(empty_cert_list));
307 onc::ONCSource current_source = NameToONCSource(GetParam()); 307 onc::ONCSource current_source = NameToONCSource(GetParam());
308 EXPECT_CALL(network_library_, LoadOncNetworks(_, current_source)); 308 EXPECT_CALL(network_library_, LoadOncNetworks(_, current_source));
309 EXPECT_CALL(*certificate_handler, ImportCertificates(_, current_source, _)) 309 EXPECT_CALL(*certificate_handler, ImportCertificates(_, current_source, _, _))
310 .WillRepeatedly(SetCertificateList(cert_list)); 310 .WillRepeatedly(SetCertificateList(cert_list));
311 // Trigger a new policy load, and spin the IO message loop to pass the 311 // Trigger a new policy load, and spin the IO message loop to pass the
312 // certificates to the |trust_provider| on the IO thread. 312 // certificates to the |trust_provider| on the IO thread.
313 updater.SetUserPolicyService(true, "hash", policy_service_.get()); 313 updater.SetUserPolicyService(true, "hash", policy_service_.get());
314 base::RunLoop loop; 314 base::RunLoop loop;
315 loop.RunUntilIdle(); 315 loop.RunUntilIdle();
316 Mock::VerifyAndClearExpectations(&network_library_); 316 Mock::VerifyAndClearExpectations(&network_library_);
317 Mock::VerifyAndClearExpectations(&certificate_handler); 317 Mock::VerifyAndClearExpectations(&certificate_handler);
318 318
319 // Certificates are only provided as trust anchors if they come from user 319 // Certificates are only provided as trust anchors if they come from user
320 // policy. 320 // policy.
321 size_t expected_certs = 0u; 321 size_t expected_certs = 0u;
322 if (GetParam() == key::kOpenNetworkConfiguration) 322 if (GetParam() == key::kOpenNetworkConfiguration)
323 expected_certs = 1u; 323 expected_certs = 1u;
324 EXPECT_EQ(expected_certs, 324 EXPECT_EQ(expected_certs,
325 trust_provider->GetAdditionalTrustAnchors().size()); 325 trust_provider->GetAdditionalTrustAnchors().size());
326 326
327 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_)); 327 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_));
328 updater.UnsetUserPolicyService(); 328 updater.UnsetUserPolicyService();
329 } 329 }
330 330
331 TEST_P(NetworkConfigurationUpdaterTestWithParam, PolicyChange) { 331 TEST_P(NetworkConfigurationUpdaterTestWithParam, PolicyChange) {
332 EXPECT_CALL(network_library_, AddNetworkProfileObserver(_)); 332 EXPECT_CALL(network_library_, AddNetworkProfileObserver(_));
333 333
334 // Ignore the initial updates. 334 // Ignore the initial updates.
335 EXPECT_CALL(network_library_, LoadOncNetworks(_, _)) 335 EXPECT_CALL(network_library_, LoadOncNetworks(_, _))
336 .Times(AnyNumber()); 336 .Times(AnyNumber());
337 StrictMock<chromeos::MockCertificateHandler>* certificate_handler = 337 StrictMock<chromeos::MockCertificateHandler>* certificate_handler =
338 new StrictMock<chromeos::MockCertificateHandler>(); 338 new StrictMock<chromeos::MockCertificateHandler>();
339 EXPECT_CALL(*certificate_handler, ImportCertificates(_, _, _)) 339 EXPECT_CALL(*certificate_handler, ImportCertificates(_, _, _, _))
340 .Times(AnyNumber()); 340 .Times(AnyNumber());
341 NetworkConfigurationUpdaterImplCros updater( 341 NetworkConfigurationUpdaterImplCros updater(
342 policy_service_.get(), 342 policy_service_.get(),
343 &network_library_, 343 &network_library_,
344 make_scoped_ptr<chromeos::CertificateHandler>(certificate_handler)); 344 make_scoped_ptr<chromeos::CertificateHandler>(certificate_handler));
345 updater.SetUserPolicyService(false, "hash", policy_service_.get()); 345 updater.SetUserPolicyService(false, "hash", policy_service_.get());
346 Mock::VerifyAndClearExpectations(&network_library_); 346 Mock::VerifyAndClearExpectations(&network_library_);
347 Mock::VerifyAndClearExpectations(&certificate_handler); 347 Mock::VerifyAndClearExpectations(&certificate_handler);
348 348
349 // We should update if policy changes. 349 // We should update if policy changes.
350 EXPECT_CALL(network_library_, LoadOncNetworks( 350 EXPECT_CALL(network_library_, LoadOncNetworks(
351 IsEqualTo(fake_network_configs_.get()), NameToONCSource(GetParam()))); 351 IsEqualTo(fake_network_configs_.get()), NameToONCSource(GetParam())));
352 EXPECT_CALL(*certificate_handler, ImportCertificates( 352 EXPECT_CALL(*certificate_handler, ImportCertificates(
353 IsEqualTo(fake_certificates_.get()), NameToONCSource(GetParam()), _)); 353 IsEqualTo(fake_certificates_.get()), NameToONCSource(GetParam()), _, _));
354 354
355 // In the current implementation, we always apply both policies. 355 // In the current implementation, we always apply both policies.
356 EXPECT_CALL(network_library_, LoadOncNetworks( 356 EXPECT_CALL(network_library_, LoadOncNetworks(
357 IsEqualTo(empty_network_configs_.get()), 357 IsEqualTo(empty_network_configs_.get()),
358 Ne(NameToONCSource(GetParam())))); 358 Ne(NameToONCSource(GetParam()))));
359 EXPECT_CALL(*certificate_handler, ImportCertificates( 359 EXPECT_CALL(*certificate_handler, ImportCertificates(
360 IsEqualTo(empty_certificates_.get()), 360 IsEqualTo(empty_certificates_.get()),
361 Ne(NameToONCSource(GetParam())), 361 Ne(NameToONCSource(GetParam())),
362 _)); 362 _, _));
363 363
364 PolicyMap policy; 364 PolicyMap policy;
365 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 365 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
366 Value::CreateStringValue(kFakeONC)); 366 Value::CreateStringValue(kFakeONC));
367 UpdateProviderPolicy(policy); 367 UpdateProviderPolicy(policy);
368 Mock::VerifyAndClearExpectations(&network_library_); 368 Mock::VerifyAndClearExpectations(&network_library_);
369 Mock::VerifyAndClearExpectations(&certificate_handler); 369 Mock::VerifyAndClearExpectations(&certificate_handler);
370 370
371 // Another update is expected if the policy goes away. In the current 371 // Another update is expected if the policy goes away. In the current
372 // implementation, we always apply both policies. 372 // implementation, we always apply both policies.
373 EXPECT_CALL(network_library_, LoadOncNetworks( 373 EXPECT_CALL(network_library_, LoadOncNetworks(
374 IsEqualTo(empty_network_configs_.get()), 374 IsEqualTo(empty_network_configs_.get()),
375 onc::ONC_SOURCE_DEVICE_POLICY)); 375 onc::ONC_SOURCE_DEVICE_POLICY));
376 EXPECT_CALL(*certificate_handler, ImportCertificates( 376 EXPECT_CALL(*certificate_handler, ImportCertificates(
377 IsEqualTo(empty_certificates_.get()), 377 IsEqualTo(empty_certificates_.get()),
378 onc::ONC_SOURCE_DEVICE_POLICY, 378 onc::ONC_SOURCE_DEVICE_POLICY,
379 _)); 379 _, _));
380 380
381 EXPECT_CALL(network_library_, LoadOncNetworks( 381 EXPECT_CALL(network_library_, LoadOncNetworks(
382 IsEqualTo(empty_network_configs_.get()), 382 IsEqualTo(empty_network_configs_.get()),
383 onc::ONC_SOURCE_USER_POLICY)); 383 onc::ONC_SOURCE_USER_POLICY));
384 EXPECT_CALL(*certificate_handler, ImportCertificates( 384 EXPECT_CALL(*certificate_handler, ImportCertificates(
385 IsEqualTo(empty_certificates_.get()), 385 IsEqualTo(empty_certificates_.get()),
386 onc::ONC_SOURCE_USER_POLICY, 386 onc::ONC_SOURCE_USER_POLICY,
387 _)); 387 _, _));
388 388
389 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_)); 389 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_));
390 390
391 policy.Erase(GetParam()); 391 policy.Erase(GetParam());
392 UpdateProviderPolicy(policy); 392 UpdateProviderPolicy(policy);
393 updater.UnsetUserPolicyService(); 393 updater.UnsetUserPolicyService();
394 } 394 }
395 395
396 INSTANTIATE_TEST_CASE_P( 396 INSTANTIATE_TEST_CASE_P(
397 NetworkConfigurationUpdaterTestWithParamInstance, 397 NetworkConfigurationUpdaterTestWithParamInstance,
398 NetworkConfigurationUpdaterTestWithParam, 398 NetworkConfigurationUpdaterTestWithParam,
399 testing::Values(key::kDeviceOpenNetworkConfiguration, 399 testing::Values(key::kDeviceOpenNetworkConfiguration,
400 key::kOpenNetworkConfiguration)); 400 key::kOpenNetworkConfiguration));
401 401
402 } // namespace policy 402 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698