mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-11-29 21:18:29 +00:00
Accept several spaces after the auth scheme
RFC 9110 allows 1*SP between the auth scheme and what follows it in both challenges and credentials. parse_www_authenticate() took the scheme up to the last whitespace before "=", so "Digest realm=..." was not recognized as Digest and the 401 was returned without a retry, and get_bearer_token_auth() returned the token of "Bearer abc" with a leading space. The scheme is now the text up to the first whitespace, with the key after it trimmed, and get_bearer_token_auth() skips the extra spaces.
This commit is contained in:
1 parent
e22f398cf2
commit
c76e1b6a98
2 files changed
+15
-6
No files matched your search
+9
-1
@@ -2340,7 +2340,8 @@ TEST(BearerTokenAuthTest, SchemeValidation) {
|
||||
{"x", ""},
|
||||
{"Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==", ""},
|
||||
{"Bearer abc123", "abc123"},
|
||||
{"bearer abc123", "abc123"}, // scheme match is case-insensitive
|
||||
{"bearer abc123", "abc123"}, // scheme match is case-insensitive
|
||||
{"Bearer abc123", "abc123"}, // 1*SP after the scheme
|
||||
};
|
||||
|
||||
for (const auto &c : cases) {
|
||||
@@ -4042,6 +4043,13 @@ TEST(DigestAuthTest, RealmContainingCommaIsNotSplit) {
|
||||
"test,realm");
|
||||
}
|
||||
|
||||
// RFC 9110 11.6.1: 1*SP separates the scheme from its first auth-param.
|
||||
TEST(DigestAuthTest, SeveralSpacesAfterScheme) {
|
||||
auto authorization =
|
||||
get_digest_retry_authorization({"Digest realm=\"r\", nonce=\"n\""});
|
||||
EXPECT_NE(std::string::npos, authorization.find("nonce=\"n\""));
|
||||
}
|
||||
|
||||
// RFC 9110 11.2: auth-param names are matched case-insensitively.
|
||||
TEST(DigestAuthTest, ParamNamesAreCaseInsensitive) {
|
||||
auto authorization = get_digest_retry_authorization(
|
||||
|
||||
Reference in new issue
Block a user