1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/dns/public/util.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace net {
namespace dns_util {
TEST(DnsPublicUtilTest, IsValidDohTemplate) {
std::string server_method;
EXPECT_TRUE(IsValidDohTemplate(
"https://dnsserver.example.net/dns-query{?dns}", &server_method));
EXPECT_EQ("GET", server_method);
EXPECT_TRUE(IsValidDohTemplate(
"https://dnsserver.example.net/dns-query{?dns,extra}", &server_method));
EXPECT_EQ("GET", server_method);
EXPECT_TRUE(IsValidDohTemplate(
"https://dnsserver.example.net/dns-query{?query}", &server_method));
EXPECT_EQ("POST", server_method);
EXPECT_TRUE(IsValidDohTemplate("https://dnsserver.example.net/dns-query",
&server_method));
EXPECT_EQ("POST", server_method);
EXPECT_TRUE(IsValidDohTemplate("https://query:{dns}@dnsserver.example.net",
&server_method));
EXPECT_EQ("GET", server_method);
EXPECT_TRUE(IsValidDohTemplate("https://dnsserver.example.net{/dns}",
&server_method));
EXPECT_EQ("GET", server_method);
// Invalid template format
EXPECT_FALSE(IsValidDohTemplate(
"https://dnsserver.example.net/dns-query{{?dns}}", &server_method));
// Must be HTTPS
EXPECT_FALSE(IsValidDohTemplate("http://dnsserver.example.net/dns-query",
&server_method));
EXPECT_FALSE(IsValidDohTemplate(
"http://dnsserver.example.net/dns-query{?dns}", &server_method));
// Template must expand to a valid URL
EXPECT_FALSE(IsValidDohTemplate("https://{?dns}", &server_method));
// The hostname must not contain the dns variable
EXPECT_FALSE(
IsValidDohTemplate("https://{dns}.dnsserver.net", &server_method));
}
} // namespace dns_util
} // namespace net
|