| 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 <utility> |
| 12 |
| 11 #include "webrtc/base/checks.h" | 13 #include "webrtc/base/checks.h" |
| 12 #include "webrtc/base/fakesslidentity.h" | 14 #include "webrtc/base/fakesslidentity.h" |
| 13 #include "webrtc/base/gunit.h" | 15 #include "webrtc/base/gunit.h" |
| 14 #include "webrtc/base/logging.h" | 16 #include "webrtc/base/logging.h" |
| 15 #include "webrtc/base/rtccertificate.h" | 17 #include "webrtc/base/rtccertificate.h" |
| 16 #include "webrtc/base/safe_conversions.h" | 18 #include "webrtc/base/safe_conversions.h" |
| 17 #include "webrtc/base/scoped_ptr.h" | 19 #include "webrtc/base/scoped_ptr.h" |
| 18 #include "webrtc/base/sslidentity.h" | 20 #include "webrtc/base/sslidentity.h" |
| 19 #include "webrtc/base/thread.h" | 21 #include "webrtc/base/thread.h" |
| 20 #include "webrtc/base/timeutils.h" | 22 #include "webrtc/base/timeutils.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 | 71 |
| 70 SSLIdentityParams params; | 72 SSLIdentityParams params; |
| 71 params.common_name = kTestCertCommonName; | 73 params.common_name = kTestCertCommonName; |
| 72 params.not_before = 0; | 74 params.not_before = 0; |
| 73 params.not_after = static_cast<time_t>(expires_s); | 75 params.not_after = static_cast<time_t>(expires_s); |
| 74 // 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 |
| 75 // is fast to generate. | 77 // is fast to generate. |
| 76 params.key_params = KeyParams::ECDSA(); | 78 params.key_params = KeyParams::ECDSA(); |
| 77 | 79 |
| 78 scoped_ptr<SSLIdentity> identity(SSLIdentity::GenerateForTest(params)); | 80 scoped_ptr<SSLIdentity> identity(SSLIdentity::GenerateForTest(params)); |
| 79 return RTCCertificate::Create(identity.Pass()); | 81 return RTCCertificate::Create(std::move(identity)); |
| 80 } | 82 } |
| 81 }; | 83 }; |
| 82 | 84 |
| 83 TEST_F(RTCCertificateTest, NewCertificateNotExpired) { | 85 TEST_F(RTCCertificateTest, NewCertificateNotExpired) { |
| 84 // Generate a real certificate without specifying the expiration time. | 86 // Generate a real certificate without specifying the expiration time. |
| 85 // 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. |
| 86 scoped_ptr<SSLIdentity> identity( | 88 scoped_ptr<SSLIdentity> identity( |
| 87 SSLIdentity::Generate(kTestCertCommonName, KeyParams::ECDSA())); | 89 SSLIdentity::Generate(kTestCertCommonName, KeyParams::ECDSA())); |
| 88 scoped_refptr<RTCCertificate> certificate = | 90 scoped_refptr<RTCCertificate> certificate = |
| 89 RTCCertificate::Create(identity.Pass()); | 91 RTCCertificate::Create(std::move(identity)); |
| 90 | 92 |
| 91 uint64_t now = NowSeconds(); | 93 uint64_t now = NowSeconds(); |
| 92 EXPECT_FALSE(HasExpiredSeconds(certificate, now)); | 94 EXPECT_FALSE(HasExpiredSeconds(certificate, now)); |
| 93 // 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 |
| 94 // for at least half an hour. | 96 // for at least half an hour. |
| 95 EXPECT_FALSE(HasExpiredSeconds(certificate, now + 30*60)); | 97 EXPECT_FALSE(HasExpiredSeconds(certificate, now + 30*60)); |
| 96 } | 98 } |
| 97 | 99 |
| 98 TEST_F(RTCCertificateTest, UsesExpiresAskedFor) { | 100 TEST_F(RTCCertificateTest, UsesExpiresAskedFor) { |
| 99 uint64_t now = NowSeconds(); | 101 uint64_t now = NowSeconds(); |
| 100 scoped_refptr<RTCCertificate> certificate = | 102 scoped_refptr<RTCCertificate> certificate = |
| 101 GenerateCertificateWithExpires(now); | 103 GenerateCertificateWithExpires(now); |
| 102 EXPECT_EQ(now, ExpiresSeconds(certificate)); | 104 EXPECT_EQ(now, ExpiresSeconds(certificate)); |
| 103 } | 105 } |
| 104 | 106 |
| 105 TEST_F(RTCCertificateTest, ExpiresInOneSecond) { | 107 TEST_F(RTCCertificateTest, ExpiresInOneSecond) { |
| 106 // Generate a certificate that expires in 1s. | 108 // Generate a certificate that expires in 1s. |
| 107 uint64_t now = NowSeconds(); | 109 uint64_t now = NowSeconds(); |
| 108 scoped_refptr<RTCCertificate> certificate = | 110 scoped_refptr<RTCCertificate> certificate = |
| 109 GenerateCertificateWithExpires(now + 1); | 111 GenerateCertificateWithExpires(now + 1); |
| 110 // Now it should not have expired. | 112 // Now it should not have expired. |
| 111 EXPECT_FALSE(HasExpiredSeconds(certificate, now)); | 113 EXPECT_FALSE(HasExpiredSeconds(certificate, now)); |
| 112 // In 2s it should have expired. | 114 // In 2s it should have expired. |
| 113 EXPECT_TRUE(HasExpiredSeconds(certificate, now + 2)); | 115 EXPECT_TRUE(HasExpiredSeconds(certificate, now + 2)); |
| 114 } | 116 } |
| 115 | 117 |
| 116 } // namespace rtc | 118 } // namespace rtc |
| OLD | NEW |