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

Unified Diff: webrtc/base/rtccertificate_unittest.cc

Issue 1898383003: RTCCertificate serialization. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase with master (std::unique_ptr) Created 4 years, 8 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/base/rtccertificate.cc ('k') | webrtc/base/rtccertificate_unittests.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/rtccertificate_unittest.cc
diff --git a/webrtc/base/rtccertificate_unittests.cc b/webrtc/base/rtccertificate_unittest.cc
similarity index 82%
rename from webrtc/base/rtccertificate_unittests.cc
rename to webrtc/base/rtccertificate_unittest.cc
index 7795fe7a18faf6383415d368e912d6f39a81a1c3..f5df7f1130be8c143ccb2915177c4e5107e94aff 100644
--- a/webrtc/base/rtccertificate_unittests.cc
+++ b/webrtc/base/rtccertificate_unittest.cc
@@ -35,6 +35,13 @@ class RTCCertificateTest : public testing::Test {
~RTCCertificateTest() {}
protected:
+ scoped_refptr<RTCCertificate> GenerateECDSA() {
+ std::unique_ptr<SSLIdentity> identity(
+ SSLIdentity::Generate(kTestCertCommonName, KeyParams::ECDSA()));
+ RTC_CHECK(identity);
+ return RTCCertificate::Create(std::move(identity));
+ }
+
// Timestamp note:
// All timestamps in this unittest are expressed in number of seconds since
// epoch, 1970-01-01T00:00:00Z (UTC). The RTCCertificate interface uses ms,
@@ -85,10 +92,7 @@ class RTCCertificateTest : public testing::Test {
TEST_F(RTCCertificateTest, NewCertificateNotExpired) {
// Generate a real certificate without specifying the expiration time.
// Certificate type doesn't matter, using ECDSA because it's fast to generate.
- std::unique_ptr<SSLIdentity> identity(
- SSLIdentity::Generate(kTestCertCommonName, KeyParams::ECDSA()));
- scoped_refptr<RTCCertificate> certificate =
- RTCCertificate::Create(std::move(identity));
+ scoped_refptr<RTCCertificate> certificate = GenerateECDSA();
uint64_t now = NowSeconds();
EXPECT_FALSE(HasExpiredSeconds(certificate, now));
@@ -115,4 +119,22 @@ TEST_F(RTCCertificateTest, ExpiresInOneSecond) {
EXPECT_TRUE(HasExpiredSeconds(certificate, now + 2));
}
+TEST_F(RTCCertificateTest, DifferentCertificatesNotEqual) {
+ scoped_refptr<RTCCertificate> a = GenerateECDSA();
+ scoped_refptr<RTCCertificate> b = GenerateECDSA();
+ EXPECT_TRUE(*a != *b);
+}
+
+TEST_F(RTCCertificateTest, CloneWithPEMSerialization) {
+ scoped_refptr<RTCCertificate> orig = GenerateECDSA();
+
+ // To PEM.
+ RTCCertificatePEM orig_pem = orig->ToPEM();
+ // Clone from PEM.
+ scoped_refptr<RTCCertificate> clone = RTCCertificate::FromPEM(orig_pem);
+ EXPECT_TRUE(clone);
+ EXPECT_TRUE(*orig == *clone);
+ EXPECT_EQ(orig->Expires(), clone->Expires());
+}
+
} // namespace rtc
« no previous file with comments | « webrtc/base/rtccertificate.cc ('k') | webrtc/base/rtccertificate_unittests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698