Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion integration/hurl/tests_ok/cookie/cookie_jar.hurl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Set-Cookie: LSID=DQAAAKEaem_vYg; Expires=Thu, 13 Jan 2078 22:23:01 GMT; HttpOnly
Set-Cookie: HSID=AYQEVnDKrdst; Domain=localhost; Expires=Thu, 13 Jan 2078 22:23:01 GMT; HttpOnly; Path=/
Set-Cookie: SSID=Ap4PGTEq; Domain=localhost; Expires=Thu, 13 Jan 2078 22:23:01 GMT; HttpOnly; Path=/
[Asserts]
header "Set-Cookie" count == 3
header "Set-Cookie" count == 4
cookie "LSID" == "DQAAAKEaem_vYg"
cookie "LSID[Value]" == "DQAAAKEaem_vYg"
cookie "LSID[Expires]" exists
Expand All @@ -19,3 +19,6 @@ cookie "LSID[Path]" == "/accounts"
cookie "LSID[Secure]" not exists
cookie "LSID[HttpOnly]" exists
cookie "LSID[SameSite]" not exists
# Following RFC-6265, we should not have spaces in cookie value, but curl accepts it, considering
# the double quotes to be part of the value.
cookie "foo" == "\"a b\""
1 change: 1 addition & 0 deletions integration/hurl/tests_ok/cookie/cookie_jar.out.pattern
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
#HttpOnly_localhost FALSE /accounts FALSE <<<(17\d{8}|3409338181)>>> LSID DQAAAKEaem_vYg
#HttpOnly_.localhost TRUE / FALSE <<<(17\d{8}|3409338181)>>> HSID AYQEVnDKrdst
#HttpOnly_.localhost TRUE / FALSE <<<(17\d{8}|3409338181)>>> SSID Ap4PGTEq
.localhost TRUE / FALSE <<<(17\d{8}|3409338181)>>> foo "a b"
8 changes: 8 additions & 0 deletions integration/hurl/tests_ok/cookie/cookie_jar.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,12 @@ def set_cookie_jar():
expires="Thu, 13 Jan 2078 22:23:01 GMT",
httponly=True,
)
resp.set_cookie(
"foo",
"a b",
domain="localhost",
path="/",
expires="Thu, 13 Jan 2078 22:23:01 GMT",
httponly=False,
)
return resp
2 changes: 1 addition & 1 deletion integration/hurl/tests_ok/cookie/cookie_storage.hurl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# manage cookie store
#

# @cookie_storage_set: localhost FALSE / FALSE 0 cookie1 valueA
# @cookie_storage_set: localhost FALSE / FALSE 0 cookie1 valueA
GET http://localhost:8000/cookie-storage/assert-that-cookie1-is-valueA
HTTP 200

Expand Down
22 changes: 2 additions & 20 deletions packages/hurl/src/http/cookie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
use core::fmt;
use std::fmt::Formatter;

use crate::util::redacted::Redact;

/// [Cookie](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie) returned by
/// the server with `Set-Cookie` header, and saved in the cookie storage of the internal HTTP
/// engine.
Expand Down Expand Up @@ -78,9 +76,9 @@ impl Cookie {
)
}

/// Creates a [`Cookie`] from a Nescape cookie formatted string.
/// Creates a [`Cookie`] from a Netscape cookie formatted string.
pub fn from_netscape_str(s: &str) -> Result<Self, ParseCookieError> {
let tokens = s.split_ascii_whitespace().collect::<Vec<&str>>();
let tokens = s.split("\t").collect::<Vec<&str>>();
let (http_only, domain) = if let Some(&v) = tokens.first() {
if let Some(domain) = v.strip_prefix("#HttpOnly_") {
(true, domain.to_string())
Expand Down Expand Up @@ -140,22 +138,6 @@ impl fmt::Display for Cookie {
}
}

impl Redact for Cookie {
fn redact(&self, secrets: &[impl AsRef<str>]) -> String {
format!(
"{}{}\t{}\t{}\t{}\t{}\t{}\t{}",
if self.http_only { "#HttpOnly_" } else { "" },
self.domain,
self.include_subdomain,
self.path,
self.https,
self.expires,
self.name,
self.value.redact(secrets)
)
}
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ParseCookieError;

Expand Down
2 changes: 1 addition & 1 deletion packages/hurl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ fn create_cookies_file(
s.push_str(&format!("# Cookies for file <{}>", run.filename));
s.push('\n');
for cookie in run.hurl_result.cookies.iter() {
s.push_str(&cookie.redact(secrets));
s.push_str(&cookie.to_netscape_str().redact(secrets));
s.push('\n');
}
}
Expand Down
Loading