diff --git a/rust/pact_verifier/tests/no-content-type.json b/rust/pact_verifier/tests/no-content-type.json new file mode 100644 index 000000000..f5d6a2df8 --- /dev/null +++ b/rust/pact_verifier/tests/no-content-type.json @@ -0,0 +1,22 @@ +{ + "consumer": { "name": "thing" }, + "provider": { "name": "other-thing" }, + "interactions": [{ + "description": "a request to the other thing", + "request": { + "method": "post", + "path": "/endpoint", + "body": { + "this": "field" + } + }, + "response": { + "status": 200 + } + }], + "metadata": { + "pactSpecification": { + "version": "2.0.0" + } + } +} diff --git a/rust/pact_verifier/tests/tests.rs b/rust/pact_verifier/tests/tests.rs index 4af7094e8..8265e2d86 100644 --- a/rust/pact_verifier/tests/tests.rs +++ b/rust/pact_verifier/tests/tests.rs @@ -948,3 +948,49 @@ async fn broker_validation_errors_should_be_shown_to_the_user() { let message_str = message.to_string(); expect!(message_str.contains("consumerVersionSelectors: cannot specify the fields branch/latest with the field deployedOrReleased (at index 0)")).to(be_true()); } + +#[test_log::test(tokio::test)] +async fn verify_pact_with_body_but_no_content_type() { + let server = PactBuilder::new_v4("no content-type", "no content-type") + .interaction("request with no content-type", "", |mut i| { + i.test_name("verify_pact_with_body_but_no_content_type"); + i.request.method("POST"); + i.request.path("/endpoint"); + i.request.body(r#"{ "this": "field" }"#); + + i.response.ok(); + i + }) + .start_mock_server(None); + + #[allow(deprecated)] + let provider = ProviderInfo { + name: "no content-type".to_string(), + host: "127.0.0.1".to_string(), + port: server.url().port(), + transports: vec![ ProviderTransport { + transport: "HTTP".to_string(), + port: server.url().port(), + path: None, + scheme: Some("http".to_string()) + } ], + .. ProviderInfo::default() + }; + + let pact_file = fixture_path("no-content-type.json"); + let pact = read_pact(pact_file.as_path()).unwrap(); + let options: VerificationOptions = VerificationOptions::default(); + let provider_states = Arc::new(DummyProviderStateExecutor{}); + + let result = verify_pact_internal( + &provider, + &FilterInfo::None, + pact, + &options, + &provider_states, + false, + Duration::default() + ).await; + + expect!(result.unwrap().results.get(0).unwrap().result.as_ref()).to(be_ok()); +}