Niels Möller | 9862c2e | 2018-10-30 12:20:03 +0100 | [diff] [blame] | 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 | |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 11 | #include "examples/turnserver/read_auth_file.h" |
| 12 | |
Mirko Bonadei | 44ca9a3 | 2018-11-13 11:16:40 +0100 | [diff] [blame] | 13 | #include <sstream> |
Niels Möller | 9862c2e | 2018-10-30 12:20:03 +0100 | [diff] [blame] | 14 | |
Niels Möller | 9862c2e | 2018-10-30 12:20:03 +0100 | [diff] [blame] | 15 | #include "test/gtest.h" |
| 16 | |
| 17 | namespace webrtc_examples { |
| 18 | |
| 19 | TEST(ReadAuthFile, HandlesEmptyFile) { |
Mirko Bonadei | 44ca9a3 | 2018-11-13 11:16:40 +0100 | [diff] [blame] | 20 | std::istringstream empty; |
Niels Möller | 9862c2e | 2018-10-30 12:20:03 +0100 | [diff] [blame] | 21 | auto map = ReadAuthFile(&empty); |
| 22 | EXPECT_TRUE(map.empty()); |
| 23 | } |
| 24 | |
| 25 | TEST(ReadAuthFile, RecognizesValidUser) { |
Mirko Bonadei | 44ca9a3 | 2018-11-13 11:16:40 +0100 | [diff] [blame] | 26 | std::istringstream file("foo=deadbeaf\n"); |
Niels Möller | 9862c2e | 2018-10-30 12:20:03 +0100 | [diff] [blame] | 27 | auto map = ReadAuthFile(&file); |
| 28 | ASSERT_NE(map.find("foo"), map.end()); |
| 29 | EXPECT_EQ(map["foo"], "\xde\xad\xbe\xaf"); |
| 30 | } |
| 31 | |
| 32 | TEST(ReadAuthFile, EmptyValueForInvalidHex) { |
Mirko Bonadei | 44ca9a3 | 2018-11-13 11:16:40 +0100 | [diff] [blame] | 33 | std::istringstream file( |
Niels Möller | 9862c2e | 2018-10-30 12:20:03 +0100 | [diff] [blame] | 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 |