blob: 772653c4dc5a2122956975efd695c9131101b285 [file] [log] [blame]
hjonaa32c3e2015-12-13 19:58:11 -08001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
hjonaa32c3e2015-12-13 19:58:11 -08003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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.
hjonaa32c3e2015-12-13 19:58:11 -08009 */
10
11#import <Foundation/Foundation.h>
Byoungchan Leec8a6fb22022-05-13 19:59:49 +090012#import <XCTest/XCTest.h>
hjonaa32c3e2015-12-13 19:58:11 -080013
14#include <vector>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "rtc_base/gunit.h"
hjonaa32c3e2015-12-13 19:58:11 -080017
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020018#import "api/peerconnection/RTCIceServer+Private.h"
19#import "api/peerconnection/RTCIceServer.h"
20#import "helpers/NSString+StdString.h"
hjonaa32c3e2015-12-13 19:58:11 -080021
Byoungchan Leec8a6fb22022-05-13 19:59:49 +090022@interface RTCIceServerTest : XCTestCase
hjonaa32c3e2015-12-13 19:58:11 -080023@end
24
25@implementation RTCIceServerTest
26
27- (void)testOneURLServer {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020028 RTC_OBJC_TYPE(RTCIceServer) *server =
29 [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithURLStrings:@[ @"stun:stun1.example.net" ]];
hjonaa32c3e2015-12-13 19:58:11 -080030
hjona2f77982016-03-04 07:09:09 -080031 webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer;
hjon6d49a8e2016-01-26 13:06:42 -080032 EXPECT_EQ(1u, iceStruct.urls.size());
hjonaa32c3e2015-12-13 19:58:11 -080033 EXPECT_EQ("stun:stun1.example.net", iceStruct.urls.front());
34 EXPECT_EQ("", iceStruct.username);
35 EXPECT_EQ("", iceStruct.password);
36}
37
38- (void)testTwoURLServer {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020039 RTC_OBJC_TYPE(RTCIceServer) *server = [[RTC_OBJC_TYPE(RTCIceServer) alloc]
40 initWithURLStrings:@[ @"turn1:turn1.example.net", @"turn2:turn2.example.net" ]];
hjonaa32c3e2015-12-13 19:58:11 -080041
hjona2f77982016-03-04 07:09:09 -080042 webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer;
hjon6d49a8e2016-01-26 13:06:42 -080043 EXPECT_EQ(2u, iceStruct.urls.size());
hjonaa32c3e2015-12-13 19:58:11 -080044 EXPECT_EQ("turn1:turn1.example.net", iceStruct.urls.front());
45 EXPECT_EQ("turn2:turn2.example.net", iceStruct.urls.back());
46 EXPECT_EQ("", iceStruct.username);
47 EXPECT_EQ("", iceStruct.password);
48}
49
50- (void)testPasswordCredential {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020051 RTC_OBJC_TYPE(RTCIceServer) *server =
52 [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithURLStrings:@[ @"turn1:turn1.example.net" ]
53 username:@"username"
54 credential:@"credential"];
hjona2f77982016-03-04 07:09:09 -080055 webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer;
hjon6d49a8e2016-01-26 13:06:42 -080056 EXPECT_EQ(1u, iceStruct.urls.size());
hjonaa32c3e2015-12-13 19:58:11 -080057 EXPECT_EQ("turn1:turn1.example.net", iceStruct.urls.front());
58 EXPECT_EQ("username", iceStruct.username);
59 EXPECT_EQ("credential", iceStruct.password);
60}
61
Emad Omaradab1d2d2017-06-16 15:43:11 -070062- (void)testHostname {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020063 RTC_OBJC_TYPE(RTCIceServer) *server =
64 [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithURLStrings:@[ @"turn1:turn1.example.net" ]
65 username:@"username"
66 credential:@"credential"
67 tlsCertPolicy:RTCTlsCertPolicySecure
68 hostname:@"hostname"];
Emad Omaradab1d2d2017-06-16 15:43:11 -070069 webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer;
70 EXPECT_EQ(1u, iceStruct.urls.size());
71 EXPECT_EQ("turn1:turn1.example.net", iceStruct.urls.front());
72 EXPECT_EQ("username", iceStruct.username);
73 EXPECT_EQ("credential", iceStruct.password);
74 EXPECT_EQ("hostname", iceStruct.hostname);
75}
76
Diogo Real1dca9d52017-08-29 12:18:32 -070077- (void)testTlsAlpnProtocols {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020078 RTC_OBJC_TYPE(RTCIceServer) *server =
79 [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithURLStrings:@[ @"turn1:turn1.example.net" ]
80 username:@"username"
81 credential:@"credential"
82 tlsCertPolicy:RTCTlsCertPolicySecure
83 hostname:@"hostname"
84 tlsAlpnProtocols:@[ @"proto1", @"proto2" ]];
Diogo Real1dca9d52017-08-29 12:18:32 -070085 webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer;
86 EXPECT_EQ(1u, iceStruct.urls.size());
87 EXPECT_EQ("turn1:turn1.example.net", iceStruct.urls.front());
88 EXPECT_EQ("username", iceStruct.username);
89 EXPECT_EQ("credential", iceStruct.password);
90 EXPECT_EQ("hostname", iceStruct.hostname);
Sergey Silkin9c147dd2018-09-12 10:45:38 +000091 EXPECT_EQ(2u, iceStruct.tls_alpn_protocols.size());
Diogo Real1dca9d52017-08-29 12:18:32 -070092}
93
Diogo Real7bd1f1b2017-09-08 12:50:41 -070094- (void)testTlsEllipticCurves {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020095 RTC_OBJC_TYPE(RTCIceServer) *server =
96 [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithURLStrings:@[ @"turn1:turn1.example.net" ]
97 username:@"username"
98 credential:@"credential"
99 tlsCertPolicy:RTCTlsCertPolicySecure
100 hostname:@"hostname"
101 tlsAlpnProtocols:@[ @"proto1", @"proto2" ]
102 tlsEllipticCurves:@[ @"curve1", @"curve2" ]];
Diogo Real7bd1f1b2017-09-08 12:50:41 -0700103 webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer;
104 EXPECT_EQ(1u, iceStruct.urls.size());
105 EXPECT_EQ("turn1:turn1.example.net", iceStruct.urls.front());
106 EXPECT_EQ("username", iceStruct.username);
107 EXPECT_EQ("credential", iceStruct.password);
108 EXPECT_EQ("hostname", iceStruct.hostname);
Sergey Silkin9c147dd2018-09-12 10:45:38 +0000109 EXPECT_EQ(2u, iceStruct.tls_alpn_protocols.size());
110 EXPECT_EQ(2u, iceStruct.tls_elliptic_curves.size());
Diogo Real7bd1f1b2017-09-08 12:50:41 -0700111}
112
hjon6d49a8e2016-01-26 13:06:42 -0800113- (void)testInitFromNativeServer {
114 webrtc::PeerConnectionInterface::IceServer nativeServer;
115 nativeServer.username = "username";
116 nativeServer.password = "password";
117 nativeServer.urls.push_back("stun:stun.example.net");
Emad Omaradab1d2d2017-06-16 15:43:11 -0700118 nativeServer.hostname = "hostname";
Diogo Real1dca9d52017-08-29 12:18:32 -0700119 nativeServer.tls_alpn_protocols.push_back("proto1");
120 nativeServer.tls_alpn_protocols.push_back("proto2");
Diogo Real7bd1f1b2017-09-08 12:50:41 -0700121 nativeServer.tls_elliptic_curves.push_back("curve1");
122 nativeServer.tls_elliptic_curves.push_back("curve2");
hjon6d49a8e2016-01-26 13:06:42 -0800123
Mirko Bonadeia81e9c82020-05-04 16:14:32 +0200124 RTC_OBJC_TYPE(RTCIceServer) *iceServer =
125 [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithNativeServer:nativeServer];
hjon6d49a8e2016-01-26 13:06:42 -0800126 EXPECT_EQ(1u, iceServer.urlStrings.count);
127 EXPECT_EQ("stun:stun.example.net",
128 [NSString stdStringForString:iceServer.urlStrings.firstObject]);
129 EXPECT_EQ("username", [NSString stdStringForString:iceServer.username]);
130 EXPECT_EQ("password", [NSString stdStringForString:iceServer.credential]);
Emad Omaradab1d2d2017-06-16 15:43:11 -0700131 EXPECT_EQ("hostname", [NSString stdStringForString:iceServer.hostname]);
Sergey Silkin9c147dd2018-09-12 10:45:38 +0000132 EXPECT_EQ(2u, iceServer.tlsAlpnProtocols.count);
133 EXPECT_EQ(2u, iceServer.tlsEllipticCurves.count);
hjon6d49a8e2016-01-26 13:06:42 -0800134}
135
hjonaa32c3e2015-12-13 19:58:11 -0800136@end