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

Side by Side Diff: webrtc/base/sslidentity_unittest.cc

Issue 1468273004: Provide method for returning certificate expiration timestamp. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Misc CL cleanups Created 5 years 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 * Copyright 2011 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2011 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <string> 11 #include <string>
12 12
13 #include "webrtc/base/gunit.h" 13 #include "webrtc/base/gunit.h"
14 #include "webrtc/base/helpers.h"
14 #include "webrtc/base/ssladapter.h" 15 #include "webrtc/base/ssladapter.h"
15 #include "webrtc/base/sslidentity.h" 16 #include "webrtc/base/sslidentity.h"
16 17
17 using rtc::SSLIdentity; 18 using rtc::SSLIdentity;
18 19
19 const char kTestCertificate[] = "-----BEGIN CERTIFICATE-----\n" 20 const char kTestCertificate[] = "-----BEGIN CERTIFICATE-----\n"
20 "MIIB6TCCAVICAQYwDQYJKoZIhvcNAQEEBQAwWzELMAkGA1UEBhMCQVUxEzARBgNV\n" 21 "MIIB6TCCAVICAQYwDQYJKoZIhvcNAQEEBQAwWzELMAkGA1UEBhMCQVUxEzARBgNV\n"
21 "BAgTClF1ZWVuc2xhbmQxGjAYBgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMRswGQYD\n" 22 "BAgTClF1ZWVuc2xhbmQxGjAYBgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMRswGQYD\n"
22 "VQQDExJUZXN0IENBICgxMDI0IGJpdCkwHhcNMDAxMDE2MjIzMTAzWhcNMDMwMTE0\n" 23 "VQQDExJUZXN0IENBICgxMDI0IGJpdCkwHhcNMDAxMDE2MjIzMTAzWhcNMDMwMTE0\n"
23 "MjIzMTAzWjBjMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDEaMBgG\n" 24 "MjIzMTAzWjBjMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDEaMBgG\n"
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 EXPECT_TRUE(SSLIdentity::PemToDer("CERTIFICATE", kTestCertificate, &der)); 289 EXPECT_TRUE(SSLIdentity::PemToDer("CERTIFICATE", kTestCertificate, &der));
289 290
290 EXPECT_EQ(kTestCertificate, SSLIdentity::DerToPem( 291 EXPECT_EQ(kTestCertificate, SSLIdentity::DerToPem(
291 "CERTIFICATE", 292 "CERTIFICATE",
292 reinterpret_cast<const unsigned char*>(der.data()), der.length())); 293 reinterpret_cast<const unsigned char*>(der.data()), der.length()));
293 } 294 }
294 295
295 TEST_F(SSLIdentityTest, GetSignatureDigestAlgorithm) { 296 TEST_F(SSLIdentityTest, GetSignatureDigestAlgorithm) {
296 TestGetSignatureDigestAlgorithm(); 297 TestGetSignatureDigestAlgorithm();
297 } 298 }
299
300 class SSLIdentityExpirationTest : public testing::Test {
301 public:
302 SSLIdentityExpirationTest() {}
303 ~SSLIdentityExpirationTest() {}
304
305 void TestExpireTime(int times) {
306 for (int i = 0; i < times; i++) {
307 rtc::SSLIdentityParams params;
308 params.common_name = "";
309 params.not_before = 0;
310 params.not_after = rtc::CreateRandomId() % 0x80000000;
hbos 2015/11/25 15:21:45 Add a comment explaining the %
torbjorng (webrtc) 2015/11/25 19:14:09 Done.
311 params.key_params = rtc::KeyParams(rtc::KT_ECDSA);
312 SSLIdentity* identity = rtc::SSLIdentity::GenerateForTest(params);
313 EXPECT_EQ((int64_t)1000 * params.not_after,
314 identity->certificate().CertificateExpirationTime());
315 delete identity;
316 }
317 }
318 };
319
320 TEST_F(SSLIdentityExpirationTest, Test) {
321 rtc::SetRandomTestMode(true);
322 TestExpireTime(100);
323 rtc::SetRandomTestMode(false);
324 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698