Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test showing the incorrect behaviour when two or more headers required #931

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions authenticated-compound-auth.yaml
Original file line number Diff line number Diff line change
@@ -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: []
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Value>) {

}

})

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"
Expand Down
Loading