From a03fc5f0f515c337a01c937bc640253c089f48c1 Mon Sep 17 00:00:00 2001 From: Ronald Holshausen Date: Fri, 4 Aug 2023 15:41:38 +1000 Subject: [PATCH] fix: V3 message binary content was not being base64 decoded correctly when loaded from a Pact file --- rust/Cargo.lock | 54 ++++++++++++++++----------------- rust/pact_models/src/message.rs | 15 ++++++--- 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 7e7b5d055..42e317870 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -197,9 +197,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "axum" -version = "0.6.19" +version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a1de45611fdb535bfde7b7de4fd54f4fd2b17b1737c0a59b69bf9b92074b8c" +checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf" dependencies = [ "async-trait", "axum-core", @@ -350,9 +350,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.80" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51f1226cd9da55587234753d1245dd5b132343ea240f26b6a9003d68706141ba" +checksum = "6c6b2562119bf28c3439f7f02db99faf0aa1a8cdfe5772a2ee155d32227239f0" dependencies = [ "jobserver", "libc", @@ -613,9 +613,9 @@ dependencies = [ [[package]] name = "deranged" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8810e7e2cf385b1e9b50d68264908ec367ba642c96d02edfe61c39e88e2a3c01" +checksum = "7684a49fb1af197853ef7b2ee694bc1f5b4179556f1e5710e1760c5db6f5e929" dependencies = [ "serde", ] @@ -1210,9 +1210,9 @@ checksum = "c40411d0e5c63ef1323c3d09ce5ec6d84d71531e18daed0743fccea279d7deb6" [[package]] name = "indicatif" -version = "0.17.5" +version = "0.17.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ff8cc23a7393a397ed1d7f56e6365cba772aba9f9912ab968b03043c395d057" +checksum = "0b297dc40733f23a0e52728a58fa9489a5b7638a324932de16b41adc3ef80730" dependencies = [ "console", "instant", @@ -1298,7 +1298,7 @@ dependencies = [ "derive-getters", "quick-xml", "strip-ansi-escapes", - "time 0.3.24", + "time 0.3.25", ] [[package]] @@ -1413,9 +1413,9 @@ dependencies = [ [[package]] name = "matchit" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67827e6ea8ee8a7c4a72227ef4fc08957040acffdb5f122733b24fa12daff41b" +checksum = "ed1202b2a6f884ae56f04cff409ab315c5ce26b5e58d7412e484f01fd52f52ef" [[package]] name = "md5" @@ -2162,7 +2162,7 @@ dependencies = [ "regex", "reqwest", "serde_json", - "time 0.3.24", + "time 0.3.25", "tokio", "tracing", "tracing-core", @@ -2706,9 +2706,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.4" +version = "0.38.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a962918ea88d644592894bc6dc55acc6c0956488adcebbfb6e273506b7fd6e5" +checksum = "1ee020b1716f0a80e2ace9b03441a749e402e86712f15f16fe8a8f75afac732f" dependencies = [ "bitflags 2.3.3", "errno", @@ -2719,9 +2719,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.21.5" +version = "0.21.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79ea77c539259495ce8ca47f53e66ae0330a8819f67e23ac96ca02f50e7b7d36" +checksum = "1d1feddffcfcc0b33f5c6ce9a29e341e4cd59c3f78e7ee45f4a40c038b1d6cbb" dependencies = [ "log", "ring", @@ -2837,18 +2837,18 @@ checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" [[package]] name = "serde" -version = "1.0.180" +version = "1.0.181" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ea67f183f058fe88a4e3ec6e2788e003840893b91bac4559cabedd00863b3ed" +checksum = "6d3e73c93c3240c0bda063c239298e633114c69a888c3e37ca8bb33f343e9890" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.180" +version = "1.0.181" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24e744d7782b686ab3b73267ef05697159cc0e5abbed3f47f9933165e5219036" +checksum = "be02f6cb0cd3a5ec20bbcfbcbd749f57daddb1a0882dc2e46a6c236c90b977ed" dependencies = [ "proc-macro2 1.0.66", "quote 1.0.32", @@ -2900,7 +2900,7 @@ dependencies = [ "serde", "serde_json", "serde_with_macros", - "time 0.3.24", + "time 0.3.25", ] [[package]] @@ -2975,7 +2975,7 @@ checksum = "acee08041c5de3d5048c8b3f6f13fafb3026b24ba43c6a695a0c76179b844369" dependencies = [ "log", "termcolor", - "time 0.3.24", + "time 0.3.25", ] [[package]] @@ -3251,9 +3251,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b79eabcd964882a646b3584543ccabeae7869e9ac32a46f6f22b7a5bd405308b" +checksum = "b0fdd63d58b18d663fbdf70e049f00a22c8e42be082203be7f26589213cd75ea" dependencies = [ "deranged", "itoa", @@ -3510,7 +3510,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09d48f71a791638519505cefafe162606f706c25592e4bde4d97600c0195312e" dependencies = [ "crossbeam-channel", - "time 0.3.24", + "time 0.3.25", "tracing-subscriber", ] @@ -3559,7 +3559,7 @@ dependencies = [ "sharded-slab", "smallvec", "thread_local", - "time 0.3.24", + "time 0.3.25", "tracing", "tracing-core", "tracing-log", @@ -4115,7 +4115,7 @@ dependencies = [ "hmac", "pbkdf2", "sha1", - "time 0.3.24", + "time 0.3.25", "zstd", ] diff --git a/rust/pact_models/src/message.rs b/rust/pact_models/src/message.rs index 3d316b1bd..77daa5692 100644 --- a/rust/pact_models/src/message.rs +++ b/rust/pact_models/src/message.rs @@ -184,7 +184,7 @@ impl Message { /// Constructs a `Message` from the `Json` struct. pub fn from_json(index: usize, json: &Value, spec_version: &PactSpecification) -> anyhow::Result { match spec_version { - &PactSpecification::V3 => { + PactSpecification::V3 => { let id = json.get("_id").map(|id| json_to_string(id)); let description = match json.get("description") { Some(v) => match *v { @@ -200,7 +200,6 @@ impl Message { }).collect(), _ => hashmap!{}, }; - let mut body = body_from_json(json, "contents", &None); let content_type = metadata.iter() .find(|(k, _)| { let key = k.to_ascii_lowercase(); @@ -209,9 +208,17 @@ impl Message { .map(|(_, v)| json_to_string(v)) .map(|s| ContentType::parse(s.as_str()).ok()) .flatten(); - if let Some(ct) = content_type { + + let body = if let Some(ct) = content_type { + let mut body = body_from_json(json, "contents", &Some(hashmap!{ + "content-type".to_string() => vec![ ct.to_string() ] + })); body.set_content_type(&ct); - } + body + } else { + body_from_json(json, "contents", &None) + }; + Ok(Message { id, description,