diff --git a/core/src/main/kotlin/io/specmatic/core/HttpHeadersPattern.kt b/core/src/main/kotlin/io/specmatic/core/HttpHeadersPattern.kt index 87f6c4148..224289230 100644 --- a/core/src/main/kotlin/io/specmatic/core/HttpHeadersPattern.kt +++ b/core/src/main/kotlin/io/specmatic/core/HttpHeadersPattern.kt @@ -227,7 +227,7 @@ data class HttpHeadersPattern( .filter { exampleHeaderName -> !specPattern.containsKey(exampleHeaderName) && !specPattern.containsKey("${exampleHeaderName}?") } .filter { exampleHeaderName -> exampleHeaderName.lowercase() !in getHeadersToExcludeNotInExamples(row.requestExample) } .filter { exampleHeaderName -> exampleHeaderName !in row.requestExample.metadata.securityHeaderNames } - .associateWith { StringPattern() } + .associateWith { exampleHeaderName -> ExactValuePattern(StringValue(row.requestExample.headers.getValue(exampleHeaderName))) } } else { emptyMap() } diff --git a/core/src/test/kotlin/integration_tests/ExtensibleHeadersTest.kt b/core/src/test/kotlin/integration_tests/ExtensibleHeadersTest.kt index c93be630e..b3c4d2b69 100644 --- a/core/src/test/kotlin/integration_tests/ExtensibleHeadersTest.kt +++ b/core/src/test/kotlin/integration_tests/ExtensibleHeadersTest.kt @@ -346,6 +346,7 @@ components: val results = feature.executeTests(object : TestExecutor { override fun execute(request: HttpRequest): HttpResponse { + assertThat(request.headers).containsEntry("Authenticate", "abc123") return HttpResponse.ok(parsedJSONObject("""{"greeting": "Hi!"}""")).also { println(request.toLogString()) println(it.toLogString()) @@ -366,6 +367,7 @@ components: val results = feature.executeTests(object : TestExecutor { override fun execute(request: HttpRequest): HttpResponse { + assertThat(request.headers).containsEntry("Authenticate", "abc123") return HttpResponse.ok(parsedJSONObject("""{"greeting": "Hi!"}""")).also { println(request.toLogString()) println(it.toLogString()) @@ -386,6 +388,7 @@ components: val results = feature.executeTests(object : TestExecutor { override fun execute(request: HttpRequest): HttpResponse { + assertThat(request.headers).containsEntry("Authenticate", "abc123") return HttpResponse.ok(parsedJSONObject("""{"greeting": "Hi!"}""")).also { println(request.toLogString()) println(it.toLogString()) diff --git a/core/src/test/kotlin/io/specmatic/conversions/ExampleFromFileTest.kt b/core/src/test/kotlin/io/specmatic/conversions/ExampleFromFileTest.kt index ae3e83b59..3800dc9cd 100644 --- a/core/src/test/kotlin/io/specmatic/conversions/ExampleFromFileTest.kt +++ b/core/src/test/kotlin/io/specmatic/conversions/ExampleFromFileTest.kt @@ -1,6 +1,8 @@ package io.specmatic.conversions +import io.specmatic.core.HttpHeadersPattern import io.specmatic.core.NoBodyValue +import io.specmatic.core.Resolver import io.specmatic.core.SpecmaticConfig import io.specmatic.core.pattern.parsedJSONObject import org.assertj.core.api.Assertions.assertThat @@ -135,5 +137,8 @@ class ExampleFromFileTest { example.toRow(SpecmaticConfig(additionalExampleParamsFilePath = "src/test/resources/additionalParamsFile.json")) assertThat(row.requestExample?.headers.orEmpty()).containsEntry("X-Tra", "info") + + val generatedHeaders = HttpHeadersPattern().newBasedOn(row, Resolver()).first().value.generate(Resolver()) + assertThat(generatedHeaders).containsEntry("X-Tra", "info") } } \ No newline at end of file