OLD | NEW |
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 Loading... |
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) { |
(...skipping 22 matching lines...) Expand all Loading... |
74 | 74 |
75 private: | 75 private: |
76 bool call_back_called_; | 76 bool call_back_called_; |
77 bool last_request_success_; | 77 bool last_request_success_; |
78 }; | 78 }; |
79 | 79 |
80 class DtlsIdentityStoreTest : public testing::Test { | 80 class DtlsIdentityStoreTest : public testing::Test { |
81 protected: | 81 protected: |
82 DtlsIdentityStoreTest() | 82 DtlsIdentityStoreTest() |
83 : worker_thread_(new rtc::Thread()), | 83 : worker_thread_(new rtc::Thread()), |
84 store_(new DtlsIdentityStore(rtc::Thread::Current(), | 84 store_(new DtlsIdentityStoreImpl(rtc::Thread::Current(), |
85 worker_thread_.get())), | 85 worker_thread_.get())), |
86 observer_( | 86 observer_( |
87 new rtc::RefCountedObject<MockDtlsIdentityRequestObserver>()) { | 87 new rtc::RefCountedObject<MockDtlsIdentityRequestObserver>()) { |
88 CHECK(worker_thread_->Start()); | 88 CHECK(worker_thread_->Start()); |
89 store_->Initialize(); | 89 store_->Initialize(); |
90 } | 90 } |
91 ~DtlsIdentityStoreTest() {} | 91 ~DtlsIdentityStoreTest() {} |
92 | 92 |
93 static void SetUpTestCase() { | 93 static void SetUpTestCase() { |
94 rtc::InitializeSSL(); | 94 rtc::InitializeSSL(); |
95 } | 95 } |
96 static void TearDownTestCase() { | 96 static void TearDownTestCase() { |
97 rtc::CleanupSSL(); | 97 rtc::CleanupSSL(); |
98 } | 98 } |
99 | 99 |
100 rtc::scoped_ptr<rtc::Thread> worker_thread_; | 100 rtc::scoped_ptr<rtc::Thread> worker_thread_; |
101 rtc::scoped_ptr<DtlsIdentityStore> store_; | 101 rtc::scoped_ptr<DtlsIdentityStoreImpl> store_; |
102 rtc::scoped_refptr<MockDtlsIdentityRequestObserver> observer_; | 102 rtc::scoped_refptr<MockDtlsIdentityRequestObserver> observer_; |
103 }; | 103 }; |
104 | 104 |
105 TEST_F(DtlsIdentityStoreTest, RequestIdentitySuccess) { | 105 TEST_F(DtlsIdentityStoreTest, RequestIdentitySuccessRSA) { |
106 EXPECT_TRUE_WAIT(store_->HasFreeIdentityForTesting(), kTimeoutMs); | 106 EXPECT_TRUE_WAIT(store_->HasFreeIdentityForTesting(), kTimeoutMs); |
107 | 107 |
108 store_->RequestIdentity(observer_.get()); | 108 store_->RequestIdentity(rtc::KT_RSA, observer_.get()); |
109 EXPECT_TRUE_WAIT(observer_->LastRequestSucceeded(), kTimeoutMs); | 109 EXPECT_TRUE_WAIT(observer_->LastRequestSucceeded(), kTimeoutMs); |
110 | 110 |
111 EXPECT_TRUE_WAIT(store_->HasFreeIdentityForTesting(), kTimeoutMs); | 111 EXPECT_TRUE_WAIT(store_->HasFreeIdentityForTesting(), kTimeoutMs); |
112 | 112 |
113 observer_->Reset(); | 113 observer_->Reset(); |
114 | 114 |
115 // Verifies that the callback is async when a free identity is ready. | 115 // Verifies that the callback is async when a free identity is ready. |
116 store_->RequestIdentity(observer_.get()); | 116 store_->RequestIdentity(rtc::KT_RSA, observer_.get()); |
117 EXPECT_FALSE(observer_->call_back_called()); | 117 EXPECT_FALSE(observer_->call_back_called()); |
118 EXPECT_TRUE_WAIT(observer_->LastRequestSucceeded(), kTimeoutMs); | 118 EXPECT_TRUE_WAIT(observer_->LastRequestSucceeded(), kTimeoutMs); |
119 } | 119 } |
120 | 120 |
121 TEST_F(DtlsIdentityStoreTest, DeleteStoreEarlyNoCrash) { | 121 TEST_F(DtlsIdentityStoreTest, RequestIdentitySuccessECDSA) { |
| 122 EXPECT_TRUE_WAIT(store_->HasFreeIdentityForTesting(), kTimeoutMs); |
| 123 |
| 124 store_->RequestIdentity(rtc::KT_ECDSA, observer_.get()); |
| 125 EXPECT_TRUE_WAIT(observer_->LastRequestSucceeded(), kTimeoutMs); |
| 126 |
| 127 EXPECT_TRUE_WAIT(store_->HasFreeIdentityForTesting(), kTimeoutMs); |
| 128 |
| 129 observer_->Reset(); |
| 130 |
| 131 // Verifies that the callback is async when a free identity is ready. |
| 132 store_->RequestIdentity(rtc::KT_RSA, observer_.get()); |
| 133 EXPECT_FALSE(observer_->call_back_called()); |
| 134 EXPECT_TRUE_WAIT(observer_->LastRequestSucceeded(), kTimeoutMs); |
| 135 } |
| 136 |
| 137 TEST_F(DtlsIdentityStoreTest, DeleteStoreEarlyNoCrashRSA) { |
122 EXPECT_FALSE(store_->HasFreeIdentityForTesting()); | 138 EXPECT_FALSE(store_->HasFreeIdentityForTesting()); |
123 | 139 |
124 store_->RequestIdentity(observer_.get()); | 140 store_->RequestIdentity(rtc::KT_RSA, observer_.get()); |
125 store_.reset(); | 141 store_.reset(); |
126 | 142 |
127 worker_thread_->Stop(); | 143 worker_thread_->Stop(); |
| 144 EXPECT_FALSE(observer_->call_back_called()); |
| 145 } |
| 146 |
| 147 TEST_F(DtlsIdentityStoreTest, DeleteStoreEarlyNoCrashECDSA) { |
| 148 EXPECT_FALSE(store_->HasFreeIdentityForTesting()); |
| 149 |
| 150 store_->RequestIdentity(rtc::KT_ECDSA, observer_.get()); |
| 151 store_.reset(); |
| 152 |
| 153 worker_thread_->Stop(); |
128 EXPECT_FALSE(observer_->call_back_called()); | 154 EXPECT_FALSE(observer_->call_back_called()); |
129 } | 155 } |
130 | 156 |
OLD | NEW |