blob: 4a6f332c27a57669f4f2b45592ece3f32ac6bc22 [file] [log] [blame]
Niels Möller9862c2e2018-10-30 12:20:03 +01001/*
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 Bonadei44ca9a32018-11-13 11:16:40 +010011#include <sstream>
Niels Möller9862c2e2018-10-30 12:20:03 +010012
13#include "examples/turnserver/read_auth_file.h"
14#include "test/gtest.h"
15
16namespace webrtc_examples {
17
18TEST(ReadAuthFile, HandlesEmptyFile) {
Mirko Bonadei44ca9a32018-11-13 11:16:40 +010019 std::istringstream empty;
Niels Möller9862c2e2018-10-30 12:20:03 +010020 auto map = ReadAuthFile(&empty);
21 EXPECT_TRUE(map.empty());
22}
23
24TEST(ReadAuthFile, RecognizesValidUser) {
Mirko Bonadei44ca9a32018-11-13 11:16:40 +010025 std::istringstream file("foo=deadbeaf\n");
Niels Möller9862c2e2018-10-30 12:20:03 +010026 auto map = ReadAuthFile(&file);
27 ASSERT_NE(map.find("foo"), map.end());
28 EXPECT_EQ(map["foo"], "\xde\xad\xbe\xaf");
29}
30
31TEST(ReadAuthFile, EmptyValueForInvalidHex) {
Mirko Bonadei44ca9a32018-11-13 11:16:40 +010032 std::istringstream file(
Niels Möller9862c2e2018-10-30 12:20:03 +010033 "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