hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 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. |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #import <Foundation/Foundation.h> |
Byoungchan Lee | c8a6fb2 | 2022-05-13 19:59:49 +0900 | [diff] [blame] | 12 | #import <XCTest/XCTest.h> |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 13 | |
| 14 | #include <vector> |
| 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "rtc_base/gunit.h" |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 17 | |
Anders Carlsson | 7bca8ca | 2018-08-30 09:30:29 +0200 | [diff] [blame] | 18 | #import "api/peerconnection/RTCIceServer+Private.h" |
| 19 | #import "api/peerconnection/RTCIceServer.h" |
Artem Titov | 63ee39d | 2022-05-13 14:46:42 +0000 | [diff] [blame] | 20 | #import "helpers/NSString+StdString.h" |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 21 | |
Byoungchan Lee | c8a6fb2 | 2022-05-13 19:59:49 +0900 | [diff] [blame] | 22 | @interface RTCIceServerTest : XCTestCase |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 23 | @end |
| 24 | |
| 25 | @implementation RTCIceServerTest |
| 26 | |
| 27 | - (void)testOneURLServer { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 28 | RTC_OBJC_TYPE(RTCIceServer) *server = |
| 29 | [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithURLStrings:@[ @"stun:stun1.example.net" ]]; |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 30 | |
hjon | a2f7798 | 2016-03-04 07:09:09 -0800 | [diff] [blame] | 31 | webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 32 | EXPECT_EQ(1u, iceStruct.urls.size()); |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 33 | 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 Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 39 | RTC_OBJC_TYPE(RTCIceServer) *server = [[RTC_OBJC_TYPE(RTCIceServer) alloc] |
| 40 | initWithURLStrings:@[ @"turn1:turn1.example.net", @"turn2:turn2.example.net" ]]; |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 41 | |
hjon | a2f7798 | 2016-03-04 07:09:09 -0800 | [diff] [blame] | 42 | webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 43 | EXPECT_EQ(2u, iceStruct.urls.size()); |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 44 | 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 Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 51 | RTC_OBJC_TYPE(RTCIceServer) *server = |
| 52 | [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithURLStrings:@[ @"turn1:turn1.example.net" ] |
| 53 | username:@"username" |
| 54 | credential:@"credential"]; |
hjon | a2f7798 | 2016-03-04 07:09:09 -0800 | [diff] [blame] | 55 | webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 56 | EXPECT_EQ(1u, iceStruct.urls.size()); |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 57 | EXPECT_EQ("turn1:turn1.example.net", iceStruct.urls.front()); |
| 58 | EXPECT_EQ("username", iceStruct.username); |
| 59 | EXPECT_EQ("credential", iceStruct.password); |
| 60 | } |
| 61 | |
Emad Omara | dab1d2d | 2017-06-16 15:43:11 -0700 | [diff] [blame] | 62 | - (void)testHostname { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 63 | 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 Omara | dab1d2d | 2017-06-16 15:43:11 -0700 | [diff] [blame] | 69 | 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 Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 77 | - (void)testTlsAlpnProtocols { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 78 | 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 Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 85 | 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 Silkin | 9c147dd | 2018-09-12 10:45:38 +0000 | [diff] [blame] | 91 | EXPECT_EQ(2u, iceStruct.tls_alpn_protocols.size()); |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Diogo Real | 7bd1f1b | 2017-09-08 12:50:41 -0700 | [diff] [blame] | 94 | - (void)testTlsEllipticCurves { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 95 | 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 Real | 7bd1f1b | 2017-09-08 12:50:41 -0700 | [diff] [blame] | 103 | 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 Silkin | 9c147dd | 2018-09-12 10:45:38 +0000 | [diff] [blame] | 109 | EXPECT_EQ(2u, iceStruct.tls_alpn_protocols.size()); |
| 110 | EXPECT_EQ(2u, iceStruct.tls_elliptic_curves.size()); |
Diogo Real | 7bd1f1b | 2017-09-08 12:50:41 -0700 | [diff] [blame] | 111 | } |
| 112 | |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 113 | - (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 Omara | dab1d2d | 2017-06-16 15:43:11 -0700 | [diff] [blame] | 118 | nativeServer.hostname = "hostname"; |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 119 | nativeServer.tls_alpn_protocols.push_back("proto1"); |
| 120 | nativeServer.tls_alpn_protocols.push_back("proto2"); |
Diogo Real | 7bd1f1b | 2017-09-08 12:50:41 -0700 | [diff] [blame] | 121 | nativeServer.tls_elliptic_curves.push_back("curve1"); |
| 122 | nativeServer.tls_elliptic_curves.push_back("curve2"); |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 123 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 124 | RTC_OBJC_TYPE(RTCIceServer) *iceServer = |
| 125 | [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithNativeServer:nativeServer]; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 126 | EXPECT_EQ(1u, iceServer.urlStrings.count); |
| 127 | EXPECT_EQ("stun:stun.example.net", |
Artem Titov | 63ee39d | 2022-05-13 14:46:42 +0000 | [diff] [blame] | 128 | [NSString stdStringForString:iceServer.urlStrings.firstObject]); |
| 129 | EXPECT_EQ("username", [NSString stdStringForString:iceServer.username]); |
| 130 | EXPECT_EQ("password", [NSString stdStringForString:iceServer.credential]); |
| 131 | EXPECT_EQ("hostname", [NSString stdStringForString:iceServer.hostname]); |
Sergey Silkin | 9c147dd | 2018-09-12 10:45:38 +0000 | [diff] [blame] | 132 | EXPECT_EQ(2u, iceServer.tlsAlpnProtocols.count); |
| 133 | EXPECT_EQ(2u, iceServer.tlsEllipticCurves.count); |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 134 | } |
| 135 | |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 136 | @end |