Skip to content

Commit

Permalink
fix existing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ducaale committed Jun 10, 2023
1 parent 1deaf2e commit e4a84bc
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 38 deletions.
4 changes: 3 additions & 1 deletion src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,16 @@ impl Session {
}
}

pub fn save_cookies(&mut self, cookies: Vec<cookie_crate::Cookie>) {
pub fn save_cookies(&mut self, mut cookies: Vec<cookie_crate::Cookie>) {
let session_cookies = match self.content.cookies {
Cookies::Map(_) => unreachable!(),
Cookies::List(ref mut cookies) => cookies,
};

session_cookies.clear();

cookies.sort_by(|a, b| a.name().cmp(b.name()));

for cookie in cookies {
session_cookies.push(Cookie {
name: cookie.name().into(),
Expand Down
84 changes: 47 additions & 37 deletions tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2018,10 +2018,10 @@ fn named_sessions() {
"xh": "0.0.0"
},
"auth": { "type": "bearer", "raw_auth": "hello" },
"cookies": {
"cook1": { "value": "one", "path": "/" },
"lang": { "value": "en" }
},
"cookies": [
{ "name": "cook1", "value": "one", "path": "/" },
{ "name": "lang", "value": "en" }
],
"headers": []
})
);
Expand Down Expand Up @@ -2060,7 +2060,9 @@ fn anonymous_sessions() {
"xh": "0.0.0"
},
"auth": { "type": "basic", "raw_auth": "me:pass" },
"cookies": { "cook1": { "value": "one" } },
"cookies": [
{ "name": "cook1", "value": "one" }
],
"headers": [
{ "name": "hello", "value": "world" }
]
Expand All @@ -2081,7 +2083,9 @@ fn anonymous_read_only_session() {
let old_session_content = serde_json::json!({
"__meta__": { "about": "xh session file", "xh": "0.0.0" },
"auth": { "type": null, "raw_auth": null },
"cookies": { "cookie1": { "value": "one" } },
"cookies": [
{ "name": "cookie1", "value": "one" }
],
"headers": [
{ "name": "hello", "value": "world" }
]
Expand Down Expand Up @@ -2141,9 +2145,9 @@ fn session_files_are_created_in_read_only_mode() {
"xh": "0.0.0"
},
"auth": { "type": null, "raw_auth": null },
"cookies": {
"lang": { "value": "ar" }
},
"cookies": [
{ "name": "lang", "value": "ar" }
],
"headers": [
{ "name": "hello", "value": "world" }
]
Expand Down Expand Up @@ -2175,9 +2179,9 @@ fn named_read_only_session() {
let old_session_content = serde_json::json!({
"__meta__": { "about": "xh session file", "xh": "0.0.0" },
"auth": { "type": null, "raw_auth": null },
"cookies": {
"cookie1": { "value": "one" }
},
"cookies": [
{ "name": "cookie1", "value": "one" }
],
"headers": [
{ "name": "hello", "value": "world" }
]
Expand Down Expand Up @@ -2218,19 +2222,22 @@ fn expired_cookies_are_removed_from_session() {
serde_json::json!({
"__meta__": { "about": "xh session file", "xh": "0.0.0" },
"auth": { "type": null, "raw_auth": null },
"cookies": {
"expired_cookie": {
"cookies": [
{
"name": "expired_cookie",
"value": "random_string",
"expires": past_timestamp
},
"unexpired_cookie": {
{
"name": "unexpired_cookie",
"value": "random_string",
"expires": future_timestamp
},
"with_out_expiry": {
{
"name": "with_out_expiry",
"value": "random_string",
}
},
],
"headers": []
})
.to_string(),
Expand All @@ -2253,15 +2260,17 @@ fn expired_cookies_are_removed_from_session() {
serde_json::json!({
"__meta__": { "about": "xh session file", "xh": "0.0.0" },
"auth": { "type": null, "raw_auth": null },
"cookies": {
"unexpired_cookie": {
"cookies": [
{
"name": "unexpired_cookie",
"value": "random_string",
"expires": future_timestamp
},
"with_out_expiry": {
"value": "random_string",
{
"name": "with_out_expiry",
"value": "random_string"
}
},
],
"headers": []
})
);
Expand Down Expand Up @@ -2295,10 +2304,10 @@ fn cookies_override_each_other_in_the_correct_order() {
serde_json::json!({
"__meta__": { "about": "xh session file", "xh": "0.0.0" },
"auth": { "type": null, "raw_auth": null },
"cookies": {
"lang": { "value": "fr" },
"cook2": { "value": "three" }
},
"cookies": [
{ "name": "lang", "value": "fr" },
{ "name": "cook2", "value": "three" }
],
"headers": []
})
.to_string(),
Expand All @@ -2324,11 +2333,11 @@ fn cookies_override_each_other_in_the_correct_order() {
serde_json::json!({
"__meta__": { "about": "xh session file", "xh": "0.0.0" },
"auth": { "type": null, "raw_auth": null },
"cookies": {
"lang": { "value": "en" },
"cook1": { "value": "one" },
"cook2": { "value": "two" }
},
"cookies": [
{ "name": "cook1", "value": "one" },
{ "name": "cook2", "value": "two" },
{ "name": "lang", "value": "en" }
],
"headers": []
})
);
Expand All @@ -2348,7 +2357,7 @@ fn basic_auth_from_session_is_used() {
serde_json::json!({
"__meta__": { "about": "xh session file", "xh": "0.0.0" },
"auth": { "type": "basic", "raw_auth": "user:pass" },
"cookies": {},
"cookies": [],
"headers": []
})
.to_string(),
Expand Down Expand Up @@ -2380,7 +2389,7 @@ fn bearer_auth_from_session_is_used() {
serde_json::json!({
"__meta__": { "about": "xh session file", "xh": "0.0.0" },
"auth": { "type": "bearer", "raw_auth": "secret-token" },
"cookies": {},
"cookies": [],
"headers": []
})
.to_string(),
Expand Down Expand Up @@ -2437,7 +2446,7 @@ fn auth_netrc_is_not_persisted_in_session() {
"xh": "0.0.0"
},
"auth": { "type": null, "raw_auth": null },
"cookies": {},
"cookies": [],
"headers": [
{ "name": "hello", "value": "world" }
]
Expand Down Expand Up @@ -2469,7 +2478,7 @@ fn multiple_headers_with_same_key_in_session() {
serde_json::json!({
"__meta__": { "about": "xh session file", "xh": "0.0.0" },
"auth": {},
"cookies": {},
"cookies": [],
"headers": [
{ "name": "hello", "value": "world" },
{ "name": "hello", "value": "people" },
Expand Down Expand Up @@ -2511,7 +2520,7 @@ fn headers_from_session_are_overwritten() {
serde_json::json!({
"__meta__": { "about": "xh session file", "xh": "0.0.0" },
"auth": {},
"cookies": {},
"cookies": [],
"headers": [
{ "name": "hello", "value": "world" },
]
Expand Down Expand Up @@ -2541,6 +2550,7 @@ fn old_session_format_is_automatically_migrated() {

let session_file = NamedTempFile::new().unwrap();

// TODO
std::fs::write(
&session_file,
serde_json::json!({
Expand Down Expand Up @@ -2568,7 +2578,7 @@ fn old_session_format_is_automatically_migrated() {
serde_json::json!({
"__meta__": { "about": "xh session file", "xh": "0.0.0" },
"auth": { "type": null, "raw_auth": null },
"cookies": {},
"cookies": [],
"headers": [
{ "name": "hello", "value": "world" }
]
Expand Down

0 comments on commit e4a84bc

Please sign in to comment.