Skip to content

Commit

Permalink
fix: Correct the use of matching rules on repeated header values
Browse files Browse the repository at this point in the history
  • Loading branch information
rholshausen committed Jun 28, 2023
1 parent 6a7e504 commit 95753e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 7 additions & 5 deletions rust/pact_matching/src/headers.rs
Expand Up @@ -3,8 +3,8 @@
use std::collections::HashMap;
use std::iter::FromIterator;

use maplit::*;

use itertools::Itertools;
use maplit::hashmap;
use pact_models::headers::PARAMETERISED_HEADERS;
use pact_models::matchingrules::MatchingRule;
use pact_models::path_exp::DocPath;
Expand Down Expand Up @@ -69,7 +69,7 @@ pub(crate) fn match_header_value(
context: &dyn MatchingContext,
single_value: bool
) -> Result<(), Vec<Mismatch>> {
let path = DocPath::root().join(key);
let path = DocPath::root().join(key.to_lowercase());
let indexed_path = path.join(index.to_string());
let expected = expected.trim();
let actual = actual.trim();
Expand Down Expand Up @@ -142,7 +142,10 @@ fn match_header_maps(
actual_values.first().unwrap(), context, true).err().unwrap_or_default();
mismatches.extend(comparison_result.iter().cloned());
} else {
for (index, val) in value.iter().enumerate() {
let empty = String::new();
for (index, val) in value.iter()
.pad_using(actual.len(), |_| &empty)
.enumerate() {
if let Some(actual_value) = actual_values.get(index) {
let comparison_result = match_header_value(key, index, val,
actual_value, context, false).err().unwrap_or_default();
Expand Down Expand Up @@ -195,7 +198,6 @@ pub fn match_headers(
mod tests {
use expectest::prelude::*;
use maplit::*;

use pact_models::matchingrules;
use pact_models::matchingrules::MatchingRule;

Expand Down
4 changes: 3 additions & 1 deletion rust/pact_verifier/src/provider_client.rs
Expand Up @@ -117,7 +117,9 @@ fn create_native_request(
}
}
}
builder = builder.headers(header_map);
if !header_map.is_empty() {
builder = builder.headers(header_map);
}
}

match request.body {
Expand Down

0 comments on commit 95753e2

Please sign in to comment.