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

Side by Side Diff: chrome/browser/net/sqlite_server_bound_cert_store_unittest.cc

Issue 10447117: Unwire the clear on exit preference from the storage systems. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/scoped_temp_dir.h" 10 #include "base/scoped_temp_dir.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 base::Time::FromInternalValue(1), 75 base::Time::FromInternalValue(1),
76 base::Time::FromInternalValue(2), 76 base::Time::FromInternalValue(2),
77 "a", "b")); 77 "a", "b"));
78 } 78 }
79 79
80 content::TestBrowserThread db_thread_; 80 content::TestBrowserThread db_thread_;
81 ScopedTempDir temp_dir_; 81 ScopedTempDir temp_dir_;
82 scoped_refptr<SQLiteServerBoundCertStore> store_; 82 scoped_refptr<SQLiteServerBoundCertStore> store_;
83 }; 83 };
84 84
85 TEST_F(SQLiteServerBoundCertStoreTest, KeepOnDestruction) {
86 store_->SetClearLocalStateOnExit(false);
87 store_ = NULL;
88 // Make sure we wait until the destructor has run.
89 scoped_refptr<base::ThreadTestHelper> helper(
90 new base::ThreadTestHelper(
91 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB)));
92 ASSERT_TRUE(helper->Run());
93
94 ASSERT_TRUE(file_util::PathExists(
95 temp_dir_.path().Append(chrome::kOBCertFilename)));
96 ASSERT_TRUE(file_util::Delete(
97 temp_dir_.path().Append(chrome::kOBCertFilename), false));
98 }
99
100 TEST_F(SQLiteServerBoundCertStoreTest, RemoveOnDestruction) {
101 store_->SetClearLocalStateOnExit(true);
102 // Replace the store effectively destroying the current one and forcing it
103 // to write its data to disk. Then we can see if after loading it again it
104 // is still there.
105 store_ = NULL;
106 // Make sure we wait until the destructor has run.
107 scoped_refptr<base::ThreadTestHelper> helper(
108 new base::ThreadTestHelper(
109 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB)));
110 ASSERT_TRUE(helper->Run());
111
112 ASSERT_FALSE(file_util::PathExists(
113 temp_dir_.path().Append(chrome::kOBCertFilename)));
114 }
115
116 // Test if data is stored as expected in the SQLite database. 85 // Test if data is stored as expected in the SQLite database.
117 TEST_F(SQLiteServerBoundCertStoreTest, TestPersistence) { 86 TEST_F(SQLiteServerBoundCertStoreTest, TestPersistence) {
118 store_->AddServerBoundCert( 87 store_->AddServerBoundCert(
119 net::DefaultServerBoundCertStore::ServerBoundCert( 88 net::DefaultServerBoundCertStore::ServerBoundCert(
120 "foo.com", 89 "foo.com",
121 net::CLIENT_CERT_ECDSA_SIGN, 90 net::CLIENT_CERT_ECDSA_SIGN,
122 base::Time::FromInternalValue(3), 91 base::Time::FromInternalValue(3),
123 base::Time::FromInternalValue(4), 92 base::Time::FromInternalValue(4),
124 "c", "d")); 93 "c", "d"));
125 94
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 // Tests the interaction with the clear on exit policy. 510 // Tests the interaction with the clear on exit policy.
542 // Crashes periodically on Mac 10.6 511 // Crashes periodically on Mac 10.6
543 // http://crbug.com/130511 512 // http://crbug.com/130511
544 #if defined(OS_MACOSX) 513 #if defined(OS_MACOSX)
545 #define MAYBE_TestClearOnExitPolicy DISABLED_TestClearOnExitPolicy 514 #define MAYBE_TestClearOnExitPolicy DISABLED_TestClearOnExitPolicy
546 #else 515 #else
547 #define MAYBE_TestClearOnExitPolicy TestClearOnExitPolicy 516 #define MAYBE_TestClearOnExitPolicy TestClearOnExitPolicy
548 #endif 517 #endif
549 TEST_F(SQLiteServerBoundCertStoreTest, MAYBE_TestClearOnExitPolicy) { 518 TEST_F(SQLiteServerBoundCertStoreTest, MAYBE_TestClearOnExitPolicy) {
550 // First, delete a possibly existing store. 519 // First, delete a possibly existing store.
551 store_->SetClearLocalStateOnExit(true);
552 store_ = NULL; 520 store_ = NULL;
553 scoped_refptr<base::ThreadTestHelper> helper( 521 scoped_refptr<base::ThreadTestHelper> helper(
554 new base::ThreadTestHelper( 522 new base::ThreadTestHelper(
555 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB))); 523 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB)));
556 ASSERT_TRUE(helper->Run()); 524 ASSERT_TRUE(helper->Run());
525 ASSERT_TRUE(file_util::Delete(
526 temp_dir_.path().Append(chrome::kOBCertFilename), false));
557 527
558 // Create a new store with three certificates in it. 528 // Create a new store with three certificates in it.
559 store_ = new SQLiteServerBoundCertStore( 529 store_ = new SQLiteServerBoundCertStore(
560 temp_dir_.path().Append(chrome::kOBCertFilename), NULL); 530 temp_dir_.path().Append(chrome::kOBCertFilename), NULL);
marja 2012/05/31 15:30:32 <unrelated whine>Instead of deleting the previous
jochen (gone - plz use gerrit) 2012/05/31 15:54:41 will do
561 531
562 ScopedVector<net::DefaultServerBoundCertStore::ServerBoundCert> certs; 532 ScopedVector<net::DefaultServerBoundCertStore::ServerBoundCert> certs;
563 ASSERT_TRUE(store_->Load(&certs.get())); 533 ASSERT_TRUE(store_->Load(&certs.get()));
564 ASSERT_EQ(0U, certs.size()); 534 ASSERT_EQ(0U, certs.size());
565 535
566 store_->AddServerBoundCert( 536 store_->AddServerBoundCert(
567 net::DefaultServerBoundCertStore::ServerBoundCert( 537 net::DefaultServerBoundCertStore::ServerBoundCert(
568 "other.com", 538 "other.com",
569 net::CLIENT_CERT_RSA_SIGN, 539 net::CLIENT_CERT_RSA_SIGN,
570 base::Time::FromInternalValue(1), 540 base::Time::FromInternalValue(1),
(...skipping 24 matching lines...) Expand all
595 scoped_refptr<ClearOnExitPolicy> clear_policy = 565 scoped_refptr<ClearOnExitPolicy> clear_policy =
596 new ClearOnExitPolicy(storage_policy.get()); 566 new ClearOnExitPolicy(storage_policy.get());
597 storage_policy->AddSessionOnly(GURL("https://session.com")); 567 storage_policy->AddSessionOnly(GURL("https://session.com"));
598 storage_policy->AddSessionOnly(GURL("https://protected.com")); 568 storage_policy->AddSessionOnly(GURL("https://protected.com"));
599 storage_policy->AddProtected(GURL("https://protected.com")); 569 storage_policy->AddProtected(GURL("https://protected.com"));
600 store_ = new SQLiteServerBoundCertStore( 570 store_ = new SQLiteServerBoundCertStore(
601 temp_dir_.path().Append(chrome::kOBCertFilename), clear_policy.get()); 571 temp_dir_.path().Append(chrome::kOBCertFilename), clear_policy.get());
602 ASSERT_TRUE(store_->Load(&certs.get())); 572 ASSERT_TRUE(store_->Load(&certs.get()));
603 ASSERT_EQ(3U, certs.size()); 573 ASSERT_EQ(3U, certs.size());
604 574
605 // Delete the store. This should apply the clear on exit policy. 575 // We've put a exit policy in place, but force the state to be saved.
576 store_->SaveSessionState();
577 store_ = NULL;
578 ASSERT_TRUE(helper->Run());
579
580 // Reload the store and check that the certs are still there.
581 store_ = new SQLiteServerBoundCertStore(
582 temp_dir_.path().Append(chrome::kOBCertFilename), clear_policy.get());
583
584 // Reload and test for persistence
585 certs.reset();
586 ASSERT_TRUE(store_->Load(&certs.get()));
587 ASSERT_EQ(3U, certs.size());
588
589 // Delete the store. This time, the exit policy should be in place.
606 store_ = NULL; 590 store_ = NULL;
607 // Make sure we wait until the destructor has run. 591 // Make sure we wait until the destructor has run.
608 ASSERT_TRUE(helper->Run()); 592 ASSERT_TRUE(helper->Run());
609 593
610 store_ = new SQLiteServerBoundCertStore( 594 store_ = new SQLiteServerBoundCertStore(
611 temp_dir_.path().Append(chrome::kOBCertFilename), clear_policy.get()); 595 temp_dir_.path().Append(chrome::kOBCertFilename), clear_policy.get());
612 596
613 // Reload and test for persistence 597 // Reload and test for persistence
614 certs.reset(); 598 certs.reset();
615 ASSERT_TRUE(store_->Load(&certs.get())); 599 ASSERT_TRUE(store_->Load(&certs.get()));
616 ASSERT_EQ(2U, certs.size()); 600 ASSERT_EQ(2U, certs.size());
617 601
618 ASSERT_TRUE(CertificateExistsInList(&certs.get(), 602 ASSERT_TRUE(CertificateExistsInList(&certs.get(),
619 "other.com", 603 "other.com",
620 net::CLIENT_CERT_RSA_SIGN, 604 net::CLIENT_CERT_RSA_SIGN,
621 "a", "b", 1, 2)); 605 "a", "b", 1, 2));
622 ASSERT_TRUE(CertificateExistsInList(&certs.get(), 606 ASSERT_TRUE(CertificateExistsInList(&certs.get(),
623 "protected.com", 607 "protected.com",
624 net::CLIENT_CERT_RSA_SIGN, 608 net::CLIENT_CERT_RSA_SIGN,
625 "n", "m", 5, 6)); 609 "n", "m", 5, 6));
626 } 610 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698