blob: 23b026429bc5c8af3dfd049df0ce75831ebbe283 [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
Jonas Olssona4d87372019-07-05 19:08:33 +020011#include "examples/turnserver/read_auth_file.h"
12
Mirko Bonadei44ca9a32018-11-13 11:16:40 +010013#include <sstream>
Niels Möller9862c2e2018-10-30 12:20:03 +010014
Niels Möller9862c2e2018-10-30 12:20:03 +010015#include "test/gtest.h"
16
17namespace webrtc_examples {
18
19TEST(ReadAuthFile, HandlesEmptyFile) {
Mirko Bonadei44ca9a32018-11-13 11:16:40 +010020 std::istringstream empty;
Niels Möller9862c2e2018-10-30 12:20:03 +010021 auto map = ReadAuthFile(&empty);
22 EXPECT_TRUE(map.empty());
23}
24
25TEST(ReadAuthFile, RecognizesValidUser) {
Mirko Bonadei44ca9a32018-11-13 11:16:40 +010026 std::istringstream file("foo=deadbeaf\n");
Niels Möller9862c2e2018-10-30 12:20:03 +010027 auto map = ReadAuthFile(&file);
28 ASSERT_NE(map.find("foo"), map.end());
29 EXPECT_EQ(map["foo"], "\xde\xad\xbe\xaf");
30}
31
32TEST(ReadAuthFile, EmptyValueForInvalidHex) {
Mirko Bonadei44ca9a32018-11-13 11:16:40 +010033 std::istringstream file(
Niels Möller9862c2e2018-10-30 12:20:03 +010034 "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