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 3260908 commit f5a8833
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 @@ -2059,10 +2059,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 @@ -2101,7 +2101,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 @@ -2122,7 +2124,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 @@ -2182,9 +2186,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 @@ -2216,9 +2220,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 @@ -2259,19 +2263,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 @@ -2294,15 +2301,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 @@ -2336,10 +2345,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 @@ -2365,11 +2374,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 @@ -2389,7 +2398,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 @@ -2421,7 +2430,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 @@ -2478,7 +2487,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 @@ -2510,7 +2519,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 @@ -2552,7 +2561,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 @@ -2582,6 +2591,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 @@ -2609,7 +2619,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 f5a8833

Please sign in to comment.