-
Notifications
You must be signed in to change notification settings - Fork 8
Clarify cookie header tests and remove duplicate callback serde test #660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -268,6 +268,9 @@ pub fn expire_ec_cookie(settings: &Settings, response: &mut fastly::Response) { | |
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use fastly::http::HeaderValue; | ||
|
|
||
| use crate::error::TrustedServerError; | ||
| use crate::test_support::tests::create_test_settings; | ||
|
|
||
| use super::*; | ||
|
|
@@ -338,7 +341,7 @@ mod tests { | |
| } | ||
|
|
||
| #[test] | ||
| fn test_handle_request_cookies_invalid_cookie_header() { | ||
| fn test_handle_request_cookies_malformed_cookie_string() { | ||
| let req = Request::get("http://example.com").with_header(header::COOKIE, "invalid"); | ||
| let jar = handle_request_cookies(&req) | ||
| .expect("should parse cookies") | ||
|
|
@@ -347,6 +350,26 @@ mod tests { | |
| assert!(jar.iter().count() == 0); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_handle_request_cookies_invalid_utf8_cookie_header() { | ||
| let invalid_cookie_value = HeaderValue::from_bytes(b"ts-ec=valid-prefix\xF0\x90\x80") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⛏ nitpick — The |
||
| .expect("should build header value"); | ||
| let req = | ||
| Request::get("http://example.com").with_header(header::COOKIE, invalid_cookie_value); | ||
|
|
||
| let err = | ||
| handle_request_cookies(&req).expect_err("should reject invalid UTF-8 cookie header"); | ||
|
|
||
| assert!( | ||
| matches!( | ||
| err.current_context(), | ||
| TrustedServerError::InvalidHeaderValue { message } | ||
| if message.contains("invalid UTF-8") | ||
| ), | ||
| "should return invalid header value error for non-UTF-8 cookie header" | ||
| ); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔧 wrench — Brittle assertion: the Fix: assert!(
matches!(
err.current_context(),
TrustedServerError::InvalidHeaderValue { .. }
),
"should return InvalidHeaderValue for non-UTF-8 cookie header"
); |
||
| } | ||
|
|
||
| #[test] | ||
| fn test_set_ec_cookie() { | ||
| let settings = create_test_settings(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛏ nitpick —
\xF0\x90\x80is a truncated 4-byte UTF-8 sequence:\xF0introduces a 4-byte code point but only two continuation bytes follow, soto_str()rejects it. A one-line comment above the literal would save future readers a trip to the Unicode tables.