-
Notifications
You must be signed in to change notification settings - Fork 114
http oracle invalid location #1554
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
6
commits into
master
Choose a base branch
from
http-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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
41c2aa6
invalid location test application
omursahin 607b464
rename
omursahin aa78b27
invalid-location implementation
omursahin 8d78fe9
handle with chain state
omursahin 61aff63
Merge branch 'master' into http-invalid-location
omursahin fb76099
add disabled get example
omursahin 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
55 changes: 55 additions & 0 deletions
55
...mples/spring/openapi/v3/httporacle/invalidlocation/base/HttpInvalidLocationApplication.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,55 @@ | ||
| package com.foo.rest.examples.spring.openapi.v3.httporacle.invalidlocation.base | ||
|
|
||
| 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.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/resources"]) | ||
| @RestController | ||
| open class HttpInvalidLocationApplication { | ||
|
|
||
| companion object { | ||
| @JvmStatic | ||
| fun main(args: Array<String>) { | ||
| SpringApplication.run(HttpInvalidLocationApplication::class.java, *args) | ||
| } | ||
|
|
||
| private val data = mutableMapOf<Int, String>() | ||
|
|
||
| fun reset(){ | ||
| data.clear() | ||
| } | ||
| } | ||
|
|
||
|
|
||
| @GetMapping(path = ["/{id}"]) | ||
| open fun get(@PathVariable("id") id: Int): ResponseEntity<String> { | ||
| val value = data[id] ?: return ResponseEntity.status(404).build() | ||
| return ResponseEntity.status(200).body(value) | ||
| } | ||
|
|
||
|
|
||
| @PutMapping(path = ["/{id}"]) | ||
| open fun put( | ||
| @PathVariable("id") id: Int | ||
| ): ResponseEntity<Any> { | ||
|
|
||
| val isNew = !data.containsKey(id) | ||
| data[id] = "$id" | ||
|
|
||
| // bug: Location header points to a different id than the one | ||
| // actually stored, so a follow-up GET on it will return 404 | ||
|
|
||
| val status = if (isNew) 201 else 200 | ||
| return ResponseEntity.status(status) | ||
| .header("Location", "/api/resources/${id + 1000}") | ||
| .build() | ||
| } | ||
| } | ||
59 changes: 59 additions & 0 deletions
59
.../openapi/v3/httporacle/invalidlocation/fullpath/HttpInvalidLocationFullPathApplication.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,59 @@ | ||
| package com.foo.rest.examples.spring.openapi.v3.httporacle.invalidlocation.fullpath | ||
|
|
||
| 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.PathVariable | ||
| import org.springframework.web.bind.annotation.PutMapping | ||
| import org.springframework.web.bind.annotation.RequestMapping | ||
| import org.springframework.web.bind.annotation.RestController | ||
| import org.springframework.web.servlet.support.ServletUriComponentsBuilder | ||
|
|
||
| @SpringBootApplication(exclude = [SecurityAutoConfiguration::class]) | ||
| @RequestMapping(path = ["/api/resources"]) | ||
| @RestController | ||
| open class HttpInvalidLocationFullPathApplication { | ||
|
|
||
| companion object { | ||
| @JvmStatic | ||
| fun main(args: Array<String>) { | ||
| SpringApplication.run(HttpInvalidLocationFullPathApplication::class.java, *args) | ||
| } | ||
|
|
||
| private val data = mutableMapOf<Int, String>() | ||
|
|
||
| fun reset(){ | ||
| data.clear() | ||
| } | ||
| } | ||
|
|
||
|
|
||
| @GetMapping(path = ["/{id}"]) | ||
| open fun get(@PathVariable("id") id: Int): ResponseEntity<String> { | ||
| val value = data[id] ?: return ResponseEntity.status(404).build() | ||
| return ResponseEntity.status(200).body(value) | ||
| } | ||
|
|
||
|
|
||
| @PutMapping(path = ["/{id}"]) | ||
| open fun put( | ||
| @PathVariable("id") id: Int | ||
| ): ResponseEntity<Any> { | ||
|
|
||
| val isNew = !data.containsKey(id) | ||
| data[id] = "$id" | ||
|
|
||
| val location = ServletUriComponentsBuilder | ||
| .fromCurrentContextPath() | ||
| .path("/api/resources/{id}") | ||
| .buildAndExpand(id + 1000) | ||
| .toUri() | ||
|
|
||
| val status = if (isNew) 201 else 200 | ||
| return ResponseEntity.status(status) | ||
| .header("Location", location.toString()) | ||
| .build() | ||
| } | ||
| } |
39 changes: 39 additions & 0 deletions
39
...ng/openapi/v3/httporacle/invalidlocation/locationget/HttpInvalidLocationGetApplication.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,39 @@ | ||
| package com.foo.rest.examples.spring.openapi.v3.httporacle.invalidlocation.locationget | ||
|
|
||
| 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.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/resources"]) | ||
| @RestController | ||
| open class HttpInvalidLocationGetApplication { | ||
|
|
||
| companion object { | ||
| @JvmStatic | ||
| fun main(args: Array<String>) { | ||
| SpringApplication.run(HttpInvalidLocationGetApplication::class.java, *args) | ||
| } | ||
|
|
||
| fun reset(){ | ||
| } | ||
| } | ||
|
|
||
|
|
||
| @GetMapping(path = ["/{id}"]) | ||
| open fun get(@PathVariable("id") id: Int): ResponseEntity<String> { | ||
| return ResponseEntity.status(200).header("Location", "/api/resources/${id + 1000}/notfound").body("Resource with id $id") | ||
| } | ||
|
|
||
| @GetMapping(path = ["/{id}/notfound"]) | ||
| open fun getNotFound(@PathVariable("id") id: Int): ResponseEntity<String> { | ||
| return ResponseEntity.status(404).body("Not found") | ||
| } | ||
|
|
||
| } |
55 changes: 55 additions & 0 deletions
55
...napi/v3/httporacle/invalidlocation/notvalidpath/HttpInvalidLocationNotValidApplication.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,55 @@ | ||
| package com.foo.rest.examples.spring.openapi.v3.httporacle.invalidlocation.notvalidpath | ||
|
|
||
| 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.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/resources"]) | ||
| @RestController | ||
| open class HttpInvalidLocationNotValidApplication { | ||
|
|
||
| companion object { | ||
| @JvmStatic | ||
| fun main(args: Array<String>) { | ||
| SpringApplication.run(HttpInvalidLocationNotValidApplication::class.java, *args) | ||
| } | ||
|
|
||
| private val data = mutableMapOf<Int, String>() | ||
|
|
||
| fun reset(){ | ||
| data.clear() | ||
| } | ||
| } | ||
|
|
||
|
|
||
| @GetMapping(path = ["/{id}"]) | ||
| open fun get(@PathVariable("id") id: Int): ResponseEntity<String> { | ||
| val value = data[id] ?: return ResponseEntity.status(404).build() | ||
| return ResponseEntity.status(200).body(value) | ||
| } | ||
|
|
||
|
|
||
| @PutMapping(path = ["/{id}"]) | ||
| open fun put( | ||
| @PathVariable("id") id: Int | ||
| ): ResponseEntity<Any> { | ||
|
|
||
| val isNew = !data.containsKey(id) | ||
| data[id] = "$id" | ||
|
|
||
| // bug: Location header points to a different id than the one | ||
| // actually stored, so a follow-up GET on it will return 404 | ||
|
|
||
| val status = if (isNew) 201 else 200 | ||
| return ResponseEntity.status(status) | ||
| .header("Location", "/somePathThatDoesNotExist") | ||
| .build() | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
...st/examples/spring/openapi/v3/httporacle/invalidlocation/HttpInvalidLocationController.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 | ||
|
|
||
| import com.foo.rest.examples.spring.openapi.v3.SpringController | ||
| import com.foo.rest.examples.spring.openapi.v3.httporacle.invalidlocation.base.HttpInvalidLocationApplication | ||
|
|
||
|
|
||
| class HttpInvalidLocationController: SpringController(HttpInvalidLocationApplication::class.java){ | ||
|
|
||
| override fun resetStateOfSUT() { | ||
| HttpInvalidLocationApplication.reset() | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
...les/spring/openapi/v3/httporacle/invalidlocation/HttpInvalidLocationFullPathController.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,13 @@ | ||
| package com.foo.rest.examples.spring.openapi.v3.httporacle.invalidlocation.fullpath | ||
|
|
||
| import com.foo.rest.examples.spring.openapi.v3.SpringController | ||
| import com.foo.rest.examples.spring.openapi.v3.httporacle.invalidlocation.base.HttpInvalidLocationApplication | ||
| import com.foo.rest.examples.spring.openapi.v3.httporacle.invalidlocation.notvalidpath.HttpInvalidLocationNotValidApplication | ||
|
|
||
|
|
||
| class HttpInvalidLocationFullPathController: SpringController(HttpInvalidLocationFullPathApplication::class.java){ | ||
|
|
||
| override fun resetStateOfSUT() { | ||
| HttpInvalidLocationFullPathApplication.reset() | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
...examples/spring/openapi/v3/httporacle/invalidlocation/HttpInvalidLocationGetController.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,13 @@ | ||
| package com.foo.rest.examples.spring.openapi.v3.httporacle.invalidlocation.locationget | ||
|
|
||
| import com.foo.rest.examples.spring.openapi.v3.SpringController | ||
| import com.foo.rest.examples.spring.openapi.v3.httporacle.invalidlocation.base.HttpInvalidLocationApplication | ||
| import com.foo.rest.examples.spring.openapi.v3.httporacle.invalidlocation.locationget.HttpInvalidLocationGetApplication | ||
|
|
||
|
|
||
| class HttpInvalidLocationGetController: SpringController(HttpInvalidLocationGetApplication::class.java){ | ||
|
|
||
| override fun resetStateOfSUT() { | ||
| HttpInvalidLocationGetApplication.reset() | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
...les/spring/openapi/v3/httporacle/invalidlocation/HttpInvalidLocationNotValidController.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,13 @@ | ||
| package com.foo.rest.examples.spring.openapi.v3.httporacle.invalidlocation.notvalidpath | ||
|
|
||
| import com.foo.rest.examples.spring.openapi.v3.SpringController | ||
| import com.foo.rest.examples.spring.openapi.v3.httporacle.invalidlocation.base.HttpInvalidLocationApplication | ||
| import com.foo.rest.examples.spring.openapi.v3.httporacle.invalidlocation.notvalidpath.HttpInvalidLocationNotValidApplication | ||
|
|
||
|
|
||
| class HttpInvalidLocationNotValidController: SpringController(HttpInvalidLocationNotValidApplication::class.java){ | ||
|
|
||
| override fun resetStateOfSUT() { | ||
| HttpInvalidLocationNotValidApplication.reset() | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions
44
...master/e2etests/spring/openapi/v3/httporacle/invalidlocation/HttpInvalidLocationEMTest.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,44 @@ | ||
| package org.evomaster.e2etests.spring.openapi.v3.httporacle.invalidlocation | ||
|
|
||
| import com.foo.rest.examples.spring.openapi.v3.httporacle.invalidlocation.HttpInvalidLocationController | ||
| 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.assertEquals | ||
| import org.junit.jupiter.api.Assertions.assertTrue | ||
| import org.junit.jupiter.api.BeforeAll | ||
| import org.junit.jupiter.api.Test | ||
|
|
||
| class HttpInvalidLocationEMTest : SpringTestBase(){ | ||
|
|
||
| companion object { | ||
| @BeforeAll | ||
| @JvmStatic | ||
| fun init() { | ||
| initClass(HttpInvalidLocationController()) | ||
| } | ||
| } | ||
|
|
||
|
|
||
| @Test | ||
| fun testRunEM() { | ||
|
|
||
| runTestHandlingFlakyAndCompilation( | ||
| "HttpInvalidLocationEM", | ||
| 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) | ||
|
|
||
| val faults = DetectedFaultUtils.getDetectedFaultCategories(solution) | ||
| assertTrue({ ExperimentalFaultCategory.HTTP_INVALID_LOCATION in faults }) | ||
| } | ||
| } | ||
| } |
43 changes: 43 additions & 0 deletions
43
...2etests/spring/openapi/v3/httporacle/invalidlocation/HttpInvalidLocationFullPathEMTest.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,43 @@ | ||
| package org.evomaster.e2etests.spring.openapi.v3.httporacle.invalidlocation | ||
|
|
||
| import com.foo.rest.examples.spring.openapi.v3.httporacle.invalidlocation.fullpath.HttpInvalidLocationFullPathController | ||
| 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 HttpInvalidLocationFullPathEMTest : SpringTestBase(){ | ||
|
|
||
| companion object { | ||
| @BeforeAll | ||
| @JvmStatic | ||
| fun init() { | ||
| initClass(HttpInvalidLocationFullPathController()) | ||
| } | ||
| } | ||
|
|
||
|
|
||
| @Test | ||
| fun testRunEM() { | ||
|
|
||
| runTestHandlingFlakyAndCompilation( | ||
| "HttpInvalidLocationFullPathEM", | ||
| 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) | ||
|
|
||
| val faults = DetectedFaultUtils.getDetectedFaultCategories(solution) | ||
| assertTrue({ ExperimentalFaultCategory.HTTP_INVALID_LOCATION in faults }) | ||
| } | ||
| } | ||
| } |
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.
also add test case for when the relative path is invalid, eg,
/somePathThatDoesNotExist, and also full URL, eg,http://localhost:$port/api/resources/${id+1000}