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> |
| 12 | |
| 13 | #include <vector> |
| 14 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #include "rtc_base/gunit.h" |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 16 | |
Anders Carlsson | 7bca8ca | 2018-08-30 09:30:29 +0200 | [diff] [blame] | 17 | #import "api/peerconnection/RTCIceServer+Private.h" |
| 18 | #import "api/peerconnection/RTCIceServer.h" |
| 19 | #import "helpers/NSString+StdString.h" |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 20 | |
| 21 | @interface RTCIceServerTest : NSObject |
| 22 | - (void)testOneURLServer; |
| 23 | - (void)testTwoURLServer; |
| 24 | - (void)testPasswordCredential; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 25 | - (void)testInitFromNativeServer; |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 26 | @end |
| 27 | |
| 28 | @implementation RTCIceServerTest |
| 29 | |
| 30 | - (void)testOneURLServer { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 31 | RTC_OBJC_TYPE(RTCIceServer) *server = |
| 32 | [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithURLStrings:@[ @"stun:stun1.example.net" ]]; |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 33 | |
hjon | a2f7798 | 2016-03-04 07:09:09 -0800 | [diff] [blame] | 34 | webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 35 | EXPECT_EQ(1u, iceStruct.urls.size()); |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 36 | EXPECT_EQ("stun:stun1.example.net", iceStruct.urls.front()); |
| 37 | EXPECT_EQ("", iceStruct.username); |
| 38 | EXPECT_EQ("", iceStruct.password); |
| 39 | } |
| 40 | |
| 41 | - (void)testTwoURLServer { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 42 | RTC_OBJC_TYPE(RTCIceServer) *server = [[RTC_OBJC_TYPE(RTCIceServer) alloc] |
| 43 | initWithURLStrings:@[ @"turn1:turn1.example.net", @"turn2:turn2.example.net" ]]; |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 44 | |
hjon | a2f7798 | 2016-03-04 07:09:09 -0800 | [diff] [blame] | 45 | webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 46 | EXPECT_EQ(2u, iceStruct.urls.size()); |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 47 | EXPECT_EQ("turn1:turn1.example.net", iceStruct.urls.front()); |
| 48 | EXPECT_EQ("turn2:turn2.example.net", iceStruct.urls.back()); |
| 49 | EXPECT_EQ("", iceStruct.username); |
| 50 | EXPECT_EQ("", iceStruct.password); |
| 51 | } |
| 52 | |
| 53 | - (void)testPasswordCredential { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 54 | RTC_OBJC_TYPE(RTCIceServer) *server = |
| 55 | [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithURLStrings:@[ @"turn1:turn1.example.net" ] |
| 56 | username:@"username" |
| 57 | credential:@"credential"]; |
hjon | a2f7798 | 2016-03-04 07:09:09 -0800 | [diff] [blame] | 58 | webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 59 | EXPECT_EQ(1u, iceStruct.urls.size()); |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 60 | EXPECT_EQ("turn1:turn1.example.net", iceStruct.urls.front()); |
| 61 | EXPECT_EQ("username", iceStruct.username); |
| 62 | EXPECT_EQ("credential", iceStruct.password); |
| 63 | } |
| 64 | |
Emad Omara | dab1d2d | 2017-06-16 15:43:11 -0700 | [diff] [blame] | 65 | - (void)testHostname { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 66 | RTC_OBJC_TYPE(RTCIceServer) *server = |
| 67 | [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithURLStrings:@[ @"turn1:turn1.example.net" ] |
| 68 | username:@"username" |
| 69 | credential:@"credential" |
| 70 | tlsCertPolicy:RTCTlsCertPolicySecure |
| 71 | hostname:@"hostname"]; |
Emad Omara | dab1d2d | 2017-06-16 15:43:11 -0700 | [diff] [blame] | 72 | webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer; |
| 73 | EXPECT_EQ(1u, iceStruct.urls.size()); |
| 74 | EXPECT_EQ("turn1:turn1.example.net", iceStruct.urls.front()); |
| 75 | EXPECT_EQ("username", iceStruct.username); |
| 76 | EXPECT_EQ("credential", iceStruct.password); |
| 77 | EXPECT_EQ("hostname", iceStruct.hostname); |
| 78 | } |
| 79 | |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 80 | - (void)testTlsAlpnProtocols { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 81 | RTC_OBJC_TYPE(RTCIceServer) *server = |
| 82 | [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithURLStrings:@[ @"turn1:turn1.example.net" ] |
| 83 | username:@"username" |
| 84 | credential:@"credential" |
| 85 | tlsCertPolicy:RTCTlsCertPolicySecure |
| 86 | hostname:@"hostname" |
| 87 | tlsAlpnProtocols:@[ @"proto1", @"proto2" ]]; |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 88 | webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer; |
| 89 | EXPECT_EQ(1u, iceStruct.urls.size()); |
| 90 | EXPECT_EQ("turn1:turn1.example.net", iceStruct.urls.front()); |
| 91 | EXPECT_EQ("username", iceStruct.username); |
| 92 | EXPECT_EQ("credential", iceStruct.password); |
| 93 | EXPECT_EQ("hostname", iceStruct.hostname); |
Sergey Silkin | 9c147dd | 2018-09-12 10:45:38 +0000 | [diff] [blame] | 94 | EXPECT_EQ(2u, iceStruct.tls_alpn_protocols.size()); |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Diogo Real | 7bd1f1b | 2017-09-08 12:50:41 -0700 | [diff] [blame] | 97 | - (void)testTlsEllipticCurves { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 98 | RTC_OBJC_TYPE(RTCIceServer) *server = |
| 99 | [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithURLStrings:@[ @"turn1:turn1.example.net" ] |
| 100 | username:@"username" |
| 101 | credential:@"credential" |
| 102 | tlsCertPolicy:RTCTlsCertPolicySecure |
| 103 | hostname:@"hostname" |
| 104 | tlsAlpnProtocols:@[ @"proto1", @"proto2" ] |
| 105 | tlsEllipticCurves:@[ @"curve1", @"curve2" ]]; |
Diogo Real | 7bd1f1b | 2017-09-08 12:50:41 -0700 | [diff] [blame] | 106 | webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer; |
| 107 | EXPECT_EQ(1u, iceStruct.urls.size()); |
| 108 | EXPECT_EQ("turn1:turn1.example.net", iceStruct.urls.front()); |
| 109 | EXPECT_EQ("username", iceStruct.username); |
| 110 | EXPECT_EQ("credential", iceStruct.password); |
| 111 | EXPECT_EQ("hostname", iceStruct.hostname); |
Sergey Silkin | 9c147dd | 2018-09-12 10:45:38 +0000 | [diff] [blame] | 112 | EXPECT_EQ(2u, iceStruct.tls_alpn_protocols.size()); |
| 113 | EXPECT_EQ(2u, iceStruct.tls_elliptic_curves.size()); |
Diogo Real | 7bd1f1b | 2017-09-08 12:50:41 -0700 | [diff] [blame] | 114 | } |
| 115 | |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 116 | - (void)testInitFromNativeServer { |
| 117 | webrtc::PeerConnectionInterface::IceServer nativeServer; |
| 118 | nativeServer.username = "username"; |
| 119 | nativeServer.password = "password"; |
| 120 | nativeServer.urls.push_back("stun:stun.example.net"); |
Emad Omara | dab1d2d | 2017-06-16 15:43:11 -0700 | [diff] [blame] | 121 | nativeServer.hostname = "hostname"; |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 122 | nativeServer.tls_alpn_protocols.push_back("proto1"); |
| 123 | nativeServer.tls_alpn_protocols.push_back("proto2"); |
Diogo Real | 7bd1f1b | 2017-09-08 12:50:41 -0700 | [diff] [blame] | 124 | nativeServer.tls_elliptic_curves.push_back("curve1"); |
| 125 | nativeServer.tls_elliptic_curves.push_back("curve2"); |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 126 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 127 | RTC_OBJC_TYPE(RTCIceServer) *iceServer = |
| 128 | [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithNativeServer:nativeServer]; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 129 | EXPECT_EQ(1u, iceServer.urlStrings.count); |
| 130 | EXPECT_EQ("stun:stun.example.net", |
| 131 | [NSString stdStringForString:iceServer.urlStrings.firstObject]); |
| 132 | EXPECT_EQ("username", [NSString stdStringForString:iceServer.username]); |
| 133 | EXPECT_EQ("password", [NSString stdStringForString:iceServer.credential]); |
Emad Omara | dab1d2d | 2017-06-16 15:43:11 -0700 | [diff] [blame] | 134 | EXPECT_EQ("hostname", [NSString stdStringForString:iceServer.hostname]); |
Sergey Silkin | 9c147dd | 2018-09-12 10:45:38 +0000 | [diff] [blame] | 135 | EXPECT_EQ(2u, iceServer.tlsAlpnProtocols.count); |
| 136 | EXPECT_EQ(2u, iceServer.tlsEllipticCurves.count); |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 137 | } |
| 138 | |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 139 | @end |
| 140 | |
| 141 | TEST(RTCIceServerTest, OneURLTest) { |
| 142 | @autoreleasepool { |
| 143 | RTCIceServerTest *test = [[RTCIceServerTest alloc] init]; |
| 144 | [test testOneURLServer]; |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | TEST(RTCIceServerTest, TwoURLTest) { |
| 149 | @autoreleasepool { |
| 150 | RTCIceServerTest *test = [[RTCIceServerTest alloc] init]; |
| 151 | [test testTwoURLServer]; |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | TEST(RTCIceServerTest, PasswordCredentialTest) { |
| 156 | @autoreleasepool { |
| 157 | RTCIceServerTest *test = [[RTCIceServerTest alloc] init]; |
| 158 | [test testPasswordCredential]; |
| 159 | } |
| 160 | } |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 161 | |
Emad Omara | dab1d2d | 2017-06-16 15:43:11 -0700 | [diff] [blame] | 162 | TEST(RTCIceServerTest, HostnameTest) { |
| 163 | @autoreleasepool { |
| 164 | RTCIceServerTest *test = [[RTCIceServerTest alloc] init]; |
| 165 | [test testHostname]; |
| 166 | } |
| 167 | } |
| 168 | |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 169 | TEST(RTCIceServerTest, InitFromNativeServerTest) { |
| 170 | @autoreleasepool { |
| 171 | RTCIceServerTest *test = [[RTCIceServerTest alloc] init]; |
| 172 | [test testInitFromNativeServer]; |
| 173 | } |
| 174 | } |