From 214a36f9a82f916e044570863e35ad30f47da2a5 Mon Sep 17 00:00:00 2001 From: Ludovic Heitz Date: Thu, 27 Jul 2023 11:00:23 +0200 Subject: [PATCH] test: Check request body has no "multipart/mixed" part --- .../test/java/com/intuit/karate/TestUtils.java | 5 +++++ .../karate/core/KarateMockHandlerTest.java | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/karate-core/src/test/java/com/intuit/karate/TestUtils.java b/karate-core/src/test/java/com/intuit/karate/TestUtils.java index 04ef04ff9..381444c4a 100644 --- a/karate-core/src/test/java/com/intuit/karate/TestUtils.java +++ b/karate-core/src/test/java/com/intuit/karate/TestUtils.java @@ -31,6 +31,11 @@ public static void matchContains(Object actual, Object expected) { Match.Result mr = Match.evaluate(actual).contains(expected); assertTrue(mr.pass, mr.message); } + + public static void notContains(Object actual, Object expected) { + Match.Result mr = Match.evaluate(actual).isNotContaining(expected); + assertTrue(mr.pass, mr.message); + } public static ScenarioEngine engine() { return new ScenarioEngine(new Config(), runtime(), new HashMap(), new Logger()); diff --git a/karate-core/src/test/java/com/intuit/karate/core/KarateMockHandlerTest.java b/karate-core/src/test/java/com/intuit/karate/core/KarateMockHandlerTest.java index e93f18e9a..2a2b4f6b0 100644 --- a/karate-core/src/test/java/com/intuit/karate/core/KarateMockHandlerTest.java +++ b/karate-core/src/test/java/com/intuit/karate/core/KarateMockHandlerTest.java @@ -390,6 +390,23 @@ void testMultiPartFile() { matchVar("response", "{ foo: [{ name: 'foo', value: '#notnull', contentType: 'text/plain', charset: 'UTF-8', filename: 'foo.txt', transferEncoding: '7bit' }] }"); } + @Test + void testMultiPartFiles() { + background().scenario( + "pathMatches('/hello')", + "def response = requestParts"); + run( + URL_STEP, + "def file1 = { name: 'file', filename: 'file1.txt', value: 'Hello 1' }", + "def file2 = { name: 'file', filename: 'file2.txt', value: 'Hello 2' }", + "multipart files ([file1, file2])", + "path 'hello'", + "method post" + ); + runtime.engine.assign(AssignType.STRING, "prevReqBody", "karate.prevRequest.body", false); + notContains(get("prevReqBody"), "multipart/mixed"); + } + @Test void testMultiPartFileNullCharset() { background().scenario(