• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright 2018 The WebRTC project authors. All Rights Reserved.
3  *
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
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 package org.webrtc;
12 
13 import static com.google.common.truth.Truth.assertThat;
14 
15 import androidx.test.filters.SmallTest;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.webrtc.PeerConnection;
19 import org.webrtc.RtcCertificatePem;
20 
21 /** Tests for RtcCertificatePem.java. */
22 public class RtcCertificatePemTest {
23   @Before
setUp()24   public void setUp() {
25     System.loadLibrary(TestConstants.NATIVE_LIBRARY);
26   }
27 
28   @Test
29   @SmallTest
testConstructor()30   public void testConstructor() {
31     RtcCertificatePem original = RtcCertificatePem.generateCertificate();
32     RtcCertificatePem recreated = new RtcCertificatePem(original.privateKey, original.certificate);
33     assertThat(original.privateKey).isEqualTo(recreated.privateKey);
34     assertThat(original.certificate).isEqualTo(recreated.certificate);
35   }
36 
37   @Test
38   @SmallTest
testGenerateCertificateDefaults()39   public void testGenerateCertificateDefaults() {
40     RtcCertificatePem rtcCertificate = RtcCertificatePem.generateCertificate();
41     assertThat(rtcCertificate.privateKey).isNotEmpty();
42     assertThat(rtcCertificate.certificate).isNotEmpty();
43   }
44 
45   @Test
46   @SmallTest
testGenerateCertificateCustomKeyTypeDefaultExpires()47   public void testGenerateCertificateCustomKeyTypeDefaultExpires() {
48     RtcCertificatePem rtcCertificate =
49         RtcCertificatePem.generateCertificate(PeerConnection.KeyType.RSA);
50     assertThat(rtcCertificate.privateKey).isNotEmpty();
51     assertThat(rtcCertificate.certificate).isNotEmpty();
52   }
53 
54   @Test
55   @SmallTest
testGenerateCertificateCustomExpiresDefaultKeyType()56   public void testGenerateCertificateCustomExpiresDefaultKeyType() {
57     RtcCertificatePem rtcCertificate = RtcCertificatePem.generateCertificate(60 * 60 * 24);
58     assertThat(rtcCertificate.privateKey).isNotEmpty();
59     assertThat(rtcCertificate.certificate).isNotEmpty();
60   }
61 
62   @Test
63   @SmallTest
testGenerateCertificateCustomKeyTypeAndExpires()64   public void testGenerateCertificateCustomKeyTypeAndExpires() {
65     RtcCertificatePem rtcCertificate =
66         RtcCertificatePem.generateCertificate(PeerConnection.KeyType.RSA, 60 * 60 * 24);
67     assertThat(rtcCertificate.privateKey).isNotEmpty();
68     assertThat(rtcCertificate.certificate).isNotEmpty();
69   }
70 }
71