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/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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 ASSERT_TRUE(network_configs_repaired); | 165 ASSERT_TRUE(network_configs_repaired); |
166 | 166 |
167 PolicyMap policy; | 167 PolicyMap policy; |
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 _)); |
| 195 EXPECT_CALL(*certificate_handler, ImportCertificates(_, _, _, _)).Times(2); |
195 | 196 |
196 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_)); | 197 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_)); |
197 | 198 |
198 updater.OnUserPolicyInitialized(false, "hash"); | 199 updater.OnUserPolicyInitialized(false, "hash"); |
199 } | 200 } |
200 | 201 |
201 class NetworkConfigurationUpdaterTestWithParam | 202 class NetworkConfigurationUpdaterTestWithParam |
202 : public NetworkConfigurationUpdaterTest, | 203 : public NetworkConfigurationUpdaterTest, |
203 public testing::WithParamInterface<const char*> { | 204 public testing::WithParamInterface<const char*> { |
204 }; | 205 }; |
(...skipping 18 matching lines...) Expand all Loading... |
223 user_networks = empty_network_configs_.get(); | 224 user_networks = empty_network_configs_.get(); |
224 user_certs = empty_certificates_.get(); | 225 user_certs = empty_certificates_.get(); |
225 } else { | 226 } else { |
226 device_networks = empty_network_configs_.get(); | 227 device_networks = empty_network_configs_.get(); |
227 device_certs = empty_certificates_.get(); | 228 device_certs = empty_certificates_.get(); |
228 user_networks = fake_network_configs_.get(); | 229 user_networks = fake_network_configs_.get(); |
229 user_certs = fake_certificates_.get(); | 230 user_certs = fake_certificates_.get(); |
230 } | 231 } |
231 | 232 |
232 EXPECT_CALL(network_library_, LoadOncNetworks( | 233 EXPECT_CALL(network_library_, LoadOncNetworks( |
233 IsEqualTo(device_networks), onc::ONC_SOURCE_DEVICE_POLICY)); | 234 IsEqualTo(device_networks), onc::ONC_SOURCE_DEVICE_POLICY, _)); |
234 StrictMock<chromeos::MockCertificateHandler>* certificate_handler = | 235 StrictMock<chromeos::MockCertificateHandler>* certificate_handler = |
235 new StrictMock<chromeos::MockCertificateHandler>(); | 236 new StrictMock<chromeos::MockCertificateHandler>(); |
236 EXPECT_CALL(*certificate_handler, ImportCertificates( | 237 EXPECT_CALL(*certificate_handler, ImportCertificates( |
237 IsEqualTo(device_certs), onc::ONC_SOURCE_DEVICE_POLICY, _)); | 238 IsEqualTo(device_certs), onc::ONC_SOURCE_DEVICE_POLICY, _, _)); |
238 | 239 |
239 NetworkConfigurationUpdaterImplCros updater( | 240 NetworkConfigurationUpdaterImplCros updater( |
240 policy_service_.get(), | 241 policy_service_.get(), |
241 &network_library_, | 242 &network_library_, |
242 make_scoped_ptr<chromeos::CertificateHandler>(certificate_handler)); | 243 make_scoped_ptr<chromeos::CertificateHandler>(certificate_handler)); |
243 Mock::VerifyAndClearExpectations(&network_library_); | 244 Mock::VerifyAndClearExpectations(&network_library_); |
244 Mock::VerifyAndClearExpectations(&certificate_handler); | 245 Mock::VerifyAndClearExpectations(&certificate_handler); |
245 | 246 |
246 // 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 |
247 // NetworkLibrary. | 248 // NetworkLibrary. |
248 EXPECT_CALL(network_library_, LoadOncNetworks( | 249 EXPECT_CALL(network_library_, LoadOncNetworks( |
249 IsEqualTo(device_networks), onc::ONC_SOURCE_DEVICE_POLICY)); | 250 IsEqualTo(device_networks), onc::ONC_SOURCE_DEVICE_POLICY, _)); |
250 EXPECT_CALL(*certificate_handler, ImportCertificates( | 251 EXPECT_CALL(*certificate_handler, ImportCertificates( |
251 IsEqualTo(device_certs), onc::ONC_SOURCE_DEVICE_POLICY, _)); | 252 IsEqualTo(device_certs), onc::ONC_SOURCE_DEVICE_POLICY, _, _)); |
252 | 253 |
253 EXPECT_CALL(network_library_, LoadOncNetworks( | 254 EXPECT_CALL(network_library_, LoadOncNetworks( |
254 IsEqualTo(user_networks), onc::ONC_SOURCE_USER_POLICY)); | 255 IsEqualTo(user_networks), onc::ONC_SOURCE_USER_POLICY, _)); |
255 EXPECT_CALL(*certificate_handler, ImportCertificates( | 256 EXPECT_CALL(*certificate_handler, ImportCertificates( |
256 IsEqualTo(user_certs), onc::ONC_SOURCE_USER_POLICY, _)); | 257 IsEqualTo(user_certs), onc::ONC_SOURCE_USER_POLICY, _, _)); |
257 | 258 |
258 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_)); | 259 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_)); |
259 | 260 |
260 updater.OnUserPolicyInitialized(false, "hash"); | 261 updater.OnUserPolicyInitialized(false, "hash"); |
261 } | 262 } |
262 | 263 |
263 TEST_P(NetworkConfigurationUpdaterTestWithParam, | 264 TEST_P(NetworkConfigurationUpdaterTestWithParam, |
264 AllowTrustedCertificatesFromPolicy) { | 265 AllowTrustedCertificatesFromPolicy) { |
265 EXPECT_CALL(network_library_, AddNetworkProfileObserver(_)); | 266 EXPECT_CALL(network_library_, AddNetworkProfileObserver(_)); |
266 | 267 |
267 const net::CertificateList empty_cert_list; | 268 const net::CertificateList empty_cert_list; |
268 | 269 |
269 const net::CertificateList cert_list = | 270 const net::CertificateList cert_list = |
270 net::CreateCertificateListFromFile(net::GetTestCertsDirectory(), | 271 net::CreateCertificateListFromFile(net::GetTestCertsDirectory(), |
271 "ok_cert.pem", | 272 "ok_cert.pem", |
272 net::X509Certificate::FORMAT_AUTO); | 273 net::X509Certificate::FORMAT_AUTO); |
273 ASSERT_EQ(1u, cert_list.size()); | 274 ASSERT_EQ(1u, cert_list.size()); |
274 | 275 |
275 EXPECT_CALL(network_library_, LoadOncNetworks(_, _)).Times(AnyNumber()); | 276 EXPECT_CALL(network_library_, LoadOncNetworks(_, _, _)).Times(AnyNumber()); |
276 StrictMock<chromeos::MockCertificateHandler>* certificate_handler = | 277 StrictMock<chromeos::MockCertificateHandler>* certificate_handler = |
277 new StrictMock<chromeos::MockCertificateHandler>(); | 278 new StrictMock<chromeos::MockCertificateHandler>(); |
278 EXPECT_CALL(*certificate_handler, ImportCertificates(_, _, _)) | 279 EXPECT_CALL(*certificate_handler, ImportCertificates(_, _, _, _)) |
279 .WillRepeatedly(SetCertificateList(empty_cert_list)); | 280 .WillRepeatedly(SetCertificateList(empty_cert_list)); |
280 NetworkConfigurationUpdaterImplCros updater( | 281 NetworkConfigurationUpdaterImplCros updater( |
281 policy_service_.get(), | 282 policy_service_.get(), |
282 &network_library_, | 283 &network_library_, |
283 make_scoped_ptr<chromeos::CertificateHandler>(certificate_handler)); | 284 make_scoped_ptr<chromeos::CertificateHandler>(certificate_handler)); |
284 net::CertTrustAnchorProvider* trust_provider = | 285 net::CertTrustAnchorProvider* trust_provider = |
285 updater.GetCertTrustAnchorProvider(); | 286 updater.GetCertTrustAnchorProvider(); |
286 ASSERT_TRUE(trust_provider); | 287 ASSERT_TRUE(trust_provider); |
287 // The initial list of trust anchors is empty. | 288 // The initial list of trust anchors is empty. |
288 content::RunAllPendingInMessageLoop(content::BrowserThread::IO); | 289 content::RunAllPendingInMessageLoop(content::BrowserThread::IO); |
289 EXPECT_TRUE(trust_provider->GetAdditionalTrustAnchors().empty()); | 290 EXPECT_TRUE(trust_provider->GetAdditionalTrustAnchors().empty()); |
290 | 291 |
291 // Initially, certificates imported from policy don't have trust flags. | 292 // Initially, certificates imported from policy don't have trust flags. |
292 updater.OnUserPolicyInitialized(false, "hash"); | 293 updater.OnUserPolicyInitialized(false, "hash"); |
293 content::RunAllPendingInMessageLoop(content::BrowserThread::IO); | 294 content::RunAllPendingInMessageLoop(content::BrowserThread::IO); |
294 Mock::VerifyAndClearExpectations(&network_library_); | 295 Mock::VerifyAndClearExpectations(&network_library_); |
295 Mock::VerifyAndClearExpectations(&certificate_handler); | 296 Mock::VerifyAndClearExpectations(&certificate_handler); |
296 EXPECT_TRUE(trust_provider->GetAdditionalTrustAnchors().empty()); | 297 EXPECT_TRUE(trust_provider->GetAdditionalTrustAnchors().empty()); |
297 | 298 |
298 // Certificates with the "Web" trust flag set should be forwarded to the | 299 // Certificates with the "Web" trust flag set should be forwarded to the |
299 // trust provider. | 300 // trust provider. |
300 EXPECT_CALL(network_library_, LoadOncNetworks(_, _)); | 301 EXPECT_CALL(network_library_, LoadOncNetworks(_, _, _)); |
301 EXPECT_CALL(*certificate_handler, ImportCertificates(_, _, _)) | 302 EXPECT_CALL(*certificate_handler, ImportCertificates(_, _, _, _)) |
302 .WillRepeatedly(SetCertificateList(empty_cert_list)); | 303 .WillRepeatedly(SetCertificateList(empty_cert_list)); |
303 onc::ONCSource current_source = NameToONCSource(GetParam()); | 304 onc::ONCSource current_source = NameToONCSource(GetParam()); |
304 EXPECT_CALL(network_library_, LoadOncNetworks(_, current_source)); | 305 EXPECT_CALL(network_library_, LoadOncNetworks(_, current_source, _)); |
305 EXPECT_CALL(*certificate_handler, ImportCertificates(_, current_source, _)) | 306 EXPECT_CALL(*certificate_handler, ImportCertificates(_, current_source, _, _)) |
306 .WillRepeatedly(SetCertificateList(cert_list)); | 307 .WillRepeatedly(SetCertificateList(cert_list)); |
307 // Trigger a new policy load, and spin the IO message loop to pass the | 308 // Trigger a new policy load, and spin the IO message loop to pass the |
308 // certificates to the |trust_provider| on the IO thread. | 309 // certificates to the |trust_provider| on the IO thread. |
309 updater.OnUserPolicyInitialized(true, "hash"); | 310 updater.OnUserPolicyInitialized(true, "hash"); |
310 base::RunLoop loop; | 311 base::RunLoop loop; |
311 loop.RunUntilIdle(); | 312 loop.RunUntilIdle(); |
312 Mock::VerifyAndClearExpectations(&network_library_); | 313 Mock::VerifyAndClearExpectations(&network_library_); |
313 Mock::VerifyAndClearExpectations(&certificate_handler); | 314 Mock::VerifyAndClearExpectations(&certificate_handler); |
314 | 315 |
315 // Certificates are only provided as trust anchors if they come from user | 316 // Certificates are only provided as trust anchors if they come from user |
316 // policy. | 317 // policy. |
317 size_t expected_certs = 0u; | 318 size_t expected_certs = 0u; |
318 if (GetParam() == key::kOpenNetworkConfiguration) | 319 if (GetParam() == key::kOpenNetworkConfiguration) |
319 expected_certs = 1u; | 320 expected_certs = 1u; |
320 EXPECT_EQ(expected_certs, | 321 EXPECT_EQ(expected_certs, |
321 trust_provider->GetAdditionalTrustAnchors().size()); | 322 trust_provider->GetAdditionalTrustAnchors().size()); |
322 | 323 |
323 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_)); | 324 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_)); |
324 } | 325 } |
325 | 326 |
326 TEST_P(NetworkConfigurationUpdaterTestWithParam, PolicyChange) { | 327 TEST_P(NetworkConfigurationUpdaterTestWithParam, PolicyChange) { |
327 EXPECT_CALL(network_library_, AddNetworkProfileObserver(_)); | 328 EXPECT_CALL(network_library_, AddNetworkProfileObserver(_)); |
328 | 329 |
329 // Ignore the initial updates. | 330 // Ignore the initial updates. |
330 EXPECT_CALL(network_library_, LoadOncNetworks(_, _)) | 331 EXPECT_CALL(network_library_, LoadOncNetworks(_, _, _)) |
331 .Times(AnyNumber()); | 332 .Times(AnyNumber()); |
332 StrictMock<chromeos::MockCertificateHandler>* certificate_handler = | 333 StrictMock<chromeos::MockCertificateHandler>* certificate_handler = |
333 new StrictMock<chromeos::MockCertificateHandler>(); | 334 new StrictMock<chromeos::MockCertificateHandler>(); |
334 EXPECT_CALL(*certificate_handler, ImportCertificates(_, _, _)) | 335 EXPECT_CALL(*certificate_handler, ImportCertificates(_, _, _, _)) |
335 .Times(AnyNumber()); | 336 .Times(AnyNumber()); |
336 NetworkConfigurationUpdaterImplCros updater( | 337 NetworkConfigurationUpdaterImplCros updater( |
337 policy_service_.get(), | 338 policy_service_.get(), |
338 &network_library_, | 339 &network_library_, |
339 make_scoped_ptr<chromeos::CertificateHandler>(certificate_handler)); | 340 make_scoped_ptr<chromeos::CertificateHandler>(certificate_handler)); |
340 updater.OnUserPolicyInitialized(false, "hash"); | 341 updater.OnUserPolicyInitialized(false, "hash"); |
341 Mock::VerifyAndClearExpectations(&network_library_); | 342 Mock::VerifyAndClearExpectations(&network_library_); |
342 Mock::VerifyAndClearExpectations(&certificate_handler); | 343 Mock::VerifyAndClearExpectations(&certificate_handler); |
343 | 344 |
344 // We should update if policy changes. | 345 // We should update if policy changes. |
345 EXPECT_CALL(network_library_, LoadOncNetworks( | 346 EXPECT_CALL(network_library_, LoadOncNetworks( |
346 IsEqualTo(fake_network_configs_.get()), NameToONCSource(GetParam()))); | 347 IsEqualTo(fake_network_configs_.get()), NameToONCSource(GetParam()), _)); |
347 EXPECT_CALL(*certificate_handler, ImportCertificates( | 348 EXPECT_CALL(*certificate_handler, ImportCertificates( |
348 IsEqualTo(fake_certificates_.get()), NameToONCSource(GetParam()), _)); | 349 IsEqualTo(fake_certificates_.get()), NameToONCSource(GetParam()), _, _)); |
349 | 350 |
350 // In the current implementation, we always apply both policies. | 351 // In the current implementation, we always apply both policies. |
351 EXPECT_CALL(network_library_, LoadOncNetworks( | 352 EXPECT_CALL(network_library_, LoadOncNetworks( |
352 IsEqualTo(empty_network_configs_.get()), | 353 IsEqualTo(empty_network_configs_.get()), |
353 Ne(NameToONCSource(GetParam())))); | 354 Ne(NameToONCSource(GetParam())), |
| 355 _)); |
354 EXPECT_CALL(*certificate_handler, ImportCertificates( | 356 EXPECT_CALL(*certificate_handler, ImportCertificates( |
355 IsEqualTo(empty_certificates_.get()), | 357 IsEqualTo(empty_certificates_.get()), |
356 Ne(NameToONCSource(GetParam())), | 358 Ne(NameToONCSource(GetParam())), |
357 _)); | 359 _, _)); |
358 | 360 |
359 PolicyMap policy; | 361 PolicyMap policy; |
360 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 362 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
361 Value::CreateStringValue(kFakeONC)); | 363 Value::CreateStringValue(kFakeONC)); |
362 UpdateProviderPolicy(policy); | 364 UpdateProviderPolicy(policy); |
363 Mock::VerifyAndClearExpectations(&network_library_); | 365 Mock::VerifyAndClearExpectations(&network_library_); |
364 Mock::VerifyAndClearExpectations(&certificate_handler); | 366 Mock::VerifyAndClearExpectations(&certificate_handler); |
365 | 367 |
366 // Another update is expected if the policy goes away. In the current | 368 // Another update is expected if the policy goes away. In the current |
367 // implementation, we always apply both policies. | 369 // implementation, we always apply both policies. |
368 EXPECT_CALL(network_library_, LoadOncNetworks( | 370 EXPECT_CALL(network_library_, LoadOncNetworks( |
369 IsEqualTo(empty_network_configs_.get()), | 371 IsEqualTo(empty_network_configs_.get()), |
370 onc::ONC_SOURCE_DEVICE_POLICY)); | 372 onc::ONC_SOURCE_DEVICE_POLICY, |
| 373 _)); |
371 EXPECT_CALL(*certificate_handler, ImportCertificates( | 374 EXPECT_CALL(*certificate_handler, ImportCertificates( |
372 IsEqualTo(empty_certificates_.get()), | 375 IsEqualTo(empty_certificates_.get()), |
373 onc::ONC_SOURCE_DEVICE_POLICY, | 376 onc::ONC_SOURCE_DEVICE_POLICY, |
374 _)); | 377 _, _)); |
375 | 378 |
376 EXPECT_CALL(network_library_, LoadOncNetworks( | 379 EXPECT_CALL(network_library_, LoadOncNetworks( |
377 IsEqualTo(empty_network_configs_.get()), | 380 IsEqualTo(empty_network_configs_.get()), |
378 onc::ONC_SOURCE_USER_POLICY)); | 381 onc::ONC_SOURCE_USER_POLICY, |
| 382 _)); |
379 EXPECT_CALL(*certificate_handler, ImportCertificates( | 383 EXPECT_CALL(*certificate_handler, ImportCertificates( |
380 IsEqualTo(empty_certificates_.get()), | 384 IsEqualTo(empty_certificates_.get()), |
381 onc::ONC_SOURCE_USER_POLICY, | 385 onc::ONC_SOURCE_USER_POLICY, |
382 _)); | 386 _, _)); |
383 | 387 |
384 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_)); | 388 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_)); |
385 | 389 |
386 policy.Erase(GetParam()); | 390 policy.Erase(GetParam()); |
387 UpdateProviderPolicy(policy); | 391 UpdateProviderPolicy(policy); |
388 } | 392 } |
389 | 393 |
390 INSTANTIATE_TEST_CASE_P( | 394 INSTANTIATE_TEST_CASE_P( |
391 NetworkConfigurationUpdaterTestWithParamInstance, | 395 NetworkConfigurationUpdaterTestWithParamInstance, |
392 NetworkConfigurationUpdaterTestWithParam, | 396 NetworkConfigurationUpdaterTestWithParam, |
393 testing::Values(key::kDeviceOpenNetworkConfiguration, | 397 testing::Values(key::kDeviceOpenNetworkConfiguration, |
394 key::kOpenNetworkConfiguration)); | 398 key::kOpenNetworkConfiguration)); |
395 | 399 |
396 } // namespace policy | 400 } // namespace policy |
OLD | NEW |