Skip to content

Commit 4d12805

Browse files
authored
Updated testing and fixed bug in SSLSNIConfig (#12248)
1 parent 992f63b commit 4d12805

4 files changed

Lines changed: 83 additions & 13 deletions

File tree

src/iocore/net/SSLSNIConfig.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ NamedElement::operator=(NamedElement &&other)
7777
if (this != &other) {
7878
match = std::move(other.match);
7979
inbound_port_ranges = std::move(other.inbound_port_ranges);
80+
rank = other.rank;
8081
}
8182
return *this;
8283
}

src/iocore/net/unit_tests/sni_conf_test.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,16 @@ sni:
3636
http2_buffer_water_mark: 256
3737
- fqdn: foo.bar.com
3838
http2: false
39+
40+
# test with mixed-case
41+
- fqdn: "MiXeDcAsE.foo.com"
42+
http2: true
43+
http2_buffer_water_mark: 256
44+
inbound_port_ranges: 31337
45+
46+
# test with mixed-case glob
47+
- fqdn: "*.MiXeDcAsE.com"
48+
http2: false
49+
50+
# test glob in the middle, this will be an exact match
51+
- fqdn: "cat.*.com"

src/iocore/net/unit_tests/test_SSLSNIConfig.cc

Lines changed: 68 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,78 +41,134 @@ TEST_CASE("Test SSLSNIConfig")
4141

4242
SECTION("The config does not match any SNIs for someport.com:577")
4343
{
44-
auto const &actions{params.get({"someport.com", std::strlen("someport.com")}, 577)};
44+
auto const &actions{params.get("someport.com", 577)};
4545
CHECK(!actions.first);
4646
}
4747

4848
SECTION("The config does not match any SNIs for someport.com:808")
4949
{
50-
auto const &actions{params.get({"someport.com", std::strlen("someport.com")}, 808)};
50+
auto const &actions{params.get("someport.com", 808)};
5151
CHECK(!actions.first);
5252
}
5353

5454
SECTION("The config does not match any SNIs for oneport.com:1")
5555
{
56-
auto const &actions{params.get({"oneport.com", std::strlen("oneport.com")}, 1)};
56+
auto const &actions{params.get("oneport.com", 1)};
5757
CHECK(!actions.first);
5858
}
5959

6060
SECTION("The config does match an SNI for oneport.com:433")
6161
{
62-
auto const &actions{params.get({"oneport.com", std::strlen("oneport.com")}, 433)};
62+
auto const &actions{params.get("oneport.com", 433)};
6363
REQUIRE(actions.first);
6464
REQUIRE(actions.first->size() == 2);
6565
}
6666

6767
SECTION("The config matches an SNI for allports.com")
6868
{
69-
auto const &actions{params.get({"allports.com", std::strlen("allports.com")}, 1)};
69+
auto const &actions{params.get("allports.com", 1)};
7070
REQUIRE(actions.first);
7171
REQUIRE(actions.first->size() == 2);
7272
}
7373

7474
SECTION("The config matches an SNI for someport.com:1")
7575
{
76-
auto const &actions{params.get({"someport.com", std::strlen("someport.com")}, 1)};
76+
auto const &actions{params.get("someport.com", 1)};
7777
REQUIRE(actions.first);
7878
REQUIRE(actions.first->size() == 3);
7979
}
8080

8181
SECTION("The config matches an SNI for someport.com:433")
8282
{
83-
auto const &actions{params.get({"someport.com", std::strlen("someport.com")}, 433)};
83+
auto const &actions{params.get("someport.com", 433)};
8484
REQUIRE(actions.first);
8585
REQUIRE(actions.first->size() == 3);
8686
}
8787

8888
SECTION("The config matches an SNI for someport:8080")
8989
{
90-
auto const &actions{params.get({"someport.com", std::strlen("someport.com")}, 8080)};
90+
auto const &actions{params.get("someport.com", 8080)};
9191
REQUIRE(actions.first);
9292
REQUIRE(actions.first->size() == 2);
9393
}
9494

