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