Skip to content

side effects of failed modification#1452

Open
omursahin wants to merge 15 commits intomasterfrom
oracle-failed-modification
Open

side effects of failed modification#1452
omursahin wants to merge 15 commits intomasterfrom
oracle-failed-modification

Conversation

@omursahin
Copy link
Copy Markdown
Collaborator

No description provided.

@omursahin omursahin requested a review from arcuri82 February 19, 2026 11:54
}

// otherwise compare entire bodies
return bodyBefore != bodyAfter
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we should return a false here, as otherwise too prone to false positives due to non-deterministic fields

/**
* Compare only the fields that were sent in the PUT/PATCH request.
* Returns true if any of those fields changed between before and after GET responses.
*/
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add comment stating this only works where the payload is a JSON object matching the resource structure. it will not work for cases like JSON Patch RFC6902

internal fun hasChangedModifiedFields(
bodyBefore: String,
bodyAfter: String,
fieldNames: Set<String>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to avoid flakiness, i think we should pass as well the bodyModify, and do check on that


if(!jsonBefore.isJsonObject || !jsonAfter.isJsonObject){
// not JSON objects, fallback to full comparison
return bodyBefore != bodyAfter
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return false. see previous explanations

val valueAfter = objAfter.get(field)

if(valueBefore != valueAfter){
return true
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

besides being different from valueBefore, we should make sure that valueAfter is equal to valueModify

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmmm, maybe this is too broad. should narrow down. the modification might be just partial. eg, the PUT/PATCH might change 2 fields, and only 1 is applied before failure. or it is a JSON Merge Patch, and only a subset of fields is present. so, valueModify == valueAfter is incorrect. we should check, field by filed, if what is different between valueBefore and valueAfter is equal in valueModify. For example, for each field x, if valueBefore.x != valueAfter.x then we need to make sure valueAfter.x = valueModify.x

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, add comment that this would be done to deal with possible flakiness issues

return false
} catch (e: Exception) {
// JSON parsing failed, fallback to full comparison
return bodyBefore != bodyAfter
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return false


/**
* Checking bugs like:
* POST|PUT /X 2xx (create resource)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this first call is not strictly necessary. resources could be already existing or created with database insertions

*
* If a PUT/PATCH fails with 4xx, it should have no side-effects.
* A GET before and after should return the same resource state.
*/
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add to comment that we need to take into account the non-determinism of the fields, eg like timestamps and UUIDs

return@forEach
}

// among those, find one that also has a successful creation step
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks. after reading this code i realized there are quite a few edge cases we need to handle. code here needs to be changed. i update the algorithm description in notes.txt

@omursahin omursahin requested a review from arcuri82 March 9, 2026 19:30
private fun extractRequestBody(modify: RestCallAction): String? {
val bodyParam = modify.parameters.find { it is BodyParam } as BodyParam?
?: return null
return bodyParam.getValueAsPrintableString(mode = GeneUtils.EscapeMode.JSON)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why JSON? is the code here making the assumption that only JSON is involved? in EvoMaster we technically support other formats as well, like url-encoded and XML. unless there are some issues in checking them, we should support them as well. if not, need to clarify here and put checks on JSON. in BodyParam, recall the presence of contentTypeGene

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, we support XML and URL-encoded, too.

if(!StatusGroup.G_4xx.isInGroup(resModify.getStatusCode())) {
return false
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we are only dealing with JSON, add a check here, and leave a TODO comment for other formats

): Boolean {

try {
val jsonBefore = JsonParser.parseString(bodyBefore)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shall not use GSON any more in EvoMaster, it has way too many problems. should rather use Jackson, eg see use and comments in JSON_FORMATTER

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used OutputFormatter for this. And also added XML support and a new function named readFields. I can read a property with that function.

}

if(!config.isEnabledFaultCategory(ExperimentalFaultCategory.HTTP_SIDE_EFFECTS_FAILED_MODIFICATION)) {
LoggingUtil.uniqueUserInfo("Skipping experimental security test for repeated PUT after CREATE, as it has been disabled via configuration")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these loggins really necessary? wouldn't this always be printed until this oracle is promoted from experimental?

val valueAfter = objAfter.get(field)

if(valueBefore != valueAfter){
return true
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmmm, maybe this is too broad. should narrow down. the modification might be just partial. eg, the PUT/PATCH might change 2 fields, and only 1 is applied before failure. or it is a JSON Merge Patch, and only a subset of fields is present. so, valueModify == valueAfter is incorrect. we should check, field by filed, if what is different between valueBefore and valueAfter is equal in valueModify. For example, for each field x, if valueBefore.x != valueAfter.x then we need to make sure valueAfter.x = valueModify.x

val getDef = actionDefinitions.find { it.verb == HttpVerb.GET && it.path.isEquivalent(path) }
?: return

// T: smallest clean individual ending with GET 2xx (no prior PUT/PATCH on same path)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any specific reason to enforce no prior? for example, what if:

  • PUT /data/42 -> 201 (created)
  • GET /data/42 -> 200
  • PATCH /data/42 -> 4xx (failed with partial modifications)

would we still be able to handle to find those cases?

val valueAfter = objAfter.get(field)

if(valueBefore != valueAfter){
return true
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, add comment that this would be done to deal with possible flakiness issues

* PUT|PATCH /path [k]
* GET /path (same auth)
*/
private fun addGetAroundFailedModification(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't understand this function... what is it for? was it for: otherwise: normal case (eg 400 and 409). find a 4xx PUT/PATCH action, copy it, and add it after the GET with same auth? if so, it is not doing this

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right. I updated the algorithm and split it into two pieces: 404 cases and others.


runTestHandlingFlakyAndCompilation(
"FailedModificationEM",
2000
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you really need so many iterations for this kind of E2E test?


runTestHandlingFlakyAndCompilation(
"FailedModificationForbiddenEM",
3000
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see previous comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated all of them with the minimum number of iterations they required.

@omursahin omursahin requested a review from arcuri82 March 30, 2026 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants