OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2015 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 <memory> |
11 #include <utility> | 12 #include <utility> |
12 | 13 |
13 #include "webrtc/base/checks.h" | 14 #include "webrtc/base/checks.h" |
14 #include "webrtc/base/fakesslidentity.h" | 15 #include "webrtc/base/fakesslidentity.h" |
15 #include "webrtc/base/gunit.h" | 16 #include "webrtc/base/gunit.h" |
16 #include "webrtc/base/logging.h" | 17 #include "webrtc/base/logging.h" |
17 #include "webrtc/base/rtccertificate.h" | 18 #include "webrtc/base/rtccertificate.h" |
18 #include "webrtc/base/safe_conversions.h" | 19 #include "webrtc/base/safe_conversions.h" |
19 #include "webrtc/base/scoped_ptr.h" | |
20 #include "webrtc/base/sslidentity.h" | 20 #include "webrtc/base/sslidentity.h" |
21 #include "webrtc/base/thread.h" | 21 #include "webrtc/base/thread.h" |
22 #include "webrtc/base/timeutils.h" | 22 #include "webrtc/base/timeutils.h" |
23 | 23 |
24 namespace rtc { | 24 namespace rtc { |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 static const char* kTestCertCommonName = "RTCCertificateTest's certificate"; | 28 static const char* kTestCertCommonName = "RTCCertificateTest's certificate"; |
29 | 29 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 RTC_CHECK(IsValueInRangeForNumericType<time_t>(expires_s)); | 70 RTC_CHECK(IsValueInRangeForNumericType<time_t>(expires_s)); |
71 | 71 |
72 SSLIdentityParams params; | 72 SSLIdentityParams params; |
73 params.common_name = kTestCertCommonName; | 73 params.common_name = kTestCertCommonName; |
74 params.not_before = 0; | 74 params.not_before = 0; |
75 params.not_after = static_cast<time_t>(expires_s); | 75 params.not_after = static_cast<time_t>(expires_s); |
76 // Certificate type does not matter for our purposes, using ECDSA because it | 76 // Certificate type does not matter for our purposes, using ECDSA because it |
77 // is fast to generate. | 77 // is fast to generate. |
78 params.key_params = KeyParams::ECDSA(); | 78 params.key_params = KeyParams::ECDSA(); |
79 | 79 |
80 scoped_ptr<SSLIdentity> identity(SSLIdentity::GenerateForTest(params)); | 80 std::unique_ptr<SSLIdentity> identity(SSLIdentity::GenerateForTest(params)); |
81 return RTCCertificate::Create(std::move(identity)); | 81 return RTCCertificate::Create(std::move(identity)); |
82 } | 82 } |
83 }; | 83 }; |
84 | 84 |
85 TEST_F(RTCCertificateTest, NewCertificateNotExpired) { | 85 TEST_F(RTCCertificateTest, NewCertificateNotExpired) { |
86 // Generate a real certificate without specifying the expiration time. | 86 // Generate a real certificate without specifying the expiration time. |
87 // Certificate type doesn't matter, using ECDSA because it's fast to generate. | 87 // Certificate type doesn't matter, using ECDSA because it's fast to generate. |
88 scoped_ptr<SSLIdentity> identity( | 88 std::unique_ptr<SSLIdentity> identity( |
89 SSLIdentity::Generate(kTestCertCommonName, KeyParams::ECDSA())); | 89 SSLIdentity::Generate(kTestCertCommonName, KeyParams::ECDSA())); |
90 scoped_refptr<RTCCertificate> certificate = | 90 scoped_refptr<RTCCertificate> certificate = |
91 RTCCertificate::Create(std::move(identity)); | 91 RTCCertificate::Create(std::move(identity)); |
92 | 92 |
93 uint64_t now = NowSeconds(); | 93 uint64_t now = NowSeconds(); |
94 EXPECT_FALSE(HasExpiredSeconds(certificate, now)); | 94 EXPECT_FALSE(HasExpiredSeconds(certificate, now)); |
95 // Even without specifying the expiration time we would expect it to be valid | 95 // Even without specifying the expiration time we would expect it to be valid |
96 // for at least half an hour. | 96 // for at least half an hour. |
97 EXPECT_FALSE(HasExpiredSeconds(certificate, now + 30*60)); | 97 EXPECT_FALSE(HasExpiredSeconds(certificate, now + 30*60)); |
98 } | 98 } |
(...skipping 10 matching lines...) Expand all Loading... |
109 uint64_t now = NowSeconds(); | 109 uint64_t now = NowSeconds(); |
110 scoped_refptr<RTCCertificate> certificate = | 110 scoped_refptr<RTCCertificate> certificate = |
111 GenerateCertificateWithExpires(now + 1); | 111 GenerateCertificateWithExpires(now + 1); |
112 // Now it should not have expired. | 112 // Now it should not have expired. |
113 EXPECT_FALSE(HasExpiredSeconds(certificate, now)); | 113 EXPECT_FALSE(HasExpiredSeconds(certificate, now)); |
114 // In 2s it should have expired. | 114 // In 2s it should have expired. |
115 EXPECT_TRUE(HasExpiredSeconds(certificate, now + 2)); | 115 EXPECT_TRUE(HasExpiredSeconds(certificate, now + 2)); |
116 } | 116 } |
117 | 117 |
118 } // namespace rtc | 118 } // namespace rtc |
OLD | NEW |