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 #include "examples/turnserver/read_auth_file.h"
12 
13 #include <sstream>
14 
15 #include "test/gtest.h"
16 
17 namespace webrtc_examples {
18 
TEST(ReadAuthFile,HandlesEmptyFile)19 TEST(ReadAuthFile, HandlesEmptyFile) {
20   std::istringstream empty;
21   auto map = ReadAuthFile(&empty);
22   EXPECT_TRUE(map.empty());
23 }
24 
TEST(ReadAuthFile,RecognizesValidUser)25 TEST(ReadAuthFile, RecognizesValidUser) {
26   std::istringstream file("foo=deadbeaf\n");
27   auto map = ReadAuthFile(&file);
28   ASSERT_NE(map.find("foo"), map.end());
29   EXPECT_EQ(map["foo"], "\xde\xad\xbe\xaf");
30 }
31 
TEST(ReadAuthFile,EmptyValueForInvalidHex)32 TEST(ReadAuthFile, EmptyValueForInvalidHex) {
33   std::istringstream file(
34       "foo=deadbeaf\n"
35       "bar=xxxxinvalidhex\n"
36       "baz=cafe\n");
37   auto map = ReadAuthFile(&file);
38   ASSERT_NE(map.find("foo"), map.end());
39   EXPECT_EQ(map["foo"], "\xde\xad\xbe\xaf");
40   EXPECT_EQ(map.find("bar"), map.end());
41   ASSERT_NE(map.find("baz"), map.end());
42   EXPECT_EQ(map["baz"], "\xca\xfe");
43 }
44 
45 }  // namespace webrtc_examples
46