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

Side by Side Diff: talk/app/webrtc/dtlsidentitystore_unittest.cc

Issue 1176383004: DtlsIdentityStore[Interface/Impl] updated, DtlsIdentityService to be removed (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Addressed rest of tommi's comments: Removed need for lock Created 5 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
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2015 Google Inc. 3 * Copyright 2015 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 14 matching lines...) Expand all
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28 #include "talk/app/webrtc/dtlsidentitystore.h" 28 #include "talk/app/webrtc/dtlsidentitystore.h"
29 29
30 #include "talk/app/webrtc/webrtcsessiondescriptionfactory.h" 30 #include "talk/app/webrtc/webrtcsessiondescriptionfactory.h"
31 #include "webrtc/base/gunit.h" 31 #include "webrtc/base/gunit.h"
32 #include "webrtc/base/logging.h" 32 #include "webrtc/base/logging.h"
33 #include "webrtc/base/ssladapter.h" 33 #include "webrtc/base/ssladapter.h"
34 34
35 using webrtc::DtlsIdentityStore; 35 using webrtc::DtlsIdentityStoreImpl;
36 using webrtc::WebRtcSessionDescriptionFactory; 36 using webrtc::WebRtcSessionDescriptionFactory;
37 37
38 static const int kTimeoutMs = 10000; 38 static const int kTimeoutMs = 10000;
39 39
40 class MockDtlsIdentityRequestObserver : 40 class MockDtlsIdentityRequestObserver :
41 public webrtc::DTLSIdentityRequestObserver { 41 public webrtc::DtlsIdentityRequestObserver {
42 public: 42 public:
43 MockDtlsIdentityRequestObserver() 43 MockDtlsIdentityRequestObserver()
44 : call_back_called_(false), last_request_success_(false) {} 44 : call_back_called_(false), last_request_success_(false) {}
45 void OnFailure(int error) override { 45 void OnFailure(int error) override {
46 EXPECT_FALSE(call_back_called_); 46 EXPECT_FALSE(call_back_called_);
47 call_back_called_ = true; 47 call_back_called_ = true;
48 last_request_success_ = false; 48 last_request_success_ = false;
49 } 49 }
50 void OnSuccess(const std::string& der_cert, 50 void OnSuccess(const std::string& der_cert,
51 const std::string& der_private_key) { 51 const std::string& der_private_key) override {
52 LOG(LS_WARNING) << "The string version of OnSuccess is called unexpectedly"; 52 LOG(LS_WARNING) << "The string version of OnSuccess is called unexpectedly";
53 EXPECT_TRUE(false); 53 EXPECT_TRUE(false);
54 } 54 }
55 void OnSuccessWithIdentityObj( 55 void OnSuccess(rtc::scoped_ptr<rtc::SSLIdentity> identity) override {
56 rtc::scoped_ptr<rtc::SSLIdentity> identity) override {
57 EXPECT_FALSE(call_back_called_); 56 EXPECT_FALSE(call_back_called_);
58 call_back_called_ = true; 57 call_back_called_ = true;
59 last_request_success_ = true; 58 last_request_success_ = true;
60 } 59 }
61 60
62 void Reset() { 61 void Reset() {
63 call_back_called_ = false; 62 call_back_called_ = false;
64 last_request_success_ = false; 63 last_request_success_ = false;
65 } 64 }
66 65
67 bool LastRequestSucceeded() const { 66 bool LastRequestSucceeded() const {
68 return call_back_called_ && last_request_success_; 67 return call_back_called_ && last_request_success_;
69 } 68 }
70 69
71 bool call_back_called() const { 70 bool call_back_called() const {
72 return call_back_called_; 71 return call_back_called_;
73 } 72 }
74 73
75 private: 74 private:
76 bool call_back_called_; 75 bool call_back_called_;
77 bool last_request_success_; 76 bool last_request_success_;
78 }; 77 };
79 78
80 class DtlsIdentityStoreTest : public testing::Test { 79 class DtlsIdentityStoreTest : public testing::Test {
81 protected: 80 protected:
82 DtlsIdentityStoreTest() 81 DtlsIdentityStoreTest()
83 : worker_thread_(new rtc::Thread()), 82 : worker_thread_(new rtc::Thread()),
84 store_(new DtlsIdentityStore(rtc::Thread::Current(), 83 store_(new DtlsIdentityStoreImpl(rtc::Thread::Current(),
85 worker_thread_.get())), 84 worker_thread_.get())),
86 observer_( 85 observer_(
87 new rtc::RefCountedObject<MockDtlsIdentityRequestObserver>()) { 86 new rtc::RefCountedObject<MockDtlsIdentityRequestObserver>()) {
88 CHECK(worker_thread_->Start()); 87 CHECK(worker_thread_->Start());
89 store_->Initialize(); 88 store_->Initialize();
90 } 89 }
91 ~DtlsIdentityStoreTest() {} 90 ~DtlsIdentityStoreTest() {}
92 91
93 static void SetUpTestCase() { 92 static void SetUpTestCase() {
94 rtc::InitializeSSL(); 93 rtc::InitializeSSL();
95 } 94 }
96 static void TearDownTestCase() { 95 static void TearDownTestCase() {
97 rtc::CleanupSSL(); 96 rtc::CleanupSSL();
98 } 97 }
99 98
100 rtc::scoped_ptr<rtc::Thread> worker_thread_; 99 rtc::scoped_ptr<rtc::Thread> worker_thread_;
101 rtc::scoped_ptr<DtlsIdentityStore> store_; 100 rtc::scoped_ptr<DtlsIdentityStoreImpl> store_;
102 rtc::scoped_refptr<MockDtlsIdentityRequestObserver> observer_; 101 rtc::scoped_refptr<MockDtlsIdentityRequestObserver> observer_;
103 }; 102 };
104 103
105 TEST_F(DtlsIdentityStoreTest, RequestIdentitySuccess) { 104 TEST_F(DtlsIdentityStoreTest, RequestIdentitySuccessRSA) {
106 EXPECT_TRUE_WAIT(store_->HasFreeIdentityForTesting(), kTimeoutMs); 105 EXPECT_TRUE_WAIT(store_->HasFreeIdentityForTesting(rtc::KT_RSA), kTimeoutMs);
107 106
108 store_->RequestIdentity(observer_.get()); 107 store_->RequestIdentity(rtc::KT_RSA, observer_.get());
109 EXPECT_TRUE_WAIT(observer_->LastRequestSucceeded(), kTimeoutMs); 108 EXPECT_TRUE_WAIT(observer_->LastRequestSucceeded(), kTimeoutMs);
110 109
111 EXPECT_TRUE_WAIT(store_->HasFreeIdentityForTesting(), kTimeoutMs); 110 EXPECT_TRUE_WAIT(store_->HasFreeIdentityForTesting(rtc::KT_RSA), kTimeoutMs);
112 111
113 observer_->Reset(); 112 observer_->Reset();
114 113
115 // Verifies that the callback is async when a free identity is ready. 114 // Verifies that the callback is async when a free identity is ready.
116 store_->RequestIdentity(observer_.get()); 115 store_->RequestIdentity(rtc::KT_RSA, observer_.get());
117 EXPECT_FALSE(observer_->call_back_called()); 116 EXPECT_FALSE(observer_->call_back_called());
118 EXPECT_TRUE_WAIT(observer_->LastRequestSucceeded(), kTimeoutMs); 117 EXPECT_TRUE_WAIT(observer_->LastRequestSucceeded(), kTimeoutMs);
119 } 118 }
120 119
121 TEST_F(DtlsIdentityStoreTest, DeleteStoreEarlyNoCrash) { 120 TEST_F(DtlsIdentityStoreTest, RequestIdentitySuccessECDSA) {
122 EXPECT_FALSE(store_->HasFreeIdentityForTesting()); 121 // Since store currently does not preemptively generate free ECDSA identities
122 // we do not invoke HasFreeIdentityForTesting between requests.
123 123
124 store_->RequestIdentity(observer_.get()); 124 store_->RequestIdentity(rtc::KT_ECDSA, observer_.get());
125 EXPECT_TRUE_WAIT(observer_->LastRequestSucceeded(), kTimeoutMs);
126
127 observer_->Reset();
128
129 // Verifies that the callback is async when a free identity is ready.
130 store_->RequestIdentity(rtc::KT_ECDSA, observer_.get());
131 EXPECT_FALSE(observer_->call_back_called());
132 EXPECT_TRUE_WAIT(observer_->LastRequestSucceeded(), kTimeoutMs);
133 }
134
135 TEST_F(DtlsIdentityStoreTest, DeleteStoreEarlyNoCrashRSA) {
136 EXPECT_FALSE(store_->HasFreeIdentityForTesting(rtc::KT_RSA));
137
138 store_->RequestIdentity(rtc::KT_RSA, observer_.get());
125 store_.reset(); 139 store_.reset();
126 140
127 worker_thread_->Stop(); 141 worker_thread_->Stop();
142 EXPECT_FALSE(observer_->call_back_called());
143 }
144
145 TEST_F(DtlsIdentityStoreTest, DeleteStoreEarlyNoCrashECDSA) {
146 EXPECT_FALSE(store_->HasFreeIdentityForTesting(rtc::KT_ECDSA));
147
148 store_->RequestIdentity(rtc::KT_ECDSA, observer_.get());
149 store_.reset();
150
151 worker_thread_->Stop();
128 EXPECT_FALSE(observer_->call_back_called()); 152 EXPECT_FALSE(observer_->call_back_called());
129 } 153 }
130 154
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698