-
Notifications
You must be signed in to change notification settings - Fork 116
fix invalid location #1666
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
Open
omursahin
wants to merge
2
commits into
master
Choose a base branch
from
fix-invalid-location
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fix invalid location #1666
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
...napi/v3/httporacle/invalidlocation/deleteonly/HttpInvalidLocationDeleteOnlyApplication.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package com.foo.rest.examples.spring.openapi.v3.httporacle.invalidlocation.deleteonly | ||
|
|
||
| import org.springframework.boot.SpringApplication | ||
| import org.springframework.boot.autoconfigure.SpringBootApplication | ||
| import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration | ||
| import org.springframework.http.ResponseEntity | ||
| import org.springframework.web.bind.annotation.DeleteMapping | ||
| import org.springframework.web.bind.annotation.PathVariable | ||
| import org.springframework.web.bind.annotation.PutMapping | ||
| import org.springframework.web.bind.annotation.RequestMapping | ||
| import org.springframework.web.bind.annotation.RestController | ||
|
|
||
| @SpringBootApplication(exclude = [SecurityAutoConfiguration::class]) | ||
| @RequestMapping(path = ["/api/products"]) | ||
| @RestController | ||
| open class HttpInvalidLocationDeleteOnlyApplication { | ||
|
|
||
| companion object { | ||
| @JvmStatic | ||
| fun main(args: Array<String>) { | ||
| SpringApplication.run(HttpInvalidLocationDeleteOnlyApplication::class.java, *args) | ||
| } | ||
|
|
||
| fun reset() {} | ||
| } | ||
|
|
||
| // Creator: returns a Location pointing to a constraint resource whose path is | ||
| // declared only for DELETE (no GET). Mirrors the features-service chain. The | ||
| // referenced constraint is never actually stored. | ||
| @PutMapping(path = ["/{productName}/constraints"]) | ||
| open fun createConstraint(@PathVariable("productName") productName: String): ResponseEntity<Any> { | ||
| return ResponseEntity.status(201) | ||
| .header("Location", "/api/products/$productName/constraints/123") | ||
| .build() | ||
| } | ||
|
|
||
| // The Location target is declared only for DELETE. A GET would be 405, so the oracle | ||
| // must probe with DELETE; that DELETE returns 404 because the constraint does not exist. | ||
| @DeleteMapping(path = ["/{productName}/constraints/{constraintId}"]) | ||
| open fun deleteConstraint( | ||
| @PathVariable("productName") productName: String, | ||
| @PathVariable("constraintId") constraintId: String | ||
| ): ResponseEntity<Any> { | ||
| return ResponseEntity.status(404).build() | ||
| } | ||
| } |
68 changes: 68 additions & 0 deletions
68
...3/httporacle/invalidlocation/verbselection/HttpInvalidLocationVerbSelectionApplication.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package com.foo.rest.examples.spring.openapi.v3.httporacle.invalidlocation.verbselection | ||
|
|
||
| import org.springframework.boot.SpringApplication | ||
| import org.springframework.boot.autoconfigure.SpringBootApplication | ||
| import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration | ||
| import org.springframework.http.ResponseEntity | ||
| import org.springframework.web.bind.annotation.GetMapping | ||
| import org.springframework.web.bind.annotation.PatchMapping | ||
| import org.springframework.web.bind.annotation.PathVariable | ||
| import org.springframework.web.bind.annotation.PutMapping | ||
| import org.springframework.web.bind.annotation.RestController | ||
|
|
||
| /** | ||
| * Single SUT exercising the extended HTTP_INVALID_LOCATION behaviour: | ||
| * - status codes beyond 404 (405, 500, 501) | ||
| * - follow-up verb chosen from the schema, not hardcoded GET | ||
| * | ||
| * Each family has a creator that returns a Location pointing to a target whose | ||
| * declared verbs / returned status differ, so the oracle exercises a distinct branch. | ||
| */ | ||
| @SpringBootApplication(exclude = [SecurityAutoConfiguration::class]) | ||
| @RestController | ||
| open class HttpInvalidLocationVerbSelectionApplication { | ||
|
|
||
| companion object { | ||
| @JvmStatic | ||
| fun main(args: Array<String>) { | ||
| SpringApplication.run(HttpInvalidLocationVerbSelectionApplication::class.java, *args) | ||
| } | ||
|
|
||
| fun reset() {} | ||
| } | ||
|
|
||
| // Family A: Location target is a declared GET that returns 500. | ||
| // Follow-up verb selected: GET. Proves 500 is treated as an invalid Location. | ||
| @PutMapping(path = ["/api/a/{id}"]) | ||
| open fun createA(@PathVariable("id") id: String): ResponseEntity<Any> = | ||
| ResponseEntity.status(201).header("Location", "/api/a/$id/child").build() | ||
|
|
||
| @GetMapping(path = ["/api/a/{id}/child"]) | ||
| open fun childA(@PathVariable("id") id: String): ResponseEntity<Any> = | ||
| ResponseEntity.status(500).build() | ||
|
|
||
| // Family B: Location target is a declared GET that returns 501. | ||
| // Proves 501 is treated as an invalid Location. | ||
| @PutMapping(path = ["/api/b/{id}"]) | ||
| open fun createB(@PathVariable("id") id: String): ResponseEntity<Any> = | ||
| ResponseEntity.status(201).header("Location", "/api/b/$id/child").build() | ||
|
|
||
| @GetMapping(path = ["/api/b/{id}/child"]) | ||
| open fun childB(@PathVariable("id") id: String): ResponseEntity<Any> = | ||
| ResponseEntity.status(501).build() | ||
|
|
||
| // Family C: Location target is declared with PUT and PATCH only (no GET, no DELETE). | ||
| // Priority order GET,DELETE,POST,PUT,PATCH -> PUT is selected. The PUT returns 405, | ||
| // proving both the verb-priority selection and that 405 is treated as invalid. | ||
| @PutMapping(path = ["/api/c/{id}"]) | ||
| open fun createC(@PathVariable("id") id: String): ResponseEntity<Any> = | ||
| ResponseEntity.status(201).header("Location", "/api/c/$id/child").build() | ||
|
|
||
| @PutMapping(path = ["/api/c/{id}/child"]) | ||
| open fun putChildC(@PathVariable("id") id: String): ResponseEntity<Any> = | ||
| ResponseEntity.status(405).build() | ||
|
|
||
| @PatchMapping(path = ["/api/c/{id}/child"]) | ||
| open fun patchChildC(@PathVariable("id") id: String): ResponseEntity<Any> = | ||
| ResponseEntity.status(405).build() | ||
| } |
12 changes: 12 additions & 0 deletions
12
...s/spring/openapi/v3/httporacle/invalidlocation/HttpInvalidLocationDeleteOnlyController.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.foo.rest.examples.spring.openapi.v3.httporacle.invalidlocation.deleteonly | ||
|
|
||
| import com.foo.rest.examples.spring.openapi.v3.SpringController | ||
| import com.foo.rest.examples.spring.openapi.v3.httporacle.invalidlocation.deleteonly.HttpInvalidLocationDeleteOnlyApplication | ||
|
|
||
|
|
||
| class HttpInvalidLocationDeleteOnlyController: SpringController(HttpInvalidLocationDeleteOnlyApplication::class.java){ | ||
|
|
||
| override fun resetStateOfSUT() { | ||
| HttpInvalidLocationDeleteOnlyApplication.reset() | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
...pring/openapi/v3/httporacle/invalidlocation/HttpInvalidLocationVerbSelectionController.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.foo.rest.examples.spring.openapi.v3.httporacle.invalidlocation.verbselection | ||
|
|
||
| import com.foo.rest.examples.spring.openapi.v3.SpringController | ||
| import com.foo.rest.examples.spring.openapi.v3.httporacle.invalidlocation.verbselection.HttpInvalidLocationVerbSelectionApplication | ||
|
|
||
|
|
||
| class HttpInvalidLocationVerbSelectionController: SpringController(HttpInvalidLocationVerbSelectionApplication::class.java){ | ||
|
|
||
| override fun resetStateOfSUT() { | ||
| HttpInvalidLocationVerbSelectionApplication.reset() | ||
| } | ||
| } |
49 changes: 49 additions & 0 deletions
49
...tests/spring/openapi/v3/httporacle/invalidlocation/HttpInvalidLocationDeleteOnlyEMTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package org.evomaster.e2etests.spring.openapi.v3.httporacle.invalidlocation | ||
|
|
||
| import com.foo.rest.examples.spring.openapi.v3.httporacle.invalidlocation.deleteonly.HttpInvalidLocationDeleteOnlyController | ||
| import org.evomaster.core.problem.enterprise.DetectedFaultUtils | ||
| import org.evomaster.core.problem.enterprise.ExperimentalFaultCategory | ||
| import org.evomaster.e2etests.spring.openapi.v3.SpringTestBase | ||
| import org.junit.jupiter.api.Assertions.assertTrue | ||
| import org.junit.jupiter.api.BeforeAll | ||
| import org.junit.jupiter.api.Test | ||
|
|
||
| class HttpInvalidLocationDeleteOnlyEMTest : SpringTestBase() { | ||
|
|
||
| companion object { | ||
| @BeforeAll | ||
| @JvmStatic | ||
| fun init() { | ||
| initClass(HttpInvalidLocationDeleteOnlyController()) | ||
| } | ||
| } | ||
|
|
||
|
|
||
| @Test | ||
| fun testRunEM() { | ||
|
|
||
| runTestHandlingFlakyAndCompilation( | ||
| "HttpInvalidLocationDeleteOnlyEM", | ||
| 20 | ||
| ) { args: MutableList<String> -> | ||
|
|
||
| setOption(args, "security", "false") | ||
| setOption(args, "schemaOracles", "false") | ||
| setOption(args, "httpOracles", "true") | ||
| setOption(args, "useExperimentalOracles", "true") | ||
|
|
||
| val solution = initAndRun(args) | ||
|
|
||
| assertTrue(solution.individuals.size >= 1) | ||
|
|
||
| // The Location points to a resource declared only for DELETE (no GET), so a GET | ||
| // would be 405. The oracle must probe with DELETE and flag the 404 it returns. | ||
| val faults = DetectedFaultUtils.getDetectedFaultCategories(solution) | ||
| assertTrue(ExperimentalFaultCategory.HTTP_INVALID_LOCATION in faults) | ||
|
|
||
| val locationFaults = DetectedFaultUtils.getDetectedFaults(solution) | ||
| .filter { it.category == ExperimentalFaultCategory.HTTP_INVALID_LOCATION } | ||
| assertTrue(locationFaults.any { it.operationId.contains("/api/products/") }) | ||
| } | ||
| } | ||
| } |
72 changes: 72 additions & 0 deletions
72
...ts/spring/openapi/v3/httporacle/invalidlocation/HttpInvalidLocationVerbSelectionEMTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| package org.evomaster.e2etests.spring.openapi.v3.httporacle.invalidlocation | ||
|
|
||
| import com.foo.rest.examples.spring.openapi.v3.httporacle.invalidlocation.verbselection.HttpInvalidLocationVerbSelectionController | ||
| import org.evomaster.core.problem.enterprise.DetectedFaultUtils | ||
| import org.evomaster.core.problem.enterprise.ExperimentalFaultCategory | ||
| import org.evomaster.core.problem.rest.data.HttpVerb | ||
| import org.evomaster.e2etests.spring.openapi.v3.SpringTestBase | ||
| import org.junit.jupiter.api.Assertions.assertTrue | ||
| import org.junit.jupiter.api.BeforeAll | ||
| import org.junit.jupiter.api.Test | ||
|
|
||
| class HttpInvalidLocationVerbSelectionEMTest : SpringTestBase() { | ||
|
|
||
| companion object { | ||
| @BeforeAll | ||
| @JvmStatic | ||
| fun init() { | ||
| initClass(HttpInvalidLocationVerbSelectionController()) | ||
| } | ||
| } | ||
|
|
||
|
|
||
| @Test | ||
| fun testRunEM() { | ||
|
|
||
| runTestHandlingFlakyAndCompilation( | ||
| "HttpInvalidLocationVerbSelectionEM", | ||
| 50 | ||
| ) { args: MutableList<String> -> | ||
|
|
||
| setOption(args, "security", "false") | ||
| setOption(args, "schemaOracles", "false") | ||
| setOption(args, "httpOracles", "true") | ||
| setOption(args, "useExperimentalOracles", "true") | ||
|
|
||
| val solution = initAndRun(args) | ||
|
|
||
| assertTrue(solution.individuals.size >= 1) | ||
|
|
||
| val faults = DetectedFaultUtils.getDetectedFaults(solution) | ||
| .filter { it.category == ExperimentalFaultCategory.HTTP_INVALID_LOCATION } | ||
|
|
||
| // Family A: Location -> declared GET returning 500. A fault here can only come from | ||
| // the 500 status, proving 500 is part of the invalid-location status set. | ||
| assertTrue(faults.any { it.operationId.contains("/api/a/") }) | ||
| // Family B: Location -> declared GET returning 501. Proves 501. | ||
| assertTrue(faults.any { it.operationId.contains("/api/b/") }) | ||
| // Family C: Location -> PUT/PATCH-only target returning 405. Proves 405. | ||
| assertTrue(faults.any { it.operationId.contains("/api/c/") }) | ||
|
|
||
| // Verb selection is proven by inspecting the generated follow-up calls (the last | ||
| // action, chained to the previous Location via usePreviousLocationId). | ||
| val followUps = solution.individuals.mapNotNull { ei -> | ||
| val actions = ei.individual.seeMainExecutableActions() | ||
| if (actions.size < 2) return@mapNotNull null | ||
| val creator = actions[actions.size - 2] | ||
| val follow = actions[actions.size - 1] | ||
| if (follow.usePreviousLocationId.isNullOrBlank()) null else Pair(creator, follow) | ||
| } | ||
|
|
||
| // Family C target declares only PUT and PATCH; priority order must pick PUT (not PATCH, | ||
| // and certainly not a default GET). | ||
| assertTrue(followUps.any { (creator, follow) -> | ||
| creator.path.toString().contains("/api/c/") && follow.verb == HttpVerb.PUT | ||
| }) | ||
| // Family A target declares GET, so GET must be selected. | ||
| assertTrue(followUps.any { (creator, follow) -> | ||
| creator.path.toString().contains("/api/a/") && follow.verb == HttpVerb.GET | ||
| }) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will not work as soon as we introduce the new verb
QUERY.add a
TODOstating to update whenQUERYis going to be added