Index: webrtc/base/sslidentity_unittest.cc |
diff --git a/webrtc/base/sslidentity_unittest.cc b/webrtc/base/sslidentity_unittest.cc |
index e8df41506ba90383e9ca89969e75b5b20fe38eeb..e12d85faa29fe425a6d37d3705fc6a1351c90766 100644 |
--- a/webrtc/base/sslidentity_unittest.cc |
+++ b/webrtc/base/sslidentity_unittest.cc |
@@ -11,6 +11,7 @@ |
#include <string> |
#include "webrtc/base/gunit.h" |
+#include "webrtc/base/helpers.h" |
#include "webrtc/base/ssladapter.h" |
#include "webrtc/base/sslidentity.h" |
@@ -295,3 +296,37 @@ TEST_F(SSLIdentityTest, PemDerConversion) { |
TEST_F(SSLIdentityTest, GetSignatureDigestAlgorithm) { |
TestGetSignatureDigestAlgorithm(); |
} |
+ |
+class SSLIdentityExpirationTest : public testing::Test { |
+ public: |
+ SSLIdentityExpirationTest() { |
+ // Set use of the test RNG to get deterministic expiration timestamp. |
+ rtc::SetRandomTestMode(true); |
+ } |
+ ~SSLIdentityExpirationTest() { |
+ // Put it back for the next test. |
+ rtc::SetRandomTestMode(false); |
+ } |
+ |
+ void TestExpireTime(int times) { |
+ for (int i = 0; i < times; i++) { |
+ rtc::SSLIdentityParams params; |
+ params.common_name = ""; |
+ params.not_before = 0; |
+ // We limit the time to < 2^31 here, i.e., we stay before 2038, since else |
+ // we hit time offset limitations in OpenSSL on some 32-bit systems. |
+ params.not_after = rtc::CreateRandomId() % 0x80000000; |
+ // We test just ECDSA here since what we're out to exercise here is the |
+ // code for expiration setting and reading. |
+ params.key_params = rtc::KeyParams::ECDSA(rtc::EC_NIST_P256); |
+ SSLIdentity* identity = rtc::SSLIdentity::GenerateForTest(params); |
+ EXPECT_EQ(params.not_after, |
+ identity->certificate().CertificateExpirationTime()); |
+ delete identity; |
+ } |
+ } |
+}; |
nisse-webrtc
2015/11/27 12:47:12
I'd like to also see unit tests for TmToSeconds an
torbjorng (webrtc)
2015/11/30 15:23:31
Done.
|
+ |
+TEST_F(SSLIdentityExpirationTest, Test) { |
+ TestExpireTime(500); |
+} |