Skip to content

Commit

Permalink
differentiate fizz ALPN exception messages.
Browse files Browse the repository at this point in the history
Summary: Use different message according to different AlpnMode in FizzException triggered by ALPN mismatch.

Reviewed By: mingtaoy

Differential Revision: D30578825

fbshipit-source-id: 690376fdb9a80371acaa621377d831dd665abec6
  • Loading branch information
frqiu authored and facebook-github-bot committed Aug 26, 2021
1 parent 0beab30 commit 7925b2e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions fizz/server/ServerProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -777,9 +777,10 @@ static Optional<std::string> negotiateAlpn(
if (!selected) {
VLOG(6) << "ALPN mismatch";
if (context.getAlpnMode() != AlpnMode::AllowMismatch) {
throw FizzException(
"ALPN mismatch when required",
AlertDescription::no_application_protocol);
auto msg = context.getAlpnMode() == AlpnMode::Optional
? "Unable to negotiate ALPN, as required by policy. policy=AlpnMode::Optional"
: "Unable to negotiate ALPN, as required by policy. policy=AlpnMode::Required";
throw FizzException(msg, AlertDescription::no_application_protocol);
}
} else {
VLOG(6) << "ALPN: " << *selected;
Expand Down
4 changes: 2 additions & 2 deletions fizz/server/test/ServerProtocolTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3709,7 +3709,7 @@ TEST_F(ServerProtocolTest, TestClientHelloMismatchAlpnOptional) {
expectError<FizzException>(
actions,
AlertDescription::no_application_protocol,
"ALPN mismatch when required");
"Unable to negotiate ALPN, as required by policy. policy=AlpnMode::Optional");
}

TEST_F(ServerProtocolTest, TestClientHelloNoAlpnRequired) {
Expand Down Expand Up @@ -3755,7 +3755,7 @@ TEST_F(ServerProtocolTest, TestClientHelloMismatchAlpnRequired) {
expectError<FizzException>(
actions,
AlertDescription::no_application_protocol,
"ALPN mismatch when required");
"Unable to negotiate ALPN, as required by policy. policy=AlpnMode::Required");
}

TEST_F(ServerProtocolTest, TestClientHelloServerPref) {
Expand Down

0 comments on commit 7925b2e

Please sign in to comment.