9595
SECTION("The config matches an SNI for someport:65535")
9696
{
97-
auto const &actions{params.get({"someport.com", std::strlen("someport.com")}, 65535)};
97+
auto const &actions{params.get("someport.com", 65535)};
9898
REQUIRE(actions.first);
9999
REQUIRE(actions.first->size() == 2);
100100
}
101101

102102
SECTION("The config matches an SNI for someport:482")
103103
{
104-
auto const &actions{params.get({"someport.com", std::strlen("someport.com")}, 482)};
104+
auto const &actions{params.get("someport.com", 482)};
105105
REQUIRE(actions.first);
106106
REQUIRE(actions.first->size() == 3);
107107
}
108108

109109
SECTION("Matching order")
110110
{
111-
std::string_view target = "foo.bar.com";
112-
auto const &actions{params.get(target, 443)};
111+
auto const &actions{params.get("foo.bar.com", 443)};
113112
REQUIRE(actions.first);
114113
REQUIRE(actions.first->size() == 5); ///< three H2 config + early data + fqdn
115114
}
115+
116+
SECTION("Test mixed-case")
117+
{
118+
auto const &actions{params.get("SoMePoRt.CoM", 65535)};
119+
REQUIRE(actions.first);
120+
REQUIRE(actions.first->size() == 2);
121+
}
122+
123+
SECTION("Test mixed-case with wildcard in yaml config")
124+
{
125+
auto const &actions{params.get("AnYtHiNg.BaR.CoM", 443)};
126+
REQUIRE(actions.first);
127+
REQUIRE(actions.first->size() == 4);
128+
// verify the capture group
129+
REQUIRE(actions.second._fqdn_wildcard_captured_groups->at(0) == "AnYtHiNg");
130+
}
131+
132+
SECTION("Test mixed-case in yaml config")
133+
{
134+
auto const &actions{params.get("mixedcase.foo.com", 31337)};
135+
REQUIRE(actions.first);
136+
REQUIRE(actions.first->size() == 4);
137+
}
138+
139+
SECTION("Test mixed-case glob in yaml config")
140+
{
141+
auto const &actions{params.get("FoO.mixedcase.com", 443)};
142+
REQUIRE(actions.first);
143+
REQUIRE(actions.first->size() == 3);
144+
// verify the capture group
145+
REQUIRE(actions.second._fqdn_wildcard_captured_groups->at(0) == "FoO");
146+
}
147+
148+
SECTION("Test empty SNI does not match")
149+
{
150+
auto const &actions{params.get("", 443)};
151+
CHECK(!actions.first);
152+
}
153+
154+
SECTION("Test SNI with special characters does not match")
155+
{
156+
auto const &actions{params.get("some$port.com", 443)};
157+
CHECK(!actions.first);
158+
}
159+
160+
SECTION("Test with invalid glob in the middle in yaml config (e.g. cat.*.com) does not match")
161+
{
162+
auto const &actions{params.get("cat.dog.com", 443)};
163+
REQUIRE(!actions.first);
164+
}
165+
166+
SECTION("Test with invalid glob in the middle in yaml config (e.g. cat.*.com) does an exact match")
167+
{
168+
auto const &actions{params.get("cat.*.com", 443)};
169+
REQUIRE(actions.first);
170+
REQUIRE(actions.first->size() == 2);
171+
}
116172
}
117173

118174
TEST_CASE("SNIConfig reconfigure callback is invoked")

src/iocore/net/unit_tests/test_YamlSNIConfig.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ TEST_CASE("YamlSNIConfig sets port ranges appropriately")
5555
FAIL(errorstream.str());
5656
}
5757
REQUIRE(zret.is_ok());
58-
REQUIRE(conf.items.size() == 7);
58+
REQUIRE(conf.items.size() == 10);
5959

6060
SECTION("If no ports were specified, port range should contain all ports.")
6161
{

0 commit comments

Comments
 (0)