mirror of
https://github.com/Orange-OpenSource/hurl.git
synced 2024-12-25 12:05:32 +03:00
Merge pull request #237 from Orange-OpenSource/feature/add-md5-query
Add md5 query
This commit is contained in:
commit
054a37a0cc
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -396,6 +396,7 @@ dependencies = [
|
||||
"hurl_core",
|
||||
"libflate",
|
||||
"libxml",
|
||||
"md5",
|
||||
"percent-encoding",
|
||||
"regex",
|
||||
"serde",
|
||||
@ -505,6 +506,12 @@ version = "0.1.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
|
||||
|
||||
[[package]]
|
||||
name = "md5"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "490cc448043f947bae3cbee9c203358d62dbee0db12107a74be5c30ccfd09771"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.4.0"
|
||||
|
@ -1 +1 @@
|
||||
<div class="hurl-file"><div class="hurl-entry"><div class="request"><span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/bytes</span></span></div><div class="response"><span class="line"><span class="version">HTTP/1.0</span> <span class="status">200</span></span><span class="line"><span class="string">Content-Type</span><span>:</span> <span class="string">application/octet-stream</span></span><span class="line section-header">[Asserts]</span><span class="line"><span class="query-type">bytes</span> <span class="predicate-type">equals</span> <span class="hex">hex,010203;</span></span><span class="line"><span class="query-type">bytes</span> <span class="predicate-type">equals</span> <span>base64,AQID;</span></span><span class="line"><span class="query-type">bytes</span> <span class="query-type">count</span> <span class="predicate-type">==</span> <span class="number">3</span></span><span class="line"><span class="query-type">bytes</span> <span class="predicate-type">startsWith</span> <span class="hex">hex,01;</span></span><span class="line"><span class="query-type">bytes</span> <span class="predicate-type">contains</span> <span class="hex">hex,02;</span></span><span class="line"><span class="query-type">sha256</span> <span class="predicate-type">equals</span> <span class="hex">hex,039058c6f2c0cb492c533b0a4d14ef77cc0f78abccced5287d84a1a2011cfb81;</span></span></div></div></div>
|
||||
<div class="hurl-file"><div class="hurl-entry"><div class="request"><span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/bytes</span></span></div><div class="response"><span class="line"><span class="version">HTTP/1.0</span> <span class="status">200</span></span><span class="line"><span class="string">Content-Type</span><span>:</span> <span class="string">application/octet-stream</span></span><span class="line section-header">[Asserts]</span><span class="line"><span class="query-type">bytes</span> <span class="predicate-type">equals</span> <span class="hex">hex,010203;</span></span><span class="line"><span class="query-type">bytes</span> <span class="predicate-type">equals</span> <span>base64,AQID;</span></span><span class="line"><span class="query-type">bytes</span> <span class="query-type">count</span> <span class="predicate-type">==</span> <span class="number">3</span></span><span class="line"><span class="query-type">bytes</span> <span class="predicate-type">startsWith</span> <span class="hex">hex,01;</span></span><span class="line"><span class="query-type">bytes</span> <span class="predicate-type">contains</span> <span class="hex">hex,02;</span></span><span class="line"><span class="query-type">sha256</span> <span class="predicate-type">equals</span> <span class="hex">hex,039058c6f2c0cb492c533b0a4d14ef77cc0f78abccced5287d84a1a2011cfb81;</span></span><span class="line"><span class="query-type">md5</span> <span class="predicate-type">equals</span> <span class="hex">hex,5289df737df57326fcdd22597afb1fac;</span></span></div></div></div>
|
@ -8,3 +8,4 @@ bytes count == 3
|
||||
bytes startsWith hex,01;
|
||||
bytes contains hex,02;
|
||||
sha256 equals hex,039058c6f2c0cb492c533b0a4d14ef77cc0f78abccced5287d84a1a2011cfb81;
|
||||
md5 equals hex,5289df737df57326fcdd22597afb1fac;
|
||||
|
@ -1 +1 @@
|
||||
{"entries":[{"request":{"method":"GET","url":"http://localhost:8000/bytes"},"response":{"version":"HTTP/1.0","status":200,"headers":[{"name":"Content-Type","value":"application/octet-stream"}],"asserts":[{"query":{"type":"bytes"},"predicate":{"type":"equal","value":"AQID","encoding":"base64"}},{"query":{"type":"bytes"},"predicate":{"type":"equal","value":"AQID","encoding":"base64"}},{"query":{"type":"bytes","subquery":{"type":"count"}},"predicate":{"type":"equal","value":3}},{"query":{"type":"bytes"},"predicate":{"type":"start-with","value":"AQ==","encoding":"base64"}},{"query":{"type":"bytes"},"predicate":{"type":"contain","value":"Ag==","encoding":"base64"}},{"query":{"type":"sha256"},"predicate":{"type":"equal","value":"A5BYxvLAy0ksUzsKTRTvd8wPeKvMztUofYShogEc+4E=","encoding":"base64"}}]}}]}
|
||||
{"entries":[{"request":{"method":"GET","url":"http://localhost:8000/bytes"},"response":{"version":"HTTP/1.0","status":200,"headers":[{"name":"Content-Type","value":"application/octet-stream"}],"asserts":[{"query":{"type":"bytes"},"predicate":{"type":"equal","value":"AQID","encoding":"base64"}},{"query":{"type":"bytes"},"predicate":{"type":"equal","value":"AQID","encoding":"base64"}},{"query":{"type":"bytes","subquery":{"type":"count"}},"predicate":{"type":"equal","value":3}},{"query":{"type":"bytes"},"predicate":{"type":"start-with","value":"AQ==","encoding":"base64"}},{"query":{"type":"bytes"},"predicate":{"type":"contain","value":"Ag==","encoding":"base64"}},{"query":{"type":"sha256"},"predicate":{"type":"equal","value":"A5BYxvLAy0ksUzsKTRTvd8wPeKvMztUofYShogEc+4E=","encoding":"base64"}},{"query":{"type":"md5"},"predicate":{"type":"equal","value":"Uonfc331cyb83SJZevsfrA==","encoding":"base64"}}]}}]}
|
@ -31,6 +31,7 @@ hex-literal = "0.3.2"
|
||||
hurl_core = { version = "1.1.0", path = "../hurl_core" }
|
||||
libflate = "1.1.0"
|
||||
libxml = "0.3.0"
|
||||
md5 = "0.7.0"
|
||||
percent-encoding = "2.1.0"
|
||||
regex = "1.5.4"
|
||||
serde = "1.0.126"
|
||||
|
@ -232,6 +232,10 @@ pub fn eval_query_value(
|
||||
let bytes = Value::Bytes(result[..].to_vec());
|
||||
Ok(Some(bytes))
|
||||
}
|
||||
QueryValue::Md5 {} => {
|
||||
let bytes = md5::compute(http_response.body).to_vec();
|
||||
Ok(Some(Value::Bytes(bytes)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -324,6 +324,7 @@ pub enum QueryValue {
|
||||
Duration {},
|
||||
Bytes {},
|
||||
Sha256 {},
|
||||
Md5 {},
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
|
@ -385,6 +385,9 @@ impl Htmlable for QueryValue {
|
||||
QueryValue::Sha256 {} => {
|
||||
buffer.push_str("<span class=\"query-type\">sha256</span>");
|
||||
}
|
||||
QueryValue::Md5 {} => {
|
||||
buffer.push_str("<span class=\"query-type\">md5</span>");
|
||||
}
|
||||
}
|
||||
buffer
|
||||
}
|
||||
|
@ -69,6 +69,7 @@ fn query_value(reader: &mut Reader) -> ParseResult<'static, QueryValue> {
|
||||
duration_query,
|
||||
bytes_query,
|
||||
sha256_query,
|
||||
md5_query,
|
||||
],
|
||||
reader,
|
||||
)
|
||||
@ -166,6 +167,11 @@ fn sha256_query(reader: &mut Reader) -> ParseResult<'static, QueryValue> {
|
||||
Ok(QueryValue::Sha256 {})
|
||||
}
|
||||
|
||||
fn md5_query(reader: &mut Reader) -> ParseResult<'static, QueryValue> {
|
||||
try_literal("md5", reader)?;
|
||||
Ok(QueryValue::Md5 {})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
@ -324,6 +324,9 @@ fn query_value_attributes(query_value: &QueryValue) -> Vec<(String, JValue)> {
|
||||
QueryValue::Sha256 {} => {
|
||||
attributes.push(("type".to_string(), JValue::String("sha256".to_string())));
|
||||
}
|
||||
QueryValue::Md5 {} => {
|
||||
attributes.push(("type".to_string(), JValue::String("md5".to_string())));
|
||||
}
|
||||
};
|
||||
attributes
|
||||
}
|
||||
|
@ -487,6 +487,7 @@ impl Tokenizable for QueryValue {
|
||||
QueryValue::Duration {} => tokens.push(Token::QueryType(String::from("duration"))),
|
||||
QueryValue::Bytes {} => tokens.push(Token::QueryType(String::from("bytes"))),
|
||||
QueryValue::Sha256 {} => tokens.push(Token::QueryType(String::from("sha256"))),
|
||||
QueryValue::Md5 {} => tokens.push(Token::QueryType(String::from("md5"))),
|
||||
}
|
||||
tokens
|
||||
}
|
||||
|
@ -300,6 +300,7 @@ impl Lintable<QueryValue> for QueryValue {
|
||||
QueryValue::Duration {} => QueryValue::Duration {},
|
||||
QueryValue::Bytes {} => QueryValue::Bytes {},
|
||||
QueryValue::Sha256 {} => QueryValue::Sha256 {},
|
||||
QueryValue::Md5 {} => QueryValue::Md5 {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user