diff --git a/authenticated-compound-auth.yaml b/authenticated-compound-auth.yaml new file mode 100644 index 000000000..2954e25ce --- /dev/null +++ b/authenticated-compound-auth.yaml @@ -0,0 +1,42 @@ +openapi: 3.0.0 +info: + title: Sample API + description: Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML. + version: 0.1.9 +servers: + - url: http://api.example.com/v1 + description: Optional server description, e.g. Main (production) server + - url: http://staging-api.example.com + description: Optional server description, e.g. Internal staging server for testing +paths: + /hello/{id}: + get: + summary: hello world + description: Optional extended description in CommonMark or HTML. + parameters: + - in: path + name: id + schema: + type: integer + required: true + description: Numeric ID + responses: + '200': + description: Says hello + content: + text/plain: + schema: + type: string +components: + securitySchemes: + ApiKeyAuthHeader: + type: apiKey + in: header + name: X-API-KEY + ApiKeyAuthHeader2: + type: apiKey + in: header + name: X-API-KEY-2 +security: + - ApiKeyAuthHeader: [] + ApiKeyAuthHeader2: [] diff --git a/core/src/test/kotlin/in/specmatic/conversions/OpenApiIntegrationTest.kt b/core/src/test/kotlin/in/specmatic/conversions/OpenApiIntegrationTest.kt index 2956396db..159543f75 100644 --- a/core/src/test/kotlin/in/specmatic/conversions/OpenApiIntegrationTest.kt +++ b/core/src/test/kotlin/in/specmatic/conversions/OpenApiIntegrationTest.kt @@ -674,6 +674,42 @@ Feature: Authenticated assertThat(result).isInstanceOf(Result.Success::class.java) } + @Test + fun `should generate one test with multiple api keys for security scheme value from row`() { + val contract: Feature = parseGherkinStringToFeature( + """ +Feature: Authenticated + + Background: + Given openapi openapi/authenticated-compound-auth.yaml + + Scenario: Compound header auth test + When GET /hello/(id:number) + Then status 200 + + Examples: + | id | + | 10 | + """.trimIndent(), sourceSpecPath + ) + + val contractTests = contract.generateContractTestScenarios(emptyList()) + val result = executeTest(contractTests.single(), object : TestExecutor { //should generate one test instead of 2 + override fun execute(request: HttpRequest): HttpResponse { + assertThat(request.headers).containsKey("X-API-KEY") + assertThat(request.headers).containsKey("X-API-KEY-2") + return HttpResponse.ok("success") + } + + override fun setServerState(serverState: Map) { + + } + + }) + + assertThat(result).isInstanceOf(Result.Success::class.java) + } + @Test fun `should generate test with api key in header security scheme with token in header from security configuration`() { val token = "APIHEADERKEY1234"