blob: de7d8ec839e8a5bdc5f00648718048c254198a9a [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
11#include <sstream> // no-presubmit-check TODO(webrtc:8982)
12
13#include "examples/turnserver/read_auth_file.h"
14#include "test/gtest.h"
15
16namespace webrtc_examples {
17
18TEST(ReadAuthFile, HandlesEmptyFile) {
19 std::istringstream empty; // no-presubmit-check TODO(webrtc:8982)
20 auto map = ReadAuthFile(&empty);
21 EXPECT_TRUE(map.empty());
22}
23
24TEST(ReadAuthFile, RecognizesValidUser) {
25 std::istringstream // no-presubmit-check TODO(webrtc:8982)
26 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
32TEST(ReadAuthFile, EmptyValueForInvalidHex) {
33 std::istringstream file( // no-presubmit-check TODO(webrtc:8982)
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