1 /*
2 * Copyright 2020 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 #include "p2p/base/transport_description.h"
12 #include "test/gtest.h"
13
14 using webrtc::RTCErrorType;
15
16 namespace cricket {
17
TEST(IceParameters,SuccessfulParse)18 TEST(IceParameters, SuccessfulParse) {
19 auto result = IceParameters::Parse("ufrag", "22+characters+long+pwd");
20 ASSERT_TRUE(result.ok());
21 IceParameters parameters = result.MoveValue();
22 EXPECT_EQ("ufrag", parameters.ufrag);
23 EXPECT_EQ("22+characters+long+pwd", parameters.pwd);
24 }
25
TEST(IceParameters,FailedParseShortUfrag)26 TEST(IceParameters, FailedParseShortUfrag) {
27 auto result = IceParameters::Parse("3ch", "22+characters+long+pwd");
28 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, result.error().type());
29 }
30
TEST(IceParameters,FailedParseLongUfrag)31 TEST(IceParameters, FailedParseLongUfrag) {
32 std::string ufrag(257, '+');
33 auto result = IceParameters::Parse(ufrag, "22+characters+long+pwd");
34 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, result.error().type());
35 }
36
TEST(IceParameters,FailedParseShortPwd)37 TEST(IceParameters, FailedParseShortPwd) {
38 auto result = IceParameters::Parse("ufrag", "21+character+long+pwd");
39 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, result.error().type());
40 }
41
TEST(IceParameters,FailedParseLongPwd)42 TEST(IceParameters, FailedParseLongPwd) {
43 std::string pwd(257, '+');
44 auto result = IceParameters::Parse("ufrag", pwd);
45 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, result.error().type());
46 }
47
TEST(IceParameters,FailedParseBadUfragChar)48 TEST(IceParameters, FailedParseBadUfragChar) {
49 auto result = IceParameters::Parse("ufrag\r\n", "22+characters+long+pwd");
50 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, result.error().type());
51 }
52
TEST(IceParameters,FailedParseBadPwdChar)53 TEST(IceParameters, FailedParseBadPwdChar) {
54 auto result = IceParameters::Parse("ufrag", "22+characters+long+pwd\r\n");
55 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, result.error().type());
56 }
57
58 } // namespace cricket
59