mirror of
https://github.com/Orange-OpenSource/hurl.git
synced 2024-11-22 15:42:20 +03:00
Fix crash with --json option when capturing 'HttpOnly' and 'Secure' cookie attribute
This commit is contained in:
parent
11dd314b1d
commit
76ef2c98bc
@ -1,4 +1,5 @@
|
||||
curl 'http://localhost:8000/captures'
|
||||
curl 'http://localhost:8000/captures-check?param1=value1¶m2=Bob'
|
||||
curl 'http://localhost:8000/captures-xml'
|
||||
curl 'http://localhost:8000/captures-cookie'
|
||||
curl 'http://localhost:8000/captures-json'
|
||||
|
@ -31,6 +31,31 @@ a_node_set: xpath "//p"
|
||||
variable "a_node_set" count == 2
|
||||
|
||||
|
||||
GET http://localhost:8000/captures-cookie
|
||||
HTTP 200
|
||||
[Captures]
|
||||
a_cookie_value_attr: cookie "foo"
|
||||
a_cookie_path_attr: cookie "foo[Path]"
|
||||
a_cookie_expires_attr: cookie "foo[Expires]"
|
||||
a_cookie_domain_attr: cookie "foo[Domain]"
|
||||
a_cookie_max_age_attr: cookie "foo[Max-Age]"
|
||||
a_cookie_http_only_attr: cookie "foo[HttpOnly]"
|
||||
[Asserts]
|
||||
variable "a_cookie_value_attr" == "value1"
|
||||
variable "a_cookie_value_attr" == {{a_cookie_value_attr}}
|
||||
variable "a_cookie_path_attr" == "/bar"
|
||||
variable "a_cookie_path_attr" == {{a_cookie_path_attr}}
|
||||
variable "a_cookie_expires_attr" format "%Y-%m-%dT%H:%M:%S%.fZ" == "2078-01-13T22:23:01Z"
|
||||
# FIXME: the next assert should pass
|
||||
# variable "a_cookie_expires_attr" == {{a_cookie_expires_attr}}
|
||||
variable "a_cookie_domain_attr" == "localhost"
|
||||
variable "a_cookie_domain_attr" == {{a_cookie_domain_attr}}
|
||||
variable "a_cookie_max_age_attr" == 2592000
|
||||
variable "a_cookie_max_age_attr" == {{a_cookie_max_age_attr}}
|
||||
variable "a_cookie_http_only_attr" exists
|
||||
|
||||
|
||||
|
||||
GET http://localhost:8000/captures-json
|
||||
HTTP 200
|
||||
[Captures]
|
||||
|
@ -18,6 +18,25 @@ def captures_check():
|
||||
return ""
|
||||
|
||||
|
||||
@app.route("/captures-cookie")
|
||||
def captures_cookie():
|
||||
resp = make_response()
|
||||
resp.set_cookie(
|
||||
"foo",
|
||||
"value1",
|
||||
domain="localhost",
|
||||
path="/bar",
|
||||
httponly=True,
|
||||
# Can't use secure attributes here because secure cookie are not
|
||||
# stored in cookie storage by curl for version < 7.79
|
||||
# See <https://github.com/curl/curl/issues/6733>
|
||||
# secure=True,
|
||||
expires="Thu, 13 Jan 2078 22:23:01 GMT",
|
||||
max_age=2592000,
|
||||
)
|
||||
return resp
|
||||
|
||||
|
||||
@app.route("/captures-xml")
|
||||
def captures_xml():
|
||||
return (
|
||||
|
File diff suppressed because one or more lines are too long
@ -44,7 +44,15 @@ impl Value {
|
||||
serde_json::Value::Object(map)
|
||||
}
|
||||
Value::Nodeset(size) => {
|
||||
// TODO: explain why we do this for nodeset.
|
||||
// For nodeset, we don't have a "native" JSON representation to use as a serialized
|
||||
// format. As a fallback, we serialize with a `type` field:
|
||||
//
|
||||
// ```json
|
||||
// {
|
||||
// "type": "nodeset",
|
||||
// "size": 4,
|
||||
// }
|
||||
// ```
|
||||
let mut map = serde_json::Map::new();
|
||||
let size = *size as i64;
|
||||
map.insert(
|
||||
@ -60,12 +68,25 @@ impl Value {
|
||||
}
|
||||
Value::Null => serde_json::Value::Null,
|
||||
Value::Regex(value) => serde_json::Value::String(value.to_string()),
|
||||
Value::Unit => todo!("how to serialize that in json?"),
|
||||
Value::Unit => {
|
||||
// Like nodeset, we don't have a "native" JSON representation for the unit type,
|
||||
// we use a general fallback with `type` field
|
||||
let mut map = serde_json::Map::new();
|
||||
map.insert(
|
||||
"type".to_string(),
|
||||
serde_json::Value::String("unit".to_string()),
|
||||
);
|
||||
serde_json::Value::Object(map)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Number {
|
||||
/// Serializes a number to JSON.
|
||||
///
|
||||
/// Numbers that are representable in JSON use the number JSON type, while big number
|
||||
/// will be serialized as string.
|
||||
pub fn to_json(&self) -> serde_json::Value {
|
||||
match self {
|
||||
Number::Integer(v) => serde_json::Value::Number(serde_json::Number::from(*v)),
|
||||
|
Loading…
Reference in New Issue
Block a user